{"record":{"id":"df207b20d59957e0","repo":"jax-ml/jax","slug":"range-rnge-is-entirely-out-of-bounds-for-shape","errorCode":null,"errorMessage":"Range {rnge} is entirely out of bounds for shape {self.shape}.","messagePattern":"Range (.+?) is entirely out of bounds for shape (.+?)\\.","errorType":"validation","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/interpret/shared_memory.py","lineNumber":317,"sourceCode":"    \"\"\"Returns the portion of `self.content` specified by `rnge`.\n\n    Args:\n      rnge: The range to read.\n\n    Raises:\n      IndexError: If `rnge` is entirely out of bounds for the allocated array in\n        the `Buffer`, i.e. `rnge` is out of bounds for `self.shape`.\n\n    Returns:\n      The portion of `self.content` specified by `rnge`.\n    \"\"\"\n    rnge = self._normalize_range(rnge)\n    rnge_or_none = interpret_utils.clip_range_to_shape(rnge, self.shape)\n    if rnge_or_none is None:\n      # Raise if reading entirely outside of the allocated shape. We leave it to\n      # the client to handle the case where out-of-bounds reads are allowed (and\n      # should return uninitialized values).\n      raise IndexError(\n          f\"Range {rnge} is entirely out of bounds for shape {self.shape}.\"\n      )\n\n    rnge = rnge_or_none\n    return self.content[rnge]\n\n  def _set_within_logical_shape(\n      self, rnge: tuple[slice | int, ...], value: np.ndarray\n  ):\n    \"\"\"Updates `self.content` with `value` for the portion of `rnge` within `self.logical_shape`.\"\"\"\n    rnge_or_none = interpret_utils.clip_range_to_shape(rnge, self.logical_shape)\n    if rnge_or_none is None:\n      return\n\n    rnge = rnge_or_none\n    shape_to_write = self.content[rnge].shape\n    self.content[rnge] = value[tuple(slice(0, s) for s in shape_to_write)]\n","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/interpret/shared_memory.py#L299-L335","documentation":"Interpret-mode Buffer.__getitem__ received an index range that lies entirely outside the allocated shape. Since even the clipped intersection is empty (clip returned None), reading is meaningless and the error is raised rather than returning uninitialized data.","triggerScenarios":"Indexing an interpret shared memory Buffer with a slice whose start is >= the allocation extent on some axis, e.g. buf[128:256, :] on a shape-(128, 64) buffer, when no out-of-bounds-read permission was arranged by the caller.","commonSituations":"Grid/block-index arithmetic that walks past the end of an allocation; incorrect grid size assumptions on edge tiles; kernels relying on padded OOB reads without configuring interpret mode to allow them.","solutions":["Fix the index computation so slice starts fall within the allocation (clamp with min(start, size - 1))","Verify grid iteration bounds match the allocation shape; shrink grid or enlarge allocation","If OOB reads are expected to return uninitialized values, route reads through APIs that handle padding (_get_with_padding / out-of-bounds handling)"],"exampleFix":"// before\nval = smem[start:block_size, :]\n// after\nval = smem[min(start, smem.shape[0] - 1):min(start + block_size, smem.shape[0]), :]","handlingStrategy":"validation","validationCode":"from jax._src.pallas.mosaic.interpret import interpret_utils\nrnge = tuple(r if isinstance(r, slice) else slice(r, r + 1) for r in rnge)\nassert interpret_utils.clip_range_to_shape(rnge, buf.shape) is not None, 'read range entirely OOB'","typeGuard":null,"tryCatchPattern":"try:\n    data = buf[rnge]\nexcept IndexError as e:\n    if 'entirely out of bounds' in str(e):\n        data = np.zeros(())  # or skip tile\n    else:\n        raise","preventionTips":["Clamp slice starts with min(start, size - 1) at grid edges","Use padded-read APIs when OOB reads should return uninitialized values"],"tags":["jax","pallas","mosaic","index-error","out-of-bounds","interpret-mode"],"backgroundTag":"index-out-of-bounds","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}