OpenCL Platform/Runtime Documentation

Version Queries

pyopencl.VERSION

Gives the numeric version of PyOpenCL as a variable-length tuple of integers. Enables easy version checks such as VERSION >= (0, 93).

pyopencl.VERSION_STATUS

A text string such as “rc4” or “beta” qualifying the status of the release.

pyopencl.VERSION_TEXT

The full release name (such as “0.93rc4”) in string form.

pyopencl.get_cl_header_version()

Return a variable-length tuple of integers representing the version of the OpenCL header against which PyOpenCL was compiled.

New in version 0.92.

Error Reporting

class pyopencl.Error

Base class for all PyOpenCL exceptions.

class pyopencl.MemoryError
class pyopencl.LogicError
class pyopencl.RuntimeError

Constants

Warning

This set of PyOpenCL documentation is incomplete because it was generated on a PyOpenCL build that did not support OpenGL.

class pyopencl.addressing_mode
CLAMP
CLAMP_TO_EDGE
MIRRORED_REPEAT

Available with OpenCL 1.1.

New in version 0.92.

NONE
REPEAT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.channel_order
A
BGRA
INTENSITY
LUMINANCE
R
RA
RG
RGB
RGBA
RGBx

Available with OpenCL 1.1.

New in version 0.92.

RGx

Available with OpenCL 1.1.

New in version 0.92.

Rx

Available with OpenCL 1.1.

New in version 0.92.

to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.channel_type
FLOAT
HALF_FLOAT
SIGNED_INT16
SIGNED_INT32
SIGNED_INT8
SNORM_INT16
SNORM_INT8
UNORM_INT16
UNORM_INT8
UNORM_INT_101010
UNORM_SHORT_555
UNORM_SHORT_565
UNSIGNED_INT16
UNSIGNED_INT32
UNSIGNED_INT8
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.command_execution_status
COMPLETE
QUEUED
RUNNING
SUBMITTED
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.command_queue_info
CONTEXT
DEVICE
PROPERTIES
REFERENCE_COUNT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.command_queue_properties
OUT_OF_ORDER_EXEC_MODE_ENABLE
PROFILING_ENABLE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.command_type
ACQUIRE_GL_OBJECTS
COPY_BUFFER
COPY_BUFFER_RECT

Available with OpenCL 1.1.

New in version 0.92.

COPY_BUFFER_TO_IMAGE
COPY_IMAGE
COPY_IMAGE_TO_BUFFER
MAP_BUFFER
MAP_IMAGE
MARKER
NATIVE_KERNEL
NDRANGE_KERNEL
READ_BUFFER
READ_BUFFER_RECT

Available with OpenCL 1.1.

New in version 0.92.

READ_IMAGE
RELEASE_GL_OBJECTS
TASK
UNMAP_MEM_OBJECT
USER

Available with OpenCL 1.1.

New in version 0.92.

WRITE_BUFFER
WRITE_BUFFER_RECT

Available with OpenCL 1.1.

New in version 0.92.

WRITE_IMAGE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.context_info
DEVICES
NUM_DEVICES

Available with OpenCL 1.1.

New in version 0.92.

PROPERTIES
REFERENCE_COUNT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.context_properties
PLATFORM
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_exec_capabilities
KERNEL
NATIVE_KERNEL
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_fp_config
DENORM
FMA
INF_NAN
ROUND_TO_INF
ROUND_TO_NEAREST
ROUND_TO_ZERO
SOFT_FLOAT

Available with OpenCL 1.1.

New in version 0.92.

to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_info
ADDRESS_BITS
AVAILABLE
COMPILER_AVAILABLE
COMPUTE_CAPABILITY_MAJOR_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

COMPUTE_CAPABILITY_MINOR_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

DRIVER_VERSION
ENDIAN_LITTLE
ERROR_CORRECTION_SUPPORT
EXECUTION_CAPABILITIES
EXTENSIONS
GLOBAL_MEM_CACHELINE_SIZE
GLOBAL_MEM_CACHE_SIZE
GLOBAL_MEM_CACHE_TYPE
GLOBAL_MEM_SIZE
GPU_OVERLAP_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

