processing: Processing

Common OpenCL abstract base classe for different processing

class KernelContainer(program)[source]

Bases: object

Those object holds a copy of all kernels accessible as attributes


return the dictionary with all kernels


get a kernel from its name


Retrieve the compile time WORK_GROUP_SIZE for a given kernel


Retrieve the compile time PREFERRED_WORK_GROUP_SIZE_MULTIPLE for a given kernel

class OpenclProcessing(ctx=None, devicetype='all', platformid=None, deviceid=None, block_size=None, memory=None, profile=False)[source]

Bases: object

Abstract class for different types of OpenCL processing.

This class provides: * Generation of the context, queues, profiling mode * Additional function to allocate/free all buffers declared as static attributes of the class * Functions to compile kernels, cache them and clean them * helper functions to clone the object

buffers = [BufferDescription(name='output', size=10, dtype=<class 'numpy.float32'>, flags=None)]
kernel_files = []
allocate_buffers(buffers=None, use_array=False)[source]

Allocate OpenCL buffers required for a specific configuration

  • buffers – a list of BufferDescriptions, leave to None for paramatrized buffers.
  • use_array – allocate memory as pyopencl.array.Array instead of pyopencl.Buffer

Note that an OpenCL context also requires some memory, as well as Event and other OpenCL functionalities which cannot and are not taken into account here. The memory required by a context varies depending on the device. Typical for GTX580 is 65Mb but for a 9300m is ~15Mb In addition, a GPU will always have at least 3-5Mb of memory in use. Unfortunately, OpenCL does NOT have a built-in way to check the actual free memory on a device, only the total memory.


Add pyopencl.array, which are allocated by pyopencl, to self.cl_mem. This should be used before calling allocate_buffers().

Parameters:parrays – a dictionary of pyopencl.array.Array or pyopencl.Buffer

Calculate the maximum workgroup size from given kernel after compilation


free all device.memory allocated on the device

compile_kernels(kernel_files=None, compile_options=None)[source]

Call the OpenCL compiler

  • kernel_files – list of path to the kernel (by default use the one declared in the class)
  • compile_options – string of compile options

Free all kernels


Switch On/Off the profiling flag of the command queue to allow debugging

Parameters:value – set to True to enable profiling, or to False to disable it. Without profiling, the processing is marginally faster

Profiling information can then be retrieved with the ‘log_profile’ method

profile_add(event, desc)[source]

Add an OpenCL event to the events lists, if profiling is enabled.

  • event – silx.opencl.processing.EventDescription.
  • desc – event description
allocate_texture(shape, hostbuf=None, support_1D=False)[source]
transfer_to_texture(arr, tex_ref)[source]

Transfer an array to a texture.

  • arr – Input array. Can be a numpy array or a pyopencl array.
  • tex_ref – texture reference (pyopencl._cl.Image).

If we are in profiling mode, prints out all timing for every single OpenCL call

Parameters:stats – if True, prints the statistics on each kernel instead of all execution timings
Returns:list of lines to print

Resets the profiling timers


Provide the default OpenCL compiler options

Parameters:x87_volatile – needed for Kahan summation
Returns:string with compiler option