Python Class Documentation & Reference

This section provides a breakdown of the Python classes and what each of their functions provide. Below is a diagram that provides insights on the relationship between Vulkan Kompute objects and Vulkan resources, which primarily encompass ownership of either CPU and/or GPU memory.

Manager

The Kompute Manager provides a high level interface to simplify interaction with underlying kp.Sequence of Operations.

class kp.Manager
destroy(*args, **kwargs)

Overloaded function.

  1. destroy(self: kp.Manager, tensor: kp.Tensor) -> None

Destroy owned Vulkan GPU resources and free GPU memory for single tensor.

@param tensors Single tensor to rebuild

  1. destroy(self: kp.Manager, tensors: List[kp.Tensor]) -> None

Destroy owned Vulkan GPU resources and free GPU memory for vector of tensors.

@param tensors Single tensor to rebuild

  1. destroy(self: kp.Manager, sequences: List[kp.Sequence]) -> None

Destroy owned Vulkan GPU resources and free GPU memory for vector of sequences. Destroying by sequence name is more efficent and hence recommended instead of by object.

@param sequences Vector for shared ptrs with sequences to destroy

  1. destroy(self: kp.Manager, sequence: kp.Sequence) -> None

Destroy owned Vulkan GPU resources and free GPU memory for single sequence. Destroying by sequence name is more efficent and hence recommended instead of by object.

@param sequences Single sequence to rebuild

  1. destroy(self: kp.Manager, sequenceName: str) -> None

Destroy owned Vulkan GPU resources and free GPU memory for sequence by name.

@param sequenceName Single name of named sequence to destroy

  1. destroy(self: kp.Manager, sequenceNames: List[str]) -> None

Destroy owned Vulkan GPU resources and free GPU memory for sequences using vector of named sequence names.

@param sequenceName Vector of sequence names to destroy

