{"record":{"id":"a6b6b9b4321cc741","repo":"jax-ml/jax","slug":"expected-a-dynamic-index-or-an-integer-got-offse","errorCode":null,"errorMessage":"Expected a dynamic index or an integer, got {offset}","messagePattern":"Expected a dynamic index or an integer, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":1077,"sourceCode":"    return BarrierRef(address, c(0, i32), phases, num_barriers)\n\n  def __iter__(self) -> Iterator[\"BarrierRef\"]:\n    if self.num_barriers == 1:\n      yield self\n    else:\n      for offset in range(self.num_barriers):\n        yield self[offset]\n\n  def __getitem__(self, offset: ir.Value | int) -> \"BarrierRef\":\n    i32 = ir.IntegerType.get_signless(32)\n    if isinstance(offset, int):\n      if offset >= self.num_barriers:\n        raise IndexError(f\"Barrier offset {offset} is out of bounds\")\n      offset = c(offset, i32)\n    elif isinstance(offset.type, ir.IndexType):\n      offset = arith.index_castui(i32, offset)\n    elif offset.type != i32:\n      raise ValueError(f\"Expected a dynamic index or an integer, got {offset}\")\n    return BarrierRef(\n        self.base_address,\n        arith.addi(self.offset, offset),\n        self.phases,\n        1,\n    )\n\n  @property\n  def _ptx_scope(self) -> str:\n    if self.base_address.type == ir.Type.parse(\"!llvm.ptr<7>\"):\n      return \"cluster\"\n    return \"cta\"\n\n  @property\n  def _nvvm_scope(self) -> nvvm.MemScopeKind:\n    if self.base_address.type == ir.Type.parse(\"!llvm.ptr<7>\"):\n      return nvvm.MemScopeKind.CLUSTER\n    return nvvm.MemScopeKind.CTA","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L1059-L1095","documentation":"Barrier offsets must be Python ints, index-typed values, or i32 values. Anything else (i64, f32, tensor, etc.) reaches the final else and raises ValueError telling you what type was passed.","triggerScenarios":"group[i64_value] where i64_value = arith.constant(1, i64); group[1.0]; passing an unconverted OpResult of non-i32 type.","commonSituations":"Computing barrier offsets with 64-bit arithmetic (e.g. byte offsets or grid math) and forgetting to cast; mixing pointer/integer width conventions between PTX asm helpers and the barrier API.","solutions":["Cast to i32: arith.trunci(ir.IntegerType.get_signless(32), val)","Use index type for dynamic offsets (auto-cast via index_castui) or plain Python ints for static ones","Validate with isinstance(offset, int) or offset.type in (i32, IndexType) before indexing"],"exampleFix":"# before\nref = group[offset_i64]\n# after\noffset = arith.trunci(ir.IntegerType.get_signless(32), offset_i64)\nref = group[offset]","handlingStrategy":"type-guard","validationCode":"i32 = ir.IntegerType.get_signless(32)\nif isinstance(offset, ir.Value) and offset.type not in (i32, ir.IndexType.get()):\n    offset = arith.trunci(i32, offset)","typeGuard":"def valid_barrier_offset(o) -> bool:\n    i32 = ir.IntegerType.get_signless(32)\n    return isinstance(o, int) or (isinstance(o, ir.Value) and o.type in (i32, ir.IndexType.get()))","tryCatchPattern":null,"preventionTips":["Do offset arithmetic in i32 or index type, not i64","Use Python ints for static barrier offsets"],"tags":["jax","mosaic-gpu","barrier","type-mismatch"],"backgroundTag":"mlir-integer-width-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}