Skip to content

AdaptiveMaxPool: change indice format to MaxPool style, support double backwards - #2722

Merged
soumith merged 2 commits into
pytorch:masterfrom
gchanan:adaptive_max_pool_indices
Sep 13, 2017
Merged

soumith merged 2 commits into
pytorch:masterfrom
gchanan:adaptive_max_pool_indices

Conversation

@gchanan

@gchanan gchanan commented Sep 13, 2017

Copy link
Copy Markdown
Contributor
  1. AdaptiveMaxPool1d/2d today has it's own index format that is relative to the kernel, i.e. in the 2d case it has a new dimension of size 2 with x and y offsets. This is inconsistent with MaxPooling (which has indices relative to the flattened dimensions over which its operating (i.e. 2 in the 2d case). It's difficult to do anything useful with this format (outside of computing the backwards), because the kernels are not equally spaced like with MaxPooling). This PR changes the format to be the same as MaxPooling.
  2. Support double backwards for AdaptiveMaxPooling. Related to 1), we implement double backwards in the same way as it's implemented for MaxPooling (i.e. with gather and always returning the indices from the autograd Function).

@gchanan

gchanan commented Sep 13, 2017

Copy link
Copy Markdown
Contributor Author

Before change:

>>> m=torch.nn.AdaptiveMaxPool2d(3, return_indices=True)
>>> m(torch.arange(1,26).view(1,5,5))[1]
Variable containing:
(0 ,0 ,.,.) =
  1  1  1
  2  2  2
  1  1  1

(1 ,0 ,.,.) =
  1  2  1
  1  2  1
  1  2  1
[torch.LongTensor of size 2x1x3x3]

After change:

>>> m=torch.nn.AdaptiveMaxPool2d(3, return_indices=True)
>>> m(torch.arange(1,26).view(1,5,5))[1]
Variable containing:
(0 ,.,.) =
   6   8   9
  16  18  19
  21  23  24
[torch.LongTensor of size 1x3x3]

@soumith
soumith merged commit d910a94 into pytorch:master Sep 13, 2017
jagadish-amd pushed a commit to jagadish-amd/pytorch that referenced this pull request Nov 25, 2025
…ytorch#2722)

These changes from upstream result in a breakage when loading external
library
```
     61170:     calling init: /opt/venv/lib/python3.12/site-packages/torchvision/_C.so
     61170:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Fatal Python error: Aborted
 
Current thread 0x00007f229fb36080 (most recent call first):
  File "/usr/lib/python3.12/ctypes/__init__.py", line 379 in __init__
  File "/pytorch/torch/_ops.py", line 1488 in load_library
  File "/opt/venv/lib/python3.12/site-packages/torchvision/extension.py", line 34 in <module>
  File "<frozen importlib._bootstrap>", line 488 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 995 in exec_module
  File "<frozen importlib._bootstrap>", line 935 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1331 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1360 in _find_and_load
  File "/opt/venv/lib/python3.12/site-packages/torchvision/__init__.py", line 9 in <module>
```

This was already reverted in rocm/7.1_internal_testing, need to
investigate whether upstream needs a fix
tinglvv added a commit that referenced this pull request Jul 23, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o.
sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the end of
the argument list and groups the dryrun sub-commands positionally, so the extra
token makes it mis-locate the input and skip the device compile. ptxas then
produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

For CUDA >= 13.3 toolkits, build sccache 0.16.0 from source with the upstream
fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Older CUDA (and non-CUDA) images keep downloading the
prebuilt binary, so their build behavior is unchanged. The gate keys off
CUDA_VERSION, so the CUDA 13.4 image picks up the patched sccache automatically.

Drop the from-source build once a sccache release including #2722 ships. See
#190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). To be validated in the
CUDA 13.4 image:

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 24, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 24, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 27, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 27, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jul 29, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jul 29, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (download prebuilt sccache) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). It locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Building from source for all images keeps a single
sccache binary across the fleet; the patch is a no-op on older CUDA (it only
changes how the input is located and falls back to the old offset).

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
…ges only)

nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Build sccache 0.16.0 from source with the upstream fix backported from
mozilla/sccache#2722 (patches/sccache-nvcc-13.3-dryrun-parsing.patch), which
locates the cicc/ptxas input by its generated-file suffix (.cpp1.ii / .ptx)
instead of by position, in both cicc.rs and nvcc.rs.

Gate the from-source build to CUDA images only (detected via nvcc): only nvcc
is affected by the bug. Non-CUDA and riscv64 images keep the prebuilt binary
from #189365 -- they never invoke nvcc, so they are unaffected, and a from-source
cargo build under the riscv64 QEMU emulation would be impractically slow. This
also avoids the (currently failing) from-source build on non-CUDA images such as
linux-jammy-py3.10-gcc11-mobile-lightweight-dispatch.

Drop the from-source build and return to the prebuilt binary everywhere once a
sccache release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). Validate in a CUDA
13.3+ CI image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
…ges only)

nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Build sccache 0.16.0 from source with the upstream fix backported from
mozilla/sccache#2722 (patches/sccache-nvcc-13.3-dryrun-parsing.patch), which
locates the cicc/ptxas input by its generated-file suffix (.cpp1.ii / .ptx)
instead of by position, in both cicc.rs and nvcc.rs.

Source the cargo env from $CARGO_HOME. The builder images set CARGO_HOME=/opt/rust
(rust is pre-installed there and /opt/rust/bin is on PATH), so rustup's env file
is /opt/rust/env, not $HOME/.cargo/env. The first from-source attempt hardcoded
`. "$HOME/.cargo/env"`, which does not exist, so every docker image that ran the
build failed at that line before reaching cargo (this is what caused the revert
of the first landing). Use `. "${CARGO_HOME:-$HOME/.cargo}/env"`.

Gate the from-source build to CUDA images only (detected via nvcc): only nvcc is
affected by the bug. Non-CUDA and riscv64 images keep the prebuilt binary from
 #189365 -- they never invoke nvcc, so they are unaffected, and this avoids the
extra cargo build (and its failure modes) on images that do not need the patch.

Drop the from-source build and return to the prebuilt binary everywhere once a
sccache release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
…ges only)

nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Build sccache 0.16.0 from source with the upstream fix backported from
mozilla/sccache#2722 (patches/sccache-nvcc-13.3-dryrun-parsing.patch), which
locates the cicc/ptxas input by its generated-file suffix (.cpp1.ii / .ptx)
instead of by position, in both cicc.rs and nvcc.rs.

Source the cargo env from $CARGO_HOME. The builder images set CARGO_HOME=/opt/rust
(rust is pre-installed there and /opt/rust/bin is on PATH), so rustup's env file
is /opt/rust/env, not $HOME/.cargo/env. The first from-source attempt hardcoded
`. "$HOME/.cargo/env"`, which does not exist, so every docker image that ran the
build failed at that line before reaching cargo (this is what caused the revert
of the first landing). Use `. "${CARGO_HOME:-$HOME/.cargo}/env"`.

Gate the from-source build to CUDA images only (detected via nvcc): only nvcc is
affected by the bug. Non-CUDA and riscv64 images keep the prebuilt binary from
 #189365 -- they never invoke nvcc, so they are unaffected, and this avoids the
extra cargo build (and its failure modes) on images that do not need the patch.

Drop the from-source build and return to the prebuilt binary everywhere once a
sccache release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm older-CUDA / non-CUDA images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Source the cargo env from $CARGO_HOME. Since #186302 the builder images
pre-install rust at /opt/rust and set CARGO_HOME=/opt/rust, so rustup's env file
is /opt/rust/env, not $HOME/.cargo/env. Hardcoding `. "$HOME/.cargo/env"` made
every from-source image fail at that line before reaching cargo (this caused the
revert of the first landing). Use `. "${CARGO_HOME:-$HOME/.cargo}/env"`.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 1, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). Build from source for all
image types (riscv64 keeps the prebuilt binary: no nvcc, no sccache-dist, and a
from-source build under QEMU emulation would be impractically slow) so the whole
fleet shares a single sccache binary.

