Line data Source code
1 : /*
2 : * Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
3 : *
4 : * Please refer to the NVIDIA end user license agreement (EULA) associated
5 : * with this source code for terms and conditions that govern your use of
6 : * this software. Any use, reproduction, disclosure, or distribution of
7 : * this software and related documentation outside the terms of the EULA
8 : * is strictly prohibited.
9 : *
10 : */
11 :
12 :
13 : // With these flags defined, this source file will dynamically
14 : // load the corresponding functions. Disabled by default.
15 : #define __CUDA_API_VERSION 4000
16 :
17 : #include <stdio.h>
18 : #include <string.h>
19 :
20 : #include <gpac/tools.h>
21 :
22 :
23 : #if ((defined(WIN32) || defined(GPAC_CONFIG_LINUX) || defined(GPAC_CONFIG_DARWIN)) && !defined(GPAC_DISABLE_NVDEC))
24 :
25 : #include "dec_nvdec_sdk.h"
26 :
27 : tcuInit *_cuInit;
28 : tcuDriverGetVersion *cuDriverGetVersion;
29 : tcuDeviceGet *cuDeviceGet;
30 : tcuDeviceGetCount *cuDeviceGetCount;
31 : tcuDeviceGetName *cuDeviceGetName;
32 : tcuDeviceComputeCapability *cuDeviceComputeCapability;
33 : tcuDeviceTotalMem *cuDeviceTotalMem;
34 : tcuDeviceGetProperties *cuDeviceGetProperties;
35 : tcuDeviceGetAttribute *cuDeviceGetAttribute;
36 : tcuCtxCreate *cuCtxCreate;
37 : tcuCtxDestroy *cuCtxDestroy;
38 : tcuCtxAttach *cuCtxAttach;
39 : tcuCtxDetach *cuCtxDetach;
40 : tcuCtxPushCurrent *cuCtxPushCurrent;
41 : tcuCtxPopCurrent *cuCtxPopCurrent;
42 : tcuCtxGetCurrent *cuCtxGetCurrent;
43 : tcuCtxSetCurrent *cuCtxSetCurrent;
44 : tcuCtxGetDevice *cuCtxGetDevice;
45 : tcuCtxSynchronize *cuCtxSynchronize;
46 : tcuModuleLoad *cuModuleLoad;
47 : tcuModuleLoadData *cuModuleLoadData;
48 : tcuModuleLoadDataEx *cuModuleLoadDataEx;
49 : tcuModuleLoadFatBinary *cuModuleLoadFatBinary;
50 : tcuModuleUnload *cuModuleUnload;
51 : tcuModuleGetFunction *cuModuleGetFunction;
52 : tcuModuleGetGlobal *cuModuleGetGlobal;
53 : tcuModuleGetTexRef *cuModuleGetTexRef;
54 : tcuModuleGetSurfRef *cuModuleGetSurfRef;
55 : tcuMemGetInfo *cuMemGetInfo;
56 : tcuMemAlloc *cuMemAlloc;
57 : tcuMemAllocPitch *cuMemAllocPitch;
58 : tcuMemFree *cuMemFree;
59 : tcuMemGetAddressRange *cuMemGetAddressRange;
60 : tcuMemAllocHost *cuMemAllocHost;
61 : tcuMemFreeHost *cuMemFreeHost;
62 : tcuMemHostAlloc *cuMemHostAlloc;
63 : tcuMemHostGetDevicePointer *cuMemHostGetDevicePointer;
64 : tcuMemHostRegister *cuMemHostRegister;
65 : tcuMemHostUnregister *cuMemHostUnregister;
66 : tcuMemcpyHtoD *cuMemcpyHtoD;
67 : tcuMemcpyDtoH *cuMemcpyDtoH;
68 : tcuMemcpyDtoD *cuMemcpyDtoD;
69 : tcuMemcpyDtoA *cuMemcpyDtoA;
70 : tcuMemcpyAtoD *cuMemcpyAtoD;
71 : tcuMemcpyHtoA *cuMemcpyHtoA;
72 : tcuMemcpyAtoH *cuMemcpyAtoH;
73 : tcuMemcpyAtoA *cuMemcpyAtoA;
74 : tcuMemcpy2D *cuMemcpy2D;
75 : tcuMemcpy2DUnaligned *cuMemcpy2DUnaligned;
76 : tcuMemcpy3D *cuMemcpy3D;
77 : tcuMemcpyHtoDAsync *cuMemcpyHtoDAsync;
78 : tcuMemcpyDtoHAsync *cuMemcpyDtoHAsync;
79 : tcuMemcpyDtoDAsync *cuMemcpyDtoDAsync;
80 : tcuMemcpyHtoAAsync *cuMemcpyHtoAAsync;
81 : tcuMemcpyAtoHAsync *cuMemcpyAtoHAsync;
82 : tcuMemcpy2DAsync *cuMemcpy2DAsync;
83 : tcuMemcpy3DAsync *cuMemcpy3DAsync;
84 : tcuMemcpy *cuMemcpy;
85 : tcuMemcpyPeer *cuMemcpyPeer;
86 : tcuMemsetD8 *cuMemsetD8;
87 : tcuMemsetD16 *cuMemsetD16;
88 : tcuMemsetD32 *cuMemsetD32;
89 : tcuMemsetD2D8 *cuMemsetD2D8;
90 : tcuMemsetD2D16 *cuMemsetD2D16;
91 : tcuMemsetD2D32 *cuMemsetD2D32;
92 : tcuFuncSetBlockShape *cuFuncSetBlockShape;
93 : tcuFuncSetSharedSize *cuFuncSetSharedSize;
94 : tcuFuncGetAttribute *cuFuncGetAttribute;
95 : tcuFuncSetCacheConfig *cuFuncSetCacheConfig;
96 : tcuLaunchKernel *cuLaunchKernel;
97 : tcuArrayCreate *cuArrayCreate;
98 : tcuArrayGetDescriptor *cuArrayGetDescriptor;
99 : tcuArrayDestroy *cuArrayDestroy;
100 : tcuArray3DCreate *cuArray3DCreate;
101 : tcuArray3DGetDescriptor *cuArray3DGetDescriptor;
102 : tcuTexRefCreate *cuTexRefCreate;
103 : tcuTexRefDestroy *cuTexRefDestroy;
104 : tcuTexRefSetArray *cuTexRefSetArray;
105 : tcuTexRefSetAddress *cuTexRefSetAddress;
106 : tcuTexRefSetAddress2D *cuTexRefSetAddress2D;
107 : tcuTexRefSetFormat *cuTexRefSetFormat;
108 : tcuTexRefSetAddressMode *cuTexRefSetAddressMode;
109 : tcuTexRefSetFilterMode *cuTexRefSetFilterMode;
110 : tcuTexRefSetFlags *cuTexRefSetFlags;
111 : tcuTexRefGetAddress *cuTexRefGetAddress;
112 : tcuTexRefGetArray *cuTexRefGetArray;
113 : tcuTexRefGetAddressMode *cuTexRefGetAddressMode;
114 : tcuTexRefGetFilterMode *cuTexRefGetFilterMode;
115 : tcuTexRefGetFormat *cuTexRefGetFormat;
116 : tcuTexRefGetFlags *cuTexRefGetFlags;
117 : tcuSurfRefSetArray *cuSurfRefSetArray;
118 : tcuSurfRefGetArray *cuSurfRefGetArray;
119 : tcuParamSetSize *cuParamSetSize;
120 : tcuParamSeti *cuParamSeti;
121 : tcuParamSetf *cuParamSetf;
122 : tcuParamSetv *cuParamSetv;
123 : tcuParamSetTexRef *cuParamSetTexRef;
124 : tcuLaunch *cuLaunch;
125 : tcuLaunchGrid *cuLaunchGrid;
126 : tcuLaunchGridAsync *cuLaunchGridAsync;
127 : tcuEventCreate *cuEventCreate;
128 : tcuEventRecord *cuEventRecord;
129 : tcuEventQuery *cuEventQuery;
130 : tcuEventSynchronize *cuEventSynchronize;
131 : tcuEventDestroy *cuEventDestroy;
132 : tcuEventElapsedTime *cuEventElapsedTime;
133 : tcuStreamCreate *cuStreamCreate;
134 : tcuStreamQuery *cuStreamQuery;
135 : tcuStreamSynchronize *cuStreamSynchronize;
136 : tcuStreamDestroy *cuStreamDestroy;
137 : tcuGraphicsUnregisterResource *cuGraphicsUnregisterResource;
138 : tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
139 : tcuGraphicsResourceGetMappedPointer *cuGraphicsResourceGetMappedPointer;
140 : tcuGraphicsResourceSetMapFlags *cuGraphicsResourceSetMapFlags;
141 : tcuGraphicsMapResources *cuGraphicsMapResources;
142 : tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
143 : tcuGetExportTable *cuGetExportTable;
144 : tcuCtxSetLimit *cuCtxSetLimit;
145 : tcuCtxGetLimit *cuCtxGetLimit;
146 : tcuMemHostGetFlags *cuMemHostGetFlags;
147 :
148 : // GL/CUDA interop
149 : #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
150 : tcuWGLGetDevice *cuWGLGetDevice;
151 : #endif
152 :
153 : //#if __CUDA_API_VERSION >= 3020
154 : tcuGLCtxCreate *cuGLCtxCreate;
155 : tcuGLCtxCreate *cuGLCtxCreate_v2;
156 : tcuGLMapBufferObject *cuGLMapBufferObject;
157 : tcuGLMapBufferObject *cuGLMapBufferObject_v2;
158 : tcuGLMapBufferObjectAsync *cuGLMapBufferObjectAsync;
159 : //#endif
160 :
161 : #if __CUDA_API_VERSION >= 6050
162 : tcuGLGetDevices *cuGLGetDevices;
163 : #endif
164 :
165 : tcuGLInit *cuGLInit; // deprecated in CUDA 3.0
166 : tcuGraphicsGLRegisterBuffer *cuGraphicsGLRegisterBuffer;
167 : tcuGraphicsGLRegisterImage *cuGraphicsGLRegisterImage;
168 : tcuGLSetBufferObjectMapFlags *cuGLSetBufferObjectMapFlags;
169 : tcuGLRegisterBufferObject *cuGLRegisterBufferObject;
170 :
171 : tcuGLUnmapBufferObject *cuGLUnmapBufferObject;
172 : tcuGLUnmapBufferObjectAsync *cuGLUnmapBufferObjectAsync;
173 :
174 : tcuGLUnregisterBufferObject *cuGLUnregisterBufferObject;
175 : tcuGLGetDevices *cuGLGetDevices; // CUDA 6.5 only
176 :
177 :
178 :
179 : #if !defined(__APPLE__)
180 : tcuvidCreateVideoSource *cuvidCreateVideoSource;
181 : tcuvidCreateVideoSourceW *cuvidCreateVideoSourceW;
182 : tcuvidDestroyVideoSource *cuvidDestroyVideoSource;
183 : tcuvidSetVideoSourceState *cuvidSetVideoSourceState;
184 : tcuvidGetVideoSourceState *cuvidGetVideoSourceState;
185 : tcuvidGetSourceVideoFormat *cuvidGetSourceVideoFormat;
186 : tcuvidGetSourceAudioFormat *cuvidGetSourceAudioFormat;
187 : #endif
188 :
189 : tcuvidCreateVideoParser *cuvidCreateVideoParser;
190 : tcuvidParseVideoData *cuvidParseVideoData;
191 : tcuvidDestroyVideoParser *cuvidDestroyVideoParser;
192 :
193 : tcuvidCreateDecoder *cuvidCreateDecoder;
194 : tcuvidDestroyDecoder *cuvidDestroyDecoder;
195 : tcuvidDecodePicture *cuvidDecodePicture;
196 :
197 : tcuvidMapVideoFrame *cuvidMapVideoFrame;
198 : tcuvidUnmapVideoFrame *cuvidUnmapVideoFrame;
199 :
200 : #if defined(WIN64) || defined(_WIN64) || defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
201 : tcuvidMapVideoFrame64 *cuvidMapVideoFrame64;
202 : tcuvidUnmapVideoFrame64 *cuvidUnmapVideoFrame64;
203 : #endif
204 :
205 : //tcuvidGetVideoFrameSurface *cuvidGetVideoFrameSurface;
206 : tcuvidCtxLockCreate *cuvidCtxLockCreate;
207 : tcuvidCtxLockDestroy *cuvidCtxLockDestroy;
208 : tcuvidCtxLock *cuvidCtxLock;
209 : tcuvidCtxUnlock *cuvidCtxUnlock;
210 :
211 :
212 :
213 : #define STRINGIFY(X) #X
214 :
215 : #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
216 : #include <windows.h>
217 :
218 : #ifdef UNICODE
219 : static LPCWSTR __CudaLibName = L"nvcuda.dll";
220 : static LPCWSTR __CuvidLibName = L"nvcuvid.dll";
221 : #else
222 : static LPCSTR __CudaLibName = "nvcuda.dll";
223 : static LPCSTR __CuvidLibName = "nvcuvid.dll";
224 : #endif
225 :
226 : typedef HMODULE CUDADRIVER;
227 : typedef HMODULE CUVIDDRIVER;
228 :
229 : static CUresult LOAD_LIBRARY_CUDA(CUDADRIVER *pInstance)
230 : {
231 : *pInstance = LoadLibrary(__CudaLibName);
232 : if (*pInstance == NULL) {
233 : GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[NVDec] LoadLibrary \"%s\" failed!\n", __CudaLibName));
234 : return CUDA_ERROR_UNKNOWN;
235 : }
236 : return CUDA_SUCCESS;
237 : }
238 :
239 : static CUresult LOAD_LIBRARY_CUVID(CUVIDDRIVER *pInstance)
240 : {
241 : *pInstance = LoadLibrary(__CuvidLibName);
242 : if (*pInstance == NULL) {
243 : GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[NVDec] LoadLibrary \"%s\" failed!\n", __CuvidLibName));
244 : return CUDA_ERROR_UNKNOWN;
245 : }
246 : return CUDA_SUCCESS;
247 : }
248 :
249 : #define GET_PROC_EX(name, alias, required) \
250 : alias = (t##name *)GetProcAddress(curr_lib, #name); \
251 : if (alias == NULL && required) { \
252 : GF_LOG(GF_LOG_WARNING, GF_LOG_MMIO, ("[NVDec] Failed to find required function \"%s\" \n", \
253 : #name)); \
254 : }
255 :
256 : #define GET_PROC_EX_V2(name, alias, required) \
257 : alias = (t##name *)GetProcAddress(curr_lib, STRINGIFY(name##_v2));\
258 : if (alias == NULL && required) { \
259 : GF_LOG(GF_LOG_WARNING, GF_LOG_MMIO, ("[NVDec] Failed to find required function \"%s\" \n", \
260 : STRINGIFY(name##_v2))); \
261 : }
262 :
263 : #elif defined(__unix__) || defined(__APPLE__) || defined(__MACOSX)
264 :
265 : #include <dlfcn.h>
266 :
267 : #if defined(__APPLE__) || defined(__MACOSX)
268 : static char __CudaLibName[] = "/usr/local/cuda/lib/libcuda.dylib";
269 : #else
270 : static char __CudaLibName[] = "libcuda.so";
271 : #endif
272 :
273 : static char __CuvidLibName[] = "libnvcuvid.so";
274 :
275 : typedef void *CUVIDDRIVER;
276 :
277 2276 : static CUresult LOAD_LIBRARY_CUDA(CUDADRIVER *pInstance)
278 : {
279 2276 : *pInstance = dlopen(__CudaLibName, RTLD_NOW);
280 2276 : if (*pInstance == NULL) {
281 2276 : GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[NVDec] dlopen \"%s\" failed!\n", __CudaLibName));
282 : return CUDA_ERROR_SHARED_OBJECT_INIT_FAILED;
283 : }
284 : return CUDA_SUCCESS;
285 : }
286 :
287 0 : static CUresult LOAD_LIBRARY_CUVID(CUVIDDRIVER *pInstance)
288 : {
289 0 : *pInstance = dlopen(__CuvidLibName, RTLD_NOW);
290 0 : if (*pInstance == NULL) {
291 0 : GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[NVDec]dlopen \"%s\" failed!\n", __CuvidLibName));
292 : return CUDA_ERROR_UNKNOWN;
293 : }
294 : return CUDA_SUCCESS;
295 : }
296 :
297 : #define GET_PROC_EX(name, alias, required) \
298 : alias = (t##name *)dlsym(curr_lib, #name); \
299 : if (alias == NULL && required) { \
300 : GF_LOG(GF_LOG_WARNING, GF_LOG_MMIO, ("[NVDec] Failed to find required function \"%s\"\n", \
301 : #name)); \
302 : }
303 :
304 : #define GET_PROC_EX_V2(name, alias, required) \
305 : alias = (t##name *)dlsym(curr_lib, STRINGIFY(name##_v2)); \
306 : if (alias == NULL && required) { \
307 : GF_LOG(GF_LOG_WARNING, GF_LOG_MMIO, ("[NVDec]Failed to find required function \"%s\"\n", \
308 : STRINGIFY(name##_v2))); \
309 : }
310 :
311 : #else
312 : #error unsupported platform
313 : #endif
314 :
315 : #define CHECKED_CALL(call) \
316 : do { \
317 : CUresult result = (call); \
318 : if (CUDA_SUCCESS != result) { \
319 : return result; \
320 : } \
321 : } while(0)
322 :
323 : #define GET_PROC_REQUIRED(name) GET_PROC_EX(name,name,1)
324 : #define GET_PROC_OPTIONAL(name) GET_PROC_EX(name,name,0)
325 : #define GET_PROC(name) GET_PROC_REQUIRED(name)
326 : #define GET_PROC_V2(name) GET_PROC_EX_V2(name,name,1)
327 :
328 0 : CUresult CUDAAPI cuInitGL(unsigned int Flags, int cudaVersion, CUDADRIVER curr_lib)
329 : {
330 :
331 0 : return CUDA_SUCCESS;
332 : }
333 :
334 : CUDADRIVER CudaDrvLib=0;
335 : CUVIDDRIVER CuvidDrvLib = 0;
336 :
337 0 : void CUDAAPI cuUninit()
338 : {
339 : #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
340 : if (CudaDrvLib) FreeLibrary((HMODULE)CudaDrvLib);
341 : if (CuvidDrvLib) FreeLibrary((HMODULE)CuvidDrvLib);
342 : #else
343 0 : if (CudaDrvLib) dlclose(CudaDrvLib);
344 0 : if (CuvidDrvLib) dlclose(CuvidDrvLib);
345 : #endif
346 0 : CudaDrvLib = 0;
347 0 : CuvidDrvLib = 0;
348 0 : }
349 :
350 2276 : CUresult CUDAAPI cuInit(unsigned int Flags, int cudaVersion)
351 : {
352 2276 : int driverVer = 1000;
353 : CUDADRIVER curr_lib ;
354 :
355 2276 : if (CudaDrvLib) return CUDA_SUCCESS;
356 :
357 : assert(CudaDrvLib == 0);
358 :
359 2276 : CHECKED_CALL(LOAD_LIBRARY_CUDA(&CudaDrvLib));
360 0 : curr_lib = CudaDrvLib;
361 :
362 : // cuInit is required; alias it to _cuInit
363 0 : GET_PROC_EX(cuInit, _cuInit, 1);
364 0 : CHECKED_CALL(_cuInit(Flags));
365 :
366 : // available since 2.2. if not present, version 1.0 is assumed
367 0 : GET_PROC_OPTIONAL(cuDriverGetVersion);
368 :
369 0 : if (cuDriverGetVersion)
370 : {
371 0 : CHECKED_CALL(cuDriverGetVersion(&driverVer));
372 : }
373 :
374 : // fetch all function pointers
375 0 : GET_PROC(cuDeviceGet);
376 0 : GET_PROC(cuDeviceGetCount);
377 0 : GET_PROC(cuDeviceGetName);
378 0 : GET_PROC(cuDeviceComputeCapability);
379 0 : GET_PROC(cuDeviceGetProperties);
380 0 : GET_PROC(cuDeviceGetAttribute);
381 0 : GET_PROC(cuCtxDestroy);
382 0 : GET_PROC(cuCtxAttach);
383 0 : GET_PROC(cuCtxDetach);
384 0 : GET_PROC(cuCtxPushCurrent);
385 0 : GET_PROC(cuCtxPopCurrent);
386 0 : GET_PROC(cuCtxGetDevice);
387 0 : GET_PROC(cuCtxSynchronize);
388 0 : GET_PROC(cuModuleLoad);
389 0 : GET_PROC(cuModuleLoadData);
390 0 : GET_PROC(cuModuleUnload);
391 0 : GET_PROC(cuModuleGetFunction);
392 0 : GET_PROC(cuModuleGetTexRef);
393 0 : GET_PROC(cuMemFreeHost);
394 0 : GET_PROC(cuMemHostAlloc);
395 0 : GET_PROC(cuFuncSetBlockShape);
396 0 : GET_PROC(cuFuncSetSharedSize);
397 0 : GET_PROC(cuFuncGetAttribute);
398 0 : GET_PROC(cuArrayDestroy);
399 0 : GET_PROC(cuTexRefCreate);
400 0 : GET_PROC(cuTexRefDestroy);
401 0 : GET_PROC(cuTexRefSetArray);
402 0 : GET_PROC(cuTexRefSetFormat);
403 0 : GET_PROC(cuTexRefSetAddressMode);
404 0 : GET_PROC(cuTexRefSetFilterMode);
405 0 : GET_PROC(cuTexRefSetFlags);
406 0 : GET_PROC(cuTexRefGetArray);
407 0 : GET_PROC(cuTexRefGetAddressMode);
408 0 : GET_PROC(cuTexRefGetFilterMode);
409 0 : GET_PROC(cuTexRefGetFormat);
410 0 : GET_PROC(cuTexRefGetFlags);
411 0 : GET_PROC(cuParamSetSize);
412 0 : GET_PROC(cuParamSeti);
413 0 : GET_PROC(cuParamSetf);
414 0 : GET_PROC(cuParamSetv);
415 0 : GET_PROC(cuParamSetTexRef);
416 0 : GET_PROC(cuLaunch);
417 0 : GET_PROC(cuLaunchGrid);
418 0 : GET_PROC(cuLaunchGridAsync);
419 0 : GET_PROC(cuEventCreate);
420 0 : GET_PROC(cuEventRecord);
421 0 : GET_PROC(cuEventQuery);
422 0 : GET_PROC(cuEventSynchronize);
423 0 : GET_PROC(cuEventDestroy);
424 0 : GET_PROC(cuEventElapsedTime);
425 0 : GET_PROC(cuStreamCreate);
426 0 : GET_PROC(cuStreamQuery);
427 0 : GET_PROC(cuStreamSynchronize);
428 0 : GET_PROC(cuStreamDestroy);
429 :
430 : // These could be _v2 interfaces
431 0 : if (cudaVersion >= 4000)
432 : {
433 0 : GET_PROC_V2(cuCtxDestroy);
434 0 : GET_PROC_V2(cuCtxPopCurrent);
435 0 : GET_PROC_V2(cuCtxPushCurrent);
436 0 : GET_PROC_V2(cuStreamDestroy);
437 0 : GET_PROC_V2(cuEventDestroy);
438 : }
439 :
440 0 : if (cudaVersion >= 3020)
441 : {
442 0 : GET_PROC_V2(cuDeviceTotalMem);
443 0 : GET_PROC_V2(cuCtxCreate);
444 0 : GET_PROC_V2(cuModuleGetGlobal);
445 0 : GET_PROC_V2(cuMemGetInfo);
446 0 : GET_PROC_V2(cuMemAlloc);
447 0 : GET_PROC_V2(cuMemAllocPitch);
448 0 : GET_PROC_V2(cuMemFree);
449 0 : GET_PROC_V2(cuMemGetAddressRange);
450 0 : GET_PROC_V2(cuMemAllocHost);
451 0 : GET_PROC_V2(cuMemHostGetDevicePointer);
452 0 : GET_PROC_V2(cuMemcpyHtoD);
453 0 : GET_PROC_V2(cuMemcpyDtoH);
454 0 : GET_PROC_V2(cuMemcpyDtoD);
455 0 : GET_PROC_V2(cuMemcpyDtoA);
456 0 : GET_PROC_V2(cuMemcpyAtoD);
457 0 : GET_PROC_V2(cuMemcpyHtoA);
458 0 : GET_PROC_V2(cuMemcpyAtoH);
459 0 : GET_PROC_V2(cuMemcpyAtoA);
460 0 : GET_PROC_V2(cuMemcpy2D);
461 0 : GET_PROC_V2(cuMemcpy2DUnaligned);
462 0 : GET_PROC_V2(cuMemcpy3D);
463 0 : GET_PROC_V2(cuMemcpyHtoDAsync);
464 0 : GET_PROC_V2(cuMemcpyDtoHAsync);
465 0 : GET_PROC_V2(cuMemcpyHtoAAsync);
466 0 : GET_PROC_V2(cuMemcpyAtoHAsync);
467 0 : GET_PROC_V2(cuMemcpy2DAsync);
468 0 : GET_PROC_V2(cuMemcpy3DAsync);
469 0 : GET_PROC_V2(cuMemsetD8);
470 0 : GET_PROC_V2(cuMemsetD16);
471 0 : GET_PROC_V2(cuMemsetD32);
472 0 : GET_PROC_V2(cuMemsetD2D8);
473 0 : GET_PROC_V2(cuMemsetD2D16);
474 0 : GET_PROC_V2(cuMemsetD2D32);
475 0 : GET_PROC_V2(cuArrayCreate);
476 0 : GET_PROC_V2(cuArrayGetDescriptor);
477 0 : GET_PROC_V2(cuArray3DCreate);
478 0 : GET_PROC_V2(cuArray3DGetDescriptor);
479 0 : GET_PROC_V2(cuTexRefSetAddress);
480 0 : GET_PROC_V2(cuTexRefSetAddress2D);
481 0 : GET_PROC_V2(cuTexRefGetAddress);
482 : }
483 : else
484 : {
485 0 : GET_PROC(cuDeviceTotalMem);
486 0 : GET_PROC(cuCtxCreate);
487 0 : GET_PROC(cuModuleGetGlobal);
488 0 : GET_PROC(cuMemGetInfo);
489 0 : GET_PROC(cuMemAlloc);
490 0 : GET_PROC(cuMemAllocPitch);
491 0 : GET_PROC(cuMemFree);
492 0 : GET_PROC(cuMemGetAddressRange);
493 0 : GET_PROC(cuMemAllocHost);
494 0 : GET_PROC(cuMemHostGetDevicePointer);
495 0 : GET_PROC(cuMemcpyHtoD);
496 0 : GET_PROC(cuMemcpyDtoH);
497 0 : GET_PROC(cuMemcpyDtoD);
498 0 : GET_PROC(cuMemcpyDtoA);
499 0 : GET_PROC(cuMemcpyAtoD);
500 0 : GET_PROC(cuMemcpyHtoA);
501 0 : GET_PROC(cuMemcpyAtoH);
502 0 : GET_PROC(cuMemcpyAtoA);
503 0 : GET_PROC(cuMemcpy2D);
504 0 : GET_PROC(cuMemcpy2DUnaligned);
505 0 : GET_PROC(cuMemcpy3D);
506 0 : GET_PROC(cuMemcpyHtoDAsync);
507 0 : GET_PROC(cuMemcpyDtoHAsync);
508 0 : GET_PROC(cuMemcpyHtoAAsync);
509 0 : GET_PROC(cuMemcpyAtoHAsync);
510 0 : GET_PROC(cuMemcpy2DAsync);
511 0 : GET_PROC(cuMemcpy3DAsync);
512 0 : GET_PROC(cuMemsetD8);
513 0 : GET_PROC(cuMemsetD16);
514 0 : GET_PROC(cuMemsetD32);
515 0 : GET_PROC(cuMemsetD2D8);
516 0 : GET_PROC(cuMemsetD2D16);
517 0 : GET_PROC(cuMemsetD2D32);
518 0 : GET_PROC(cuArrayCreate);
519 0 : GET_PROC(cuArrayGetDescriptor);
520 0 : GET_PROC(cuArray3DCreate);
521 0 : GET_PROC(cuArray3DGetDescriptor);
522 0 : GET_PROC(cuTexRefSetAddress);
523 0 : GET_PROC(cuTexRefSetAddress2D);
524 0 : GET_PROC(cuTexRefGetAddress);
525 : }
526 :
527 : // The following functions are specific to CUDA versions
528 0 : if (driverVer >= 2010)
529 : {
530 0 : GET_PROC(cuModuleLoadDataEx);
531 0 : GET_PROC(cuModuleLoadFatBinary);
532 : }
533 :
534 0 : if (driverVer >= 2030)
535 : {
536 0 : GET_PROC(cuMemHostGetFlags);
537 : }
538 :
539 0 : if (driverVer >= 3000)
540 : {
541 0 : GET_PROC(cuMemcpyDtoDAsync);
542 0 : GET_PROC(cuFuncSetCacheConfig);
543 :
544 0 : GET_PROC(cuGraphicsUnregisterResource);
545 0 : GET_PROC(cuGraphicsSubResourceGetMappedArray);
546 :
547 : #if (__CUDA_API_VERSION >= 3020)
548 0 : if (cudaVersion >= 3020)
549 : {
550 0 : GET_PROC_V2(cuGraphicsResourceGetMappedPointer);
551 : }
552 : else
553 : {
554 0 : GET_PROC(cuGraphicsResourceGetMappedPointer);
555 : }
556 : #endif
557 0 : GET_PROC(cuGraphicsResourceSetMapFlags);
558 0 : GET_PROC(cuGraphicsMapResources);
559 0 : GET_PROC(cuGraphicsUnmapResources);
560 0 : GET_PROC(cuGetExportTable);
561 : }
562 :
563 0 : if (driverVer >= 3010)
564 : {
565 0 : GET_PROC(cuModuleGetSurfRef);
566 0 : GET_PROC(cuSurfRefSetArray);
567 0 : GET_PROC(cuSurfRefGetArray);
568 0 : GET_PROC(cuCtxSetLimit);
569 0 : GET_PROC(cuCtxGetLimit);
570 : }
571 :
572 0 : if (driverVer >= 4000)
573 : {
574 0 : GET_PROC(cuCtxSetCurrent);
575 0 : GET_PROC(cuCtxGetCurrent);
576 0 : GET_PROC(cuMemHostRegister);
577 0 : GET_PROC(cuMemHostUnregister);
578 0 : GET_PROC(cuMemcpy);
579 0 : GET_PROC(cuMemcpyPeer);
580 0 : GET_PROC(cuLaunchKernel);
581 : }
582 :
583 : /*load openGL*/
584 0 : if (cudaVersion >= 2010)
585 : {
586 0 : GET_PROC(cuGLCtxCreate);
587 0 : GET_PROC(cuGraphicsGLRegisterBuffer);
588 0 : GET_PROC(cuGraphicsGLRegisterImage);
589 : #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
590 : GET_PROC(cuWGLGetDevice);
591 : #endif
592 : }
593 0 : if (cudaVersion >= 2030)
594 : {
595 0 : GET_PROC(cuGraphicsGLRegisterBuffer);
596 0 : GET_PROC(cuGraphicsGLRegisterImage);
597 : }
598 0 : if (cudaVersion >= 3000)
599 : {
600 0 : GET_PROC(cuGLGetDevices);
601 : #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
602 : GET_PROC(cuWGLGetDevice);
603 : #endif
604 0 : GET_PROC_V2(cuGLCtxCreate);
605 :
606 0 : GET_PROC_V2(cuGLMapBufferObject);
607 0 : GET_PROC(cuGLUnmapBufferObject);
608 0 : GET_PROC(cuGLMapBufferObjectAsync);
609 0 : GET_PROC(cuGLUnmapBufferObjectAsync);
610 0 : GET_PROC(cuGLRegisterBufferObject);
611 0 : GET_PROC(cuGLUnregisterBufferObject);
612 0 : GET_PROC(cuGLSetBufferObjectMapFlags);
613 : }
614 :
615 : //init cuvid
616 0 : CHECKED_CALL(LOAD_LIBRARY_CUVID(&CuvidDrvLib));
617 :
618 0 : curr_lib = CuvidDrvLib;
619 : #if !defined(__APPLE__)
620 : // fetch all function pointers
621 0 : GET_PROC(cuvidCreateVideoSource);
622 0 : GET_PROC(cuvidCreateVideoSourceW);
623 0 : GET_PROC(cuvidDestroyVideoSource);
624 0 : GET_PROC(cuvidSetVideoSourceState);
625 0 : GET_PROC(cuvidGetVideoSourceState);
626 0 : GET_PROC(cuvidGetSourceVideoFormat);
627 0 : GET_PROC(cuvidGetSourceAudioFormat);
628 : #endif
629 :
630 0 : GET_PROC(cuvidCreateVideoParser);
631 0 : GET_PROC(cuvidParseVideoData);
632 0 : GET_PROC(cuvidDestroyVideoParser);
633 :
634 0 : GET_PROC(cuvidCreateDecoder);
635 0 : GET_PROC(cuvidDestroyDecoder);
636 0 : GET_PROC(cuvidDecodePicture);
637 :
638 : #if defined(WIN64) || defined(_WIN64) || defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
639 0 : GET_PROC(cuvidMapVideoFrame64);
640 0 : GET_PROC(cuvidUnmapVideoFrame64);
641 0 : cuvidMapVideoFrame = cuvidMapVideoFrame64;
642 0 : cuvidUnmapVideoFrame = cuvidUnmapVideoFrame64;
643 : #else
644 : GET_PROC(cuvidMapVideoFrame);
645 : GET_PROC(cuvidUnmapVideoFrame);
646 : #endif
647 :
648 : // GET_PROC(cuvidGetVideoFrameSurface);
649 0 : GET_PROC(cuvidCtxLockCreate);
650 0 : GET_PROC(cuvidCtxLockDestroy);
651 0 : GET_PROC(cuvidCtxLock);
652 0 : GET_PROC(cuvidCtxUnlock);
653 :
654 :
655 : return CUDA_SUCCESS;
656 : }
657 :
658 :
659 : // CUDA Driver API errors
660 0 : const char *cudaGetErrorEnum(CUresult error)
661 : {
662 0 : switch (error) {
663 : case CUDA_SUCCESS: return "CUDA_SUCCESS";
664 0 : case CUDA_ERROR_INVALID_VALUE: return "CUDA_ERROR_INVALID_VALUE";
665 0 : case CUDA_ERROR_OUT_OF_MEMORY: return "CUDA_ERROR_OUT_OF_MEMORY";
666 0 : case CUDA_ERROR_NOT_INITIALIZED: return "CUDA_ERROR_NOT_INITIALIZED";
667 0 : case CUDA_ERROR_DEINITIALIZED: return "CUDA_ERROR_DEINITIALIZED";
668 0 : case CUDA_ERROR_PROFILER_DISABLED: return "CUDA_ERROR_PROFILER_DISABLED";
669 0 : case CUDA_ERROR_PROFILER_NOT_INITIALIZED: return "CUDA_ERROR_PROFILER_NOT_INITIALIZED";
670 0 : case CUDA_ERROR_PROFILER_ALREADY_STARTED: return "CUDA_ERROR_PROFILER_ALREADY_STARTED";
671 0 : case CUDA_ERROR_PROFILER_ALREADY_STOPPED: return "CUDA_ERROR_PROFILER_ALREADY_STOPPED";
672 0 : case CUDA_ERROR_NO_DEVICE: return "CUDA_ERROR_NO_DEVICE";
673 0 : case CUDA_ERROR_INVALID_DEVICE: return "CUDA_ERROR_INVALID_DEVICE";
674 0 : case CUDA_ERROR_INVALID_IMAGE: return "CUDA_ERROR_INVALID_IMAGE";
675 0 : case CUDA_ERROR_INVALID_CONTEXT: return "CUDA_ERROR_INVALID_CONTEXT";
676 0 : case CUDA_ERROR_CONTEXT_ALREADY_CURRENT: return "CUDA_ERROR_CONTEXT_ALREADY_CURRENT";
677 0 : case CUDA_ERROR_MAP_FAILED: return "CUDA_ERROR_MAP_FAILED";
678 0 : case CUDA_ERROR_UNMAP_FAILED: return "CUDA_ERROR_UNMAP_FAILED";
679 0 : case CUDA_ERROR_ARRAY_IS_MAPPED: return "CUDA_ERROR_ARRAY_IS_MAPPED";
680 0 : case CUDA_ERROR_ALREADY_MAPPED: return "CUDA_ERROR_ALREADY_MAPPED";
681 0 : case CUDA_ERROR_NO_BINARY_FOR_GPU: return "CUDA_ERROR_NO_BINARY_FOR_GPU";
682 0 : case CUDA_ERROR_ALREADY_ACQUIRED: return "CUDA_ERROR_ALREADY_ACQUIRED";
683 0 : case CUDA_ERROR_NOT_MAPPED: return "CUDA_ERROR_NOT_MAPPED";
684 0 : case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: return "CUDA_ERROR_NOT_MAPPED_AS_ARRAY";
685 0 : case CUDA_ERROR_NOT_MAPPED_AS_POINTER: return "CUDA_ERROR_NOT_MAPPED_AS_POINTER";
686 0 : case CUDA_ERROR_ECC_UNCORRECTABLE: return "CUDA_ERROR_ECC_UNCORRECTABLE";
687 0 : case CUDA_ERROR_UNSUPPORTED_LIMIT: return "CUDA_ERROR_UNSUPPORTED_LIMIT";
688 0 : case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: return "CUDA_ERROR_CONTEXT_ALREADY_IN_USE";
689 0 : case CUDA_ERROR_INVALID_SOURCE: return "CUDA_ERROR_INVALID_SOURCE";
690 0 : case CUDA_ERROR_FILE_NOT_FOUND: return "CUDA_ERROR_FILE_NOT_FOUND";
691 0 : case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: return "CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND";
692 0 : case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: return "CUDA_ERROR_SHARED_OBJECT_INIT_FAILED";
693 0 : case CUDA_ERROR_OPERATING_SYSTEM: return "CUDA_ERROR_OPERATING_SYSTEM";
694 0 : case CUDA_ERROR_INVALID_HANDLE: return "CUDA_ERROR_INVALID_HANDLE";
695 0 : case CUDA_ERROR_NOT_FOUND: return "CUDA_ERROR_NOT_FOUND";
696 0 : case CUDA_ERROR_NOT_READY: return "CUDA_ERROR_NOT_READY";
697 0 : case CUDA_ERROR_LAUNCH_FAILED: return "CUDA_ERROR_LAUNCH_FAILED";
698 0 : case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: return "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES";
699 0 : case CUDA_ERROR_LAUNCH_TIMEOUT: return "CUDA_ERROR_LAUNCH_TIMEOUT";
700 0 : case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: return "CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING";
701 0 : case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: return "CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED";
702 0 : case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: return "CUDA_ERROR_PEER_ACCESS_NOT_ENABLED";
703 0 : case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: return "CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE";
704 0 : case CUDA_ERROR_CONTEXT_IS_DESTROYED: return "CUDA_ERROR_CONTEXT_IS_DESTROYED";
705 0 : case CUDA_ERROR_PEER_MEMORY_ALREADY_REGISTERED: return "CUDA_ERROR_PEER_MEMORY_ALREADY_REGISTERED";
706 0 : case CUDA_ERROR_PEER_MEMORY_NOT_REGISTERED: return "CUDA_ERROR_PEER_MEMORY_NOT_REGISTERED";
707 0 : case CUDA_ERROR_UNKNOWN: return "CUDA_ERROR_UNKNOWN";
708 : }
709 0 : return "<unknown>";
710 : }
711 :
712 : #endif // ((defined(WIN32) || defined(GPAC_CONFIG_LINUX) || defined(GPAC_CONFIG_DARWIN)) && !defined(GPAC_DISABLE_NVDEC))
|