HOST_UNIFIED_MEMORY

Available with OpenCL 1.1.

New in version 0.92.

IMAGE2D_MAX_HEIGHT
IMAGE2D_MAX_WIDTH
IMAGE3D_MAX_DEPTH
IMAGE3D_MAX_HEIGHT
IMAGE3D_MAX_WIDTH
IMAGE_SUPPORT
INTEGRATED_MEMORY_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

KERNEL_EXEC_TIMEOUT_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

LOCAL_MEM_SIZE
LOCAL_MEM_TYPE
MAX_CLOCK_FREQUENCY
MAX_COMPUTE_UNITS
MAX_CONSTANT_ARGS
MAX_CONSTANT_BUFFER_SIZE
MAX_MEM_ALLOC_SIZE
MAX_PARAMETER_SIZE
MAX_READ_IMAGE_ARGS
MAX_SAMPLERS
MAX_WORK_GROUP_SIZE
MAX_WORK_ITEM_DIMENSIONS
MAX_WORK_ITEM_SIZES
MAX_WRITE_IMAGE_ARGS
MEM_BASE_ADDR_ALIGN
MIN_DATA_TYPE_ALIGN_SIZE
NAME
NATIVE_VECTOR_WIDTH_CHAR

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_DOUBLE

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_FLOAT

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_HALF

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_INT

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_LONG

Available with OpenCL 1.1.

New in version 0.92.

NATIVE_VECTOR_WIDTH_SHORT

Available with OpenCL 1.1.

New in version 0.92.

OPENCL_C_VERSION

Available with OpenCL 1.1.

New in version 0.92.

PLATFORM
PREFERRED_VECTOR_WIDTH_CHAR
PREFERRED_VECTOR_WIDTH_DOUBLE
PREFERRED_VECTOR_WIDTH_FLOAT
PREFERRED_VECTOR_WIDTH_HALF

Available with OpenCL 1.1.

New in version 0.92.

PREFERRED_VECTOR_WIDTH_INT
PREFERRED_VECTOR_WIDTH_LONG
PREFERRED_VECTOR_WIDTH_SHORT
PROFILE
PROFILING_TIMER_RESOLUTION
QUEUE_PROPERTIES
REGISTERS_PER_BLOCK_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

SINGLE_FP_CONFIG
TYPE
VENDOR
VENDOR_ID
VERSION
WARP_SIZE_NV

Available with the cl_nv_device_attribute_query extension.

New in version 0.92.

to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_local_mem_type
GLOBAL
LOCAL
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_mem_cache_type
NONE
READ_ONLY_CACHE
READ_WRITE_CACHE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.device_type
ACCELERATOR
ALL
CPU
DEFAULT
GPU
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.event_info
COMMAND_EXECUTION_STATUS
COMMAND_QUEUE
COMMAND_TYPE
CONTEXT

Available with OpenCL 1.1.

New in version 0.92.

REFERENCE_COUNT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.filter_mode
LINEAR
NEAREST
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.gl_context_info

Only available when PyOpenCL is compiled with GL support. See have_gl().

to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.image_info
DEPTH
ELEMENT_SIZE
FORMAT
HEIGHT
ROW_PITCH
SLICE_PITCH
WIDTH
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.kernel_info
CONTEXT
FUNCTION_NAME
NUM_ARGS
PROGRAM
REFERENCE_COUNT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.kernel_work_group_info
COMPILE_WORK_GROUP_SIZE
LOCAL_MEM_SIZE
PREFERRED_WORK_GROUP_SIZE_MULTIPLE

Available with OpenCL 1.1.

New in version 0.92.

PRIVATE_MEM_SIZE

Available with OpenCL 1.1.

New in version 0.92.

WORK_GROUP_SIZE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.map_flags
READ
WRITE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.mem_flags
ALLOC_HOST_PTR
COPY_HOST_PTR
READ_ONLY
READ_WRITE
USE_HOST_PTR
WRITE_ONLY
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.mem_info
ASSOCIATED_MEMOBJECT

