Choose OpenCL platform and device corresponding to current active graphics card

I have a simple Win32 application performing some GPU computations with OpenCL and further displaying the results with OpenGL.

Given this OpenCL-OpenGL interop, how can I choose the right OpenCL platform and device? Meaning the platform and device corresponding to the currently active graphics card?

Calling EnumDisplayDevices would allow me to find a DeviceString for the active gpu device (by checking the DISPLAY_DEVICE_ACTIVE flag in StateFlags field), but this does not match the CL_DEVICE_NAME accesible through clGetDeviceInfo for a device. (In my case, DeviceString is “NVIDIA GeForce GTX 280” while CL_DEVICE_NAME returns “GeForce GTX 280”). Can I assume DeviceString always contains the vendor name before the device name?

Is there other solution than using platform specific calls?


+1 It would be great to have a flag available on clGetDeviceInfo for devices that are actually driving a display, either for openCL/OpenGL interop but also to automatically select devices that don’t drive any display on multi-GPU configuration!

Until then, another solution would be to temporary create an OpenGL context (I did this using a dummy win32 window and wglCreateContext) and call clGetGLContextInfoKHR for each platform until the function succeeds and the returned deviceID is != NULL.

Will have to try it, it could be fun to implement two multi-platform functions, one to have the OpenGL-enabled GPU, the other to obtain only the non-OpenGL GPU devices, it might simplify device selection!