Skip to main content
`Ctrl`+`K`

# `processing`: Processing

Common OpenCL abstract base classe for different processing

class KernelContainer(program)

  Bases: `object`

  Those object holds a copy of all kernels accessible as attributes

  get_kernels()

    return the dictionary with all kernels

  get_kernel(name)

    get a kernel from its name

  max_workgroup_size(kernel_name)

    Retrieve the compile time WORK_GROUP_SIZE for a given kernel

  min_workgroup_size(kernel_name)

    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)

  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()
  allocate_buffers(buffers=None, use_array=False)

    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)

    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)

    Calculate the maximum workgroup size from given kernel after compilation

  free_buffers()

    free all device.memory allocated on the device

  compile_kernels(kernel_files=None, compile_options=None)

    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()

    Free all kernels

  set_profiling(value=True)

    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)

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

    Parameters:

      - event – pyopencl.NanyEvent.

      - desc – event description

  profile_multi(event_lists)

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

    Parameters:

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

  log_profile(stats=False)

    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()

    Resets the profiling timers

  allocate_texture(shape, hostbuf=None, support_1D=False)
  transfer_to_texture(arr, tex_ref)

    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

    This enforces float32/64 operations to be performed actually with 32/64 bit precision and not larger (80 bits) as the x87 unit is capable of. This unit is used only with POCL driver when running on a 32 bits platform x86

  property apple_gpu_option

    This overwrites the preprocessor variable cl_khr_fp64 with the proper value, 0 or 1. On Apple GPU driver, this variable is wrongly set to 1 while the driver has no support for double precision and crashes the compilation. The value obtained from the driver is apparently correct

  get_compiler_options(x87_volatile=False, apple_gpu=False)

    Provide the default OpenCL compiler options

    Parameters:

      - x87_volatile – needed for Kahan summation

      - apple_gpu – work around for bug on AppleSilicon GPU compiler

    Returns:

      string with compiler option