opencl.Platform not constructible.
Use opencl.get_platforms() to get a list of connected platoforms.
list of all devices attached to this platform
platform extensions as a string
return a list of devices by type.
platform name
return the plafrom profile info
platform vendor
return the version string of the platform
A device is a collection of compute units. A command-queue is used to queue commands to a device. Examples of commands include executing kernels, or reading and writing memory objects.
OpenCL devices typically correspond to a GPU, a multi-core CPU, and other processors such as DSPs and the Cell/B.E. processor.
flag: device type default.
flag: for all devices
flag: for all CPU devices
flag: for all GPU devices
test if this device supports the openc.Image class
test if this device supports native python kernels
test if this device supports out_of_order_exec_mode for queues
test if this device supports profiling for queues
return the clock frequency.
The number of parallel compute cores on the OpenCL device. The minimum value is 1.
Maximum dimensions that specify the global and local work-item IDs used by the data parallel execution model. (Refer to clEnqueueNDRangeKernel).
The minimum value is 3.
Maximum number of work-items that can be specified in each dimension to opencl.Queue.enqueue_nd_range_kernel.
Returns: | n entries, where n is the value returned by the query for opencl.Device.max_work_item_dimensions |
---|
the name of this device
return the platform this device is associated with.
return queue properties as a bitfield
see also has_queue_out_of_order_exec_mode and has_queue_profiling
return device type: one of [Device.DEFAULT, Device.ALL, Device.GPU or Device.CPU]
return the vendor ID
An event object can be used to track the execution status of a command. The API calls that enqueue commands to a command-queue create a new event object that is returned in the event argument.
Registers a user callback function for on completion of the event.
Parameters: | callback – must be of the signature callback(event, status) |
---|
the current status of the event.
Waits on the host thread for commands identified by event objects in event_list to complete. A command is considered complete if its execution status is CL_COMPLETE or a negative value.
Create an opencl program.
Parameters: |
|
---|
To get a kernel do program.name or program.kernel(‘name’).
return a dict of {device:bytes} for each device associated with this program
Binaries may be used in a program constructor.
return a dict of device:binary_size for each device associated with this program
Builds (compiles & links) a program executable from the program source or binary for all the devices or a specific device(s) in the OpenCL context associated with program.
OpenCL allows program executables to be built using the source or the binary.
get the context associated with this program
returns a list of devices associate with this program.
Return a kernel object.
get the build logs for each device.
return a dict of {device:str} for each device associated with this program.
number of devices to build on
get the source code used to build this program
return a dict of {device:int} for each device associated with this program.
Valid statuses:
- Program.NONE
- Program.ERROR
- Program.SUCCESS
- Program.IN_PROGRESS
Memory objects are categorized into two types: buffer objects, and image objects. A buffer object stores a one-dimensional collection of elements whereas an image object is used to store a two- or three- dimensional texture, frame-buffer or image.
Registers a user callback function with a memory object. Each call to add_destructor_callback registers the specified user callback function on a callback stack associated with memobj.
The registered user callback functions are called in the reverse order in which they were registered. The user callback functions are called and then the memory object’s resources are freed and the memory object is deleted. This provides a mechanism for the application (and libraries) using memobj to be notified when the memory referenced by host_ptr, specified when the memory object is created and used as the storage bits for the memory object, can be reused or freed.
Parameters: | callback – function with the signature callback(memobj, *args, **kwargs) |
---|
Return the original memobject if this is a sub-buffer.
Return the context that this object was created with.
Return the pointer to the opencl memory object.
Return the size in bytes of this memory object.
return the enumed type of this object. One of MemoryObject.BUFFER, MemoryObject.IMAGE2D or MemoryObject.IMAGE3D
A buffer object stores a one-dimensional collection of elements. Elements of a buffer object can be a scalar data type (such as an int, float), vector data type, or a user-defined structure
Copy this buffer into a new object
ctype format of the elements
Create an OpenCL buffer from a Python memoryview object.
is this array C-contiguous
Return a python object if the size of this array is 1.
size of each element
enqueues a command to map a region of the buffer object given by buffer into the host address space and returns a pointer to this mapped region.
Total number of bytes
number of dimensions
offset from base buffer
Read this buffer into a memory view
Is this memory writable
Shape of the array
Total number of elements
Strides of the array
Write data from a memoryview to the device.
opencl.Context(devices=(), device_type=cl.Device.DEFAULT, ContextProperties properties=None, callback=print_context_error)
Creates an OpenCL context. An OpenCL context is created with one or more devices. Contexts are used by the OpenCL runtime for managing objects such as command-queues, memory, program and kernel objects and for executing kernels on one or more devices specified in the context.
Parameters: |
|
---|
return a list of devices associated with this context
return the number of devices
return a ContextProperties object
return opencl internal refrence count of this object
Memory ‘type’ descriptor.
Return the type that this object is a pointer to.
Return a ctypes.c_void_p from arg.
Parameters: | arg – must be a MemoryObject. |
---|
openCl kernel object.
A kernel object encapsulates a specific __kernel function declared in a program and the argument values to be used when executing this __kernel function.
Get or set the argument names. len(argnames) must equal kernel.nargs
Assign a tuple of ctypes types to specify the argument types that the function accepts
len(argtypes) must equal kernel.nargs.
It is now possible to put items in argtypes which are not ctypes types, but each item must have a from_param() method which returns a value usable as argument (integer, string, ctypes instance). This allows to define adapters that can adapt custom objects as function parameters.
Returns the work-group size specified by the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier.
The context this kernel was created with.
Returns the amount of local memory in bytes being used by a kernel. This includes local memory that may be needed by an implementation to execute the kernel, variables declared inside the kernel with the __local address qualifier and local memory to be allocated for arguments to the kernel declared as pointers with the __local address qualifier and whose size is specified with clSetKernelArg
The name of this kernel
Number of arguments that this kernel takes
Returns the preferred multiple of workgroup size for launch. This is a performance hint. Specifying a workgroup size that is not a multiple of the value returned by this query as the value of the local work size argument to clEnqueueNDRangeKernel will not fail to enqueue the kernel for execution unless the work-group size specified is larger than the device maximum.
Returns the minimum amount of private memory, in bytes, used by each workitem in the kernel. This value may include any private memory needed by an implementation to execute the kernel, including that used by the language built-ins and variable declared inside the kernel with the __private qualifier.
Set the arguments for this kernel
This provides a mechanism for the application to query the maximum work-group size that can be used to execute a kernel on a specific device given by device. The OpenCL implementation uses the resource requirements of the kernel (register usage etc.) to determine what this workgroup size should be.
opencl.Queue(context, device=None, out_of_order_exec_mode=False, profiling=False)
OpenCL objects such as memory, program and kernel objects are created using a context. Operations on these objects are performed using a command-queue. The command-queue can be used to queue a set of operations (referred to as commands) in order. Having multiple command-queues allows applications to queue multiple independent commands without requiring synchronization. Note that this should work as long as these objects are not being shared. Sharing of objects across multiple command-queues will require the application to perform appropriate synchronization
Parameters: |
|
---|
Enqueues a barrier operation. The queue.barrier command ensures that all queued commands in command_queue have finished execution before the next batch of commands can begin execution. The queue.barrier command is a synchronization point
Return the context that this queue was created with
Return the device associated with this queue
Enqueues a command to copy a buffer object identified by source to another buffer object identified by dest.
Parameters: |
|
---|
TODO: document this.
Enqueues a command to execute a python function.
Parameters: |
|
---|
Enqueues a command to execute a kernel on a device
Parameters: |
|
---|
Parameters: | wait_on – A list of events |
---|
Read a buffer object to host memory.
Enqueues a command to execute a kernel on a device. The kernel is executed using a single work-item.
Parameters: |
|
---|
queue.enqueue_wait_for_events(self, eventlist)
Enqueues a wait for a specific event or a list of events to complete before any future commands queued in the command-queue are executed. num_events specifies the number of events given by event_list.
queue.enqueue_read_buffer(source, dest, offset=0, size=0, wait_on=(), blocking_read=False)
Write host memory into a buffer object.
Blocks until all previously queued OpenCL commands in command_queue are issued to the associated device and have completed. clFinish does not return until all queued commands in command_queue have been processed and completed. clFinish is also a synchronization point
Issues all previously queued OpenCL commands in command_queue to the device associated with command_queue. clFlush only guarantees that all queued commands to command_queue will eventually be submitted to the appropriate device. There is no guarantee that they will be complete after clFlush returns.
Enqueues a marker command to command_queue. The marker command is not completed until all commands enqueued before it have completed. The marker command returns an event which can be waited on, i.e. this event can be waited on to insure that all commands, which have been queued before the marker command, have been completed.