Available with OpenCL 1.1.

New in version 0.92.

CONTEXT
FLAGS
HOST_PTR
MAP_COUNT
OFFSET

Available with OpenCL 1.1.

New in version 0.92.

REFERENCE_COUNT
SIZE
TYPE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.mem_object_type
BUFFER
IMAGE2D
IMAGE3D
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.platform_info
EXTENSIONS
NAME
PROFILE
VENDOR
VERSION
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.profiling_info
END
QUEUED
START
SUBMIT
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.program_build_info
LOG
OPTIONS
STATUS
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.program_info
BINARIES
BINARY_SIZES
CONTEXT
DEVICES
NUM_DEVICES
REFERENCE_COUNT
SOURCE
to_string(value)

Returns a str representing value.

New in version 0.91.

class pyopencl.sampler_info
ADDRESSING_MODE
CONTEXT
FILTER_MODE
NORMALIZED_COORDS
REFERENCE_COUNT
to_string(value)

Returns a str representing value.

New in version 0.91.

Platforms, Devices and Contexts

pyopencl.get_platforms()

Return a list of Platform instances.

class pyopencl.Platform
info

Lower case versions of the platform_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See platform_info for values of param.

get_devices(device_type=device_type.ALL)

Return a list of devices matching device_type. See device_type for values of device_type.

Two instances of this class may be compared using “==” and ”!=”.

class pyopencl.Device
info

Lower case versions of the device_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See device_info for values of param.

Two instances of this class may be compared using ==” and ”!=”.

class pyopencl.Context(devices=None, properties=None, dev_type=None)

Create a new context. properties is a list of key-value tuples, where each key must be one of context_properties. At most one of devices and dev_type may be not None, where devices is a list of Device instances, and dev_type is one of the device_type constants. If neither is specified, a context with a dev_type of device_type.DEFAULT is created.

Note

Calling the constructor with no arguments will fail for recent CL drivers that support the OpenCL ICD. If you want similar, just-give-me-a-context-already behavior, we recommend create_some_context(). See, e.g. this explanation by AMD.

Note

For context_properties.CL_GL_CONTEXT_KHR, context_properties.CL_EGL_DISPLAY_KHR, context_properties.CL_GLX_DISPLAY_KHR, context_properties.CL_WGL_HDC_KHR, and context_properties.CL_CGL_SHAREGROUP_KHR the value in the key-value pair is a PyOpenGL context or display instance.

Changed in version 0.91.2: Constructor arguments dev_type added.

info

Lower case versions of the context_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See context_info for values of param.

Two instances of this class may be compared using “==” and ”!=”.

pyopencl.create_some_context(interactive=True)

Create a Context ‘somehow’.

If multiple choices for platform and/or device exist, interactive is True, and sys.stdin.isatty() is also True, then the user is queried about which device should be chosen. Otherwise, a device is chosen in an implementation-defined manner.

Command Queues and Events

class pyopencl.CommandQueue(context, device=None, properties=None)

Create a new command queue. properties is a bit field consisting of command_queue_properties values.

if device is None, one of the devices in context is chosen in an implementation-defined manner.

info

Lower case versions of the command_queue_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See command_queue_info for values of param.

set_property(prop, enable)

See command_queue_properties for possible values of prop. enable is a bool.

Unavailable in OpenCL 1.1 and newer.

flush()
finish()

Two instances of this class may be compared using “==” and ”!=”.

class pyopencl.Event
info

Lower case versions of the event_info constants may be used as attributes on instances of this class to directly query info attributes.

profile.info

Lower case versions of the profiling_info constants may be used as attributes on the attribute profile of this class to directly query profiling info.

For example, you may use evt.profile.end instead of evt.get_profiling_info(pyopencl.profiling_info.END).

get_info(param)

See event_info for values of param.

get_profiling_info(param)

See profiling_info for values of param. See profile for an easier way of obtaining the same information.

wait()

Two instances of this class may be compared using “==” and ”!=”.

pyopencl.wait_for_events(events)
pyopencl.enqueue_marker(queue)

Returns an Event.

pyopencl.enqueue_wait_for_events(queue, events)

Returns an Event.

pyopencl.enqueue_barrier(queue)

Enqueues a barrier operation. which ensures that all queued commands in command_queue have finished execution. This command is a synchronization point.

New in version 0.91.5.

class pyopencl.UserEvent(context)

A subclass of Event. Only available with OpenCL 1.1 and newer.

New in version 0.92.

set_status(status)

See command_execution_status for possible values of status.

Memory

class pyopencl.MemoryObject
info

Lower case versions of the mem_info constants may be used as attributes on instances of this class to directly query info attributes.

hostbuf
get_info(param)

See mem_info for values of param.

release()
get_host_array(shape, dtype, order="C")

Return the memory object’s associated host memory area as a numpy.ndarray of the given shape, dtype and order.

Two instances of this class may be compared using “==” and ”!=”.

Buffers

class pyopencl.Buffer(context, flags, size=0, hostbuf=None)

Create a Buffer. See mem_flags for values of flags. If hostbuf is specified, size defaults to the size of the specified buffer if it is passed as zero.

Buffer is a subclass of MemoryObject.

get_sub_region(origin, size, flags=0)
__getitem__(slc)

slc is a slice object indicating from which byte index range a sub-buffer is to be created. The flags argument of get_sub_region() is set to the same flags with which self was created.

pyopencl.enqueue_read_buffer(queue, mem, hostbuf, device_offset=0, wait_for=None, is_blocking=True)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

hostbuf must implement the Python buffer interface. (e.g. by being an numpy.ndarray)

Changed in version 2011.1.

pyopencl.enqueue_write_buffer(queue, mem, hostbuf, device_offset=0, wait_for=None, is_blocking=True)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

hostbuf must implement the Python buffer interface. (e.g. by being an numpy.ndarray)

Changed in version 2011.1.

pyopencl.enqueue_copy_buffer(queue, src, dst, byte_count=0, src_offset=0, dst_offset=0, wait_for=None)

If byte_count is passed as 0 (the default), the size of the Buffer src is used instead.

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

New in version 0.91.5.

pyopencl.enqueue_read_buffer_rect(queue, mem, hostbuf, buffer_origin, host_origin, region, buffer_pitches=None, host_pitches=None, wait_for=None, is_blocking=True)

The origin and region parameters are tuple instances of length three or shorter. The pitches parameters are tuple instances of length two or shorter, which may be zero to indicate ‘tight packing’.

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

hostbuf must implement the Python buffer interface. (e.g. by being an numpy.ndarray)

Only available in OpenCL 1.1 and newer.

New in version 0.92.

Changed in version 2011.1.

pyopencl.enqueue_write_buffer_rect(queue, mem, hostbuf, buffer_origin, host_origin, region, buffer_pitches=None, host_pitches=None, wait_for=None, is_blocking=True)

The origin and region parameters are tuple instances of length three or shorter. The pitches parameters are tuple instances of length two or shorter, which may be zero to indicate ‘tight packing’.

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

hostbuf must implement the Python buffer interface. (e.g. by being an numpy.ndarray)

Only available in OpenCL 1.1 and newer.

New in version 0.92.

Changed in version 2011.1.

pyopencl.enqueue_copy_buffer_rect(queue, src, dst, src_origin, dst_origin, region, src_pitches=None, dst_pitches=None, wait_for=None)

The origin and region parameters are tuple instances of length three or shorter. The pitches parameters are tuple instances of length two or shorter, which may be zero to indicate ‘tight packing’.

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

Only available in OpenCL 1.1 and newer.

New in version 0.92.

Image Formats

class pyopencl.ImageFormat([channel_order, channel_type])

Changed in version 0.91: Constructor arguments added.

channel_order

See channel_order for possible values.

channel_data_type

See channel_type for possible values.

channel_count

New in version 0.91.5.

dtype_size

New in version 0.91.5.

itemsize

New in version 0.91.5.

__repr__()

Returns a str representation of the image format.

New in version 0.91.

pyopencl.get_supported_image_formats(context, flags, image_type)

See mem_flags for possible values of flags and mem_object_type for possible values of image_type.

Images

class pyopencl.Image(context, flags, format, shape=None, pitches=None, hostbuf=None)

See mem_flags for values of flags. shape is a 2- or 3-tuple. format is an instance of ImageFormat. pitches is a 1-tuple for 2D images and a 2-tuple for 3D images, indicating the distance in bytes from one scan line to the next, and from one 2D image slice to the next.

If hostbuf is given and shape is None, then hostbuf.shape is used as the shape parameter.

Image is a subclass of MemoryObject.

Note

If you want to load images from numpy.ndarray instances or read images back into them, be aware that OpenCL images expect the x dimension to vary fastest, whereas in the default (C) order of numpy arrays, the last index varies fastest. If your array is arranged in the wrong order in memory, there are two possible fixes for this:

  • Convert the array to Fortran (column-major) order using numpy.asarray().
  • Pass ary.T.copy() to the image creation function.

New in version 0.91.

info

Lower case versions of the mem_info and image_info constants may be used as attributes on instances of this class to directly query info attributes.

shape

Return the value of the shape constructor argument as a tuple.

get_image_info(param)

See image_info for values of param.

release()

Two instances of this class may be compared using “==” and ”!=”.

pyopencl.enqueue_read_image(queue, mem, origin, region, hostbuf, row_pitch=0, slice_pitch=0, wait_for=None, is_blocking=True)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

Changed in version 0.91: pitch arguments defaults to zero, moved.

Changed in version 2011.1.

pyopencl.enqueue_write_image(queue, mem, origin, region, hostbuf, row_pitch=0, slice_pitch=0, wait_for=None, is_blocking=True)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

Changed in version 0.91: pitch arguments defaults to zero, moved.

Changed in version 2011.1.

pyopencl.enqueue_copy_image(queue, src, dest, src_origin, dest_origin, region, wait_for=None)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

pyopencl.enqueue_copy_image_to_buffer(queue, src, dest, origin, region, offset, wait_for=None)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

pyopencl.enqueue_copy_buffer_to_image(queue, src, dest, offset, origin, region, wait_for=None)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

Mapping Memory into Host Address Space

class pyopencl.MemoryMap
release(queue=None, wait_for=None)
pyopencl.enqueue_map_buffer(queue, buf, flags, offset, shape, dtype, order, wait_for=None, is_blocking=True)

wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction. shape, dtype, and order have the same meaning as in numpy.empty(). See map_flags for possible values of flags.

Returns:a tuple (array, event). array is a numpy.ndarray representing the host side of the map. Its .base member contains a MemoryMap.

Changed in version 2011.1.

pyopencl.enqueue_map_image(queue, buf, flags, origin, region, shape, dtype, order, wait_for=None, is_blocking=True)

wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction. shape, dtype, and order have the same meaning as in numpy.empty(). See map_flags for possible values of flags.

Returns:a tuple (array, event). array is a numpy.ndarray representing the host side of the map. Its .base member contains a MemoryMap.

Changed in version 2011.1.

Samplers

class pyopencl.Sampler(context, normalized_coords, addressing_mode, filter_mode)

normalized_coords is a bool indicating whether to use coordinates between 0 and 1 (True) or the texture’s natural pixel size (False). See addressing_mode and filter_mode for possible argument values.

info

Lower case versions of the sampler_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See sampler_info for values of param.

Two instances of this class may be compared using “==” and ”!=”.

Programs and Kernels

class pyopencl.Program(context, src)
class pyopencl.Program(context, devices, binaries)

binaries must contain one binary for each entry in devices.

info

Lower case versions of the program_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See program_info for values of param.

get_build_info(device, param)

See program_build_info for values of param.

build(options="", devices=None)

options is a string of compiler flags. Returns self.

kernel_name

Kernel objects can be produced from a built (see build()) program simply by attribute lookup.

Note

The program_info attributes live in the same name space and take precedence over Kernel names.

Two instances of this class may be compared using “==” and ”!=”.

all_kernels()

