Visible to Intel only — GUID: yso1579037937509
Ixiasoft
Visible to Intel only — GUID: yso1579037937509
Ixiasoft
6.8. Sharing Multiple Devices Across Multiple Host Programs
You can then pass these devices to clCreateContext function where the devices are locked by that OpenCL program until it either calls clReleaseContext function or terminates.
Multiple processes or multiple trusted users can arbitrate between devices in a multi-device system using this locking mechanism. In case users have decided ahead of time which device (by name) each person uses, they can use clGetDeviceInfo function to select the cl_device_id with the name that a user is assigned to. To arbitrate more dynamically in case each of the N users want Di devices, use the following scheme:
- Each user queries the clGetDeviceIDs function to obtain a list of devices.
- Each user chooses Di devices (ideally randomly to minimize collisions) and passes those to the clCreateContext function.
It is possible that during step 2, another user may have already called clCreateContext function with that same device, in which case, the clCreateContext function call fails. The user should then repeat steps 2 (optionally changing the device selection) until it succeeds.
Consider the following example code snippet:
do {
for(i = num_devices - 1; i >= 0; i--) {
context = clCreateContext(0, 1, &(device_ids[i]), NULL, NULL, &status);
if (status != CL_SUCCESS) {
printf("Failed to get context with %d (error: %d), waiting\n", i, status
sleep(1);
} else {
device_id = device_ids[i];
break;
}
}
} while (status != CL_SUCCESS);
// Exit this loop only when we’ve succeeded in creating a context