Repository navigation
feat(mir): implement device-side SetDiscriminant lowering - #307
Merged
Merged
Conversation
goog00
force-pushed
the
feat-set-discriminant
branch
from
June 29, 2026 11:45
0bb8c20 to
fa87944
Compare
Add mir.set_discriminant op, wire it through mir-importer and mir-lower, and convert error_set_discriminant_unhandled into a passing example. Direct-tag enums are now supported; niche-encoded enums are rejected loudly until their payload encoding is handled. Signed-off-by: sunteng <[email protected]>
nihalpasham
force-pushed
the
feat-set-discriminant
branch
2 times, most recently
from
July 1, 2026 09:04
88fde1b to
af3b5e9
Compare
Classify direct, niche, single, and empty layouts explicitly; reject impossible variants; and add lowering plus end-to-end regression coverage. Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
feat-set-discriminant
branch
from
July 1, 2026 09:11
af3b5e9 to
b564a25
Compare
Collaborator
|
Thanks for the PR. It LGTM A couple of points:
This rounds out the inhabited direct-tag part of #306; but I think #306 should stay open for niche encoding. |
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
Two host-side launch-path fixes, measured with the new `host_overhead` bench (RTX 5090, µs per launch). Site misses (a scalar argument's divisibility hint changed, or a new specialization) no longer pay filesystem and environment lookups per launch: the assembler fingerprint, resolved toolchain and `CUTILE_BYTECODE_VERSION` override are trusted for one second before being re-checked, so a mid-process toolchain switch still takes effect within that window. Missed launch 5.73 → 4.29. Site hits no longer allocate in the launcher: the kernel-argument arena lives inline in the launch (heap only beyond 32 parameter slots), shape validation compares the bound partition shape in place, the site probe borrows fixed arrays, and grid inference takes the first exact bound without collecting. Heap allocations per four-tensor launch 15 → 2; hit 1.905 → 1.696 against a 1.30 driver floor for the same twelve-parameter `cuLaunchKernel`. Awaited launches and graph replays are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #306.
Implements lowering for MIR
StatementKind::SetDiscriminanton the device.Previously, enum discriminant writes were rejected with an "unsupported" diagnostic (after an earlier silent-miscompile regression where they were dropped entirely). This PR adds a dedicatedmir.set_discriminantoperation and lowers it through the full pipeline so that direct-tag enums can now be mutated inside#[kernel]functions. Niche-encoded enums are still rejected loudly until their payload-scalar encoding is handled.Changes
MirSetDiscriminantOptodialect-mirwith verifier tests.mir-importerto translateSetDiscriminantintomir.constant+mir.set_discriminantinstead of erroring.mir-lowerto convertmir.set_discriminanttollvm.getelementptr(to the enum tag slot) +llvm.store.error_set_discriminant_unhandledto the positive exampleset_discriminantand updatedSTATUS.mdandscripts/smoketest.shaccordingly.Testing
cargo test -p dialect-mir -p mir-importer -p mir-lower --lib --testspasses.cargo clippy -p dialect-mir -p mir-importer -p mir-lower --lib -- -D warningspasses.cargo oxide run set_discriminantpasses on RTX 5090 (sm_120a):PASS: all 64 threads observed the SetDiscriminant write.
scripts/smoketest.shpasses.Follow-up
Issue #306 also covers niche-encoded enums such as
Option<&T>andOption<NonZeroU32>, where the discriminant is encoded in the payload scalar itself rather than a separate tag. A follow-up PR will implement the payload-scalar rewrite path for those cases.Checklist
git commit -s)cuda-bindings/modified by an external contributor (see CONTRIBUTING.md)