Returns a list of all Kernel objects in the Program.

pyopencl.unload_compiler()
class pyopencl.Kernel(program, name)
info

Lower case versions of the kernel_info constants may be used as attributes on instances of this class to directly query info attributes.

get_info(param)

See kernel_info for values of param.

get_work_group_info(param, device)

See kernel_work_group_info for values of param.

set_arg(self, index, arg)

arg may be

  • None: This may be passed for __global memory references to pass a NULL pointer to the kernel.

  • Anything that satisfies the Python buffer interface, in particular numpy.ndarray, str, or numpy‘s sized scalars, such as numpy.int32 or numpy.float64.

    Note

    Note that Python’s own int or float objects will not work out of the box. See Kernel.set_scalar_arg_dtypes() for a way to make them work. Alternatively, the standard library module struct can be used to convert Python’s native number types to binary data in a str.

  • An instance of MemoryObject. (e.g. Buffer, Image, etc.)

  • An instance of LocalMemory.

  • An instance of Sampler.

set_args(self, *args)

Invoke set_arg() on each element of args in turn.

..versionadded:: 0.92

set_scalar_arg_dtypes(arg_dtypes)

Inform the wrapper about the sized types of scalar Kernel arguments. For each argument, arg_dtypes contains an entry. For non-scalars, this must be None. For scalars, it must be an object acceptable to the numpy.dtype constructor, indicating that the corresponding scalar argument is of that type.

After invoking this function with the proper information, most suitable number types will automatically be cast to the right type for kernel invocation.

__call__(queue, global_size, local_size, *args, global_offset=None, wait_for=None)

Use enqueue_nd_range_kernel() to enqueue a kernel execution, after using set_args() to set each argument in turn. See the documentation for set_arg() to see what argument types are allowed. Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

None may be passed for local_size

Changed in version 0.92: local_size was promoted to third positional argument from being a keyword argument. The old keyword argument usage will continue to be accepted with a warning throughout the 0.92 release cycle. This is a backward-compatible change (just barely!) because local_size as third positional argument can only be a tuple or None. tuple instances are never valid Kernel arguments, and None is valid as an argument, but its treatment in the wrapper had a bug (now fixed) that prevented it from working.

Two instances of this class may be compared using “==” and ”!=”.

class pyopencl.LocalMemory(size)

A helper class to pass __local memory arguments to kernels.

New in version 0.91.2.

size

The size of local buffer in bytes to be provided.

pyopencl.enqueue_nd_range_kernel(queue, kernel, global_work_size, local_work_size, global_work_offset=None, wait_for=None)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

pyopencl.enqueue_task(queue, kernel, wait_for=None)

Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

GL Interoperability

Functionality in this section is only available when PyOpenCL is compiled with GL support. See have_gl().

New in version 0.91.

pyopencl.have_gl()

Return True if PyOpenCL was compiled with OpenGL interoperability, otherwise False.

class pyopencl.GLBuffer(context, flags, bufobj)

GLBuffer is a subclass of MemoryObject.

gl_object
class pyopencl.GLRenderBuffer(context, flags, bufobj)

GLRenderBuffer is a subclass of MemoryObject.

gl_object
class pyopencl.GLTexture(context, flags, texture_target, miplevel, texture, dims)

dims is either 2 or 3. GLTexture is a subclass of Image.

gl_object
get_gl_texture_info(param)

See gl_texture_info for values of param. Only available when PyOpenCL is compiled with GL support. See have_gl().

pyopencl.enqueue_acquire_gl_objects(queue, mem_objects, wait_for=None)

mem_objects is a list of MemoryObject instances. Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

pyopencl.enqueue_release_gl_objects(queue, mem_objects, wait_for=None)

mem_objects is a list of MemoryObject instances. Returns a new Event. wait_for may either be None or a list of Event instances for whose completion this command waits before starting exeuction.

pyopencl.get_gl_context_info_khr(properties, param_name)

Get information on which CL device corresponds to a given GL/EGL/WGL/CGL device.

See the Context constructor for the meaning of properties and gl_context_info for param_name.