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
- 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 = []#
- 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
- 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
- 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
- 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#