clCreateContext() fails with MGPUs + OGL interop

When I try to create OpenCL context across multiple GPUs with OpenGL interop, it immediately fails. All these MGPU examples in SDKs don’t use OpenGL sharing and start crashing as well as soon as I add OGL inteop into them.

The problem appeared with the new GPU Computing SDK 4.0RC (previous versions of SDK don’t support new GPUs).

clCreateContext reports ‘invalid operation’ if I try to create a context for 4 GPUs with OGL interop (however it succeeds if I either remove OGL interop or create this context for any single GPU). According to documentation this error means that:

  • some of GPUs doesn’t support OGL sharing

  • driver implementation does not support sharing

However ogl sharing extension is reported for all GPUs and moreover I can successfully create a shared OGL context for each single GPU (even if this GPU is not the primary one).

Also when I use this code:


typedef CL_API_ENTRY cl_int (CL_API_CALL

	*P1)(const cl_context_properties *properties,

	cl_gl_context_info param_name,

	size_t param_value_size,

	void *param_value,

	size_t *param_value_size_ret);


	*myclGetGLContextInfoKHR)(const cl_context_properties *properties,

	cl_gl_context_info param_name,

	size_t param_value_size,

	void *param_value,

	size_t *param_value_size_ret)=NULL;


	cl_device_id cdDeviceID[1000]; 

	size_t size;

	ciErrNum = myclGetGLContextInfoKHR(props, CL_DEVICES_FOR_GL_CONTEXT_KHR, sizeof(cdDeviceID), cdDeviceID, &size); 

    oclCheckError(ciErrNum, CL_SUCCESS);


it reports that the number of such GPUs is 0. Does anyone have any success of using multiple GPUs with OGL sharing with GPU Computing SDK 4.0RC and dev drivers 270.32?

I’m going to bump this, because I have the same problem.

I have a GeForce GTX 690 (dual GPU) and an OpenCL program using OpenGL interop. I’m currently trying to extend the program from using just one of the devices to using both (still just one context). I too run in to the CL_INVALID_OPERATION when trying to create my context. Any news on the matter?

Try creating/setting the GL stuff before any CUDA call


If being restricted to C is not mandatory, I would highly advise using the C++ wrapper that is bundled with the AMD SDK (at least the newest version, since they are the ones developing it). It HIGHLY facilitates using OpenCL, making use of RAII so that you definately don’t leak handles which will cause problems on longer simulations.

And yes, you must create ALL OpenGL resources that you want to share before any OpenCL stuff. (Practically only context creation and stuff after that, but it’s better to do all inits in one place. initGL, then initCL.