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 <rodrigo.arias@bsc.es>
Tested-by: Rodrigo Arias Mallo <rodrigo.arias@bsc.es>
This commit is contained in:
Aleix Roca Nonell 2023-12-05 11:58:04 +01:00 committed by Rodrigo Arias Mallo
parent 3f2b9a766b
commit c4d5135fde
6 changed files with 39 additions and 16 deletions

View File

@ -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;
};
};

View File

@ -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

View File

@ -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;
};
}

View File

@ -84,6 +84,6 @@ in
];
passthru = {
nosv = nosv;
inherit nosv;
};
}

View File

@ -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

View File

@ -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