Question

I'm working on a hybrid OpenCL application that has to decide at run time whether to use or not to use the GPU implementation.

Is there a cross platform (i.e. for intel, nvidia, and ati) way to dermine, whether the computer, where the application is running, has the opencl framework support, without crashing of the application? At the beginning I am only developing for the Windows platform.

#include <CL/cl.h>
#include <iostream>

int main() 
{
    std::cout << "Start cross paltform testing" << std::endl;
    cl_platform_id platform[1];
    clGetPlatformIDs(1, platform, 0);
    std::cout << "End cross paltform testing" << std::endl;
    return 0;
}

At the moment I get the error:

The application was unable to start correctly (0xc000007b)...

if I try to start it in the situation that I described above.

NB: Actually, at least for the nvidia it should be possible. I have tested oclDeviceQuery from the nvidia GPU SDK in this scenario and it works correctly. It is only necessary to copy the "opencl.dll" form Windows/System folder into the application folder. I have no idea why my app is crashing under the same circumstances.

Thank you in advance.

Was it helpful?

Solution

The OpenCL.dll is the same for all implementations, so instead of manually loading library as @talonmies proposed (which is better but more complex) you can just carry one with you. It just provides an interface to access installed platforms.

To check whether there is any platform installed, you should use

int main() 
{
    std::cout << "Start cross paltform testing" << std::endl;
    int num_platforms;
    cl_platform_id *platform;
    clGetPlatformIDs(0, NULL, &num_platforms);
    std::cout << "End cross paltform testing: " << num_platforms << " found" << std::endl;
    // Get platform IDs (not necessary right now, for future use)
    platform = new cl_platform_id[num_platforms];
    clGetPlatformIDs(num_platforms, platform, NULL);
    // ........
    delete platform;
    return 0;
}

since your code will say that everything is alright even if there is no OpenCL platform installed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top