I would like to be able to match OpenCL devices with GPUs in the system on multi-GPU systems identified by PCI IDs.
For example, if I have a system with multiple GPUs, possibly from different vendors, I can list the devices by enumerating the PCI bus. This gives me PCI vendor, device and bus IDs. If I choose one of these (GPU) PCI devices to use for OpenCL computation based on some selection criteria, how do I match it to the OpenCL device?
I can enumerate GPU devices in OpenCL using clGetDeviceIDs() but there is no obvious way to match OpenCL devices to PCI devices. The OpenCL function clGetDeviceInfo() provides access to the PCI vendor ID and device name but not PCI device or bus IDs. I could try to match the PCI device name with the OpenCL device name but it's possible that you have more than one of the same type of device and the names are not always the same anyway.
Why is this necessary? Say I know that program X is running CUDA or something else on GPU A. I want to avoid also using GPU A for an OpenCL operation so I choose GPU B. I then need to figure out which OpenCL device is GPU A and which is GPU B. PCI IDs seem to be the only consistent and cross platform way of identifying GPU devices.
BTW, the CUDA API does give you PCI, bus and slot IDs (CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID) but CUDA only works with NVidia devices.
Ideally I need a solution using either C or C++.