Skip to content

python3Packages.bitsandbytes: fix cuda build#483507

Draft
GaetanLepage wants to merge 1 commit into
NixOS:masterfrom
GaetanLepage:bitsandbytes
Draft

python3Packages.bitsandbytes: fix cuda build#483507
GaetanLepage wants to merge 1 commit into
NixOS:masterfrom
GaetanLepage:bitsandbytes

Conversation

@GaetanLepage

Copy link
Copy Markdown
Contributor

Things done

Since the latest staging-next PR was merged into master, glibc was updated from 2.40 to 2.42.
Some maths functions (cospi, sinpi, ...) now have noexcept(true) in their declarations.
However, CUDA's crt/math_functions.h declares the same functions without matching exception specs.
Hence, we get such errors during the cmake configure step:

-- Configuring bitsandbytes (Backend: cuda)
CMake Error at /nix/store/lxkvigfj5xy6w2bs7h4xwr3d7wb7piqb-cmake-4.1.2/share/cmake-4.1/Modules/CMakeDetermineCompilerId.cmake:928 (message):
  Compiling the CUDA compiler identification source file
  "CMakeCUDACompilerId.cu" failed.

  Compiler:
  /nix/store/k3dps7npc4mb3k1dd2ksfkhfpdmg5i1k-cuda12.8-cuda_nvcc-12.8.93/bin/nvcc

  Build flags:

  Id flags:
  --keep;--keep-dir;tmp;-ccbin=/nix/store/aygjy2g4372sx18khagd07d7ir1dwxs4-gcc-wrapper-14.3.0/bin/c++
  -v

...

  /nix/store/rwalsamz4246k8f1zzxa54qx7w3fbzdg-glibc-2.42-47-dev/include/bits/mathcalls.h(83):
  error: exception specification is incompatible with that of previous
  function "cospi" (declared at line 2601 of
  /nix/store/w2657dnk2y6970ph0fqkyr0x7j34m7kf-cuda-native-redist-12.8/include/crt/math_functions.h)

     extern double cospi (double __x) noexcept (true); extern double __cospi (double __x) noexcept (true);

...

  6 errors detected in the compilation of "CMakeCUDACompilerId.cu".

  # --error 0x2 --





Call Stack (most recent call first):
  /nix/store/lxkvigfj5xy6w2bs7h4xwr3d7wb7piqb-cmake-4.1.2/share/cmake-4.1/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  /nix/store/lxkvigfj5xy6w2bs7h4xwr3d7wb7piqb-cmake-4.1.2/share/cmake-4.1/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
  /nix/store/lxkvigfj5xy6w2bs7h4xwr3d7wb7piqb-cmake-4.1.2/share/cmake-4.1/Modules/CMakeDetermineCUDACompiler.cmake:162 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:105 (enable_language)


-- Configuring incomplete, errors occurred!

cc @NixOS/cuda-maintainers @kirillrdy @bcdarwin @06kellyjac

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • 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.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: python Python is a high-level, general-purpose programming language. labels Jan 25, 2026
@kirillrdy

Copy link
Copy Markdown
Member

i got it working by patching cuda

       cuda_nvcc = prevCuda.cuda_nvcc.overrideAttrs (old: {
          postInstall = (old.postInstall or "") + ''
            for f in $(find $out -name math_functions.h); do
              sed -i -E "s/(\b(sinpi|cospi|rsqrt)\s*\(\s*double\s*x\s*\))\s*;/\1 noexcept (true);/g" "$f"
              sed -i -E "s/(\b(sinpi|cospi|rsqrt)f\s*\(\s*float\s*x\s*\))\s*;/\1 noexcept (true);/g" "$f"
            done
          '';
        });
        cuda_crt = if prevCuda ? cuda_crt then prevCuda.cuda_crt.overrideAttrs (old: {
          postInstall = (old.postInstall or "") + ''
            for f in $(find $out -name math_functions.h); do
              sed -i -E "s/(\b(sinpi|cospi|rsqrt)\s*\(\s*double\s*x\s*\))\s*;/\1 noexcept (true);/g" "$f"
              sed -i -E "s/(\b(sinpi|cospi|rsqrt)f\s*\(\s*float\s*x\s*\))\s*;/\1 noexcept (true);/g" "$f"
            done
          '';

maybe there are upstream fixes ?

@ConnorBaker

Copy link
Copy Markdown
Contributor

You had to patch both cuda_nvcc and cuda_crt? It’s good to know about this though since I’ll probably have to patch a bunch of stuff in cuda-legacy 🫩

@kirillrdy

Copy link
Copy Markdown
Member

actually for python3Packages.bitsandbytes you only need to patch cuda_nvcc, cuda_crt was needed for something else in my env

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants