问题
Is there a solution to restrict the used number of GPUs for AMD OpenCL platforms? For NVIDIA platforms one can simply set the environment variable CUDA_VISIBLE_DEVICES
to limit the set of GPUs available to OpenCL.
EDIT: I know, that I can create a context with a reduced set of devices. However, I am looking for ways to control the number of devices for the OpenCL platform from "outside".
回答1:
AMD have the GPU_DEVICE_ORDINAL environment variable for both Windows and Linux. This allows you to specify the indices of the GPUs that you want to be visible from your OpenCL application. For example:
jprice@nowai:~/benchmark$ python benchmark.py -clinfo
Platform 0: AMD Accelerated Parallel Processing
-> Device 0: Tahiti
-> Device 1: Tahiti
-> Device 2: Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
jprice@nowai:~/benchmark$ export GPU_DEVICE_ORDINAL=0
jprice@nowai:~/benchmark$ python benchmark.py -clinfo
Platform 0: AMD Accelerated Parallel Processing
-> Device 0: Tahiti
-> Device 1: Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
A more detailed description can be found in the AMD APP OpenCL Programming Guide (currently in section 2.4.3 "Masking Visible Devices"): http://developer.amd.com/wordpress/media/2013/07/AMD_Accelerated_Parallel_Processing_OpenCL_Programming_Guide-rev-2.7.pdf
回答2:
OpenCL host APIs allow you to specify the the the number of devices when you get the device ids list
_int clGetDeviceIDs(
cl_platform_id platform,
cl_device_type device_type,
cl_uint num_entries, // Controls the minimum number of devices
cl_device_id *devices,
cl_uint *num_devices)
The device id pointer *devices can be used to create the context with a specific number of devices.
Here is what the spec says
num_entries is the number of cl_device entries that can be added to devices. If devices is not NULL, the num_entries must be greater than zero. devices returns a list of OpenCL devices found. The cl_device_id values returned in devices can be used to identify a specific OpenCL device. If devices argument is NULL, this argument is ignored. The number of OpenCL devices returned is the minimum of the value specified by num_entries or the number of OpenCL devices whose type matches device_type. num_devices returns the number of OpenCL devices available that match device_type. If num_devices is NULL, this argument is ignored
cl_context clCreateContext(
const cl_context_properties *properties,
cl_uint num_devices, // Number of devices
const cl_device_id *devices,
(voidCL_CALLBACK *pfn_notify) (
const char *errinfo,
const void *private_info, size_t cb,
void *user_data
),
void *user_data,
cl_int *errcode_ret)
Each device is then addressed through its own device queue.
回答3:
There is not a portable solution defined by the OpenCL specification.
NVIDIA has the solution you mentioned. I don't think AMD has a standard; your OpenCL programs will have to come up with a way to share the available devices.
Note that AMD does have OpenCL extensions (some of which have become more official in OpenCL 1.2) for "device fission" which is used for splitting up a single device among multiple programs (but that is different than what you are asking).
来源:https://stackoverflow.com/questions/14380927/restrict-number-of-gpus-for-amd-opencl