vllm.v1.attention.ops.prefix_prefill ¶
_paged_kv_cache_offsets(B_Loc, cur_batch, token_indices, token_valid, offs_d, cur_kv_head, x, stride_b_loc_b, stride_b_loc_s, stride_k_cache_bs, stride_k_cache_h, stride_k_cache_d, stride_k_cache_bl, stride_k_cache_x, stride_v_cache_bs, stride_v_cache_h, stride_v_cache_d, stride_v_cache_bl, PHYSICAL_BLOCK_SIZE, MASK_BLOCK_TABLE=False) ¶
Compute paged K/V cache element offsets for a tile of token positions.
token_indices holds the absolute sequence positions of the tile. The logical block for each token is looked up in B_Loc (handling cross-block tiles), then the physical element offsets are built with the same layout the kernel uses everywhere: K cache: [num_blocks, num_kv_heads, head_size // x, block_size, x] V cache: [num_blocks, num_kv_heads, head_size, block_size] Returns (off_k, off_v) with shapes [D, N] and [N, D] respectively.
When MASK_BLOCK_TABLE is set, the block-table load is masked with token_valid so padded lanes (a tile that extends past the end of the sequence) cannot read a block-table entry past this batch's row. Invalid lanes resolve to block 0 (always in-bounds) and are dropped by the caller's later K/V load mask. When it is not set, token_valid is unused and the load is emitted exactly as before.