{"record":{"id":"939dbd971bee05c5","repo":"jax-ml/jax","slug":"mask-cannot-be-a-block-if-pointer-is-not-a-block","errorCode":null,"errorMessage":"mask cannot be a block if pointer is not a block","messagePattern":"mask cannot be a block if pointer is not a block","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/triton/lowering.py","lineNumber":2050,"sourceCode":"          f\"unsupported eviction policy: {eviction_policy}\"\n      ) from None\n\n  if _is_triton_pointer_type(ptr.type):\n    ptr_type = tt_dialect.PointerType(ptr.type)\n    if isinstance(ptr_type.pointee_type, ir.RankedTensorType):\n      raise NotImplementedError(\"loading from a block pointer is not supported\")\n\n  ptr_type = _element_type(ptr.type)\n  if not _is_triton_pointer_type(ptr_type):\n    raise ValueError(f\"unsupported pointer type: {ptr_type}\")\n  ptr_type = tt_dialect.PointerType(ptr_type)\n  if other is not None and mask is None:\n    raise ValueError(\"other requires mask to be provided\")\n  if not isinstance(ptr.type, ir.RankedTensorType):\n    if other is not None and isinstance(other.type, ir.RankedTensorType):\n      raise ValueError(\"other cannot be a block if pointer is not a block\")\n    if mask is not None and isinstance(mask.type, ir.RankedTensorType):\n      raise ValueError(\"mask cannot be a block if pointer is not a block\")\n\n  pointee_type = ptr_type.pointee_type\n  is_int1 = isinstance(pointee_type, ir.IntegerType) and pointee_type.width == 1\n  if is_int1:\n    pointee_type = ir.IntegerType.get_signless(8)\n    ptr = _ir_cast(\n        ptr,\n        tt_dialect.PointerType.get(pointee_type, ptr_type.address_space),\n        signed=False,\n    )\n\n  if other is not None:\n    other = _ir_cast(other, pointee_type, signed=False)\n\n  result = tt_dialect.load(\n      ptr,\n      mask=mask,\n      other=other,","sourceCodeStart":2032,"sourceCodeEnd":2068,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/triton/lowering.py#L2032-L2068","documentation":"For a scalar (non-block) pointer load, the mask must also be scalar. A tensor-typed (block) mask is inconsistent with a scalar load and is rejected with this ValueError in _load.","triggerScenarios":"Passing a block-shaped boolean mask with a scalar pointer, e.g. pl.load(ref, mask=idx_block < n) where ref refers to a single element, inside a Triton Pallas kernel.","commonSituations":"Boundary-checking masks written for block loads reused on scalar loads; broadcasting assumptions carried over from XLA.","solutions":["Use a scalar mask (e.g. a single boolean condition) for scalar pointer loads","Or perform a block load from a block reference so the mask shape matches","Skip the mask for unconditional scalar loads"],"exampleFix":"// before\nv = pl.load(scalar_ref, mask=idx_block < n, other=0.0)\n\n// after\nv = pl.load(scalar_ref, mask=scalar_cond, other=0.0)","handlingStrategy":"validation","validationCode":"def check_load_shapes(ptr_is_block: bool, mask):\n    if not ptr_is_block and mask is not None:\n        assert getattr(mask, 'shape', ()) == (), 'mask must be scalar for scalar loads'","typeGuard":"def mask_matches_pointer(ptr_is_block: bool, mask) -> bool:\n    if mask is None:\n        return True\n    mask_is_block = getattr(mask, 'shape', ()) != ()\n    return ptr_is_block == mask_is_block","tryCatchPattern":"try:\n    v = pl.load(ref, mask=m, other=o)\nexcept ValueError:\n    v = pl.load(ref, mask=bool(m_scalar), other=o)","preventionTips":["Keep mask rank equal to pointer rank (scalar for scalar loads)","Compute scalar conditions for scalar loads","Use shared helpers that build mask/other pairs consistently"],"tags":["jax","triton","pallas","load","mask","shape","validation"],"backgroundTag":"argument-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}