Debian Codegraph @

include/cuda/cuda.h

raw
1 /* CUDA Driver API description.
2 Copyright (C) 2017-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>.
24
25 This header provides parts of the CUDA Driver API, without having to rely on
26 the proprietary CUDA toolkit. */
27
28 #ifndef GCC_CUDA_H
29 #define GCC_CUDA_H
30
31 #include <stdlib.h>
32
33 #define CUDA_VERSION 8000
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 typedef void *CUcontext;
40 typedef int CUdevice;
41 #if defined(__LP64__) || defined(_WIN64)
42 typedef unsigned long long CUdeviceptr;
43 #else
44 typedef unsigned CUdeviceptr;
45 #endif
46 typedef void *CUevent;
47 typedef void *CUfunction;
48 typedef void *CUlinkState;
49 typedef void *CUmodule;
50 typedef void *CUarray;
51 typedef size_t (*CUoccupancyB2DSize)(int);
52 typedef void *CUstream;
53
54 typedef enum {
55 CUDA_SUCCESS = 0,
56 CUDA_ERROR_INVALID_VALUE = 1,
57 CUDA_ERROR_OUT_OF_MEMORY = 2,
58 CUDA_ERROR_NOT_INITIALIZED = 3,
59 CUDA_ERROR_DEINITIALIZED = 4,
60 CUDA_ERROR_NO_DEVICE = 100,
61 CUDA_ERROR_INVALID_CONTEXT = 201,
62 CUDA_ERROR_INVALID_HANDLE = 400,
63 CUDA_ERROR_NOT_FOUND = 500,
64 CUDA_ERROR_NOT_READY = 600,
65 CUDA_ERROR_LAUNCH_FAILED = 719,
66 CUDA_ERROR_COOPERATIVE_LAUNCH_TOO_LARGE = 720,
67 CUDA_ERROR_NOT_PERMITTED = 800,
68 CUDA_ERROR_NOT_SUPPORTED = 801,
69 CUDA_ERROR_UNKNOWN = 999
70 } CUresult;
71
72 typedef enum {
73 CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK = 1,
74 CU_DEVICE_ATTRIBUTE_WARP_SIZE = 10,
75 CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK = 12,
76 CU_DEVICE_ATTRIBUTE_CLOCK_RATE = 13,
77 CU_DEVICE_ATTRIBUTE_GPU_OVERLAP = 15,
78 CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT = 16,
79 CU_DEVICE_ATTRIBUTE_INTEGRATED = 18,
80 CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY = 19,
81 CU_DEVICE_ATTRIBUTE_COMPUTE_MODE = 20,
82 CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS = 31,
83 CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39,
84 CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40,
85 CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41,
86 CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82,
87 CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS = 88
88 } CUdevice_attribute;
89
90 enum {
91 CU_EVENT_DEFAULT = 0,
92 CU_EVENT_DISABLE_TIMING = 2
93 };
94
95 typedef enum {
96 CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK = 0,
97 CU_FUNC_ATTRIBUTE_NUM_REGS = 4
98 } CUfunction_attribute;
99
100 typedef enum {
101 CU_JIT_WALL_TIME = 2,
102 CU_JIT_INFO_LOG_BUFFER = 3,
103 CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES = 4,
104 CU_JIT_ERROR_LOG_BUFFER = 5,
105 CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES = 6,
106 CU_JIT_OPTIMIZATION_LEVEL = 7,
107 CU_JIT_GENERATE_DEBUG_INFO = 11,
108 CU_JIT_LOG_VERBOSE = 12,
109 CU_JIT_GENERATE_LINE_INFO = 13,
110 } CUjit_option;
111
112 typedef enum {
113 CU_JIT_INPUT_PTX = 1
114 } CUjitInputType;
115
116 enum {
117 CU_CTX_SCHED_AUTO = 0
118 };
119
120 #define CU_LAUNCH_PARAM_END ((void *) 0)
121 #define CU_LAUNCH_PARAM_BUFFER_POINTER ((void *) 1)
122 #define CU_LAUNCH_PARAM_BUFFER_SIZE ((void *) 2)
123 #define CU_MEMHOSTALLOC_DEVICEMAP 0x02U
124
125 enum {
126 CU_STREAM_DEFAULT = 0,
127 CU_STREAM_NON_BLOCKING = 1
128 };
129
130 typedef enum {
131 CU_LIMIT_STACK_SIZE = 0x00,
132 CU_LIMIT_MALLOC_HEAP_SIZE = 0x02,
133 } CUlimit;
134
135 typedef enum {
136 CU_MEMORYTYPE_HOST = 0x01,
137 CU_MEMORYTYPE_DEVICE = 0x02,
138 CU_MEMORYTYPE_ARRAY = 0x03,
139 CU_MEMORYTYPE_UNIFIED = 0x04
140 } CUmemorytype;
141
142 typedef struct {
143 size_t srcXInBytes, srcY;
144 CUmemorytype srcMemoryType;
145 const void *srcHost;
146 CUdeviceptr srcDevice;
147 CUarray srcArray;
148 size_t srcPitch;
149
150 size_t dstXInBytes, dstY;
151 CUmemorytype dstMemoryType;
152 void *dstHost;
153 CUdeviceptr dstDevice;
154 CUarray dstArray;
155 size_t dstPitch;
156
157 size_t WidthInBytes, Height;
158 } CUDA_MEMCPY2D;
159
160 typedef struct {
161 size_t srcXInBytes, srcY, srcZ;
162 size_t srcLOD;
163 CUmemorytype srcMemoryType;
164 const void *srcHost;
165 CUdeviceptr srcDevice;
166 CUarray srcArray;
167 void *reserved0;
168 size_t srcPitch, srcHeight;
169
170 size_t dstXInBytes, dstY, dstZ;
171 size_t dstLOD;
172 CUmemorytype dstMemoryType;
173 void *dstHost;
174 CUdeviceptr dstDevice;
175 CUarray dstArray;
176 void *reserved1;
177 size_t dstPitch, dstHeight;
178
179 size_t WidthInBytes, Height, Depth;
180 } CUDA_MEMCPY3D;
181
182 typedef struct {
183 size_t srcXInBytes, srcY, srcZ;
184 size_t srcLOD;
185 CUmemorytype srcMemoryType;
186 const void *srcHost;
187 CUdeviceptr srcDevice;
188 CUarray srcArray;
189 CUcontext srcContext;
190 size_t srcPitch, srcHeight;
191
192 size_t dstXInBytes, dstY, dstZ;
193 size_t dstLOD;
194 CUmemorytype dstMemoryType;
195 void *dstHost;
196 CUdeviceptr dstDevice;
197 CUarray dstArray;
198 CUcontext dstContext;
199 size_t dstPitch, dstHeight;
200
201 size_t WidthInBytes, Height, Depth;
202 } CUDA_MEMCPY3D_PEER;
203
204 typedef struct {
205 char bytes[16];
206 } CUuuid;
207
208 #define cuCtxCreate cuCtxCreate_v2
209 CUresult cuCtxCreate (CUcontext *, unsigned, CUdevice);
210 #define cuCtxDestroy cuCtxDestroy_v2
211 CUresult cuCtxDestroy (CUcontext);
212 CUresult cuCtxGetCurrent (CUcontext *);
213 CUresult cuCtxGetDevice (CUdevice *);
214 #define cuCtxPopCurrent cuCtxPopCurrent_v2
215 CUresult cuCtxPopCurrent (CUcontext *);
216 #define cuCtxPushCurrent cuCtxPushCurrent_v2
217 CUresult cuCtxPushCurrent (CUcontext);
218 CUresult cuCtxSynchronize (void);
219 CUresult cuCtxSetLimit (CUlimit, size_t);
220 CUresult cuDeviceGet (CUdevice *, int);
221 /* _v2 was added in CUDA 11.4 and 'will supplant' the old one in 12.0. */
222 CUresult cuDeviceGetUuid (CUuuid*, CUdevice);
223 CUresult cuDeviceGetUuid_v2 (CUuuid*, CUdevice);
224 #define cuDeviceTotalMem cuDeviceTotalMem_v2
225 CUresult cuDeviceTotalMem (size_t *, CUdevice);
226 CUresult cuDeviceGetAttribute (int *, CUdevice_attribute, CUdevice);
227 CUresult cuDeviceGetCount (int *);
228 CUresult cuDeviceGetName (char *, int, CUdevice);
229 CUresult cuEventCreate (CUevent *, unsigned);
230 #define cuEventDestroy cuEventDestroy_v2
231 CUresult cuEventDestroy (CUevent);
232 CUresult cuEventElapsedTime (float *, CUevent, CUevent);
233 CUresult cuEventQuery (CUevent);
234 CUresult cuEventRecord (CUevent, CUstream);
235 CUresult cuEventSynchronize (CUevent);
236 CUresult cuFuncGetAttribute (int *, CUfunction_attribute, CUfunction);
237 CUresult cuGetErrorString (CUresult, const char **);
238 CUresult cuGetErrorName (CUresult, const char **);
239 CUresult cuInit (unsigned);
240 CUresult cuDriverGetVersion (int *);
241 CUresult cuLaunchKernel (CUfunction, unsigned, unsigned, unsigned, unsigned,
242 unsigned, unsigned, unsigned, CUstream, void **, void **);
243 #define cuLinkAddData cuLinkAddData_v2
244 CUresult cuLinkAddData (CUlinkState, CUjitInputType, void *, size_t, const char *,
245 unsigned, CUjit_option *, void **);
246 CUresult cuLinkComplete (CUlinkState, void **, size_t *);
247 #define cuLinkCreate cuLinkCreate_v2
248 CUresult cuLinkCreate (unsigned, CUjit_option *, void **, CUlinkState *);
249 CUresult cuLinkDestroy (CUlinkState);
250 #define cuMemGetInfo cuMemGetInfo_v2
251 CUresult cuMemGetInfo (size_t *, size_t *);
252 #define cuMemAlloc cuMemAlloc_v2
253 CUresult cuMemAlloc (CUdeviceptr *, size_t);
254 #define cuMemAllocHost cuMemAllocHost_v2
255 CUresult cuMemAllocHost (void **, size_t);
256 CUresult cuMemHostAlloc (void **, size_t, unsigned int);
257 CUresult cuMemcpy (CUdeviceptr, CUdeviceptr, size_t);
258 CUresult cuMemcpyPeer (CUdeviceptr, CUcontext, CUdeviceptr, CUcontext, size_t);
259 CUresult cuMemcpyPeerAsync (CUdeviceptr, CUcontext, CUdeviceptr, CUcontext, size_t, CUstream);
260 #define cuMemcpyDtoDAsync cuMemcpyDtoDAsync_v2
261 CUresult cuMemcpyDtoDAsync (CUdeviceptr, CUdeviceptr, size_t, CUstream);
262 #define cuMemcpyDtoH cuMemcpyDtoH_v2
263 CUresult cuMemcpyDtoH (void *, CUdeviceptr, size_t);
264 #define cuMemcpyDtoHAsync cuMemcpyDtoHAsync_v2
265 CUresult cuMemcpyDtoHAsync (void *, CUdeviceptr, size_t, CUstream);
266 #define cuMemcpyHtoD cuMemcpyHtoD_v2
267 CUresult cuMemcpyHtoD (CUdeviceptr, const void *, size_t);
268 #define cuMemcpyHtoDAsync cuMemcpyHtoDAsync_v2
269 CUresult cuMemcpyHtoDAsync (CUdeviceptr, const void *, size_t, CUstream);
270 #define cuMemcpy2D cuMemcpy2D_v2
271 CUresult cuMemcpy2D (const CUDA_MEMCPY2D *);
272 #define cuMemcpy2DAsync cuMemcpy2DAsync_v2
273 CUresult cuMemcpy2DAsync (const CUDA_MEMCPY2D *, CUstream);
274 #define cuMemcpy2DUnaligned cuMemcpy2DUnaligned_v2
275 CUresult cuMemcpy2DUnaligned (const CUDA_MEMCPY2D *);
276 #define cuMemcpy3D cuMemcpy3D_v2
277 CUresult cuMemcpy3D (const CUDA_MEMCPY3D *);
278 #define cuMemcpy3DAsync cuMemcpy3DAsync_v2
279 CUresult cuMemcpy3DAsync (const CUDA_MEMCPY3D *, CUstream);
280 CUresult cuMemcpy3DPeer (const CUDA_MEMCPY3D_PEER *);
281 CUresult cuMemcpy3DPeerAsync (const CUDA_MEMCPY3D_PEER *, CUstream);
282 #define cuMemFree cuMemFree_v2
283 CUresult cuMemFree (CUdeviceptr);
284 CUresult cuMemFreeHost (void *);
285 #define cuMemGetAddressRange cuMemGetAddressRange_v2
286 CUresult cuMemGetAddressRange (CUdeviceptr *, size_t *, CUdeviceptr);
287 #define cuMemHostGetDevicePointer cuMemHostGetDevicePointer_v2
288 CUresult cuMemHostGetDevicePointer (CUdeviceptr *, void *, unsigned);
289 CUresult cuModuleGetFunction (CUfunction *, CUmodule, const char *);
290 #define cuModuleGetGlobal cuModuleGetGlobal_v2
291 CUresult cuModuleGetGlobal (CUdeviceptr *, size_t *, CUmodule, const char *);
292 CUresult cuModuleLoad (CUmodule *, const char *);
293 CUresult cuModuleLoadData (CUmodule *, const void *);
294 CUresult cuModuleUnload (CUmodule);
295 CUresult cuOccupancyMaxPotentialBlockSize(int *, int *, CUfunction,
296 CUoccupancyB2DSize, size_t, int);
297 typedef void (*CUstreamCallback)(CUstream, CUresult, void *);
298 CUresult cuStreamAddCallback(CUstream, CUstreamCallback, void *, unsigned int);
299 CUresult cuStreamCreate (CUstream *, unsigned);
300 #define cuStreamDestroy cuStreamDestroy_v2
301 CUresult cuStreamDestroy (CUstream);
302 CUresult cuStreamQuery (CUstream);
303 CUresult cuStreamSynchronize (CUstream);
304 CUresult cuStreamWaitEvent (CUstream, CUevent, unsigned);
305
306 #ifdef __cplusplus
307 }
308 #endif
309
310 #endif /* GCC_CUDA_H */