← Back to Pull requests

Lower cuda.lanemask_lt() by reading the %lanemask_lt special register #420

Closed
unknown closed this pull request without merging on Dec 03, 2026 17:58 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 19:08 UTC
Author

Fixes #373

cuda.lanemask_lt() is listed in the kernel API reference and types as () -> uint32, but it had no lowering, so a kernel that calls it failed to compile:

UserFacingInternalCompilerError: This line in your program has triggered a compiler bug ...
  caused by NotImplementedError: NotImplemented lowering call to <class 'numba_cuda_mlir.numba_cuda.stubs.lanemask_lt'>
  signature: () -> uint32

This PR:

  • adds a @lower(cuda.lanemask_lt) in lowering/cuda.py that emits nvvm.read_ptx_sreg_lanemask_lt();

  • adds NVVM::LaneMaskLtOp to the special-register table in the LLVM 7 translator (cext/mlir-llvm70/lib/LLVM70Target.cpp, translateSregOp and the translateNVVMOp case list), lowering it to mov.u32 $0, %lanemask_lt; like the other special registers. Without it the translator rejects the op with "unsupported NVVM op: nvvm.read.ptx.sreg.lanemask.lt";

  • adds a read_lanemask_lt case to cext/mlir-llvm70/test/sreg_extra.mlir that checks both the LLVM IR and the PTX.
  • The existing test_warp_ops.py::test_lanemask_lt (ported from numba-cuda) already checks lane i against (1 << i) - 1. Its xfail(True, reason="Lanemask not implemented") marker is removed.

    (The first version of this PR read the register with inline asm from Python. It was switched to the translator approach after review.)

    Testing

    RTX 4050 Laptop (sm_89), CUDA 13.4, Python 3.12.

  • I can't build the C++ extension locally, so the translator change and the lit test haven't run yet. I'll test with this PR's CI wheel once CI has run.

  • The Python side was checked against the bd28aef wheel: nvvm.read_ptx_sreg_lanemask_lt() builds and prints as nvvm.read.ptx.sreg.lanemask.lt : i32, the op the new translator case matches.

  • The first, inline-asm version passed the repro from the issue (lane i returned (1 << i) - 1) and test_lanemask_lt. pytest -n 4 tests --ignore=tests/benchmarks matched the unmodified wheel except for test_lanemask_lt moving from xfail to pass.

  • pre-commit passes on the changed files.
  • This change was developed with AI assistance (Claude Code).

    Diff: 264 lines (+198 / -66) across 3 files Reviewer: atmnp Review duration: 48890m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 264 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.334
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #420"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.5% · Safe to merge
    15.5%