Skip to content

Don't cache ptxas PTX-verification passes - #2809

Merged
sylvestre merged 2 commits into
mozilla:mainfrom
tinglvv:ptxas-ptx-verify-noncacheable
Nov 2, 2026
Merged

sylvestre merged 2 commits into
mozilla:mainfrom
tinglvv:ptxas-ptx-verify-noncacheable

Conversation

@tinglvv

@tinglvv tinglvv commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

When nvcc emits a PTX-only target, it can run ptxas without an output file to verify the PTX. sccache currently marks that command cacheable and then fails with Missing "cubin" file output.

Mark ptxas commands without an explicit output as non-cacheable so they run directly. Keep cubin-producing commands cacheable for all supported output forms: -o file, -o=file, --output-file file, and --output-file=file. Extend the ptxas argument parser to recognize these forms.

The regression test extends the existing nvcc dry-run fixture for both Windows and Unix. It checks that a virtual-only compute_120 verification pass is non-cacheable and that a normal SASS compile remains cacheable. Additional cases cover the alternate output flags and their parsed output paths.

Follow-up to #2722. Originally observed while building the torchao extension in https://github.com/pytorch/pytorch/actions/runs/30797328141/job/91700085985 with mixed real and virtual targets.

Validation:

  • cargo fmt --all -- --check passed.
  • cargo test --locked --no-default-features --lib compiler:: passed: 304 tests, on macOS arm64 with Rust 1.91.0.
  • Confirmed the regression test fails when ptxas commands are unconditionally marked Cacheable::Yes.

The original fix was also carried as a source patch in PyTorch CI, where it fixed the torchao build against CUDA 13.2.

@tinglvv

tinglvv commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

cc @mbrobbel @sylvestre please review

@mike-wendt

Copy link
Copy Markdown

@tinglvv thanks for this! I was just making a PR to fix this gap as well

I've verified this fix works (full compiler:: suite green, 315/315) and reproduced the bug as you reported in #2722 with local mocks

Thanks again

@codecov-commenter

codecov-commenter commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.79%. Comparing base (a24b058) to head (4b491d3).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/compiler/cicc.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2809      +/-   ##
==========================================
- Coverage   78.53%   73.79%   -4.74%     
==========================================
  Files          74       74              
  Lines       43991    43938      -53     
==========================================
- Hits        34547    32425    -2122     
- Misses       9444    11513    +2069     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre

Copy link
Copy Markdown
Collaborator

Could you please add a test to make sure we don't regress? thanks

@sylvestre

Copy link
Copy Markdown
Collaborator

@mbrobbel i am confused why you approved this change? it doesn't have tests :/

@mbrobbel

Copy link
Copy Markdown
Contributor

@mbrobbel i am confused why you approved this change? it doesn't have tests :/

Oh you are right, I'm sorry about that. Can I suggest the following patch for the regression test?

diff --git a/src/compiler/nvcc.rs b/src/compiler/nvcc.rs
index 8f618efd..d455ce94 100644
--- a/src/compiler/nvcc.rs
+++ b/src/compiler/nvcc.rs
@@ -1592,6 +1592,9 @@ mod test {
 #$ cl -D__CUDA_ARCH__=800 -D__CUDACC__ -E -x c++ "kernel.cu" > "kernel.cpp1.ii"
 #$ cicc --device-c -arch compute_80 --module_id_file_name "kernel.module_id" --gen_c_file_name "kernel.cudafe1.c" --stub_file_name "kernel.cudafe1.stub.c" --gen_device_file_name "kernel.cudafe1.gpu" "kernel.cpp1.ii" --simt-only -o "kernel.ptx"
 #$ ptxas -arch=sm_80 --compile-only "kernel.ptx" -o "kernel.cubin"
+#$ cl -D__CUDA_ARCH__=1200 -D__CUDACC__ -E -x c++ "kernel.cu" > "kernel.compute_120.cpp1.ii"
+#$ cicc --device-c -arch compute_120 "kernel.compute_120.cpp1.ii" -o "kernel.compute_120.ptx"
+#$ ptxas -arch=compute_120 -m64 "kernel.compute_120.ptx"
 #$ fatbinary --create="kernel.fatbin" "--image3=kind=elf,sm=80,file=kernel.cubin" --embedded-fatbin="kernel.fatbin.c" --device-c
 #$ cl -D__CUDA_ARCH__=800 -D__CUDACC__ -c -x c++ "kernel.cudafe1.cpp" -Fo"kernel.o"
 "#
@@ -1604,6 +1607,9 @@ mod test {
 #$ gcc -D__CUDA_ARCH__=800 -D__CUDACC__ -E -x c++ "kernel.cu" -o "kernel.cpp1.ii"
 #$ cicc --device-c -arch compute_80 --module_id_file_name "kernel.module_id" --gen_c_file_name "kernel.cudafe1.c" --stub_file_name "kernel.cudafe1.stub.c" --gen_device_file_name "kernel.cudafe1.gpu" "kernel.cpp1.ii" --simt-only -o "kernel.ptx"
 #$ ptxas -arch=sm_80 --compile-only "kernel.ptx" -o "kernel.cubin"
+#$ gcc -D__CUDA_ARCH__=1200 -D__CUDACC__ -E -x c++ "kernel.cu" -o "kernel.compute_120.cpp1.ii"
+#$ cicc --device-c -arch compute_120 "kernel.compute_120.cpp1.ii" -o "kernel.compute_120.ptx"
+#$ ptxas -arch=compute_120 -m64 "kernel.compute_120.ptx"
 #$ fatbinary --create="kernel.fatbin" "--image3=kind=elf,sm=80,file=kernel.cubin" --embedded-fatbin="kernel.fatbin.c" --device-c
 #$ gcc -D__CUDA_ARCH__=800 -D__CUDACC__ -c -x c++ "kernel.cudafe1.cpp" -o "kernel.o"
 "#
@@ -1647,7 +1653,7 @@ mod test {
             .find(|group| {
                 group
                     .iter()
-                    .any(|cmd| cmd.exe.file_stem().and_then(|stem| stem.to_str()) == Some("cicc"))
+                    .any(|cmd| cmd.args.iter().any(|arg| arg == "kernel.cubin"))
             })
             .expect("missing device compile group");

@@ -1671,6 +1677,17 @@ mod test {
             .find(|cmd| cmd.exe.file_stem().and_then(|stem| stem.to_str()) == Some("ptxas"))
             .unwrap();
         assert!(ptxas.args.iter().any(cicc::is_ptxas_input));
+        assert_eq!(Cacheable::Yes, ptxas.cacheable);
+
+        let virtual_ptxas = groups
+            .iter()
+            .flatten()
+            .find(|cmd| {
+                cmd.exe.file_stem().and_then(|stem| stem.to_str()) == Some("ptxas")
+                    && cmd.args.iter().any(|arg| arg == "kernel.compute_120.ptx")
+            })
+            .expect("missing virtual-only ptxas command");
+        assert_eq!(Cacheable::No, virtual_ptxas.cacheable);
     }

     #[test]

Comment thread src/compiler/nvcc.rs Resolved
Comment thread src/compiler/nvcc.rs Resolved
Comment thread src/compiler/nvcc.rs Resolved
@bernardladenthin

Copy link
Copy Markdown
Contributor

We hit this in java-llama.cpp (Java bindings for llama.cpp; its CI builds the CUDA natives through sccache) with sccache 0.18.0 and CUDA 13.4.3 (V13.4.92), building ggml-cuda at llama.cpp b11815 with ggml's default CMAKE_CUDA_ARCHITECTURES for CUDA 13 (75-virtual;80-virtual;86-real;89-real;90-virtual;120a-real;121a-real): every .cu TU fails with Missing "cubin" file output, as #2862 describes. (The Compiler killed by signal 126 printed after it is a separate reporting issue, #2932.)

With this PR applied to v0.18.0 (27261de, applies cleanly) the same build succeeds: six ggml-cuda TUs, 204 s cold, 23 s warm with 78/78 hits; host code and device SASS of the objects are identical to nvcc's own output (only nvcc's tmpxft_* temp names differ, which nvcc varies per run anyway). A list without a PTX-only compute_90/compute_120 target (e.g. ...;121-real;121-virtual) works with unpatched 0.18.0, which matches the cause described here: nvcc runs the ptxas check pass without -o only for some virtual targets.

Would mbrobbel's regression-test patch from the comment above be enough to get this merged? Happy to open a PR with #2809 plus that test if that helps.

@tinglvv

tinglvv commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi, will review the comments and get this PR merged soon. Thanks

@tinglvv

tinglvv commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @sylvestre, could you approve the workflow run? CI is not triggered yet. Thanks

tinglvv and others added 2 commits October 25, 2026 10:41
For a virtual-only gencode such as -gencode arch=compute_120,code=compute_120
there is no SASS to emit, so nvcc runs ptxas purely to syntax-check the PTX and
passes no -o at all:

  ptxas -arch=compute_120 -m64 kernel.compute_120.ptx

group_nvcc_subcommands_by_compilation_stage marks every ptxas sub-command
Cacheable::Yes, and the caching path requires an "obj" output that only -o
populates, so the whole compile dies in cicc::generate_compile_commands with
`Missing "cubin" file output`. Any target carrying a +PTX architecture can hit
this; it surfaced building torchao's mxfp8 extension, which appends
compute_120,code=compute_120 alongside a real compute_100,code=sm_100 gencode.

Decide cacheability at the grouping stage instead. Cacheable::No routes the
sub-command to the path nvcc.rs already uses for non-cacheable steps: build the
command and run it directly. Returning CompilerArguments::CannotCache from
cicc::parse_arguments does not work, because the sub-command dispatch turns
CannotCache into an error rather than falling back to running the command, so it
only moves the failure to "Cannot cache(no output file)". Cacheable::No with a
group is already how the host preprocessor steps are handled.

Test Plan:
Carried as a source patch in PyTorch CI, where it fixes the inductor build that
compiles torchao against CUDA 13.2:

```
python .ci/pytorch/smoke_test/smoke_test.py --package=torchonly
```

No unit test here: reproducing it needs a mocked nvcc --dryrun emitting the
virtual-only sub-command shape, which is worth adding separately once the shape
can be captured from real nvcc output rather than hand-written.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@sylvestre
sylvestre force-pushed the ptxas-ptx-verify-noncacheable branch from d1cdc39 to 4b491d3 Compare October 25, 2026 09:41
@tinglvv

tinglvv commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Hi @sylvestre, does this PR look good to merge? Thanks

@sylvestre
sylvestre merged commit f71a7dc into mozilla:main Nov 2, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

Kataglyphis added a commit to Kataglyphis/ANTfrastructure that referenced this pull request Dec 2, 2026
…new releases

sccache leaves the hub's 0.19.0 build. Linux (x86_64, aarch64, riscv64)
and Windows install mozilla's release. 0.20 carries the PTX-only ptxas
pass that the ORT CUDA build needs (mozilla/sccache#2809).

- versions.env: SCCACHE_LINUX_VERSION and SCCACHE_WINDOWS_VERSION are
  0.20.1. The four digests come from GitHub's release-asset digests.
- A Renovate github-releases hint sits above SCCACHE_LINUX_VERSION.
  `bump_versions.py --write --only SCCACHE_LINUX_VERSION` applies a new
  release and moves its digests with it.
- bump_tools.py: spec_sccache (newest stable tag, asset digests).
- windows/Dockerfile.base ARG mirror, deps table, SBOM and website
  licenses regenerated.
- Tests: the bump spec and the installer pins. The Pester assertion
  accepts 0.20 and later.
- Docs and CHANGELOG follow the change. shared/upstream/sccache is no
  longer installed; its source pins remain.

Not run here: image builds, the CUDA canary on 0.20.1, the riscv64
binary, Pester (no pwsh), Renovate's own run. The first build after this
bump rebuilds the C/C++ cache entries once.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E5kGgD7mjYi7ay9b3s1gNb
Kataglyphis added a commit to Kataglyphis/ANTfrastructure that referenced this pull request Dec 2, 2026
The sccache commit left three gates red on develop:

- test-bump-versions.sh was 817 lines. The spec_sccache case moves to
  test-bump-sccache.sh; the old file is 797 lines.
- bump_versions.py: spec_sccache sorts after spec_rust (ruff I001).
- Mutation sccache.ptx-only-pass-runs-uncached now retargets the Windows
  pin (0.20.1 -> 0.19.0). The ptxas patch is redundant with 0.20.x and
  installed by nothing, so the old target guarded nothing.

The Pester comment cites the merged fix (mozilla/sccache#2809); #2862 is
an open bug report.

develop stays red on code-duplication: a token-shingle hit on two one-line
helpers in test-sccache-evict.sh and test-sccache-launcher.sh, present on
9662d20 too. It needs an owner decision.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E5kGgD7mjYi7ay9b3s1gNb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants