High-level Python API

OpenCL interface

Platforms

class pocky.Platform(id: Capsule, name: str, version: str)

Encapsulated OpenCL platform ID with basic information.

Parameters:
  • id – Unique platform ID

  • name – Platform name, as reported by the hardware

  • version – Platform version, as reported by the hardware

Danger

Do not instantiate this class directly! Rather, use valid output from pocky.list_all_platforms().

pocky.list_all_platforms() list[Platform]

Get a list of all available OpenCL platforms.

Returns:

A list of available platforms

Devices

class pocky.Device(iterable=(), /)

This is a stub

pocky.list_all_devices(platform: Platform) list[Device]

Get a list of all available OpenCL devices for a platform.

Parameters:

platform – The platform to query for available devices

Returns:

A list of devices available on the platform

Contexts

class pocky.Context

Opaque object encapsulating the OpenCL context, command queues, kernels, and program.

Danger

Do not instantiate this class directly! Rather, use valid output from pocky.Context.default() or pocky.Context.from_device_list().

default() Context

Create a context with the default OpenCL platform and devices.

Returns:

An initialized Context

devices

This is a stub

from_device_list(devices: list[Device]) Context

Create a context from a subset of OpenCL devices on the same platform.

Parameters:

devices – The devices to include in the returned context

Returns:

An initialized Context

Buffers

class pocky.BufferPair(context: Context, host_array: numpy.ndarray)

Pair of buffers, one host and one device, used for input and output to compiled kernels. Copy operations are carried out before and after each kernel execution.

Parameters:
  • context – Valid existing OpenCL context

  • host_array – NumPy array to serve as host memory buffer

copy_from_device()

Copy the specified device data to the host

copy_to_device()

Copy the host data to the specified device

dirty

Indicates that the host array needs to be copied to the device (True) or that it is unchanged since the last copy (False). This can be used by external modules to avoid redundant copies, but it is not updated dynamically by pocky.

host

Exposes the underlying NumPy host array. The size of the array cannot be increased after the BufferPair is created, but the array can be replaced by one of the same dtype and equal or smaller size.