From 98cc20e30968518b5c9aadf7ca64ba8e0e9d8685 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Fri, 3 Jan 2025 20:42:52 +0000 Subject: [PATCH 1/2] ucc: general fixups --- pkgs/by-name/uc/ucc/package.nix | 87 ++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/pkgs/by-name/uc/ucc/package.nix b/pkgs/by-name/uc/ucc/package.nix index 7c93a36f1b62..ea51eea1e6b7 100644 --- a/pkgs/by-name/uc/ucc/package.nix +++ b/pkgs/by-name/uc/ucc/package.nix @@ -1,28 +1,45 @@ { - stdenv, - lib, - fetchFromGitHub, - libtool, - automake, autoconf, - ucx, + automake, config, - enableCuda ? config.cudaSupport, cudaPackages, + fetchFromGitHub, + lib, + libtool, + stdenv, + ucx, + # Configuration options enableAvx ? stdenv.hostPlatform.avxSupport, + enableCuda ? config.cudaSupport, enableSse41 ? stdenv.hostPlatform.sse4_1Support, enableSse42 ? stdenv.hostPlatform.sse4_2Support, }: +let + inherit (lib.lists) optionals; + inherit (lib.strings) concatStringsSep; + + inherit (cudaPackages) + cuda_cccl + cuda_cudart + cuda_nvcc + cudaFlags + ; +in +stdenv.mkDerivation (finalAttrs: { + __structuredAttrs = true; + # TODO: When strictDeps is enabled, the CUDA build fails during configurePhase because it can't find all the CUDA + # dependencies. As such, we hold off on enabling strictDeps until CUDA compilation works. + # https://github.com/openucx/ucc/blob/0c0fc21559835044ab107199e334f7157d6a0d3d/config/m4/cuda.m4 + strictDeps = false; -stdenv.mkDerivation rec { pname = "ucc"; version = "1.3.0"; src = fetchFromGitHub { owner = "openucx"; repo = "ucc"; - rev = "v${version}"; - sha256 = "sha256-xcJLYktkxNK2ewWRgm8zH/dMaIoI+9JexuswXi7MpAU="; + tag = "v${finalAttrs.version}"; + hash = "sha256-xcJLYktkxNK2ewWRgm8zH/dMaIoI+9JexuswXi7MpAU="; }; outputs = [ @@ -32,44 +49,46 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; + # NOTE: We use --replace-quiet because not all Makefile.am files contain /bin/bash. postPatch = '' - for comp in $(find src/components -name Makefile.am); do - substituteInPlace $comp \ - --replace "/bin/bash" "${stdenv.shell}" + substituteInPlace "$comp" \ + --replace-quiet \ + "/bin/bash" \ + "${stdenv.shell}" done ''; nativeBuildInputs = [ - libtool - automake autoconf - ] ++ lib.optionals enableCuda [ cudaPackages.cuda_nvcc ]; + automake + libtool + ] ++ optionals enableCuda [ cuda_nvcc ]; + buildInputs = [ ucx ] - ++ lib.optionals enableCuda [ - cudaPackages.cuda_cccl - cudaPackages.cuda_cudart + ++ optionals enableCuda [ + cuda_cccl + cuda_cudart ]; - preConfigure = - '' - ./autogen.sh - '' - + lib.optionalString enableCuda '' - configureFlagsArray+=( "--with-nvcc-gencode=${builtins.concatStringsSep " " cudaPackages.cudaFlags.gencode}" ) - ''; + preConfigure = '' + ./autogen.sh + ''; + configureFlags = - [ ] - ++ lib.optional enableSse41 "--with-sse41" - ++ lib.optional enableSse42 "--with-sse42" - ++ lib.optional enableAvx "--with-avx" - ++ lib.optional enableCuda "--with-cuda=${cudaPackages.cuda_cudart}"; + optionals enableSse41 [ "--with-sse41" ] + ++ optionals enableSse42 [ "--with-sse42" ] + ++ optionals enableAvx [ "--with-avx" ] + ++ optionals enableCuda [ + "--with-cuda=${cuda_cudart}" + "--with-nvcc-gencode=${concatStringsSep " " cudaFlags.gencode}" + ]; postInstall = '' - find $out/lib/ -name "*.la" -exec rm -f \{} \; + find "$out/lib/" -name "*.la" -exec rm -f \{} \; - moveToOutput bin/ucc_info $dev + moveToOutput bin/ucc_info "$dev" ''; meta = with lib; { @@ -79,4 +98,4 @@ stdenv.mkDerivation rec { maintainers = [ maintainers.markuskowa ]; platforms = platforms.linux; }; -} +}) From 7844184e59cc9cae387ea7cf021f5992aa35c4fb Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Fri, 3 Jan 2025 21:52:11 +0000 Subject: [PATCH 2/2] ucc: CUDA fixups --- pkgs/by-name/uc/ucc/package.nix | 35 +++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/uc/ucc/package.nix b/pkgs/by-name/uc/ucc/package.nix index ea51eea1e6b7..72ed49bf5181 100644 --- a/pkgs/by-name/uc/ucc/package.nix +++ b/pkgs/by-name/uc/ucc/package.nix @@ -1,4 +1,4 @@ -{ +inputs@{ autoconf, automake, config, @@ -15,6 +15,7 @@ enableSse42 ? stdenv.hostPlatform.sse4_2Support, }: let + inherit (lib.attrsets) getLib; inherit (lib.lists) optionals; inherit (lib.strings) concatStringsSep; @@ -22,15 +23,21 @@ let cuda_cccl cuda_cudart cuda_nvcc + cuda_nvml_dev cudaFlags + nccl ; + + stdenv = throw "Use effectiveStdenv instead"; + effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else inputs.stdenv; in -stdenv.mkDerivation (finalAttrs: { +effectiveStdenv.mkDerivation (finalAttrs: { __structuredAttrs = true; - # TODO: When strictDeps is enabled, the CUDA build fails during configurePhase because it can't find all the CUDA - # dependencies. As such, we hold off on enabling strictDeps until CUDA compilation works. - # https://github.com/openucx/ucc/blob/0c0fc21559835044ab107199e334f7157d6a0d3d/config/m4/cuda.m4 - strictDeps = false; + # TODO(@connorbaker): + # When strictDeps is enabled, `cuda_nvcc` is required as the argument to `--with-cuda` in `configureFlags` or else + # configurePhase fails with `checking for cuda_runtime.h... no`. + # This is odd, especially given `cuda_runtime.h` is provided by `cuda_cudart.dev`, which is already in `buildInputs`. + strictDeps = true; pname = "ucc"; version = "1.3.0"; @@ -55,7 +62,7 @@ stdenv.mkDerivation (finalAttrs: { substituteInPlace "$comp" \ --replace-quiet \ "/bin/bash" \ - "${stdenv.shell}" + "${effectiveStdenv.shell}" done ''; @@ -70,8 +77,20 @@ stdenv.mkDerivation (finalAttrs: { ++ optionals enableCuda [ cuda_cccl cuda_cudart + cuda_nvml_dev + nccl ]; + # NOTE: With `__structuredAttrs` enabled, `LDFLAGS` must be set under `env` so it is assured to be a string; + # otherwise, we might have forgotten to convert it to a string and Nix would make LDFLAGS a shell variable + # referring to an array! + env.LDFLAGS = builtins.toString ( + optionals enableCuda [ + # Fake libnvidia-ml.so (the real one is deployed impurely) + "-L${getLib cuda_nvml_dev}/lib/stubs" + ] + ); + preConfigure = '' ./autogen.sh ''; @@ -81,7 +100,7 @@ stdenv.mkDerivation (finalAttrs: { ++ optionals enableSse42 [ "--with-sse42" ] ++ optionals enableAvx [ "--with-avx" ] ++ optionals enableCuda [ - "--with-cuda=${cuda_cudart}" + "--with-cuda=${cuda_nvcc}" "--with-nvcc-gencode=${concatStringsSep " " cudaFlags.gencode}" ];