Hello, NVIDIA CUDA community. I am trying to write a C# program that uses the CUDA runtime API to find CUDA-friendly GPUs and their information. In particular, I am trying to use the following commands:
-
cudaGetDeviceCount(int*)
-
cudaGetDeviceProperties(…, …)
-
cudaMemGetInfo(…, …)
-
cudaDeviceReset()
as described here: http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE. I’m trying to use these functions through the platform invoke (pinvoke) technique in C# in .NET 2013.
I’m having trouble figuring out the right function signatures/declarations to get the pinvoking to work though.
As an example, I’m trying the following
[DllImport("cudart64_75.dll")]
private static extern cudaError cudaGetDeviceCount(int* device);
public enum cudaError
{
/**
* The API call returned with no errors. In the case of query calls, this
* can also mean that the operation being queried is complete (see
* ::cudaEventQuery() and ::cudaStreamQuery()).
*/
cudaSuccess = 0,
/**
* The device function being invoked (usually via ::cudaLaunchKernel()) was not
* previously configured via the ::cudaConfigureCall() function.
*/
cudaErrorMissingConfiguration = 1,
// REST OF ENUMERATION EXCLUDED
}
public void TestFunction()
{
int a = 0;
int* devCount = &a;
cudaError rVal = cudaGetDeviceCount(devCount);
}
And I’m getting a BadImageFormation exception, with the info:
[i]An unhandled exception of type ‘System.BadImageFormatException’ occurred in CsGpuQuery.exe
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)[/i]
Any help would be greatly appreciated. In particular, I’m not sure what “host device” means in front of the function declarations here http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE, and how they relate to pinvoking.
Thanks and regards.