diff --git a/flake/src.nix b/flake/src.nix index ce9a53bc..aaadd42b 100644 --- a/flake/src.nix +++ b/flake/src.nix @@ -9,6 +9,7 @@ sha256 = "0xzfgdz7s8kzxmcm3k6n9nqd0isfzj23nxfq0y3ca9f046gp4zp3"; }; version = "24.11"; + cudaVersion = "12.6"; }; iso = pkgs.fetchurl { diff --git a/packages/nvhpc.nix b/packages/nvhpc.nix index 534b0524..3876240c 100644 --- a/packages/nvhpc.nix +++ b/packages/nvhpc.nix @@ -1,44 +1,84 @@ { - version ? "24.7", - stdenvNoCC, fetchurl, buildFHSEnv, - gfortran, flock -}: -let - versions = - { - "24.7" = "0lzqfpvdjl13vd4hd622jdpgl6zdrg0xs3zskfzvrgf55ym9885z"; - "24.1" = "1n0x1x7ywvr3623ylvrjagayn44mbvfas3c3062p7y3asmgjx697"; - "23.1" = "1xg933f4n1bw39y1x1vrjrbzpx36sbmjgvi332hfck3dbx0n982m"; - }; - releaseName = version: - let versions = builtins.splitVersion version; - in "nvhpc_20${builtins.elemAt versions 0}_${builtins.concatStringsSep "" versions}_Linux_x86_64_cuda_multi"; - builder = buildFHSEnv - { - name = "builder"; - targetPkgs = pkgs: with pkgs; [ coreutils ]; - extraBwrapArgs = [ "--bind" "$out" "$out" ]; - }; -in stdenvNoCC.mkDerivation + src, stdenv, autoPatchelfHook, wrapCCWith, writeText, addAttrsToDerivation, config, overrideCC, symlinkJoin, + gcc, glibc_multi, libz, zstd, libxml2, flock, numactl, ncurses, dpkg, cudaPackages, openssl, gmp, openssl_1_1 +}: stdenv.mkDerivation { pname = "nvhpc"; - inherit version; - src = fetchurl - { - url = "https://developer.download.nvidia.com/hpc-sdk/${version}/${releaseName version}.tar.gz"; - sha256 = versions.${version}; - }; - dontFixup = true; + inherit (src) src version; + buildInputs = [ libz libxml2 zstd numactl ncurses openssl gmp openssl_1_1 ]; + nativeBuildInputs = [ autoPatchelfHook dpkg flock ]; + langFortran = true; + unpackPhase = ''dpkg-deb -x $src .''; + dontConfigure = true; dontBuild = true; - buildInputs = [ gfortran flock ]; installPhase = '' - export NVHPC_SILENT=true - export NVHPC_INSTALL_TYPE=single - export NVHPC_INSTALL_DIR=$out/share/nvhpc - # $out should exist before bwrap - mkdir -p $out - ${builder}/bin/builder ./install + # install component + # NVHPC use very complex mechanism to identify the location of compilers, headers, etc. + # we should keep the original structure + mkdir -p $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/ + cp -r opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/{compilers,cuda} \ + $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version} ''; - requiredSystemFeatures = [ "gccarch-exact-${stdenvNoCC.hostPlatform.gcc.arch}" "big-parallel" ]; -} + postFixup = + '' + sed -i '/makelocalrc executed by/d' $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin/makelocalrc + $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin/makelocalrc \ + $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin -x + ln -s $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin $out + ''; + # fix /usr/lib/crt1.o impure path used in link + customLocalrc = writeText "localrc" + '' + set DEFLIBDIR=${glibc_multi}/lib; + set DEFSTDOBJDIR=${glibc_multi}/lib; + ''; + cudaCapability = builtins.concatStringsSep "," + ( + (builtins.map (cap: "cc${builtins.replaceStrings ["."] [""] cap}") config.cudaCapabilities) + ++ [ "cuda${src.cudaVersion}" ] + ); + setupHook = writeText "setup-hook.sh" + '' + addNvhpcEnvVars() { + export nvhome=$out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version} + } + + addEnvHooks "$hostOffset" addNvhpcEnvVars + ''; +}; + wrapper = (wrapCCWith + { + cc = nvhpc; + extraBuildCommands = + '' + echo "-L${gcc}/lib" >> $out/nix-support/cc-ldflags + + echo "-tp=${config.nvhpcArch}" >> $out/nix-support/cc-cflags-before + echo "-gpu=${cudaCapability}" >> $out/nix-support/cc-cflags-before + + echo "-noswitcherror" >> $out/nix-support/cc-cflags + + echo 'export "PATH=${gcc}/bin:$PATH"' >> $out/nix-support/cc-wrapper-hook + + # print verbose output for debugging + echo "-v" >> $out/nix-support/cc-cflags + # echo "-#" >> $out/nix-support/cc-cflags + + # echo "" > $out/nix-support/add-hardening.sh + + # substitute -idirafter in libc-cflags + # somehow -isystem does not work + sed -i 's/-idirafter/-I/g' $out/nix-support/libc-cflags + + for i in nvc nvc++ nvcc nvfortran; do + wrap $i $wrapper $ccPath/$i + done + ''; + }).overrideAttrs (prev: { installPhase = prev.installPhase + + '' + export named_cc=nvc + export named_cxx=nvc++ + export named_fc=nvfortran + '';}); +in addAttrsToDerivation { NVLOCALRC = customLocalrc; } (overrideCC stdenv wrapper) diff --git a/packages/nvhpcStdenv.nix b/packages/nvhpcStdenv.nix deleted file mode 100644 index cbfcfb61..00000000 --- a/packages/nvhpcStdenv.nix +++ /dev/null @@ -1,79 +0,0 @@ -{ - src, stdenv, autoPatchelfHook, wrapCCWith, writeText, addAttrsToDerivation, config, overrideCC, symlinkJoin, - gcc, glibc_multi, libz, zstd, libxml2, flock, numactl, ncurses, dpkg, cudaPackages, openssl, gmp, openssl_1_1 -}: -let - nvhpc = stdenv.mkDerivation - { - pname = "nvhpc"; - inherit (src) src version; - buildInputs = [ libz libxml2 zstd numactl ncurses openssl gmp openssl_1_1 ]; - nativeBuildInputs = [ autoPatchelfHook dpkg flock ]; - langFortran = true; - dontConfigure = true; - dontBuild = true; - unpackPhase = ''dpkg-deb -x $src .''; - installPhase = - '' - # install component - # NVHPC use very complex mechanism to identify the location of compilers, headers, etc. - # we should keep the original structure - mkdir -p $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/ - cp -r opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/{compilers,cuda} \ - $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version} - ''; - postFixup = - '' - sed -i '/makelocalrc executed by/d' $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin/makelocalrc - $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin/makelocalrc \ - $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin -x - ln -s $out/opt/nvidia/hpc_sdk/Linux_x86_64/${src.version}/compilers/bin $out - ''; - }; - # fix /usr/lib/crt1.o impure path used in link - customLocalrc = writeText "localrc" - '' - set DEFLIBDIR=${glibc_multi}/lib; - set DEFSTDOBJDIR=${glibc_multi}/lib; - ''; - # do not set -gpu=cuda12.4 since this only switch the cuda version installed with NVHPC - cudaCapability = builtins.concatStringsSep "," - ( - (builtins.map (cap: "cc${builtins.replaceStrings ["."] [""] cap}") config.cudaCapabilities) - ++ [ "cuda12.6" ] - ); - wrapper = (wrapCCWith - { - cc = nvhpc; - extraBuildCommands = - '' - echo "-L${gcc}/lib" >> $out/nix-support/cc-ldflags - - echo "-tp=${config.nvhpcArch}" >> $out/nix-support/cc-cflags-before - echo "-gpu=${cudaCapability}" >> $out/nix-support/cc-cflags-before - - echo "-noswitcherror" >> $out/nix-support/cc-cflags - - echo 'export "PATH=${gcc}/bin:$PATH"' >> $out/nix-support/cc-wrapper-hook - - # print verbose output for debugging - echo "-v" >> $out/nix-support/cc-cflags - # echo "-#" >> $out/nix-support/cc-cflags - - # echo "" > $out/nix-support/add-hardening.sh - - # substitute -idirafter in libc-cflags - # somehow -isystem does not work - sed -i 's/-idirafter/-I/g' $out/nix-support/libc-cflags - - for i in nvc nvc++ nvcc nvfortran; do - wrap $i $wrapper $ccPath/$i - done - ''; - }).overrideAttrs (prev: { installPhase = prev.installPhase + - '' - export named_cc=nvc - export named_cxx=nvc++ - export named_fc=nvfortran - '';}); -in addAttrsToDerivation { NVLOCALRC = customLocalrc; } (overrideCC stdenv wrapper)