View Full Version : NVIDIA GTX 560M and clGetGLContextInfoKHR

10-15-2013, 06:17 PM
Hello forum,

I am working with the OpenCL 1.1 specification and i an having issue with the implementation of the functions mentioned above. Lets narrate the procedure i am trying to do :

1. At the beginning of the main application file , i am defining the following :

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#include <CL/cl.h>
#include <CL/cl_gl.h>
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)(
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);

// Rename references to this dynamically linked function to avoid
// collision with static link version
#define clGetGLContextInfoKHR clGetGLContextInfoKHR_proc
static clGetGLContextInfoKHR_fn clGetGLContextInfoKHR;

Then i am defining the context as follows:

cl_context_properties cps[] =
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
CL_CONTEXT_PLATFORM, (cl_context_properties)platform,

//re-initialize the properties if the platform is found
cl_context_properties *cprops = (NULL == platform) ? NULL : cps;

clGetGLContextInfoKHR = (clGetGLContextInfoKHR_fn) clGetExtensionFunctionAddress("clGetGLContextInfoKHR");

std::cout << "Failed to query proc address for clGetGLContextInfoKHR." << std::endl;

size_t deviceSize;

status = clGetGLContextInfoKHR(cps,CL_CURRENT_DEVICE_FOR_GL _CONTEXT_KHR,0,NULL,&deviceSize);

if(deviceSize == 0)
std::cout << "Current context does not support any device " << std::endl;

I am getting device size 0 which should not be. It should be 1.

Any hint on what i am missing ?



10-16-2013, 06:28 AM
According to OpenCL 1.1 specification, param_value_size cannot be 0. With CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, it must be equal to sizeof(cl_device_id). param_value can safely be a pointer to a cl_device_id variable because clGetGLContextInfoKHR returns at most one value.