← Back to Pull requests

Let a custom mapping define the linear index of its work-items #848

Closed
unknown closed this pull request without merging on Oct 07, 2026 08:17 UTC
View on GitHub
unknown unknown commented on Oct 06, 2026 12:08 UTC
Author

For a custom NDRange mapping, @index(Global, Linear) is linear_index(__ndrange(ctx), expand(iterspace, group, item)): the position of the expanded index within the context's ndrange. That doesn't fit a mapping whose linear index isn't a function of the expanded index alone. The motivating case is Oceananigans launching kernels over a list of active cells (CliMA/Oceananigans.jl#5799), where the linear index of a work-item is its position in the list. A cell can't be mapped back to that position without a reverse lookup, so that PR overrides the internal __index_Global_Linear for its context type instead. #781 documents that as something not to do, and it only works as long as @index lowers through that function.

This adds a hook on the iteration space:

NDIteration.linear_index(iterspace::NDRange, ndrange, groupidx::CartesianIndex, idx::CartesianIndex)

It defaults to the previous definition, linear_index(ndrange, expand(iterspace, groupidx, idx)), and global_linear calls it for iteration spaces other than KernelAbstractions' own. A mapping specializes it on its NDRange type, e.g. for Oceananigans:

NDIteration.linear_index(r::MappedNDRange, ::MappedIndices, g::CartesianIndex{1}, i::CartesianIndex{1}) = mapped_position(r, g, i)

KernelAbstractions' built-in iteration spaces (identity and offsets) still take the direct path, so their code doesn't change.

Open points

  • If this goes in, the contract documented in #781 should list the hook next to expand and cartesian. I've left #781 alone.
  • Testing

  • New test: the launch testsuite gets a launch over a list of indices, with a partial last workgroup. It checks that each listed index is visited once, that nothing else is touched, and that @index(Global, Linear) is the position in the list. Without the hook the kernel doesn't compile (linear_index(::ListedIndices, ::CartesianIndex) has no method); with it the test passes on the CPU backend. The GPU back-ends will run it through the shared testsuite.

  • Existing tests: the full test suite passes locally on Julia 1.12 with the hook (run before the new test was added; the launch testsuite including it passes on its own).

  • Oceananigans: a standalone copy of the IndexMap launch from CliMA/Oceananigans.jl@6852216 passes with the hook in place of the __index_Global_Linear override.
  • 🤖 Generated with Claude Code

    Diff: 306 lines (+229 / -77) across 3 files Reviewer: giordano Review duration: 1208m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 306 lines diff across 3 files
    0.40
    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.343
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #848"
    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: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    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.9% · Safe to merge
    15.9%