Skip to main content

Mojo struct

KVCacheMHAOperand

@register_passable(trivial) struct KVCacheMHAOperand[cache_t: KVCacheT]

An implementation for mo.opaque KVCacheT arguments to MHA kernels.

We can eventually remove this trait and just add it as a sub-trait in the KVCacheT type, but we need to solve some cyclic dependencies first.

Fields

  • cache (cache_t):

Implemented traits

AnyType, Copyable, DevicePassable, ImplicitlyCopyable, MHAOperand, Movable, UnknownDestructibility

comptime members

__copyinit__is_trivial

comptime __copyinit__is_trivial = cache_t.__copyinit__is_trivial

__del__is_trivial

comptime __del__is_trivial = cache_t.__del__is_trivial

__moveinit__is_trivial

comptime __moveinit__is_trivial = cache_t.__moveinit__is_trivial

device_type

comptime device_type = KVCacheMHAOperand[cache_t]

dtype

comptime dtype = cache_t.dtype

page_size

comptime page_size = cache_t.page_size_

Methods

__init__

__init__(cache: cache_t) -> Self

get_type_name

static get_type_name() -> String

Returns:

String

get_device_type_name

static get_device_type_name() -> String

Returns:

String

block_paged_ptr

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

Returns:

LegacyUnsafePointer

cache_length

cache_length(self, batch_idx: Int) -> Int

Returns:

Int

max_context_length

max_context_length(self) -> UInt32

Returns:

UInt32

row_idx

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

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

Returns:

UInt32

create_tma_tile

create_tma_tile[BN: Int, depth: Int, swizzle_mode: TensorMapSwizzle, BK: Int = depth](self, ctx: DeviceContext, out tma: TMATensorTile[KVCacheMHAOperand[cache_t].dtype, _split_last_layout[KVCacheMHAOperand[cache_t].dtype](IndexList[3, DType.int64](BN, 1, BK, Tuple[]()), swizzle_mode, True), _ragged_desc_layout[KVCacheMHAOperand[cache_t].dtype](IndexList[3, DType.int64](BN, 1, BK, Tuple[]()), swizzle_mode)])

Creates a TMA tile for efficient GPU memory transfers.

Returns:

TMATensorTile

Was this page helpful?