numba_vulkan.vktypes#

Numba types specific to the Vulkan target.

Classes#

VulkanArray

An array backed by a storage buffer at a descriptor binding.

HalfArray

Type of a float16 array argument before it is given a binding.

VulkanArrayIterator

Iterator over the first axis of a VulkanArray.

VulkanDispatcherType

Type of a Vulkan-compiled function used inside another one.

VulkanExpr

An array expression that is evaluated element by element.

VulkanRecord

An element of a structured (record) array in a buffer.

Module Contents#

class numba_vulkan.vktypes.VulkanArray(dtype, ndim, layout, binding, readonly=False, aligned=True, half=False)#

An array backed by a storage buffer at a descriptor binding.

Vulkan shaders have no general pointers, so every access names the buffer by its binding, which must be a constant in the shader. Arrays allocated in a kernel (shared, local, constant arrays) have it in their type. Kernel arguments carry it as a value (binding=None), so that a function taking arrays is compiled once for all of them; after inlining into the kernel, the value is a constant (see numba_vulkan.buffers.expand_buffer_access).

Parameters:
  • dtype (numba.types.Type) – Element type.

  • ndim (int) – Number of dimensions.

  • layout ({'C', 'A'}) – Memory layout: 'C' for contiguous arrays, 'A' for views with arbitrary strides.

  • binding (int or None) – Descriptor binding of the buffer holding the data, or None for arrays that carry it as a value.

  • readonly (bool, optional) – Whether the array is immutable.

  • aligned (bool, optional) – Whether the data is aligned.

  • half (bool, optional) – Whether the buffer holds float16 values; the elements are then float32 to the kernel.

Variables:
  • binding (int or None) – As given.

  • half (bool) – As given.

binding#
half = False#
copy(dtype=None, ndim=None, layout=None, readonly=None)#

Return a copy of this type with some properties replaced.

Unlike numba.types.Array.copy, the result keeps the binding, so types that Numba derives from an array still refer to its buffer.

Parameters:
  • dtype (numba.types.Type, optional) – New element type.

  • ndim (int, optional) – New number of dimensions.

  • layout (str, optional) – New memory layout.

  • readonly (bool, optional) – New mutability.

Return type:

VulkanArray

property iterator_type#

Type of iter(array).

Return type:

VulkanArrayIterator

property key#

Numba’s array key plus the binding.

Return type:

tuple

Type:

Identity of the type

class numba_vulkan.vktypes.HalfArray(ndim, layout, readonly=False)#

Type of a float16 array argument before it is given a binding.

Its elements are float32; see VulkanArray.

copy(dtype=None, ndim=None, layout=None, readonly=None)#

Return a copy with some properties replaced (but not the dtype).

property key#

Identity of the type.

class numba_vulkan.vktypes.VulkanArrayIterator#

Iterator over the first axis of a VulkanArray.

A type of its own, so that iteration can be lowered without the data pointer that Numba’s array iterator relies on.

class numba_vulkan.vktypes.VulkanDispatcherType#

Type of a Vulkan-compiled function used inside another one.

It exists so that constants of this type can be lowered to a dummy value: calls are resolved at compile time, and the default lowering of numba.types.Dispatcher would embed a host address.

class numba_vulkan.vktypes.VulkanExpr(op, operands, dtype, ndim)#

An array expression that is evaluated element by element.

Kernels cannot allocate memory, so a * 2 or np.sqrt(a) + b on arrays does not compute a new array. Its value is the operation and its operands; an element is computed when it is read, by indexing, a reduction, iteration or an assignment to a slice.

Parameters:
  • op (callable) – The operator or ufunc, such as operator.add or np.sqrt.

  • operands (tuple of numba.types.Type) – Types of the operands: arrays, expressions or scalars.

  • dtype (numba.types.Type) – Type of an element of the result.

  • ndim (int) – Number of dimensions of the result, after broadcasting.

Variables:

ndim (op, operands, dtype,) – As given.

op#
operands#
dtype#
ndim#
property key#

the operation and the operand types.

Return type:

tuple

Type:

Identity of the type

class numba_vulkan.vktypes.VulkanRecord(record)#

An element of a structured (record) array in a buffer.

Numba represents a record as a pointer to its bytes, which shaders do not have. A Vulkan record is the binding of its buffer and the position of its first byte there; its fields are read from and written to the buffer’s 32-bit words (see numba_vulkan.vkimpl). It is the element type of record arrays, so indexing one gives a record.

Parameters:

record (numba.types.Record) – The layout: names, types and offsets of the fields, as the buffer holds them.

Variables:

record (numba.types.Record) – As given.

record#
property key#

the record layout.

Return type:

numba.types.Record

Type:

Identity of the type

property size#

Bytes per element.

Return type:

int

field(name)#

Type and byte offset of a field.

Return type:

tuple of (numba.types.Type, int)