The backport gates #2722 rather than taking it verbatim. Upstream replaces the
positional lookup with a search for the input's generated-file suffix
(.cpp1.ii / .ptx) unconditionally, for both cicc and ptxas. Upstream's own
dryrun fixture shows --simt-only on the cudafe++ and cicc lines but not on the
ptxas line, so ptxas offsets were already correct and did not need changing;
running the search there regressed CUDA < 13.3, where torchao's mxfp8 extension
fails to build with `Missing "cubin" file output` while stock sccache builds it
fine. Here the suffix search runs only when the argument at the historical
offset is not a generated input file, so every command line nvcc still emits in
the old shape parses exactly as stock 0.16.0 does -- same input, same cache keys
-- and 13.3+ still gets the fix on the cicc line that needs it.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. Reaching that error means the input was located at the wrong
argument and -o was consumed or dropped, and nvcc reshapes these sub-commands
between CUDA releases, so the argument vector as sccache saw it is the thing
needed to diagnose the next occurrence.

Two alternatives were considered. Dropping the ptxas half of #2722 outright is a
smaller diff, but it leaves cicc's search unconditional on older CUDA (the same
pattern, one compiler over) and gives ptxas no fallback if NVIDIA later shifts
its input off the offset the way it did for cicc. Disabling sccache on 13.3+
avoids the parser entirely but gives up CUDA caching, which is the point of
having sccache at all.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in a CUDA 13.3+ CI image (e.g. cuda13.4):

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm the CUDA 13.0/13.2 torchao build (which regressed on the ungated
backport) plus non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). Build from source for all
image types (riscv64 keeps the prebuilt binary: no nvcc, no sccache-dist, and a
from-source build under QEMU emulation would be impractically slow) so the whole
fleet shares a single sccache binary.

The backport gates #2722 rather than taking it verbatim. Upstream replaces the
positional lookup with a search for the input's generated-file suffix
(.cpp1.ii / .ptx) unconditionally, for both cicc and ptxas. Upstream's own
dryrun fixture shows --simt-only on the cudafe++ and cicc lines but not on the
ptxas line, so ptxas offsets were already correct and did not need changing;
running the search there regressed CUDA < 13.3, where torchao's mxfp8 extension
fails to build with `Missing "cubin" file output` while stock sccache builds it
fine. Here the suffix search runs only when the argument at the historical
offset is not a generated input file, so every command line nvcc still emits in
the old shape parses exactly as stock 0.16.0 does -- same input, same cache keys
-- and 13.3+ still gets the fix on the cicc line that needs it.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. Reaching that error means the input was located at the wrong
argument and -o was consumed or dropped, and nvcc reshapes these sub-commands
between CUDA releases, so the argument vector as sccache saw it is the thing
needed to diagnose the next occurrence.

Two alternatives were considered. Dropping the ptxas half of #2722 outright is a
smaller diff, but it leaves cicc's search unconditional on older CUDA (the same
pattern, one compiler over) and gives ptxas no fallback if NVIDIA later shifts
its input off the offset the way it did for cicc. Disabling sccache on 13.3+
avoids the parser entirely but gives up CUDA caching, which is the point of
having sccache at all.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in a CUDA 13.3+ CI image (e.g. cuda13.4):

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm the CUDA 13.0/13.2 torchao build (which regressed on the ungated
backport) plus non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

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

