XLL+ Class Library (7.0)

Working without CUDA

You should consider how to handle the situation where there is no appropriate GPU available. There are several reasons why you might include a non-GPU alternative:

If you decide to support a non-GPU version, you should provide a function that tests for the presence and capabilities of a GPU, such as the following:

CopyC++
bool IsGpuAvailable(bool doublePrecisionRequired)
{
    cudaError_t cudaResult;
    struct cudaDeviceProp deviceProperties;

    // Get device properties
    cudaResult = cudaGetDeviceProperties(&deviceProperties, 0);
    if (cudaResult != cudaSuccess)
    {
        return false;
    }

    // Check precision is valid 
    unsigned int deviceVersion = deviceProperties.major * 10 + deviceProperties.minor;
    if (doublePrecisionRequired && (deviceVersion < 13))
    {
        return false;
    }    

    return true;
}

Next: Floating point types >>