xopto.cl.clinfo module¶
This module provides functions for working with OpenCL resources.
info()
- lists the available OpenCL platforms and devicesall_devices()
- lists all the available OpenCL devicesgpus()
- lists the available OpenCL GPU devicescpus()
- lists the available OpenCL CPU devicesdevice_info()
- returns a dictionary with information on the specified devicedevice()
- find a device that matches the given search criteria
- all_devices(platform: Optional[str] = None, device: Optional[str] = None) → List[pyopencl._cl.Device][source]¶
Returns a list of all available OpenCl devices (a list of cl.Device). Devices can be filtered by the platform and device name. The matching of names is case insensitive.
- Parameters
platform (str) – If not None, the platform name of the returned devices must include this string (matching is case insensitive).
device (str) – If not None, the device name of the returned devices must include this string (matching is case insensitive).
- Returns
devices – List of found OpenCL devices.
- Return type
List[cl.Device]
- cpu(platform: Optional[str] = None, device: Optional[str] = None, index: int = 0) → pyopencl._cl.Device[source]¶
Returns an available OpenCL CPU device at the specified index. Devices can be filtered by the platform and device name. The matching of names is case insensitive.
- Parameters
platform (str) – If not None, the platform name of the returned devices must include this string (matching is case insensitive).
device (str) – If not None, the device name of the returned devices must include this string (matching is case insensitive).
index (int) – Sets the number of matching OpenCL devices that will be skipped during the search. Useful for hosts with multiple equal OpenCL devices. Default value is 0 (return the first matching OpenCL device).
- Returns
device – The first founfd OpenCL CPU device.
- Return type
cp.Device
- cpus(platform=None, device=None) → List[pyopencl._cl.Device][source]¶
Returns a list of all available OpenCL CPU devices (a list of pyopencl.Device). Devices can be filtered by the platform and device name. The matching of names is case insensitive.
- Parameters
platform (str) – If not None, the platform name of the returned devices must include this string (matching is case insensitive).
device (str) – If not None, the device name of the returned devices must include this string (matching is case insensitive).
- Returns
devices – List of found OpenCL CPU devices.
- Return type
List[cl.Device]
- device(what: Optional[str] = None, index: int = 0) → pyopencl._cl.Device[source]¶
Finds an OpenCl device according to the given keyword(s). The keywords are compared to the OpenCL device name, device vendor name and device platform name of each available OpenCL device.
- Parameters
device (str or list[str] or cl.Device) – A keyword or a list of keywords that are compared to the OpenCL device name, device vendor name and device platform name (comparison is case insensitive). The first OpenCL device that contains the keyword is returned if the index argument is set to 0. If this parameter is an instance of
pyopencl.Device
, the instance is immediately returned without any further action.index (int) – Sets the number of matching OpenCL devices that will be skipped during the search. Useful for hosts with multiple equal OpenCL devices. Default value is 0 (return the first matching OpenCL device).
what (str or a list/tuple of str) –
- Returns
dev – An OpenCl device if one that matches the keywords is found.
- Return type
cl.Device
Examples
Searches through all available OpenCL devices for the “amd” keyword. If none is found, the next keyword “nvidia” is used, and finally the “cpu” keyword is used if the first two keywords are not found in any of the available OpenCL device name, vendor name or platform name.
>>> import clinfo >>> dev = clinfo.device(["amd", "nvidia", "cpu"])
- device_extension(device: pyopencl._cl.Device, extension: str) → bool[source]¶
Checks if the OpenCL device supports the given extension. See https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/EXTENSION.html for a list of extensions supported by the OpenCl 1.2 language version. Some frequently used extensions:
- cl_khr_fp64
Double precision floating point.
- cl_khr_fp16
Half precision floating point.
- cl_khr_int64_base_atomics
64-bit integer atomic operations.
- cl_khr_int64_extended_atomics
64-bit integer extended atomic operations that include “min”, “max” “and”, “or” and “xor” operations.
- Parameters
device (cl.Device) – OpenCl device instance.
extension (str or list/tuple of str) – OpenCL extensions.
- Returns
available – True, if the extension is supported by the device, else False.
- Return type
bool or list of bool
- device_info(device: pyopencl._cl.Device) → dict[source]¶
Returns a dict with information on the given OpenCL device. the returned dict will have the following fields:
name: str
vendor: str
available: bool
extensions: List[str],
addressSpace: int,
platform: str,
maxConstKernelArgs: int,
maxKernelArgSize: int,
type: str,
globalMemory: int,
globalMemoryCacheSize: int,
maxAllocationSize: int,
localMemory: int,
constantMemory: int,
maxClkFrequency: int,
computeUnits: int,
maxWorkGroupSize: int
- Parameters
device (cl.Device) – An OpenCL device. Use the all_devices, gpus or cpus functions to get a list of all available OpenCl or just GPU or CPU devices, respectively.
- Returns
info – A dictionary with device information.
- Return type
dict
- gpu(platform=None, device=None, index=0) → pyopencl._cl.Device[source]¶
Returns an available OpenCl GPU device at the specified index. Devices can be filtered by the platform and device name. The matching of names is case insensitive.
- Parameters
platform (str) – If not None, the platform name of the returned devices must include this string (matching is case insensitive).
device (str) – If not None, the device name of the returned devices must include this string (matching is case insensitive).
index (int) – Sets the number of matching OpenCL devices that will be skipped during the search. Useful for hosts with multiple equal OpenCL devices. Default value is 0 (return the first matching OpenCL device).
- Returns
device – The first founfd OpenCL GPU device.
- Return type
cl.Device
- gpus(platform: Optional[str] = None, device: Optional[str] = None) → List[pyopencl._cl.Device][source]¶
Returns a list of all available OpenCl GPU devices (a list of cl.Device). Devices can be filtered by the platform and device name. The matching of names is case insensitive.
- Parameters
platform (str) – If not None, the platform name of the returned devices must include this string (matching is case insensitive).
device (str) – If not None, the device name of the returned devices must include this string (matching is case insensitive).
- Returns
devices – List of found OpenCL GPU devices.
- Return type
List[cl.Device]
- info(show: bool = True, devices: Optional[list] = None) → str[source]¶
Returns a string descriptor of all installed OpenCl devices.
- Parameters
show (bool) – If set to True, the information is displayed on screen.
devices (list[cl.Device]) – List of OpenCL devices or None. If None (default), all OpenCL devices are listed.
- Returns
descriptor – If parameter show is False, a string descriptor is returned, otherwise the information is displayed on screen.
- Return type
str
Examples
Dispalys information of all available OpenCL devices.
>>> import clinfo >>> clinfo.info()