From c4d5135fde108401417fdcdf5e1c8d11aeca4f32 Mon Sep 17 00:00:00 2001 From: Aleix Roca Nonell Date: Tue, 5 Dec 2023 11:58:04 +0100 Subject: [PATCH] Split openmp versions in separate derivations The openmp derivation provides both libomp and libompv. To avoid accidentally linking with the wrong library and to avoid the nosv dependency on libomp, this patch separates each version in a different derivation. Also, it adapts the clang wrappers and stdenvs to provide an stdenv per openmp library where each openmp will be used by default when the compiler flag "-fopenmp" is used. This eases linking ompv with nixpkgs libraries, such as blis, that expect openmp to be provided with stdenv. Reviewed-by: Rodrigo Arias Mallo Tested-by: Rodrigo Arias Mallo --- overlay.nix | 15 +++++++++------ pkgs/llvm-ompss2/default.nix | 14 ++++++++++++++ pkgs/llvm-ompss2/openmp.nix | 18 ++++++++++++++---- pkgs/nodes/default.nix | 2 +- test/compilers/clang-openmp-nosv.nix | 3 +-- test/compilers/clang-openmp.nix | 3 --- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/overlay.nix b/overlay.nix index 4e866fd..77390ec 100644 --- a/overlay.nix +++ b/overlay.nix @@ -12,9 +12,9 @@ let bscPkgs = { bench6 = callPackage ./pkgs/bench6/default.nix { }; clangOmpss2 = callPackage ./pkgs/llvm-ompss2/default.nix { }; - openmp = callPackage ./pkgs/llvm-ompss2/openmp.nix { monorepoSrc = final.clangOmpss2Unwrapped.src; version = final.clangOmpss2Unwrapped.version; }; clangOmpss2Nanos6 = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nanos6; }; - clangOmpss2Nodes = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; }; + clangOmpss2Nodes = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmp; }; + clangOmpss2NodesOmpv = callPackage ./pkgs/llvm-ompss2/default.nix { ompss2rt = final.nodes; openmp = final.openmpv; }; clangOmpss2Unwrapped = callPackage ./pkgs/llvm-ompss2/clang.nix { }; #extrae = callPackage ./pkgs/extrae/default.nix { }; # Broken and outdated gpi-2 = callPackage ./pkgs/gpi-2/default.nix { }; @@ -30,6 +30,8 @@ let #nix-wrap = callPackage ./pkgs/nix-wrap/default.nix { }; nodes = callPackage ./pkgs/nodes/default.nix { }; nosv = callPackage ./pkgs/nosv/default.nix { }; + openmp = callPackage ./pkgs/llvm-ompss2/openmp.nix { monorepoSrc = final.clangOmpss2Unwrapped.src; version = final.clangOmpss2Unwrapped.version; }; + openmpv = final.openmp.override { enableNosv = true; }; osumb = callPackage ./pkgs/osu/default.nix { }; ovni = callPackage ./pkgs/ovni/default.nix { }; ovniGit = final.ovni.override { useGit = true; }; @@ -40,6 +42,7 @@ let stdenvClangOmpss2 = final.stdenv.override { cc = final.clangOmpss2; allowedRequisites = null; }; stdenvClangOmpss2Nanos6 = final.stdenv.override { cc = final.clangOmpss2Nanos6; allowedRequisites = null; }; stdenvClangOmpss2Nodes = final.stdenv.override { cc = final.clangOmpss2Nodes; allowedRequisites = null; }; + stdenvClangOmpss2NodesOmpv = final.stdenv.override { cc = final.clangOmpss2NodesOmpv; allowedRequisites = null; }; tagaspi = callPackage ./pkgs/tagaspi/default.nix { }; tampi = callPackage ./pkgs/tampi/default.nix { }; wxparaver = callPackage ./pkgs/paraver/default.nix { }; @@ -76,11 +79,11 @@ in bscPkgs // { clangNosvOpenmp-task = callPackage ./test/compilers/clang-openmp.nix { stdenv = final.stdenvClangOmpss2Nodes; }; - clangNosvOpenmp-nosv = callPackage ./test/compilers/clang-openmp-nosv.nix { - stdenv = final.stdenvClangOmpss2Nodes; + clangNosvOmpv-nosv = callPackage ./test/compilers/clang-openmp-nosv.nix { + stdenv = final.stdenvClangOmpss2NodesOmpv; }; - clangNosvOpenmp-ld = callPackage ./test/compilers/clang-openmp-ld.nix { - stdenv = final.stdenvClangOmpss2Nodes; + clangNosvOmpv-ld = callPackage ./test/compilers/clang-openmp-ld.nix { + stdenv = final.stdenvClangOmpss2NodesOmpv; }; }; diff --git a/pkgs/llvm-ompss2/default.nix b/pkgs/llvm-ompss2/default.nix index d35c706..81b972a 100644 --- a/pkgs/llvm-ompss2/default.nix +++ b/pkgs/llvm-ompss2/default.nix @@ -3,15 +3,24 @@ , lib , gcc , clangOmpss2Unwrapped +, openmp ? null , wrapCCWith , llvmPackages_latest , ompss2rt ? null }: +let + usingNodesAndOmpv = (openmp.pname == "openmp-v" && ompss2rt.pname == "nodes"); + sameNosv = openmp.nosv == ompss2rt.nosv; +in + +assert lib.assertMsg (usingNodesAndOmpv -> sameNosv) "OpenMP-V and NODES must share the same nOS-V"; let homevar = if ompss2rt.pname == "nanos6" then "NANOS6_HOME" else "NODES_HOME"; rtname = if ompss2rt.pname == "nanos6" then "libnanos6" else "libnodes"; + ompname = if openmp.pname == "openmp-v" then "libompv" else "libomp"; + # We need to replace the lld linker from bintools with our linker just built, # otherwise we run into incompatibility issues when mixing compiler and linker @@ -27,6 +36,8 @@ let cc = clangOmpss2Unwrapped; in wrapCCWith { inherit cc bintools; + # extraPackages adds packages to depsTargetTargetPropagated + extraPackages = lib.optional (openmp != null) openmp; extraBuildCommands = '' echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags @@ -43,6 +54,9 @@ in wrapCCWith { echo "--gcc-toolchain=${gcc}" >> $out/nix-support/cc-cflags wrap clang++ $wrapper $ccPath/clang++ + + '' + lib.optionalString (openmp != null) '' + echo "export OPENMP_RUNTIME=${ompname}" >> $out/nix-support/cc-wrapper-hook '' + lib.optionalString (ompss2rt != null) '' echo "export OMPSS2_RUNTIME=${rtname}" >> $out/nix-support/cc-wrapper-hook echo "export ${homevar}=${ompss2rt}" >> $out/nix-support/cc-wrapper-hook diff --git a/pkgs/llvm-ompss2/openmp.nix b/pkgs/llvm-ompss2/openmp.nix index 5f79822..654294b 100644 --- a/pkgs/llvm-ompss2/openmp.nix +++ b/pkgs/llvm-ompss2/openmp.nix @@ -9,6 +9,7 @@ , pkg-config , version , nosv +, enableNosv ? false , enableDebug ? false }: @@ -16,22 +17,23 @@ let stdenv = llvmPackages_latest.stdenv; in stdenv.mkDerivation rec { - pname = "openmp"; + pname = "openmp" + (lib.optionalString enableNosv "-v"); inherit version; src = runCommand "${pname}-src" {} '' mkdir -p "$out" cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/openmp "$out" ''; - sourceRoot = "${src.name}/${pname}"; + sourceRoot = "${src.name}/openmp"; nativeBuildInputs = [ cmake ninja perl pkg-config + ] ++ lib.optionals enableNosv [ nosv ]; @@ -48,10 +50,18 @@ stdenv.mkDerivation rec { "-DOPENMP_ENABLE_LIBOMPTARGET=OFF" ]; - # Remove support for GNU and Intel Openmp + # Remove support for GNU and Intel Openmp. + # Also, remove libomp if building with nosv, as there is no support to build + # only one runtime at a time. postInstall = '' rm -f $out/lib/libgomp* rm -f $out/lib/libiomp* + '' + lib.optionalString enableNosv '' + rm -f $out/lib/libomp.* ''; + + passthru = { + inherit nosv; + }; } diff --git a/pkgs/nodes/default.nix b/pkgs/nodes/default.nix index f834525..fd1f76c 100644 --- a/pkgs/nodes/default.nix +++ b/pkgs/nodes/default.nix @@ -84,6 +84,6 @@ in ]; passthru = { - nosv = nosv; + inherit nosv; }; } diff --git a/test/compilers/clang-openmp-nosv.nix b/test/compilers/clang-openmp-nosv.nix index d11f2e1..237e466 100644 --- a/test/compilers/clang-openmp-nosv.nix +++ b/test/compilers/clang-openmp-nosv.nix @@ -2,7 +2,6 @@ stdenv , nosv , writeText -, openmp }: let @@ -41,7 +40,7 @@ in stdenv.mkDerivation { # fail to run otherwise, so we disable the sandbox for this test. __noChroot = true; - buildInputs = [ nosv openmp ]; + buildInputs = [ nosv ]; buildPhase = '' set -x diff --git a/test/compilers/clang-openmp.nix b/test/compilers/clang-openmp.nix index 7f3e0d8..42044c7 100644 --- a/test/compilers/clang-openmp.nix +++ b/test/compilers/clang-openmp.nix @@ -1,7 +1,6 @@ { stdenv , writeText -, openmp }: let @@ -29,8 +28,6 @@ in stdenv.mkDerivation { # fail to run otherwise, so we disable the sandbox for this test. __noChroot = true; - buildInputs = [ openmp ]; - buildPhase = '' set -x