retrieve opencl platform that match the opengl one

Started by
4 comments, last by Malek hej 5 years, 4 months ago

Hello !

I have two gpu on my computer, one from my cpu and another one from my graphic card.

I am trying to use the opengl/opencl interop capabilities. But I am stuck at the creation of the opencl context, I don't know how to identify which platform / device of the two one is used by opengl.

In the above code, which fonction should I use in the test "DEVICE MATCHING OPENGL ONE" to test if the device is the one used by OpenGL, or what should I do to test if the platform_id is the good one ? 


sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
sf::Window window(sf::VideoMode(2048, 1024), "GAME",
        sf::Style::Fullscreen, settings);

glewInit();

cl_platform_id platform_ids[16] = { NULL };
cl_device_id device_id = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
    
cl_platform_id platform_id = 0;
cl_int ret = clGetPlatformIDs(_countof(platform_ids), platform_ids,
            &ret_num_platforms);

size_t n = 0;

cl_context_properties props[] = { CL_GL_CONTEXT_KHR,
    (cl_context_properties) wglGetCurrentContext(), CL_WGL_HDC_KHR,
    (cl_context_properties) wglGetCurrentDC(), CL_CONTEXT_PLATFORM,
    (cl_context_properties) platform_id, 0 };

for (size_t i = 0; i < ret_num_platforms; ++i) {
    platform_id = platform_ids[i];
    cl_device_id curDevices_id[16];

        ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU,
                _countof(curDevices_id), curDevices_id, &ret_num_devices);

    for (cl_uint nDevices = 0; nDevices < ret_num_devices; ++nDevices) {
        cl_device_id curDevice_id = curDevices_id[nDevices];

        clGetGLContextInfoKHR_fn clGetGLContextInfo =
                reinterpret_cast<clGetGLContextInfoKHR_fn> 
                   (clGetExtensionFunctionAddressForPlatform(
                            platform_id, "clGetGLContextInfoKHR"));

        if (clGetGLContextInfo) {
            cl_device_id clGLDevice = 0;
            props[5] =
                    reinterpret_cast<cl_context_properties>(platform_id);
            clGetGLContextInfo(props,
                    CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,
                    sizeof(clGLDevice), &clGLDevice, &n);

            if (DEVICE MATCHING OPENGL ONE) {
                device_id = clGLDevice;
            }
        }
    }
    if (device_id) {
        break;
    }
}

cl_context context = clCreateContext(props, 1, &device_id, NULL, NULL,
        &ret);

Thanks for your future help!

Advertisement

Hi, @Alex Garcin

I have already answered you:


if (clGLDevice == curDevice_id) {
    device_id = clGLDevice;
    break;
}

does't it code work ?

Quote

or what should I do to test if the platform_id is the good one ?

You should choice the platform that supports GPU and can interop with OpenGL.

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms


clGLDevice == curDevice_id

This assertion is true for both the two platform. 

Each of the platform support GPU so how to get the one that is used by opengl ?

Hi @Alex Garcin,

14 hours ago, Alex Garcin said:


clGLDevice == curDevice_id

This assertion is true for both the two platform. 

Each of the platform support GPU so how to get the one that is used by opengl ?

How many OpenGL Contexts do you have ? I don't know how to create OpenGL context on GPU that is not connected to Monitor. How do you have more than one context on you system with single monitor ?

I have already answered, did you try it ? 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

jhbk

 

This topic is closed to new replies.

Advertisement