Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
CudaDriverLoader Class Reference

Singleton class that dynamically loads libcuda.so (Linux) or nvcuda.dll (Windows) at runtime. More...

#include <CudaDriverLoader.h>

Collaboration diagram for CudaDriverLoader:
Collaboration graph

Public Member Functions

 CudaDriverLoader (const CudaDriverLoader &)=delete
 
CudaDriverLoaderoperator= (const CudaDriverLoader &)=delete
 
bool isAvailable () const
 
const std::string & getErrorMessage () const
 

Static Public Member Functions

static CudaDriverLoadergetInstance ()
 

Public Attributes

CUresult(* cuInit )(unsigned int Flags) = nullptr
 
CUresult(* cuDeviceGet )(CUdevice *device, int ordinal) = nullptr
 
CUresult(* cuDeviceGetCount )(int *count) = nullptr
 
CUresult(* cuDeviceGetName )(char *name, int len, CUdevice dev) = nullptr
 
CUresult(* cuCtxCreate )(CUcontext *pctx, unsigned int flags, CUdevice dev) = nullptr
 
CUresult(* cuCtxDestroy )(CUcontext ctx) = nullptr
 
CUresult(* cuCtxPushCurrent )(CUcontext ctx) = nullptr
 
CUresult(* cuCtxPopCurrent )(CUcontext *pctx) = nullptr
 
CUresult(* cuCtxSynchronize )(void) = nullptr
 
CUresult(* cuDevicePrimaryCtxRetain )(CUcontext *pctx, CUdevice dev) = nullptr
 
CUresult(* cuDevicePrimaryCtxRelease )(CUdevice dev) = nullptr
 
CUresult(* cuMemAlloc )(CUdeviceptr *dptr, size_t bytesize) = nullptr
 
CUresult(* cuMemAllocPitch )(CUdeviceptr *dptr, size_t *pPitch, size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes) = nullptr
 
CUresult(* cuMemFree )(CUdeviceptr dptr) = nullptr
 
CUresult(* cuMemcpy2D )(const CUDA_MEMCPY2D *pCopy) = nullptr
 
CUresult(* cuMemcpy2DAsync )(const CUDA_MEMCPY2D *pCopy, CUstream hStream) = nullptr
 
CUresult(* cuStreamCreate )(CUstream *phStream, unsigned int Flags) = nullptr
 
CUresult(* cuStreamDestroy )(CUstream hStream) = nullptr
 
CUresult(* cuStreamSynchronize )(CUstream hStream) = nullptr
 
CUresult(* cuGraphicsEGLRegisterImage )(CUgraphicsResource *pCudaResource, EGLImageKHR image, unsigned int flags) = nullptr
 
CUresult(* cuGraphicsResourceGetMappedEglFrame )(CUeglFrame *eglFrame, CUgraphicsResource resource, unsigned int index, unsigned int mipLevel) = nullptr
 
CUresult(* cuGraphicsUnregisterResource )(CUgraphicsResource resource) = nullptr
 
CUresult(* cuGetErrorName )(CUresult error, const char **pStr) = nullptr
 
CUresult(* cuGetErrorString )(CUresult error, const char **pStr) = nullptr
 

Private Member Functions

 CudaDriverLoader ()
 
 ~CudaDriverLoader ()
 
template<typename FuncPtr >
void loadSymbol (FuncPtr &funcPtr, const char *symbolName)
 

Private Attributes

void * libHandle = nullptr
 
std::string errorMessage
 

Detailed Description

Singleton class that dynamically loads libcuda.so (Linux) or nvcuda.dll (Windows) at runtime.

This allows the executable to start even when the CUDA driver is not available. When GPU is not present (e.g., GitHub CI runners), the library fails to load gracefully, and isAvailable() returns false. Modules requiring CUDA can check availability and throw appropriate exceptions.

Platform-specific behavior:

  • Linux: Uses dlopen/dlsym to load libcuda.so.1
  • Windows: Uses LoadLibrary/GetProcAddress to load nvcuda.dll

Usage: auto& loader = CudaDriverLoader::getInstance(); if (!loader.isAvailable()) { throw AIPException(AIP_NOTEXEPCTED, "CUDA driver not available"); } CUresult result = loader.cuInit(0);

Constructor & Destructor Documentation

◆ CudaDriverLoader() [1/2]

CudaDriverLoader::CudaDriverLoader ( const CudaDriverLoader & )
delete

◆ CudaDriverLoader() [2/2]

CudaDriverLoader::CudaDriverLoader ( )
private
Here is the call graph for this function:

◆ ~CudaDriverLoader()

CudaDriverLoader::~CudaDriverLoader ( )
private

Member Function Documentation

◆ getErrorMessage()

const std::string & CudaDriverLoader::getErrorMessage ( ) const
inline

◆ getInstance()

static CudaDriverLoader & CudaDriverLoader::getInstance ( )
inlinestatic
Here is the caller graph for this function:

◆ isAvailable()

bool CudaDriverLoader::isAvailable ( ) const
inline

◆ loadSymbol()

template<typename FuncPtr >
void CudaDriverLoader::loadSymbol ( FuncPtr & funcPtr,
const char * symbolName )
inlineprivate
Here is the caller graph for this function:

◆ operator=()

CudaDriverLoader & CudaDriverLoader::operator= ( const CudaDriverLoader & )
delete

Member Data Documentation

◆ cuCtxCreate

CUresult(* CudaDriverLoader::cuCtxCreate) (CUcontext *pctx, unsigned int flags, CUdevice dev) = nullptr

◆ cuCtxDestroy

CUresult(* CudaDriverLoader::cuCtxDestroy) (CUcontext ctx) = nullptr

◆ cuCtxPopCurrent

CUresult(* CudaDriverLoader::cuCtxPopCurrent) (CUcontext *pctx) = nullptr

◆ cuCtxPushCurrent

CUresult(* CudaDriverLoader::cuCtxPushCurrent) (CUcontext ctx) = nullptr

◆ cuCtxSynchronize

CUresult(* CudaDriverLoader::cuCtxSynchronize) (void) = nullptr

◆ cuDeviceGet

CUresult(* CudaDriverLoader::cuDeviceGet) (CUdevice *device, int ordinal) = nullptr

◆ cuDeviceGetCount

CUresult(* CudaDriverLoader::cuDeviceGetCount) (int *count) = nullptr

◆ cuDeviceGetName

CUresult(* CudaDriverLoader::cuDeviceGetName) (char *name, int len, CUdevice dev) = nullptr

◆ cuDevicePrimaryCtxRelease

CUresult(* CudaDriverLoader::cuDevicePrimaryCtxRelease) (CUdevice dev) = nullptr

◆ cuDevicePrimaryCtxRetain

CUresult(* CudaDriverLoader::cuDevicePrimaryCtxRetain) (CUcontext *pctx, CUdevice dev) = nullptr

◆ cuGetErrorName

CUresult(* CudaDriverLoader::cuGetErrorName) (CUresult error, const char **pStr) = nullptr

◆ cuGetErrorString

CUresult(* CudaDriverLoader::cuGetErrorString) (CUresult error, const char **pStr) = nullptr

◆ cuGraphicsEGLRegisterImage

CUresult(* CudaDriverLoader::cuGraphicsEGLRegisterImage) (CUgraphicsResource *pCudaResource, EGLImageKHR image, unsigned int flags) = nullptr

◆ cuGraphicsResourceGetMappedEglFrame

CUresult(* CudaDriverLoader::cuGraphicsResourceGetMappedEglFrame) (CUeglFrame *eglFrame, CUgraphicsResource resource, unsigned int index, unsigned int mipLevel) = nullptr

◆ cuGraphicsUnregisterResource

CUresult(* CudaDriverLoader::cuGraphicsUnregisterResource) (CUgraphicsResource resource) = nullptr

◆ cuInit

CUresult(* CudaDriverLoader::cuInit) (unsigned int Flags) = nullptr

◆ cuMemAlloc

CUresult(* CudaDriverLoader::cuMemAlloc) (CUdeviceptr *dptr, size_t bytesize) = nullptr

◆ cuMemAllocPitch

CUresult(* CudaDriverLoader::cuMemAllocPitch) (CUdeviceptr *dptr, size_t *pPitch, size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes) = nullptr

◆ cuMemcpy2D

CUresult(* CudaDriverLoader::cuMemcpy2D) (const CUDA_MEMCPY2D *pCopy) = nullptr

◆ cuMemcpy2DAsync

CUresult(* CudaDriverLoader::cuMemcpy2DAsync) (const CUDA_MEMCPY2D *pCopy, CUstream hStream) = nullptr

◆ cuMemFree

CUresult(* CudaDriverLoader::cuMemFree) (CUdeviceptr dptr) = nullptr

◆ cuStreamCreate

CUresult(* CudaDriverLoader::cuStreamCreate) (CUstream *phStream, unsigned int Flags) = nullptr

◆ cuStreamDestroy

CUresult(* CudaDriverLoader::cuStreamDestroy) (CUstream hStream) = nullptr

◆ cuStreamSynchronize

CUresult(* CudaDriverLoader::cuStreamSynchronize) (CUstream hStream) = nullptr

◆ errorMessage

std::string CudaDriverLoader::errorMessage
private

◆ libHandle

void* CudaDriverLoader::libHandle = nullptr
private

The documentation for this class was generated from the following files: