tinygrad runtime.ops_gpu

Note

You likely want the upstream tinygrad, not tinygrab. Tinygrab contains AI generated docstrings for a tinygrad snapshot. Upstream: https://tinygrad.org

class tinygrad.runtime.ops_gpu.CLAllocator(device: CLDevice)[source]

Bases: LRUAllocator

OpenCL memory allocator.

device

The device to use for memory allocation.

Type:

CLDevice

copyin(dest: LP_struct__cl_mem, src: memoryview)[source]

Copies data from host memory to device memory.

Parameters:
  • dest (cl.cl_mem) – The destination buffer on the device.

  • src (memoryview) – The source data in host memory.

copyout(dest: memoryview, src: LP_struct__cl_mem)[source]

Copies data from device memory to host memory.

Parameters:
  • dest (memoryview) – The destination buffer in host memory.

  • src (cl.cl_mem) – The source buffer on the device.

class tinygrad.runtime.ops_gpu.CLDevice(device: str = '')[source]

Bases: Compiled

This class represents an OpenCL device. It is responsible for managing the context, queue and synchronization of the device.

device_ids

Global list of available device IDs, initialized once.

Type:

List[cl.cl_device_id]

compiler_context

The first created context used for compilation.

Type:

Optional[CLDevice]

compiler_context = None
device_ids = None
synchronize()[source]

Synchronize the queue and clear any pending copy operations.

This function ensures that all commands in the queue are executed before proceeding with further operations. It is particularly useful when you need to make sure all OpenCL operations have completed before continuing with the rest of your program.

self

The instance of the class calling the synchronize method.

Type:

obj

Returns:

None

Raises:

Exception – If there is an issue with finishing the queue (clFinish() returns non-zero).

class tinygrad.runtime.ops_gpu.CLProgram(device: CLDevice, name: str, lib: bytes)[source]

Bases: object

This class represents a Compute Program (CLProgram) in OpenCL. It is initialized with a device, name and binary code.

device

The device where the program will be executed.

Type:

CLDevice

name

The name of the kernel function to be executed.

Type:

str

lib

The compiled binary code for the OpenCL program.

Type:

bytes

__init__(self, device

CLDevice, name: str, lib: bytes) -> None: Initializes the program with given device, name and binary code.

__del__(self) None[source]

Releases the kernel and program when the object is destroyed.

__call__(self, *bufs

cl.cl_mem, global_size: Tuple[int, …], local_size: Optional[Tuple[int, …]] = None, vals: Tuple[int, …] = (), wait=False) -> Optional[float]: Executes the kernel with given arguments and returns execution time if wait is True.

tinygrad.runtime.ops_gpu.GPUDevice

alias of CLDevice

tinygrad.runtime.ops_gpu.check(status)[source]

Check the status of an OpenCL operation.

This function checks the status of an OpenCL operation and raises a RuntimeError if the status is not equal to zero, indicating an error has occurred.

Parameters:

status (int) – The status code returned by an OpenCL operation.

Raises:

RuntimeError – If the status is not equal to zero, indicating an error has occurred in the OpenCL operation.

tinygrad.runtime.ops_gpu.checked(ret, status)[source]

Check the status of an OpenCL operation and return the result.

This function checks the status of an OpenCL operation, raises a RuntimeError if the status is not equal to zero, indicating an error has occurred, and returns the result of the operation.

Parameters:
  • ret (Any) – The result of an OpenCL operation.

  • status (int) – The status code returned by an OpenCL operation.

Returns:

The result of the OpenCL operation if the status is zero, otherwise raises a RuntimeError.

Return type:

Any

Raises:

RuntimeError – If the status is not equal to zero, indicating an error has occurred in the OpenCL operation.