{"record":{"id":"c7e52dc2d6c03be2","repo":"jax-ml/jax","slug":"cannot-cast-src-to-dst-type","errorCode":null,"errorMessage":"cannot cast {src} to {dst_type}","messagePattern":"cannot cast (.+?) to (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/triton/lowering.py","lineNumber":1735,"sourceCode":"  if _is_triton_pointer_type(src_element_type) and isinstance(\n      dst_element_type, ir.IntegerType\n  ):\n    if dst_element_type.width == 64:\n      return tt_dialect.ptr_to_int(dst_type, src)\n    elif dst_element_type.width == 1:\n      x = _ir_cast(src, ir.IntegerType.get_signless(64), signed=signed)\n      zero = _zeros_like(x)\n      return _ir_cast(_not_equal(x, zero, signed=signed), dst_type, signed=signed)\n  if isinstance(src_element_type, ir.IntegerType) and _is_triton_pointer_type(\n      dst_element_type\n  ):\n    return tt_dialect.int_to_ptr(dst_type, src)\n  if _is_triton_pointer_type(src_element_type) and _is_triton_pointer_type(\n      dst_element_type\n  ):\n    return tt_dialect.bitcast(dst_type, src)\n\n  raise NotImplementedError(f\"cannot cast {src} to {dst_type}\")\n\n\n@register_lowering(lax.convert_element_type_p)\ndef _convert_element_type_lowering_rule(\n    ctx: LoweringRuleContext, x, *, new_dtype, weak_type, sharding\n):\n  [x_aval] = ctx.avals_in\n  x = _ensure_ir_value(x, x_aval)\n  if new_dtype == x_aval.dtype:\n    return x\n  cc = ctx.context.compute_capability\n  return _cast(x, x_aval.dtype, new_dtype, compute_capability=cc)\n\n\n@register_lowering(lax.select_n_p)\ndef select_n_lowering_rule(ctx: LoweringRuleContext, pred, x, y):\n  pred_aval, a_aval, b_aval = ctx.avals_in\n  [out_aval] = ctx.avals_out","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/triton/lowering.py#L1717-L1753","documentation":"This is the final fallback in _ir_cast: the cast between the given MLIR types has no lowering rule implemented in JAX's Triton Pallas backend. Only int<->int, float<->float (via F32 for f16/bf16), ptr<->ptr bitcasts and a few signed/unsigned combinations are handled; everything else falls through to this NotImplementedError.","triggerScenarios":"Casting between type classes the lowering does not handle, e.g. float to pointer, integer to float (in some paths), complex types, or casts involving Triton pointer types not matching the int_to_ptr/ptr bitcast branches. Typically surfaces from convert_element_type, load/store `other` values, or index computation.","commonSituations":"Exotic casts inside Pallas kernels (e.g. reinterpret-style tricks that worked in Triton-lang), complex64 kernels, bool/int1 handling edge cases, or version mismatches where the kernel was written against newer lowering capabilities.","solutions":["Split the cast into supported steps (e.g. via f32 for float types, or explicit signed casts)","Avoid pointer<->numeric casts in the Python kernel body; compute integer offsets instead","Print src/dst MLIR types at the failure site to identify which branch is missing and restructure the kernel accordingly","File/check a JAX GitHub issue — missing cast combinations are implemented incrementally"],"exampleFix":"// before\np = x.astype some_ptr_type  # float -> pointer\n\n// after\noff = x.astype(jnp.int32)\np = base_ptr + off  # use pointer arithmetic on integer offsets","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    lowered = kernel_compile_and_run(...)\nexcept NotImplementedError as e:\n    if 'cannot cast' in str(e):\n        # inspect e for src/dst types and split the cast via f32\n        x = x.astype(jnp.float32).astype(target)","preventionTips":["Restrict kernel casts to numeric->numeric via f32 intermediates","Avoid pointer reinterpretation in Python-level Pallas kernels","Pin JAX version; missing cast lowerings are added frequently"],"tags":["jax","triton","pallas","mlir","cast","not-implemented"],"backgroundTag":"unsupported-operation-not-implemented","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}