Skip to content

python3Packages.triton: hardcode CC for runtime JIT compilation - #526003

Closed
rbpdt wants to merge 1 commit into
NixOS:stagingfrom
rbpdt:fix/triton-hardcode-cc-for-jit
Closed

rbpdt wants to merge 1 commit into
NixOS:stagingfrom
rbpdt:fix/triton-hardcode-cc-for-jit

Conversation

@rbpdt

@rbpdt rbpdt commented May 30, 2026

Copy link
Copy Markdown
Contributor

Triton JIT-compiles cuda_utils.c at runtime using whatever cc/gcc is on PATH. When no properly wrapped compiler is available the fallback gcc cannot locate glibc's crti.o, -lc, or -lgcc_s, and JIT compilation fails.

This patch hardcodes the Nix cc-wrapper path in build.py's CC lookup here.

Reproducer:

from triton.backends.nvidia.driver import CudaUtils
utils = CudaUtils()

gives

$ python repro_triton.py
/nix/store/<hash>-cc-wrapper/bin/ld: cannot find crti.o: No such file or directory
/nix/store/<hash>-cc-wrapper/bin/ld: cannot find -lgcc_s: No such file or directory
/nix/store/<hash>-cc-wrapper/bin/ld: cannot find -lc: No such file or directory
/nix/store/<hash>-cc-wrapper/bin/ld: cannot find -lgcc_s: No such file or directory
/nix/store/<hash>-cc-wrapper/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
Traceback (most recent call last):
  File "repro_triton.py", line 4, in <module>
    utils = CudaUtils()
  File "/nix/store/<hash>-python3.13-triton-3.7.0/lib/python3.13/site-packages/triton/backends/nvidia/driver.py", line 70, in __init__
    mod = compile_module_from_src(
        src=Path(os.path.join(dirname, "driver.c")).read_text(),
    ...<3 lines>...
        libraries=libraries,
    )
  File "/nix/store/<hash>-python3.13-triton-3.7.0/lib/python3.13/site-packages/triton/runtime/build.py", line 101, in compile_module_from_src
    so = _build(name, src_path, tmpdir, library_dirs or [], include_dirs or [], libraries or [], ccflags or [])
  File "/nix/store/<hash>-python3.13-triton-3.7.0/lib/python3.13/site-packages/triton/runtime/build.py", line 56, in _build
    subprocess.check_call(cc_cmd, stdout=subprocess.DEVNULL)
  File "/nix/store/<hash>-python3.13/lib/python3.13/subprocess.py", line 419, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/nix/store/<hash>-gcc/bin/gcc', '/tmp/tmptx61pdd9/cuda_utils.c', '-O3', '-shared', '-fPIC', '-Wno-psabi', '-o', '/tmp/tmptx61pdd9/cuda_utils.cpython-313-x86_64-linux-gnu.so', '-l:libcuda.so.1', '-L/nix/store/<hash>-python3.13-triton-3.7.0/lib/python3.13/site-packages/triton/backends/nvidia/lib', '-L/nix/store/<hash>-cuda13.2-cuda_cudart-13.2.51/lib/stubs', '-I/nix/store/<hash>-cuda13.2-cuda_cudart-13.2.51/include', '-I/nix/store/<hash>-python3.13-triton-3.7.0/lib/python3.13/site-packages/triton/backends/nvidia/include', '-I/tmp/tmptx61pdd9', '-I/nix/store/<hash>-python3.13/include/python3.13', '-Wl,-rpath,/run/opengl-driver/lib']' returned non-zero exit status 1.

Assisted-by: Claude Code (claude-opus-4-6)

Things done

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
    • [NixOS tests] in [nixos/tests].
    • [Package tests] at passthru.tests.
    • Tests in [lib/tests] or [pkgs/test] for functions and "core" functionality.
  • Ran nixpkgs-review on this PR. See [nixpkgs-review usage].
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits [CONTRIBUTING.md], [pkgs/README.md], [maintainers/README.md] and other READMEs.
  • Follows the [automation/AI policy].

nixpkgs-branch-check[bot]

This comment was marked as outdated.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 6.topic: python Python is a high-level, general-purpose programming language. labels May 30, 2026
@rbpdt
rbpdt force-pushed the fix/triton-hardcode-cc-for-jit branch from 484272c to 2564a33 Compare May 30, 2026 15:54
@rbpdt
rbpdt changed the base branch from master to staging May 30, 2026 15:56
@nixpkgs-ci nixpkgs-ci Bot closed this May 30, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this May 30, 2026
nixpkgs-branch-check[bot]

This comment was marked as outdated.

@rbpdt
rbpdt marked this pull request as draft May 30, 2026 15:57
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)
@nixpkgs-ci nixpkgs-ci Bot added 8.has: package (new) This PR adds a new package 8.has: package (update) This PR updates a package to a newer version 2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: LXQt The Lightweight Qt Desktop Environment 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions 8.has: documentation This PR adds or changes documentation 6.topic: policy discussion Discuss policies to work in and around Nixpkgs and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels May 30, 2026
@rbpdt
rbpdt force-pushed the fix/triton-hardcode-cc-for-jit branch from 2564a33 to 8ba00c4 Compare May 30, 2026 16:02
@nixpkgs-branch-check
nixpkgs-branch-check Bot dismissed their stale review May 30, 2026 16:03

Review dismissed automatically

@nixpkgs-branch-check
nixpkgs-branch-check Bot dismissed their stale review May 30, 2026 16:03

Review dismissed automatically

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. and removed 2.status: merge conflict This PR has merge conflicts with the target branch 8.has: package (new) This PR adds a new package 8.has: package (update) This PR updates a package to a newer version 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: LXQt The Lightweight Qt Desktop Environment 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions labels May 30, 2026
@rbpdt
rbpdt marked this pull request as ready for review May 30, 2026 16:11
GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request May 31, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
@GaetanLepage

Copy link
Copy Markdown
Contributor

Thanks for the submission!

As #519925 will already lead to a full rebuild of triton and its consumers, I cherry picked your commit and included it there.
As such, it should end up on master sooner that if we would have gone through a full staging cycle.

@rbpdt

rbpdt commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Sounds good, thanks!

GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request Jun 1, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
@SomeoneSerge

SomeoneSerge commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Maaaaaaaaaaaan GitHub lost the Email reply again...

This probably came before though I'm not completely sure...

I don't care much at this point, but be mindful that this change:

1 Means this GCC is forced into the closure even if the user wants to use a different toolchain at runtime
2 You only remove it from to closure by rebuilding everything
3 As is, this is linking the build platform's compiler instead of host platform's compiler, which is understandable since the buildPackages (EDIT: targetPackages) incantation is ugly and scary

GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request Jun 1, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request Jun 2, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request Jun 2, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
GaetanLepage pushed a commit to GaetanLepage/nixpkgs that referenced this pull request Jun 3, 2026
Triton JIT-compiles cuda_utils.c at runtime using whatever `cc`/`gcc`
is on PATH. In environments without a compiler in PATH (e.g. deployed
Nix environments), this fails with linker errors (cannot find crti.o,
-lc, -lgcc_s).

Hardcode the Nix cc-wrapper path as the default fallback for the CC
lookup in build.py, matching the pattern already used in the test's
axpy-cuda derivation.

Assisted-by: Claude Code (claude-opus-4-6)

Originally submitted at NixOS#526003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: policy discussion Discuss policies to work in and around Nixpkgs 6.topic: python Python is a high-level, general-purpose programming language. 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants