Skip to content

fix(examples): future_apis needs sm_90, not sm_80 - #666

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/future-apis-tma-floor
Aug 6, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/future-apis-tma-floor

Conversation

@vyncint

@vyncint vyncint commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #658, which I got wrong for this one example.

What was wrong

#658 gated future_apis at sm_80, reasoning from its mbarrier_{init,arrive,test_wait,inval} calls. Those really are sm_80 instructions and they are the only arch-sensitive ones the emitted PTX contains — but the kernels also construct ManagedBarrier<_, TmaBarrier>, and the backend detects that as a TMA feature. Asking for anything lower is refused outright:

error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed:
CUDA target sm_86 cannot lower detected feature Tma + Sm80; cuda-oxide
requires a target compatible with sm_100 for this module

Under an auto-detected target the build instead succeeds at .target sm_100, and the module then fails to load. So the too-low floor did not present as a clean skip — it presented as DriverError(218, "a PTX JIT compilation failed") on every pre-Blackwell device, Ampere and Hopper alike, not merely the pre-Ampere hardware #658 was aimed at.

Both compiler behaviours are the designed ones: fail closed on an explicit low --arch, raise the target when it is auto-detected. Only the floor in the example was wrong.

The change

major < 8 → major < 10, matching clc and tma_multicast, with the compiler's own diagnostic quoted in the comment so the floor is not re-derived from the visible instructions next time. That was exactly my mistake: the instructions in the PTX say sm_80, and they are not what sets the requirement.

Verification

NVIDIA A10G (compute_cap 8.6):

[ 1/ 2] future_apis                      ... PASS (skipped)
[ 2/ 2] vecadd                           ... PASS
Pass:    2 / 2
=== Future APIs Test (Unified) ===

skipping: TMA-typed barriers require sm_100+ (device is sm_86)

Before this change, the same example on the same device failed with DriverError(218) — including after touch crates/*/src/lib.rs to force a full backend rebuild, so it was not a stale-artifact effect. cargo fmt --check clean.

How this went unnoticed in #658

@nihalpasham validated #658 on CC 12.0, where sm_100 ≤ the device and the example runs its real path correctly — so nothing there could have shown it. I validated on sm_75, where the guard fires and the example skips, which also hides it. The failure only appears in the band between the two, on Ampere and Hopper, and that is where I found it: running the full suite on an A10G, which sits inside the documented sm_80+ support floor.

Worth noting for the target-selection discussion in #656: Tma + Sm80 resolving to a requirement of sm_100 rather than sm_90 is the part I do not understand, since TMA itself is Hopper. I have not investigated whether that mapping is intentional and am not proposing a change to it here — this PR only corrects the example's floor to match whatever the backend requires today.

vyncint and others added 2 commits August 5, 2026 21:35
The guard added in NVIDIA#658 gates future_apis at sm_80 on the strength of its
mbarrier calls. Those would indeed run on Ampere, but the kernels also
construct `ManagedBarrier<_, TmaBarrier>`, and the backend detects that as a
TMA feature. Building for anything lower is refused outright:

  error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed:
  CUDA target sm_86 cannot lower detected feature Tma + Sm80; cuda-oxide
  requires a target compatible with sm_100 for this module

Under an auto-detected target the build instead succeeds at .target sm_100 and
the module then fails to load, so the too-low floor surfaced as
DriverError(218, "a PTX JIT compilation failed") on every pre-Blackwell
device -- Ampere and Hopper alike, not just the pre-Ampere hardware the
original guard was aimed at. Both behaviours are the designed ones; only the
floor was wrong.

Raised to sm_100, matching clc and tma_multicast.

Verified on an NVIDIA A10G (sm_86): future_apis now reports
"skipping: TMA-typed barriers require sm_100+ (device is sm_86)" and the
smoketest passes 2/2 with vecadd as an executing control. Before this change
the same example failed with DriverError(218) on that device, including after
a forced full backend rebuild.

Refs NVIDIA#656

Signed-off-by: Vyncint Ng <[email protected]>
The requirement comes from fence.proxy.async, an sm_90 instruction that
ManagedBarrier::init_by emits for every barrier kind; the TmaBarrier
typestate parameter is inert PhantomData and detects nothing. On real
hardware the device hint resolves the target, so a Hopper box builds
and runs this example at sm_90; skipping below sm_100 would silently
drop coverage on exactly the generation these mbarrier/proxy-fence
APIs were built for. Guard at major < 9 and let the comment and skip
message carry the correct derivation.

Verified on an RTX 5090 (sm_120): all five tests execute and pass.
@nihalpasham nihalpasham added bug Something isn't working examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples labels Aug 6, 2026
@vyncint vyncint changed the title fix(examples): future_apis needs sm_100, not sm_80 fix(examples): future_apis needs sm_90, not sm_80 Aug 6, 2026
@vyncint

vyncint commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up for review: the description above documents the superseded first revision. The head of this branch is 8615368f, which corrects the floor to sm_90, so the title (now fixed) and the sm_100 reasoning and skip-message output quoted in the body no longer match the diff. The code comment on the branch is the accurate account.

I confirmed the sm_90 floor independently today, arriving at it from the other direction, and it can be pinned with no GPU by rewriting only the .target line of the generated PTX:

cd crates/rustc-codegen-cuda/examples/future_apis
for arch in sm_86 sm_90; do
  sed "s/^\.target .*/.target $arch/" future_apis.ptx > /tmp/fa_$arch.ptx
  printf '%-8s : ' "$arch"; ptxas -arch=$arch /tmp/fa_$arch.ptx -o /dev/null 2>&1 | head -1; echo
done
sm_86    : ptxas fatal   : Modifier '.async' requires .target sm_90 or higher
sm_90    :

The module contains no actual TMA — cp.async.bulk., expect_tx, .sync_restrict, tcgen05 and clusterlaunchcontrol. are all absent — so the proxy fence emitted next to every mbarrier.init is the sole trigger for both the sm_90 requirement and the Tma classification.

I also verified on an A10G (sm_86, driver 595.71.05) that the major < 9 gate takes the skip path and exits 0, so the example reports PASS (skipped). That was via #677, which made the identical change before I realised this PR already existed; I have closed it as a duplicate. The skip message string differs between the two, so I am not quoting output as if it came from this branch.

One question, which I raised on #676 before closing that as a duplicate too: ManagedBarrier::init_by emits fence.proxy.async for every Kind. Its purpose is to make generic-proxy writes visible to the async proxy, so a ManagedBarrier<_, GeneralBarrier> that never feeds an async copy plausibly does not need it. If the fence can be predicated on Kind, plain barriers would keep working on Ampere exactly as the original sm_80 comment intended, instead of the whole API being Hopper+. I have not attempted it because I do not want to guess at the ordering requirement. Worth a separate issue, or is the unconditional fence deliberate?

@nihalpasham

Copy link
Copy Markdown
Collaborator

Good catch on the symptom; the floor needed one correction, which I pushed on top:

  • the guard is major < 9, not < 10: the requirement is fence.proxy.async (sm_90; ptxas rejects it below that), emitted by ManagedBarrier::init_by for every barrier kind — the TmaBarrier typestate is inert PhantomData and detects nothing.
  • On a Hopper box the device hint resolves the target to sm_90 and the example genuinely runs, so skipping below sm_100 would have silently dropped coverage on exactly the generation these APIs were built for.

Verified on RTX 5090 (sm_120):

  • all five tests execute and pass; on pre-Hopper devices the guard now exits with a clean skip instead of DriverError(218).

Closes #676.

The compiler-side question it leaves open (a bare sm_90 fence classified as Tma with an sm_100 no-hint default) is split into its own issue.

@nihalpasham
nihalpasham merged commit dbccfaf into NVIDIA:main Aug 6, 2026
57 of 65 checks passed
nihalpasham added a commit that referenced this pull request Aug 19, 2026
…time gate (#1017)

* docs(examples): three READMEs state a minimum GPU below their own runtime gate

Fourteen examples gate `main` on compute capability. Three of them also state a
**Minimum GPU** in their README, and all three state one lower than the gate
they ship with -- so the README says the example runs on hardware where it
prints `skipping:` and returns:

  example            README said           gate in main()   gate's own message
  future_apis        Volta (sm_70)         major < 9        "fence.proxy.async ... requires sm_90+"
  coop_groups_demo   Volta (sm_70+)        major < 9        "thread block clusters require sm_90+"
  barrier            Volta (sm_70)         major < 8        "mbarrier requires sm_80+"

`future_apis` is the one with history: 8615368 corrected that gate to
`major < 9` during the #666 review -- the requirement is `fence.proxy.async`,
emitted by `ManagedBarrier::init_by` for every barrier kind, which ptxas
rejects below sm_90, and the `TmaBarrier` typestate is inert `PhantomData` that
detects nothing. The gate moved; the README did not.

In all three cases the sm_70 figure is not invented -- it is the floor of *one*
instruction family the example touches (mbarrier, or `match.any.sync`) rather
than the floor for running the example. Each entry now states the real floor,
cites the gate that enforces it, and keeps the sm_70 fact as the aside it
always was, so the next reader does not have to reconcile them.

Every gate here is in `main()` and returns immediately, so this is the whole
example's floor, not one test's.

Verified: swept all 215 example READMEs -- these three were the only ones whose
stated Minimum GPU did not match a gate in their own `main`, and after this
change none do. check-error-example-status and
check-example-smoketest-contract pass.

Signed-off-by: Vyncint Ng <[email protected]>

* docs(examples): fix mbarrier floor asides and unreachable gate text

The three README floors from the parent commit were right, but four
asides still contradicted the runtime gates:

- barrier: the sm_70 mbarrier claim is libcu++'s software fallback,
  not the PTX instructions this example emits (those need sm_80+,
  matching cuda-device's barrier support notes)
- barrier: drop the Pre-Volta troubleshooting row; the sm_80 gate in
  main skips before any kernel could hit it
- coop_groups_demo: pre-Hopper devices never reach the combined
  cluster+cooperative message; main exits at its sm_90 skip line first
- future_apis: mbarrier instructions need sm_80+, and fence.proxy.async
  is what sets the sm_90 floor

---------

Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working examples Example kernels and host harnesses under crates/rustc-codegen-cuda/examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants