Take the 2-minute tour ×

Assuming I compile a program which makes use of the CUDA Toolkit and I run the program on hardware that does not support the required compute capability or maybe doesn't even have an NVIDIA GPU supporting the CUDA interface, how do I know from a programming-level? In order to fall back on CPU procedures or show error-messages.

share|improve this question
add comment

1 Answer

If you have the CUDA Toolkit with samples installed already, I suggest that you look at the deviceQuery project. This shows an example on how to query the device for attributes such as the Capability Major/Minor version number.

Short snippet attached:

    cudaDeviceProp deviceProp;
    cudaGetDeviceProperties(&deviceProp, dev);

    printf("\nDevice %d: \"%s\"\n", dev, deviceProp.name);

    // Console log
    printf("  CUDA Driver Version / Runtime Version          %d.%d / %d.%d\n", driverVersion/1000, (driverVersion%100)/10, runtimeVersion/1000, (runtimeVersion%100)/10);
    printf("  CUDA Capability Major/Minor version number:    %d.%d\n", deviceProp.major, deviceProp.minor);

As for if the the system doesn't have a GPU, you could use the code snippet below although I believe you need to have static libraries at that point.

int deviceCount = 0;
cudaError_t error_id = cudaGetDeviceCount(&deviceCount);

if (error_id != cudaSuccess)
    printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id));

if (deviceCount == 0)
    printf("There are no available device(s) that support CUDA\n");
    printf("Detected %d CUDA Capable device(s)\n", deviceCount);
share|improve this answer
You don't need static libraries, but you do need to distribute the cudart DLL/SO with your app. The EULA specifically allows redistribution for this purpose. –  Tom Feb 14 '13 at 7:54
add comment

Your Answer


