Runtime-loaded CUDA driver-API table. Owns the libcuda handle. More...
Detailed Description
Runtime-loaded CUDA driver-API table. Owns the libcuda handle.
Usage: CudaFunctions cu; if(!cu.load()) { ...no CUDA driver available... } cu.init(0); // cuInit cu.deviceGet(...); cu.ctxSetCurrent(c);
One instance per consumer is fine — dlopen is refcounted by the loader, and the table itself is ~30 pointers. If a shared instance is desired later, swap to a singleton accessor without changing call sites.
Public Types | |
| using | FN_cuInit = CUresult(*)(unsigned int) |
| using | FN_cuDeviceGetCount = CUresult(*)(int *) |
| using | FN_cuDeviceGet = CUresult(*)(CUdevice *, int) |
| using | FN_cuDeviceGetAttribute = CUresult(*)(int *, CUdevice_attribute, CUdevice) |
| using | FN_cuDevicePrimaryCtxRetain = CUresult(*)(CUcontext *, CUdevice) |
| using | FN_cuDevicePrimaryCtxRelease = CUresult(*)(CUdevice) |
| using | FN_cuCtxSetCurrent = CUresult(*)(CUcontext) |
| using | FN_cuCtxGetDevice = CUresult(*)(CUdevice *) |
| using | FN_cuCtxPushCurrent = CUresult(*)(CUcontext) |
| using | FN_cuCtxPopCurrent = CUresult(*)(CUcontext *) |
| using | FN_cuStreamCreate = CUresult(*)(CUstream *, unsigned int) |
| using | FN_cuStreamDestroy = CUresult(*)(CUstream) |
| using | FN_cuStreamSynchronize = CUresult(*)(CUstream) |
| using | FN_cuGetErrorString = CUresult(*)(CUresult, const char **) |
| using | FN_cuGraphicsMapResources = CUresult(*)(unsigned int, CUgraphicsResource *, CUstream) |
| using | FN_cuGraphicsUnmapResources = CUresult(*)(unsigned int, CUgraphicsResource *, CUstream) |
| using | FN_cuGraphicsUnregisterResource = CUresult(*)(CUgraphicsResource) |
| using | FN_cuGraphicsResourceGetMappedPointer = CUresult(*)(CUdeviceptr *, size_t *, CUgraphicsResource) |
| using | FN_cuGraphicsGLRegisterBuffer = CUresult(*)(CUgraphicsResource *, unsigned int, unsigned int) |
| using | FN_cuGraphicsGLRegisterImage = CUresult(*)(CUgraphicsResource *, unsigned int, unsigned int, unsigned int) |
| using | FN_cuGraphicsSubResourceGetMappedArray = CUresult(*)(CUarray *, CUgraphicsResource, unsigned int, unsigned int) |
| using | FN_cuImportExternalMemory = CUresult(*)(CUexternalMemory *, const CUDA_EXTERNAL_MEMORY_HANDLE_DESC *) |
| using | FN_cuExternalMemoryGetMappedBuffer = CUresult(*)(CUdeviceptr *, CUexternalMemory, const CUDA_EXTERNAL_MEMORY_BUFFER_DESC *) |
| using | FN_cuExternalMemoryGetMappedMipmappedArray = CUresult(*)(CUmipmappedArray *, CUexternalMemory, const CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC *) |
| using | FN_cuMipmappedArrayGetLevel = CUresult(*)(CUarray *, CUmipmappedArray, unsigned int) |
| using | FN_cuMipmappedArrayDestroy = CUresult(*)(CUmipmappedArray) |
| using | FN_cuDestroyExternalMemory = CUresult(*)(CUexternalMemory) |
| using | FN_cuImportExternalSemaphore = CUresult(*)(CUexternalSemaphore *, const CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC *) |
| using | FN_cuWaitExternalSemaphoresAsync = CUresult(*)(const CUexternalSemaphore *, const CUDA_EXTERNAL_SEMAPHORE_WAIT_PARAMS *, unsigned int, CUstream) |
| using | FN_cuDestroyExternalSemaphore = CUresult(*)(CUexternalSemaphore) |
| using | FN_cuMemcpy2DAsync = CUresult(*)(const CUDA_MEMCPY2D *, CUstream) |
| using | FN_cuMemcpy2DUnaligned = CUresult(*)(const CUDA_MEMCPY2D *) |
| using | FN_cuMemcpyHtoD = CUresult(*)(CUdeviceptr, const void *, size_t) |
| using | FN_cuMemcpyDtoH = CUresult(*)(void *, CUdeviceptr, size_t) |
| using | FN_cuMemcpyDtoDAsync = CUresult(*)(CUdeviceptr, CUdeviceptr, size_t, CUstream) |
| using | FN_cuMemAlloc = CUresult(*)(CUdeviceptr *, size_t) |
| using | FN_cuMemFree = CUresult(*)(CUdeviceptr) |
| using | FN_cuMemCreate = CUresult(*)(CUmemGenericAllocationHandle *, size_t, const CUmemAllocationProp *, unsigned long long) |
| using | FN_cuMemAddressReserve = CUresult(*)(CUdeviceptr *, size_t, size_t, CUdeviceptr, unsigned long long) |
| using | FN_cuMemMap = CUresult(*)(CUdeviceptr, size_t, size_t, CUmemGenericAllocationHandle, unsigned long long) |
| using | FN_cuMemSetAccess = CUresult(*)(CUdeviceptr, size_t, const CUmemAccessDesc *, size_t) |
| using | FN_cuMemUnmap = CUresult(*)(CUdeviceptr, size_t) |
| using | FN_cuMemAddressFree = CUresult(*)(CUdeviceptr, size_t) |
| using | FN_cuMemRelease = CUresult(*)(CUmemGenericAllocationHandle) |
| using | FN_cuMemExportToShareableHandle = CUresult(*)(void *, CUmemGenericAllocationHandle, int, unsigned long long) |
| using | FN_cuMemGetAllocationGranularity = CUresult(*)(size_t *, const CUmemAllocationProp *, CUmemAllocationGranularity_flags) |
| using | FN_cuMemGetHandleForAddressRange = CUresult(*)(void *, CUdeviceptr, size_t, CUmemRangeHandleType, unsigned long long) |
| using | FN_cuPointerSetAttribute = CUresult(*)(const void *, int, CUdeviceptr) |
Public Member Functions | |
| bool | loaded () const noexcept |
| bool | load () |
| Load libcuda + resolve all symbols. Idempotent. | |
| bool | dmaBufExportSupported (CUdevice device) const noexcept |
| void | unload () noexcept |
| CudaFunctions (const CudaFunctions &)=delete | |
| CudaFunctions & | operator= (const CudaFunctions &)=delete |
Public Attributes | |
| void * | lib {} |
| FN_cuInit | init {} |
| FN_cuDeviceGetCount | deviceGetCount {} |
| FN_cuDeviceGet | deviceGet {} |
| FN_cuDeviceGetAttribute | deviceGetAttribute {} |
| FN_cuDevicePrimaryCtxRetain | primaryCtxRetain {} |
| FN_cuDevicePrimaryCtxRelease | primaryCtxRelease {} |
| FN_cuCtxSetCurrent | ctxSetCurrent {} |
| FN_cuCtxGetDevice | ctxGetDevice {} |
| FN_cuCtxPushCurrent | ctxPush {} |
| FN_cuCtxPopCurrent | ctxPop {} |
| FN_cuStreamCreate | streamCreate {} |
| FN_cuStreamDestroy | streamDestroy {} |
| FN_cuStreamSynchronize | streamSync {} |
| FN_cuGetErrorString | getErrorString {} |
| FN_cuGraphicsMapResources | graphicsMap {} |
| FN_cuGraphicsUnmapResources | graphicsUnmap {} |
| FN_cuGraphicsUnregisterResource | graphicsUnregister {} |
| FN_cuGraphicsResourceGetMappedPointer | graphicsGetMappedPointer {} |
| FN_cuGraphicsGLRegisterBuffer | graphicsGLRegisterBuffer {} |
| FN_cuGraphicsGLRegisterImage | graphicsGLRegisterImage {} |
| FN_cuGraphicsSubResourceGetMappedArray | graphicsSubResourceGetMappedArray {} |
| FN_cuImportExternalMemory | importExtMem {} |
| FN_cuExternalMemoryGetMappedBuffer | extMemGetMappedBuffer {} |
| FN_cuExternalMemoryGetMappedMipmappedArray | getMapArray {} |
| FN_cuMipmappedArrayGetLevel | getLevel {} |
| FN_cuMipmappedArrayDestroy | destroyMipArray {} |
| FN_cuDestroyExternalMemory | destroyExtMem {} |
| FN_cuImportExternalSemaphore | importExtSem {} |
| FN_cuWaitExternalSemaphoresAsync | waitExtSems {} |
| FN_cuDestroyExternalSemaphore | destroyExtSem {} |
| FN_cuMemcpy2DAsync | memcpy2DAsync {} |
| FN_cuMemcpy2DUnaligned | memcpy2DUnaligned {} |
| FN_cuMemcpyHtoD | memcpyHtoD {} |
| FN_cuMemcpyDtoH | memcpyDtoH {} |
| FN_cuMemcpyDtoDAsync | memcpyDtoDAsync {} |
| FN_cuMemAlloc | memAlloc {} |
| FN_cuMemFree | memFree {} |
| FN_cuMemCreate | memCreate {} |
| FN_cuMemAddressReserve | memAddressReserve {} |
| FN_cuMemMap | memMap {} |
| FN_cuMemSetAccess | memSetAccess {} |
| FN_cuMemUnmap | memUnmap {} |
| FN_cuMemAddressFree | memAddressFree {} |
| FN_cuMemRelease | memRelease {} |
| FN_cuMemExportToShareableHandle | memExportToShareableHandle {} |
| FN_cuMemGetAllocationGranularity | memGetGranularity {} |
| FN_cuMemGetHandleForAddressRange | memGetHandleForAddressRange {} |
| FN_cuPointerSetAttribute | pointerSetAttribute {} |
| bool | vmmSupported {} |
Member Typedef Documentation
◆ FN_cuMemGetHandleForAddressRange
| using score::gfx::CudaFunctions::FN_cuMemGetHandleForAddressRange = CUresult (*)(void*, CUdeviceptr, size_t, CUmemRangeHandleType, unsigned long long) |
Optional: export a mapped device VA range as a dma-buf fd (the cross-API handle type importable into Vulkan/GL as an aliasing image). Present in libcuda since 11.7, but only usable when the device reports CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED != 0 — otherwise it returns CUDA_ERROR_NOT_SUPPORTED (801). Null on very old drivers.
Member Function Documentation
◆ dmaBufExportSupported()
|
inlinenoexcept |
True when device can export a mapped VA range as a dma-buf fd via cuMemGetHandleForAddressRange (the CUDA→Vulkan/GL zero-copy aliasing route). This queries CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED; it is 0 on Turing/Ada Quadro and GeForce parts, so callers MUST check this and fall back to the bounce path — the export otherwise returns CUDA_ERROR_NOT_SUPPORTED. Requires a current context on the device.
◆ load()
|
inline |
Load libcuda + resolve all symbols. Idempotent.
- Returns
- true if the library opened and all REQUIRED symbols resolved. Optional symbols (D3D11/GL interop) may be null on systems that don't support them — check the corresponding pointer before use.
Member Data Documentation
◆ memExportToShareableHandle
| FN_cuMemExportToShareableHandle score::gfx::CudaFunctions::memExportToShareableHandle {} |
Optional (not part of the vmmSupported bundle): export a VMM allocation as an OS shareable handle (POSIX fd / NT handle) for Vulkan/D3D import. Null on very old drivers.
◆ vmmSupported
| bool score::gfx::CudaFunctions::vmmSupported {} |
True when every VMM entry point resolved. False on pre-CUDA-10.2 drivers; callers must check before calling memCreate et al.
The documentation for this struct was generated from the following file: