DriverAPI: Problem with cuDeviceTotalMem

Hello,

I’m trying to get the total amount of memory using the driver API in CUDA 4.0 in C#. with interop (Tesla C2075, 6GB)
Therefore I’m using the cuDeviceTotalMem function which I loaded using DllImport from nvcuda.dll.
The problem is now that the result is always 4,2GB. If I now switch to cuDeviceTotalMem_v2 everything works and the 6GB are returned in the bytes result parameter.
What happens here, can I still rely on all my DllImported methods, or do I have to switch every method to …_v2?

If I look at the code in cuda.h it seems that the problem should be solved by aliasing the cuDeviceTotalMem_v2 to cuDeviceTotalMem for example, but it doesn’t work:

#if defined(__CUDA_API_VERSION_INTERNAL) || __CUDA_API_VERSION >= 3020
#define cuDeviceTotalMem cuDeviceTotalMem_v2
#define cuCtxCreate cuCtxCreate_v2
#define cuModuleGetGlobal cuModuleGetGlobal_v2
#define cuMemGetInfo cuMemGetInfo_v2
#define cuMemAlloc cuMemAlloc_v2
#define cuMemAllocPitch cuMemAllocPitch_v2
#define cuMemFree cuMemFree_v2
#define cuMemGetAddressRange cuMemGetAddressRange_v2
#define cuMemAllocHost cuMemAllocHost_v2
#define cuMemHostGetDevicePointer cuMemHostGetDevicePointer_v2
#define cuMemcpyHtoD cuMemcpyHtoD_v2
#define cuMemcpyDtoH cuMemcpyDtoH_v2
#define cuMemcpyDtoD cuMemcpyDtoD_v2
#define cuMemcpyDtoA cuMemcpyDtoA_v2
#define cuMemcpyAtoD cuMemcpyAtoD_v2
#define cuMemcpyHtoA cuMemcpyHtoA_v2
#define cuMemcpyAtoH cuMemcpyAtoH_v2
#define cuMemcpyAtoA cuMemcpyAtoA_v2
#define cuMemcpyHtoAAsync cuMemcpyHtoAAsync_v2
#define cuMemcpyAtoHAsync cuMemcpyAtoHAsync_v2
#define cuMemcpy2D cuMemcpy2D_v2
#define cuMemcpy2DUnaligned cuMemcpy2DUnaligned_v2
#define cuMemcpy3D cuMemcpy3D_v2
#define cuMemcpyHtoDAsync cuMemcpyHtoDAsync_v2
#define cuMemcpyDtoHAsync cuMemcpyDtoHAsync_v2
#define cuMemcpyDtoDAsync cuMemcpyDtoDAsync_v2
#define cuMemcpy2DAsync cuMemcpy2DAsync_v2
#define cuMemcpy3DAsync cuMemcpy3DAsync_v2
#define cuMemsetD8 cuMemsetD8_v2
#define cuMemsetD16 cuMemsetD16_v2
#define cuMemsetD32 cuMemsetD32_v2
#define cuMemsetD2D8 cuMemsetD2D8_v2
#define cuMemsetD2D16 cuMemsetD2D16_v2
#define cuMemsetD2D32 cuMemsetD2D32_v2
#define cuArrayCreate cuArrayCreate_v2
#define cuArrayGetDescriptor cuArrayGetDescriptor_v2
#define cuArray3DCreate cuArray3DCreate_v2
#define cuArray3DGetDescriptor cuArray3DGetDescriptor_v2
#define cuTexRefSetAddress cuTexRefSetAddress_v2
#define cuTexRefSetAddress2D cuTexRefSetAddress2D_v2
#define cuTexRefGetAddress cuTexRefGetAddress_v2
#define cuGraphicsResourceGetMappedPointer cuGraphicsResourceGetMappedPointer_v2
#endif /* __CUDA_API_VERSION_INTERNAL || __CUDA_API_VERSION >= 3020 */

Thanks
Martin

You need to use the latest version for all function calls. Most of the time that’s a v2, we might have a v3 sometime though (if we don’t already). You can’t really mix and match.

Hi tmurray,

thanks for your answer, but doesn’t the code in my explanation show that the _v2 or even _v3 versions are aliased to the original method without _vx?

Thanks

Martin

I had the same issue and wrote the follwong:

#define   cuda_text( name )   #name
cuda_text( cuDeviceTotalMem )

The #define cuDeviceTotalMem cuDeviceTotalMem_v2 in the header means you end up with a string of “cuDeviceTotalMem_v2”