---
title: "ClikaRT::nn::KVCache::StepIndices"
sidebar_label: "KVCache::StepIndices"
description: "The device-side index tensors one varlen decode/prefill step consumes, derived from the host-side step description (see prepare_step)."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--struct">struct</span>

**Header:** `ClikaRT/nn/kv_cache.h`

The device-side index tensors one varlen decode/prefill step consumes, derived from the host-side step description (see [`prepare_step`](./KVCache.md#prepare_step)).

## Member functions

### for\_layer() {#for_layer}

<div class="api-signature">

`const` [`StepIndices`](./KVCache.StepIndices.md)`&` **`for_layer`**(`int` `layer`) `const`

</div>

The view layer `layer` binds: its row group's index tensors. On a uniform cache every layer returns this object's own fields (zero-copy); a mixed-layout cache returns the layer's group forms (a continuous row's [`slot_ids`](./KVCache.StepIndices.md#slot_ids) beside a paged row's gathered block table). An out-of-range `layer` returns the flat fields.

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 603

</div>

## Data members

### cu\_seqlens\_q {#cu_seqlens_q}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`cu_seqlens_q`**

</div>

`[B+1]` Int32, the query cumulative.

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 571

</div>

### cu\_seqlens\_k {#cu_seqlens_k}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`cu_seqlens_k`**

</div>

per-seq post-append KV lengths (see [`prepare_step`](./KVCache.md#prepare_step)).

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 572

</div>

### kvcache\_start {#kvcache_start}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`kvcache_start`**

</div>

paged: `[B, blocks_per_seq]` gathered block table; continuous: the rank-1 `[B]` selector (see [`prepare_step`](./KVCache.md#prepare_step)).

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 575

</div>

### slot\_ids {#slot_ids}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`slot_ids`**

</div>

continuous: `[B]` Int32 slot ids on device, the attention op's [`slot_ids`](./KVCache.StepIndices.md#slot_ids); undefined on a paged cache.

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 578

</div>

### kv\_position\_offset {#kv_position_offset}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`kv_position_offset`**

</div>

A paged cache whose attention window has released a sequence's early blocks: `[B]` Int32, each sequence's served-key offset. Sequence b's served key at position i of its view sits at absolute position i + offset\[b\], so rotary and the window read true positions. Undefined on every other cache; pass it on as-is.

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 584

</div>

### max\_seqlen\_k {#max_seqlen_k}

<div class="api-signature">

`std::int64_t` **`max_seqlen_k`** `= 0`

</div>

the step's max per-seq post-append KV length (host scalar).

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 585

</div>

### groups {#groups}

<div class="api-signature">

`std::vector<`[`StepIndices`](./KVCache.StepIndices.md)`>` **`groups`**

</div>

Row-group views + the layer→group map. A group is the set of layers sharing one index shape (layout / window / K-V geometry); a uniform cache has one group and leaves both vectors EMPTY. Filled only on a cache carrying more than one group; every entry shares [`cu_seqlens_q`](./KVCache.StepIndices.md#cu_seqlens_q), and tensor handles are shared, never copied.

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 593

</div>

### group\_of\_layer {#group_of_layer}

<div class="api-signature">

`std::vector<std::int32_t>` **`group_of_layer`**

</div>

Row-group index per layer ([`group_of_layer`](./KVCache.StepIndices.md#group_of_layer)`[layer]` -\> the [`groups`](./KVCache.StepIndices.md#groups) entry that layer's view binds).

<div class="api-declared">

Declared in `ClikaRT/nn/kv_cache.h`, line 596

</div>