eval_algo_data(self: kp.Manager, tensors: List[kp.Tensor], sequence_name: str, bytes: bytes, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates an operation using a custom shader provided as spirv bytes with explicitly named Sequence

eval_algo_data_def(self: kp.Manager, tensors: List[kp.Tensor], bytes: bytes, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates an operation using a custom shader provided as spirv bytes with new anonymous Sequence

eval_algo_file(self: kp.Manager, tensors: List[kp.Tensor], sequence_name: str, data: str, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates an operation using a custom shader provided from a shader path with explicitly named Sequence

eval_algo_file_def(self: kp.Manager, tensors: List[kp.Tensor], data: str, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates an operation using a custom shader provided from a shader path with new anonymous Sequence

eval_async_algo_data(self: kp.Manager, tensors: List[kp.Tensor], sequence_name: str, bytes: bytes, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates asynchronously an operation using a custom shader provided as raw string or spirv bytes with explicitly named Sequence

eval_async_algo_data_def(self: kp.Manager, tensors: List[kp.Tensor], bytes: bytes, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates asynchronously an operation using a custom shader provided as raw string or spirv bytes with anonymous Sequence

eval_async_algo_file(self: kp.Manager, tensors: List[kp.Tensor], sequence_name: str, data: str, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates asynchronously an operation using a custom shader provided from a shader path with explicitly named Sequence

eval_async_algo_file_def(self: kp.Manager, tensors: List[kp.Tensor], data: str, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → None

Evaluates asynchronously an operation using a custom shader provided from a shader path with anonymous Sequence

eval_async_tensor_copy(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates asynchronously operation to copy one tensor to one or many tensors with explicitly named Sequence

eval_async_tensor_copy_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates asynchronously operation to copy one tensor to one or many tensors with anonymous Sequence

eval_async_tensor_sync_device(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates asynchronously operation to sync tensor from local memory to GPU memory with explicitly named Sequence

eval_async_tensor_sync_device_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates asynchronously operation to sync tensor from local memory to GPU memory with anonymous Sequence

eval_async_tensor_sync_local(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates asynchronously operation to sync tensor(s) from GPU memory to local memory with explicitly named Sequence

eval_async_tensor_sync_local_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates asynchronously operation to sync tensor(s) from GPU memory to local memory with anonymous Sequence

eval_await(self: kp.Manager, sequenceName: str, waitFor: int = 18446744073709551615) → None

Awaits for asynchronous operation on a named Sequence

eval_await_def(self: kp.Manager, waitFor: int = 18446744073709551615) → None

Awaits for asynchronous operation on the last anonymous Sequence created

eval_tensor_copy(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates operation to copy one tensor to one or many tensors with explicitly named Sequence

eval_tensor_copy_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates operation to copy one tensor to one or many tensors with new anonymous Sequence

eval_tensor_create_def(self: kp.Manager, tensors: List[kp.Tensor], syncDataToGPU: bool = True) → None

Temporary backwards compatibility for tensor creation function which will be removed in the next version.

eval_tensor_sync_device(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates operation to sync tensor from local memory to GPU memory with explicitly named Sequence

eval_tensor_sync_device_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates operation to sync tensor from local memory to GPU memory with new anonymous Sequence

eval_tensor_sync_local(self: kp.Manager, arg0: List[kp.Tensor], arg1: str) → None

Evaluates operation to sync tensor(s) from GPU memory to local memory with explicitly named Sequence

eval_tensor_sync_local_def(self: kp.Manager, arg0: List[kp.Tensor]) → None

Evaluates operation to sync tensor(s) from GPU memory to local memory with new anonymous Sequence

rebuild(*args, **kwargs)

Overloaded function.

  1. rebuild(self: kp.Manager, tensors: List[kp.Tensor], syncDataToGPU: bool = True) -> None

Build and initialise list of tensors

  1. rebuild(self: kp.Manager, tensor: kp.Tensor, syncDataToGPU: bool = True) -> None

Build and initialise tensor

sequence(self: kp.Manager, name: str = '', queueIndex: int = 0)kp.Sequence

Get or create a sequence with specific name and specified index of available queues

tensor(self: kp.Manager, data: List[float], tensorType: kp.TensorTypes = <TensorTypes.device: 0>, syncDataToGPU: bool = True)kp.Tensor

Build and initialise tensor

Sequence

The Kompute Sequence consists of batches of Kompute Operations, which are executed on a respective GPU queue. The execution of sequences can be synchronous or asynchronous, and it can be coordinated through its respective Vulkan Fence.

class kp.Sequence
begin(self: kp.Sequence) → bool

Begins recording commands for commands to be submitted into the command buffer.

@return Boolean stating whether execution was successful.

end(self: kp.Sequence) → bool

Ends the recording and stops recording commands when the record command is sent.

@return Boolean stating whether execution was successful.

eval(self: kp.Sequence) → bool

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.

@return Boolean stating whether execution was successful.

eval_async(self: kp.Sequence) → bool

Eval Async sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier. EvalAwait() must be called after to ensure the sequence is terminated correctly.

@return Boolean stating whether execution was successful.

eval_await(self: kp.Sequence, arg0: int) → bool

Eval Await waits for the fence to finish processing and then once it finishes, it runs the postEval of all operations.

@param waitFor Number of milliseconds to wait before timing out. @return Boolean stating whether execution was successful.

init(self: kp.Sequence) → None

Initialises sequence including the creation of the command pool and the command buffer.

is_init(self: kp.Sequence) → bool

Returns true if the sequence has been successfully initialised.

@return Boolean stating if sequence has been initialised.

is_rec(self: kp.Sequence) → bool

Returns true if the sequence is currently in recording activated.

@return Boolean stating if recording ongoing.

is_running(self: kp.Sequence) → bool

Returns true if the sequence is currently running - mostly used for async workloads.

@return Boolean stating if currently running.

record_algo_data(self: kp.Sequence, tensors: List[kp.Tensor], bytes: bytes, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → bool

Records an operation using a custom shader provided as spirv bytes

record_algo_file(self: kp.Sequence, tensors: List[kp.Tensor], data: str, workgroup: List[int[3]] = [0, 0, 0], constants: List[float] = []) → bool

Records an operation using a custom shader provided from a shader path

record_tensor_copy(self: kp.Sequence, arg0: List[kp.Tensor]) → bool

Record function for operation to be added to the GPU queue in batch. This template requires classes to be derived from the OpBase class. This function also requires the Sequence to be recording, otherwise it will not be able to add the operation.

@param tensors Vector of tensors to use for the operation @param TArgs Template parameters that are used to initialise operation which allows for extensible configurations on initialisation.

record_tensor_sync_device(self: kp.Sequence, arg0: List[kp.Tensor]) → bool

Records operation to sync tensor from local memory to GPU memory

record_tensor_sync_local(self: kp.Sequence, arg0: List[kp.Tensor]) → bool

Records operation to sync tensor(s) from GPU memory to local memory

Tensor

The Kompute Tensor is the atomic unit in Kompute, and it is used primarily for handling Host and GPU Device data.

class kp.Tensor

Structured data used in GPU operations.

Tensors are the base building block in Kompute to perform operations across GPUs. Each tensor would have a respective Vulkan memory and buffer, which would be used to store their respective data. The tensors can be used for GPU data storage or transfer.

data(self: kp.Tensor) → List[float]

Returns the vector of data currently contained by the Tensor. It is important to ensure that there is no out-of-sync data with the GPU memory.

@return Reference to vector of elements representing the data in the tensor.

is_init(self: kp.Tensor) → bool

Checks whether the tensor GPU memory has been initialised.

map_data_from_host(self: kp.Tensor) → None

Maps data into GPU memory from tensor local data.

map_data_into_host(self: kp.Tensor) → None

Maps data from GPU memory into tensor local data.

numpy(self: kp.Tensor) → numpy.ndarray

Returns stored data as a new numpy array.

set_data(self: kp.Tensor, arg0: numpy.ndarray[numpy.float32]) → None

Overrides the data in the local Tensor memory.

size(self: kp.Tensor) → int

Retrieves the size of the Tensor data as per the local Tensor memory.

tensor_type(self: kp.Tensor)kp.TensorTypes

Retreves the memory type of the tensor.

TensorType

class kp.Shader

Shader class

static compile_source(source: str, entryPoint: str = 'main', definitions: List[Tuple[str, str]] = []) → bytes

Compiles string source provided and returns the value in bytes

static compile_sources(sources: List[str], files: List[str] = [], entryPoint: str = 'main', definitions: List[Tuple[str, str]] = []) → bytes

Compiles sources provided with file names and returns the value in bytes

class kp.Tensor

Structured data used in GPU operations.

Tensors are the base building block in Kompute to perform operations across GPUs. Each tensor would have a respective Vulkan memory and buffer, which would be used to store their respective data. The tensors can be used for GPU data storage or transfer.

data(self: kp.Tensor) → List[float]

Returns the vector of data currently contained by the Tensor. It is important to ensure that there is no out-of-sync data with the GPU memory.

@return Reference to vector of elements representing the data in the tensor.

is_init(self: kp.Tensor) → bool

Checks whether the tensor GPU memory has been initialised.

map_data_from_host(self: kp.Tensor) → None

Maps data into GPU memory from tensor local data.

map_data_into_host(self: kp.Tensor) → None

Maps data from GPU memory into tensor local data.

numpy(self: kp.Tensor) → numpy.ndarray

Returns stored data as a new numpy array.

set_data(self: kp.Tensor, arg0: numpy.ndarray[numpy.float32]) → None

Overrides the data in the local Tensor memory.

size(self: kp.Tensor) → int

Retrieves the size of the Tensor data as per the local Tensor memory.

tensor_type(self: kp.Tensor)kp.TensorTypes

Retreves the memory type of the tensor.

class kp.TensorTypes

Type for tensors created: Device allows memory to be transferred from staging buffers. Staging are host memory visible. Storage are device visible but are not set up to transfer or receive data (only for shader storage).

Members:

device : Tensor holding data in GPU memory.

host : Tensor used for CPU visible GPU data.

storage : Tensor with host visible gpu memory.

property name