Skip to content

nabu.opencl.utils

source module nabu.opencl.utils

Functions

  • get_opencl_devices List available OpenCL devices.

  • usable_opencl_devices Test the available OpenCL platforms/devices.

  • detect_opencl_gpus Get the available OpenCL-compatible GPUs.

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

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

  • get_opencl_context Create an OpenCL context. Please refer to 'get_opencl_devices' documentation

  • replace_array_memory 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.

  • pick_opencl_cpu_platform 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.

  • allocate_texture Allocate an OpenCL image ("texture").

  • check_textures_availability Check whether textures are supported on the current OpenCL context.

  • copy_to_texture

source get_opencl_devices(device_type, vendor=None, name=None, order_by='global_mem_size', exclude_platforms=None, exclude_vendors=None, prefer_GPU=True)

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 pyopencl.Device List of OpenCL devices matching the criteria, and ordered by the 'order_by' parameter. The list may be empty.

source usable_opencl_devices()

Test the available OpenCL platforms/devices.

Returns

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

source detect_opencl_gpus()

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.

source collect_opencl_gpus()

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

source collect_opencl_cpus()

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

source get_opencl_context(device_type, **kwargs)

Create an OpenCL context. Please refer to 'get_opencl_devices' documentation

Raises

  • RuntimeError

source replace_array_memory(arr, new_shape)

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.

source pick_opencl_cpu_platform(opencl_cpus)

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 : dict A dictionary describing the CPU.

Raises

  • ValueError

source allocate_texture(ctx, shape, support_1D=False)

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

source check_textures_availability(ctx)

Check whether textures are supported on the current OpenCL context.

source copy_to_texture(queue, dst_texture, src_array, dtype=np.float32)

Raises

  • TypeError