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 WORK_GROUP_SIZE for a given kernel

min_workgroup_size(kernel_name)[source]#

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 = [('output', 10, <class 'numpy.float32'>, None)]#
kernel_files = []#
check_textures_availability()[source]#
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 – pyopencl.NanyEvent.

  • desc – event description

profile_multi(event_lists)[source]#

Extract profiling info from several OpenCL event, if profiling is enabled.

Parameters:

event_lists – list of (“desc”, pyopencl.NanyEvent).

log_profile(stats=False)[source]#

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

reset_log()[source]#

Resets the profiling timers

allocate_texture(shape, hostbuf=None, support_1D=False)[source]#
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).

property 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