﻿# Pallas BlockSpec: an index map selects blocks rather than ordinary element offsets

Validate Pallas BlockSpec mappings by translating invocation coordinates into logical array slices, keeping block indices, element offsets and tail handling distinct.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-pallas-blockspec-block-index-contract/
Language: en

## Draw the intended slices before writing the kernel

A custom feature kernel works on tiles, but its first implementation skips most of the input. The author multiplied a program coordinate by the tile length inside an index map that already uses block coordinates. The [BlockSpec guide](https://docs.jax.dev/en/latest/pallas/grid_blockspec.html) defines this blocked-index distinction. Write down the intended logical slice for a representative invocation before optimizing arithmetic. This exposes an incorrect coordinate system even when the kernel body is numerically correct for every tile it actually receives.

## Separate invocation space from array space

A grid describes kernel invocations; an input specification maps those invocations to the blocks they access. A matrix operation can reuse an input tile across several output invocations, so a grid coordinate need not correspond directly to the same array axis in every operand. Name the roles of each coordinate. An explicit mapping table makes shared inputs and distinct outputs understandable without relying on coincidentally equal grid sizes or similarly named dimensions.

## Match references to the declared block interface

The [pallas_call reference](https://docs.jax.dev/en/latest/_autosummary/jax.experimental.pallas.pallas_call.html) connects input and output specifications to the references supplied to the kernel. Review the shape visible inside the kernel separately from the full array shape. Local indexing operates within the selected block interface. A helper copied from an ordinary array implementation can accidentally apply global offsets again, reading the wrong region even though its arithmetic expression looks identical to the reference algorithm.

## Define what partial tiles mean mathematically

Do not assume values outside the logical input are useful numerical padding. Establish how invalid tile positions are excluded or replaced by a neutral value before a reduction. Discarding an exterior output position does not prevent an exterior input value from influencing a valid aggregate. Test dimensions that leave a partial final tile so correctness does not depend on every example dividing evenly into the selected block geometry.

## Verify the mapping with recognizable data

The [Pallas quickstart](https://docs.jax.dev/en/latest/pallas/quickstart.html) demonstrates block-oriented custom kernels. Use recognizable row and column patterns to verify the complete operation against a normal array implementation. The guides on [tensor memory descriptors](/journal/learn-tensor-memory-descriptor/) and [parallel reduction order](/journal/learn-parallel-reduction-tree/) provide related context. Correct tiling requires both the intended slice mapping and valid local arithmetic. Passing a single full-tile example establishes neither complete coverage nor safe handling of the final partial region.
