nabu.opencl.utils module

nabu.opencl.utils.get_opencl_devices(device_type, vendor=None, name=None, order_by='global_mem_size', exclude_platforms=None, exclude_vendors=None, prefer_GPU=True)[source]

List available OpenCL devices.

Parameters:
  • device_type (str) – Type of device, can be “CPU”, “GPU” or “all”.

  • vendor (str, optional) – Filter devices by vendor, eg. “NVIDIA”

  • name (Filter devices by names, eg. "GeForce RTX 3080") –

  • order_by (str, optional) – Order results in decreasing order of this value. Default is to sort by global memory size.

  • exclude_platforms (str, optional) – Platforms to exclude, eg. “Portable Computing Language”

  • exclude_vendors (str, optional) – Vendors to be excluded

  • prefer_GPU (bool, optional) – Whether to put GPUs on top of the returned list, regardless of the “order_by” parameter. This can be useful when sorting by global memory size, as CPUs often have a bigger memory size.

Returns:

devices – List of OpenCL devices matching the criteria, and ordered by the ‘order_by’ parameter. The list may be empty.

Return type:

list of pyopencl.Device

nabu.opencl.utils.usable_opencl_devices()[source]

Test the available OpenCL platforms/devices.

Returns:

platforms – Dictionary where the key is the platform name, and the value is a list of silx.opencl.common.Device object.

Return type:

dict

nabu.opencl.utils.detect_opencl_gpus()[source]

Get the available OpenCL-compatible GPUs.

Returns:

  • gpus (dict) – Nested dictionary where the keys are OpenCL platform names, values are dictionary of GPU IDs and silx.opencl.common.Device object.

  • error_msg (str) – In the case where there is an error, the message is returned in this item. Otherwise, it is a None object.

nabu.opencl.utils.collect_opencl_gpus()[source]

Return a dictionary of platforms and brief description of each OpenCL-compatible GPU with a few fields

nabu.opencl.utils.collect_opencl_cpus()[source]

Return a dictionary of platforms and brief description of each OpenCL-compatible CPU with a few fields

nabu.opencl.utils.get_opencl_context(device_type, **kwargs)[source]

Create an OpenCL context. Please refer to ‘get_opencl_devices’ documentation

nabu.opencl.utils.replace_array_memory(arr, new_shape)[source]

Replace the underlying buffer data of a pyopencl.array.Array. This function is dangerous ! It should merely be used to clear memory, the array should not be used afterwise.

nabu.opencl.utils.pick_opencl_cpu_platform(opencl_cpus)[source]

Pick the best OpenCL implementation for the opencl cpu. This function assume that there is only one opencl-enabled CPU on the current machine, but there might be several OpenCL implementations/vendors.

Parameters:

opencl_cpus (dict) – Dictionary with the available opencl-enabled CPUs. Usually obtained with collect_opencl_cpus().

Returns:

cpu – A dictionary describing the CPU.

Return type:

dict

nabu.opencl.utils.allocate_texture(ctx, shape, support_1D=False)[source]

Allocate an OpenCL image (“texture”).

Parameters:
  • ctx (OpenCL context) – OpenCL context

  • shape (tuple of int) – Shape of the image. Note that pyopencl and OpenCL < 1.2 do not support 1D images, so 1D images are handled as 2D with one row

  • support_1D (bool, optional) – force the image to be 1D if the shape has only one dim

nabu.opencl.utils.check_textures_availability(ctx)[source]

Check whether textures are supported on the current OpenCL context.

nabu.opencl.utils.copy_to_texture(queue, dst_texture, src_array, dtype=<class 'numpy.float32'>)[source]