我正在动态加载cudart(Cuda运行时库)以仅访问cudaGetDeviceProperties
函数。这个需要两个参数:
cudaDeviceProp
结构; 我没有包含cuda_runtime.h
标题,以免得到我不想使用的额外常量,宏,枚举,类......
但是,我需要cudaDeviceProp
结构。有没有办法在没有重新定义的情况下获得它?我写了以下代码:
struct cudaDeviceProp;
class CudaRTGPUInfoDL
{
typedef int(*CudaDriverVersion)(int*);
typedef int(*CudaRunTimeVersion)(int*);
typedef int(*CudaDeviceProperties)(cudaDeviceProp*,int);
public:
struct Properties
{
char name[256]; /**< ASCII string identifying device */
size_t totalGlobalMem; /**< Global memory available on device in bytes */
size_t sharedMemPerBlock; /**< Shared memory available per block in bytes */
int regsPerBlock; /**< 32-bit registers available per block */
int warpSize; /**< Warp size in threads */
size_t memPitch; /**< Maximum pitch in bytes allowed by memory copies */
/*... Tons of members follow..*/
};
public:
CudaRTGPUInfoDL();
~CudaRTGPUInfoDL();
int getCudaDriverVersion();
int getCudaRunTimeVersion();
const Properties& getCudaDeviceProperties();
private:
QLibrary library;
private:
CudaDriverVersion cuDriverVer;
CudaRunTimeVersion cuRTVer;
CudaDeviceProperties cuDeviceProp;
Properties properties;
};
每个人都可以看到,我只是简单地“复制粘贴”了结构的声明。
为了获得GPU属性,我只使用这个方法:
const CudaRTGPUInfoDL::Properties& CudaRTGPUInfoDL::getCudaDeviceProperties()
{
// Unsafe but needed.
cuDeviceProp(reinterpret_cast<cudaDeviceProp*>(&properties), 0);
return properties;
}
感谢您的回答。
答案 0 :(得分:2)
如果您需要完整的结构,您应该定义它(可能包括适当的标题)。
如果您只是要传递引用或指针,例如在您显示的方法中,那么它不需要完整,只能向前声明:
class cudaDeviceProp;