IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo struct

PagedKVRemap

struct PagedKVRemap[page_size: Int]

Writes each slot's physical paged-cache row, as the remap kernel would.

The value written for slot idx is exactly what paged_sparse_kv_index_remap produces for it, so a consumer can take this buffer in place of running that kernel.

Parameters​

  • ​page_size (Int): Tokens per page of the cache lut indexes.

Fields​

  • ​physical_out (Pointer[Int32, MutUntrackedOrigin]): Flat output buffer, laid out like the logical indices.
  • ​lut (Pointer[UInt32, ImmUntrackedOrigin]): Row-major [lut_rows, lut_cols] page lookup table.
  • ​lut_cols (Int32): Logical pages per batch entry.
  • ​lut_rows (Int32): Batch entries in lut.
  • ​invalid_block_id (UInt32): Block ids at or above this (the page count) are invalid.

Implemented traits​

AnyType, Copyable, Deinitable, DevicePassable, ImplicitlyCopyable, Movable, RegisterPassable, SparseIndexRemap, TrivialRegisterPassable

comptime members​

device_type​

comptime device_type = PagedKVRemap[page_size]

Device-side type alias; the struct is trivially device-passable.

enabled​

comptime enabled = True

Physical rows are written.

Methods​

__init__​

def __init__(physical_out: Pointer[Int32], lut: Pointer[UInt32], lut_cols: Int, lut_rows: Int, invalid_block_id: UInt32) -> Self

Describes the cache to remap into and where to write.

Args:

  • ​physical_out (Pointer[Int32]): Flat output buffer, laid out like the logical indices.
  • ​lut (Pointer[UInt32]): Row-major [lut_rows, lut_cols] page lookup table.
  • ​lut_cols (Int): Logical pages per batch entry.
  • ​lut_rows (Int): Batch entries in lut.
  • ​invalid_block_id (UInt32): Block ids at or above this are invalid; the cache's page count.

offset​

def offset(self, slots: Int) -> Self

Returns this remap with physical_out advanced by slots.

Args:

  • ​slots (Int): Flat slots to advance by.

Returns:

Self: The advanced remap.

store​

def store(self, idx: Int, batch: Int, logical: Int32)

Writes physical_out[idx] for logical position logical.

Args:

  • ​idx (Int): Flat output slot.
  • ​batch (Int): Batch entry the slot's row belongs to.
  • ​logical (Int32): The slot's logical token position, or -1.

get_type_name​

static def get_type_name() -> String

Returns the type name for runtime diagnostics.

Returns:

String: Always "PagedKVRemap".

Was this page helpful?