It syntax-checks the PTX and emits nothing. sccache unconditionally requires an
"obj" output, which only -o populates, so it fails the whole compile with
`Missing "cubin" file output`. This is not a regression from #2722: stock
0.16.0 fails identically here, since with a three-argument list the offset picks
-arch=compute_120 as the input and there is still no -o to find. Any target
carrying a +PTX architecture can hit it; here it was torchao's mxfp8 extension,
built as a dependency of inductor-build-cuda132. A verification pass has no
artifact to cache, so treat the missing output as CannotCache and let the
command run directly rather than failing the build.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in CI. The torchao mxfp8 extension built by inductor-build-cuda132 is
the direct regression test for the second fix, since it carries a
code=compute_120 gencode. For the first, in a CUDA 13.3+ image:

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally. Worth
watching sccache hit rates on CUDA jobs afterwards: CannotCache on the
verification pass may suppress caching more of an nvcc invocation than that one
sub-command.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

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

It syntax-checks the PTX and emits nothing. sccache marks every ptxas
sub-command Cacheable::Yes, and the caching path requires an "obj" output that
only -o populates, so the whole compile fails with `Missing "cubin" file
output`. This is not a regression from #2722: stock 0.16.0 fails identically
here, since with a three-argument list the offset picks -arch=compute_120 as the
input and there is still no -o to find. Any target carrying a +PTX architecture
can hit it; here it was torchao's mxfp8 extension, built as a dependency of
inductor-build-cuda132.

Mark that sub-command Cacheable::No instead, which routes it to the path nvcc.rs
already uses for non-cacheable sub-commands: build the command and run it. The
first attempt at this returned CompilerArguments::CannotCache from
cicc::parse_arguments, but the nvcc sub-command dispatch converts CannotCache
into an error rather than falling back to running the command, so it only moved
the failure ("Cannot cache(no output file)"). Deciding at the grouping stage
avoids that path entirely; Cacheable::No with a group is already how the host
preprocessor steps are handled.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
The patch applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

The second bug reproduces without PyTorch or torchao, on any CUDA install, from
the virtual-only gencode alone:

```
echo '__global__ void k() {}' > repro.cu
cargo build --manifest-path /tmp/sccache/Cargo.toml --release
/tmp/sccache/target/release/sccache nvcc -gencode=arch=compute_100,code=sm_100 \
    -gencode=arch=compute_120,code=compute_120 -c repro.cu -o repro.o
```

In CI, the torchao mxfp8 extension built by inductor-build-cuda132 is the direct
regression test. For the first bug, in a CUDA 13.3+ image:

```
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 5, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

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

It syntax-checks the PTX and emits nothing. sccache marks every ptxas
sub-command Cacheable::Yes, and the caching path requires an "obj" output that
only -o populates, so the whole compile fails with `Missing "cubin" file
output`. This is not a regression from #2722: stock 0.16.0 fails identically
here, since with a three-argument list the offset picks -arch=compute_120 as the
input and there is still no -o to find. Any target carrying a +PTX architecture
can hit it; here it was torchao's mxfp8 extension, built as a dependency of
inductor-build-cuda132.

Mark that sub-command Cacheable::No instead, which routes it to the path nvcc.rs
already uses for non-cacheable sub-commands: build the command and run it. The
first attempt at this returned CompilerArguments::CannotCache from
cicc::parse_arguments, but the nvcc sub-command dispatch converts CannotCache
into an error rather than falling back to running the command, so it only moved
the failure ("Cannot cache(no output file)"). Deciding at the grouping stage
avoids that path entirely; Cacheable::No with a group is already how the host
preprocessor steps are handled.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
The patch applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

The second bug reproduces without PyTorch or torchao, on any CUDA install, from
the virtual-only gencode alone:

```
echo '__global__ void k() {}' > repro.cu
cargo build --manifest-path /tmp/sccache/Cargo.toml --release
/tmp/sccache/target/release/sccache nvcc -gencode=arch=compute_100,code=sm_100 \
    -gencode=arch=compute_120,code=compute_120 -c repro.cu -o repro.o
```

In CI, the torchao mxfp8 extension built by inductor-build-cuda132 is the direct
regression test. For the first bug, in a CUDA 13.3+ image:

```
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

2 participants