Prefer to read without ads? Become a member — from $10/month — and support the work. Already a member? Log in to read ad-free on this device.

A.3 Driver API facilities

chDrv.h contains some useful facilities for driver API developers: the chCUDADevice() class simplifies management of devices and contexts, and the loadModuleFromFile() method simplifies the creation of a module from a .cubin or .ptx file.

In addition, the chGetErrorString() function passes back a read-only string corresponding to an error value. Besides implementing this function for the driver API’s CUresult type, a specialization of chGetErrorString() also wraps the CUDA runtime’s cudaGetErrorString() function.

class chCUDADevice{public:    chCUDADevice();    virtual ~chCUDADevice();     CUresult Initialize(         int ordinal,         list<string>& moduleList,        unsigned int Flags = 0,        unsigned int numOptions = 0,        CUjit_option *options = NULL,        void **optionValues = NULL );    CUresult loadModuleFromFile(         CUmodule *pModule,        string fileName,        unsigned int numOptions = 0,        CUjit_option *options = NULL,        void **optionValues = NULL );     CUdevice device() const { return m_device; }    CUcontext context() const { return m_context; }    CUmodule module( string s ) const { return (*m_modules.find(s)).second; } private:    CUdevice m_device;    CUcontext m_context;    map<string, CUmodule> m_modules; };
Listing A-1.chCUDADevice class. (source on GitHub)