Dear people,
In our project we introduced OpenCL to accelerate the image analysis of OpenGL rendered images. This analysis was originally done on the CPU. Although the execution is much faster on the GPU than on the CPU, the main benefit, in our case, is the reduction in PCIe traffic. This is so because the image analysis only results in a few bytes of data (say, we need the pixel location of the brightest pixel).
To really benefit from the bandwidth reduction it is required that the OpenCL kernel runs on the same device as the OpenGL context. The issue that I have is that I don’t know which OpenCL platform_id and device_id I must select that corresponds with the device that OpenGL uses to render the image.
What I was/am looking for is an identifier that uniquely identifies a device and that is consistent over both OpenCL and OpenGL, say, the serial number of the GPU chip. But to no avail; I can get a vendor string in both OpenCL and OpenGL, but that is not enough, I can get a device name in both OpenCL and OpenGL, but the return a different string. And still there is the issue in case there are multiple identical cards in the system.
The only cumbersome mechanism I can think of now is:
create OpenGL context
create 2Mx2M pixel texture in the OpenGL context
for each (candidate) OpenCL device
create OpenCL context based on OpenGL context
create OpenCL image based on OpenGL texture
glFinish()
measture start_time
acquire OpenCL image // this is fast on the right device.
clFinish()
measure stop_time
end
The right device is the device with the smallest stop_time - start_time.
Is there someone that knows how to select the OpenCL platform and device such that the OpenCL context runs on the same device as the OpenGL context from which it is created?
Best regards,
Edwin