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

get_kernels()[source]

return the dictionary with all kernels

get_kernel(name)[source]

get a kernel from its name

max_workgroup_size(kernel_name)[source]

Retrieve the compile time max_workgroup_size 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

Parameters:
  • 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_to_cl_mem(parrays)[source]

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
check_workgroup_size(kernel_name)[source]

Calculate the maximum workgroup size from given kernel after compilation

free_buffers()[source]

free all device.memory allocated on the device

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

Call the OpenCL compiler

Parameters:
  • kernel_files – list of path to the kernel (by default use the one declared in the class)
  • compile_options – string of compile options
free_kernels()[source]

Free all kernels

set_profiling(value=True)[source]

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.

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

Allocate an OpenCL image (“texture”).

Parameters:
  • shape – 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 – force the image to be 1D if the shape has only one dim
transfer_to_texture(arr, tex_ref)[source]

Transfer an array to a texture.

Parameters:
  • arr – Input array. Can be a numpy array or a pyopencl array.
  • tex_ref – texture reference (pyopencl._cl.Image).
log_profile()[source]

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

reset_log()[source]

Resets the profiling timers

x87_volatile_option
get_compiler_options(x87_volatile=False)[source]

Provide the default OpenCL compiler options

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