Skip to main content

Mojo trait

MHAOperand

This serves as the trait to support arguments to our MHA kernel.

Implemented traits

AnyType, DevicePassable, UnknownDestructibility

Aliases

__del__is_trivial

alias __del__is_trivial

A flag (often compiler generated) to indicate whether the implementation of __del__ is trivial.

The implementation of __del__ is considered to be trivial if:

  • The struct has a compiler-generated trivial destructor and all its fields have a trivial __del__ method.

In practice, it means that the __del__ can be considered as no-op.

device_type

alias device_type

Indicate the type being used on accelerator devices.

dtype

alias dtype

Required methods

block_paged_ptr

block_paged_ptr[tile_size: Int](self: _Self, batch_idx: UInt32, start_tok_idx: UInt32, head_idx: UInt32, head_dim_idx: UInt32 = 0) -> UnsafePointer[Scalar[_Self.dtype]]

Returns:

UnsafePointer

cache_length

cache_length(self: _Self, batch_idx: Int) -> Int

Returns the length of the cache for a given batch index.

Returns:

Int

max_context_length

max_context_length(self: _Self) -> UInt32

Returns the maximum cache length in a given batch index.

Returns:

UInt32

row_idx

row_idx(self: _Self, batch_idx: UInt32, start_tok_idx: UInt32) -> UInt32

Returns the row idx when viewing the memory as a matrix.

Returns:

UInt32

col_idx

col_idx(self: _Self, head_idx: UInt32) -> UInt32

Returns the col idx when viewing the memory as a matrix.

Returns:

UInt32

create_tma_tile

create_tma_tile[tile_m: Int, tile_n: Int, swizzle_mode: TensorMapSwizzle, *, is_k_major: Bool](self: _Self, ctx: DeviceContext) -> TMATensorTile[_Self.dtype, tile_layout_k_major[_Self.dtype, tile_m, tile_n, swizzle_mode]() if is_k_major else tile_layout_mn_major[_Self.dtype, tile_n, tile_m, swizzle_mode](), _tma_desc_tile_layout[_Self.dtype, 2, IndexList[2, DType.int64](tile_m, tile_n, Tuple[]()), is_k_major, swizzle_mode](), is_k_major]

Creates a TMA tile for efficient GPU memory transfers.

Returns:

TMATensorTile

get_type_name

static get_type_name() -> String

Gets the name of the host type (the one implementing this trait). For example, Int would return "Int", DeviceBuffer[DType.float32] would return "DeviceBuffer[DType.float32]". This is used for error messages when passing types to the device. TODO: This method will be retired soon when better kernel call error messages arrive.

Returns:

String: The host type's name.

get_device_type_name

static get_device_type_name() -> String

Gets device_type's name. For example, because DeviceBuffer's device_type is UnsafePointer, DeviceBuffer[DType.float32]'s get_device_type_name() should return something like "UnsafePointer[Scalar[DType.float32]]". This is used for error messages when passing types to the device. TODO: This method will be retired soon when better kernel call error messages arrive.

Returns:

String: The device type's name.

Was this page helpful?