Merge pull request #327438 from doronbehar/pkg/openmpi

openmpi: 4.1.6 -> 5.0.3
This commit is contained in:
Doron Behar 2024-08-07 06:13:56 +00:00 committed by GitHub
commit 9d67f432e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 314 additions and 99 deletions

View File

@ -0,0 +1,80 @@
{
lib,
stdenv,
removeReferencesTo,
fetchFromGitHub,
autoconf,
automake,
libtool,
gitMinimal,
perl,
python3,
flex,
hwloc,
libevent,
zlib,
pmix,
}:
stdenv.mkDerivation rec {
pname = "prrte";
version = "3.0.5";
src = fetchFromGitHub {
owner = "openpmix";
repo = "prrte";
rev = "v${version}";
sha256 = "sha256-RDxd4veLGbN+T7xCDnNp2lbOM7mwKKD+SKdPmExr1C8=";
fetchSubmodules = true;
};
outputs = [
"out"
"dev"
];
postPatch = ''
patchShebangs ./autogen.pl ./config
'';
preConfigure = ''
./autogen.pl
'';
postInstall = ''
moveToOutput "bin/prte_info" "''${!outputDev}"
# Fix a broken symlink, created due to FHS assumptions
rm "$out/bin/pcc"
ln -s ${lib.getDev pmix}/bin/pmixcc "''${!outputDev}"/bin/pcc
remove-references-to -t "''${!outputDev}" $(readlink -f $out/lib/libprrte${stdenv.hostPlatform.extensions.library})
'';
nativeBuildInputs = [
removeReferencesTo
perl
python3
autoconf
automake
libtool
flex
gitMinimal
];
buildInputs = [
libevent
hwloc
zlib
pmix
];
enableParallelBuilding = true;
meta = {
description = "PMIx Reference Runtime Environment";
homepage = "https://docs.prrte.org/";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ markuskowa ];
platforms = lib.platforms.linux;
};
}

View File

@ -1,136 +1,270 @@
{ lib, stdenv, fetchurl, removeReferencesTo, gfortran, perl, libnl
, rdma-core, zlib, numactl, libevent, hwloc, targetPackages
, libpsm2, libfabric, pmix, ucx, ucc, makeWrapper
, config
# Enable CUDA support
, cudaSupport ? config.cudaSupport, cudaPackages
# Enable the Sun Grid Engine bindings
, enableSGE ? false
# Pass PATH/LD_LIBRARY_PATH to point to current mpirun by default
, enablePrefix ? false
# Enable libfabric support (necessary for Omnipath networks) on x86_64 linux
, fabricSupport ? stdenv.isLinux && stdenv.isx86_64
# Enable Fortran support
, fortranSupport ? true
{
lib,
stdenv,
fetchurl,
removeReferencesTo,
gfortran,
perl,
libnl,
rdma-core,
zlib,
numactl,
libevent,
hwloc,
targetPackages,
libpsm2,
libfabric,
pmix,
ucx,
ucc,
prrte,
makeWrapper,
python3,
config,
# Enable CUDA support
cudaSupport ? config.cudaSupport,
cudaPackages,
# Enable the Sun Grid Engine bindings
enableSGE ? false,
# Pass PATH/LD_LIBRARY_PATH to point to current mpirun by default
enablePrefix ? false,
# Enable libfabric support (necessary for Omnipath networks) on x86_64 linux
fabricSupport ? stdenv.isLinux && stdenv.isx86_64,
# Enable Fortran support
fortranSupport ? true,
# AVX/SSE options. See passthru.defaultAvxOptions for the available options.
# note that opempi fails to build with AVX disabled, meaning that everything
# up to AVX is enabled by default.
avxOptions ? { },
}:
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
pname = "openmpi";
version = "4.1.6";
version = "5.0.3";
src = with lib.versions; fetchurl {
url = "https://www.open-mpi.org/software/ompi/v${major version}.${minor version}/downloads/${pname}-${version}.tar.bz2";
sha256 = "sha256-90CZRIVRbetjtTEa8SLCZRefUyig2FelZ7hdsAsR5BU=";
src = fetchurl {
url = "https://www.open-mpi.org/software/ompi/v${lib.versions.majorMinor finalAttrs.version}/downloads/openmpi-${finalAttrs.version}.tar.bz2";
sha256 = "sha256-mQWC8gazqzLpOKoxu/B8Y5No5EBdyhlvq+fw927tqQs=";
};
postPatch = ''
patchShebangs ./
# Ensure build is reproducible
ts=`date -d @$SOURCE_DATE_EPOCH`
sed -i 's/OPAL_CONFIGURE_USER=.*/OPAL_CONFIGURE_USER="nixbld"/' configure
sed -i 's/OPAL_CONFIGURE_HOST=.*/OPAL_CONFIGURE_HOST="localhost"/' configure
sed -i "s/OPAL_CONFIGURE_DATE=.*/OPAL_CONFIGURE_DATE=\"$ts\"/" configure
find -name "Makefile.in" -exec sed -i "s/\`date\`/$ts/" \{} \;
# This is dynamically detected. Configure does not provide fine grained options
# We just disable the check in the configure script for now
${lib.pipe (finalAttrs.passthru.defaultAvxOptions // avxOptions) [
(lib.mapAttrsToList (
option: val: ''
substituteInPlace configure \
--replace-fail \
ompi_cv_op_avx_check_${option}=yes \
ompi_cv_op_avx_check_${option}=${if val then "yes" else "no"}
''
))
(lib.concatStringsSep "\n")
]}
'';
outputs = [ "out" "man" "dev" ];
# Ensure build is reproducible according to manual
# https://docs.open-mpi.org/en/v5.0.x/release-notes/general.html#general-notes
env = {
USER = "nixbld";
HOSTNAME = "localhost";
SOURCE_DATE_EPOCH = "0";
};
buildInputs = [ zlib ]
++ lib.optionals stdenv.isLinux [ libnl numactl pmix ucx ucc ]
outputs =
[ "out" ]
++ lib.optionals stdenv.isLinux [
"man"
"dev"
];
buildInputs =
[
zlib
libevent
hwloc
]
++ lib.optionals stdenv.isLinux [
libnl
numactl
pmix
ucx
ucc
prrte
]
++ lib.optionals cudaSupport [ cudaPackages.cuda_cudart ]
++ [ libevent hwloc ]
++ lib.optional (stdenv.isLinux || stdenv.isFreeBSD) rdma-core
++ lib.optionals fabricSupport [ libpsm2 libfabric ];
++ lib.optionals (stdenv.isLinux || stdenv.isFreeBSD) [ rdma-core ]
# needed for internal pmix
++ lib.optionals (!stdenv.isLinux) [ python3 ]
++ lib.optionals fabricSupport [
libpsm2
libfabric
];
nativeBuildInputs = [ perl removeReferencesTo makeWrapper ]
nativeBuildInputs =
[
perl
removeReferencesTo
makeWrapper
]
++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ]
++ lib.optionals fortranSupport [ gfortran ];
configureFlags = lib.optional (!cudaSupport) "--disable-mca-dso"
++ lib.optional (!fortranSupport) "--disable-mpi-fortran"
++ lib.optionals stdenv.isLinux [
"--with-libnl=${lib.getDev libnl}"
"--with-pmix=${lib.getDev pmix}"
"--with-pmix-libdir=${pmix}/lib"
"--enable-mpi-cxx"
] ++ lib.optional enableSGE "--with-sge"
++ lib.optional enablePrefix "--enable-mpirun-prefix-by-default"
configureFlags = [
(lib.enableFeature cudaSupport "mca-dso")
(lib.enableFeature fortranSupport "mpi-fortran")
(lib.withFeatureAs stdenv.isLinux "libnl" (lib.getDev libnl))
"--with-pmix=${if stdenv.isLinux then (lib.getDev pmix) else "internal"}"
(lib.withFeatureAs stdenv.isLinux "pmix-libdir" "${lib.getLib pmix}/lib")
# Puts a "default OMPI_PRTERUN" value to mpirun / mpiexec executables
(lib.withFeatureAs stdenv.isLinux "prrte" (lib.getBin prrte))
(lib.withFeature enableSGE "sge")
(lib.enableFeature enablePrefix "mpirun-prefix-by-default")
# TODO: add UCX support, which is recommended to use with cuda for the most robust OpenMPI build
# https://github.com/openucx/ucx
# https://www.open-mpi.org/faq/?category=buildcuda
++ lib.optionals cudaSupport [ "--with-cuda=${lib.getDev cudaPackages.cuda_cudart}" "--enable-dlopen" ]
++ lib.optionals fabricSupport [ "--with-psm2=${lib.getDev libpsm2}" "--with-libfabric=${lib.getDev libfabric}" ]
;
(lib.withFeatureAs cudaSupport "cuda" (lib.getDev cudaPackages.cuda_cudart))
(lib.enableFeature cudaSupport "dlopen")
(lib.withFeatureAs fabricSupport "psm2" (lib.getDev libpsm2))
(lib.withFeatureAs fabricSupport "ofi" (lib.getDev libfabric))
# The flag --without-ofi-libdir is not supported from some reason, so we
# don't use lib.withFeatureAs
] ++ lib.optionals fabricSupport [ "--with-ofi-libdir=${lib.getLib libfabric}/lib" ];
enableParallelBuilding = true;
postInstall = ''
find $out/lib/ -name "*.la" -exec rm -f \{} \;
postInstall =
let
# The file names we need to iterate are a combination of ${p}${s}, and there
# are 7x3 such options. We use lib.mapCartesianProduct to iterate them all.
fileNamesToIterate = {
p = [
"mpi"
"shmem"
"osh"
];
s =
[
"CC"
"c++"
"cxx"
"cc"
]
++ lib.optionals fortranSupport [
"f77"
"f90"
"fort"
];
};
wrapperDataSubstitutions =
{
# The attr key is the filename prefix. The list's 1st value is the
# compiler=_ line that should be replaced by a compiler=#2 string, where
# #2 is the 2nd value in the list.
"cc" = [
"gcc"
"${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc"
];
"c++" = [
"g++"
"${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++"
];
}
// lib.optionalAttrs fortranSupport {
"fort" = [
"gfortran"
"${targetPackages.gfortran}/bin/${targetPackages.gfortran.targetPrefix}gfortran"
];
};
# The -wrapper-data.txt files that are not symlinks, need to be iterated as
# well, here they start withw ${part1}${part2}, and we use
# lib.mapCartesianProduct as well.
wrapperDataFileNames = {
part1 = [
"mpi"
"shmem"
];
part2 = builtins.attrNames wrapperDataSubstitutions;
};
in
''
find $out/lib/ -name "*.la" -exec rm -f \{} \;
for f in mpi shmem osh; do
for i in f77 f90 CC c++ cxx cc fort; do
moveToOutput "bin/$f$i" "''${!outputDev}"
echo "move $fi$i"
moveToOutput "share/openmpi/$f$i-wrapper-data.txt" "''${!outputDev}"
# The main wrapper that all the rest of the commonly used binaries are
# symlinked to
moveToOutput "bin/opal_wrapper" "''${!outputDev}"
# All of the following files are symlinks to opal_wrapper
${lib.pipe fileNamesToIterate [
(lib.mapCartesianProduct (
{ p, s }:
''
echo "handling ${p}${s}"
moveToOutput "bin/${p}${s}" "''${!outputDev}"
moveToOutput "share/openmpi/${p}${s}-wrapper-data.txt" "''${!outputDev}"
''
))
(lib.concatStringsSep "\n")
]}
# default compilers should be indentical to the
# compilers at build time
${lib.pipe wrapperDataFileNames [
(lib.mapCartesianProduct (
{ part1, part2 }:
''
substituteInPlace "''${!outputDev}/share/openmpi/${part1}${part2}-wrapper-data.txt" \
--replace-fail \
compiler=${lib.elemAt wrapperDataSubstitutions.${part2} 0} \
compiler=${lib.elemAt wrapperDataSubstitutions.${part2} 1}
''
))
(lib.concatStringsSep "\n")
]}
# A symlink to ${lib.getDev pmix}/bin/pmixcc upstreeam puts here as well
# from some reason.
moveToOutput "bin/pcc" "''${!outputDev}"
# Handle informative binaries about the compilation
for i in {prte,ompi,oshmem}_info; do
moveToOutput "bin/$i" "''${!outputDev}"
done
done
'';
for i in ortecc orte-info ompi_info oshmem_info opal_wrapper; do
moveToOutput "bin/$i" "''${!outputDev}"
done
postFixup =
lib.optionalString (lib.elem "man" finalAttrs.outputs) ''
remove-references-to -t "''${!outputMan}" $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
''
+ lib.optionalString (lib.elem "dev" finalAttrs.outputs) ''
remove-references-to -t "''${!outputDev}" $out/bin/mpirun
remove-references-to -t "''${!outputDev}" $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
moveToOutput "share/openmpi/ortecc-wrapper-data.txt" "''${!outputDev}"
'';
postFixup = ''
remove-references-to -t $dev $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
remove-references-to -t $man $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
# The path to the wrapper is hard coded in libopen-pal.so, which we just cleared.
wrapProgram $dev/bin/opal_wrapper \
--set OPAL_INCLUDEDIR $dev/include \
--set OPAL_PKGDATADIR $dev/share/openmpi
# default compilers should be indentical to the
# compilers at build time
echo "$dev/share/openmpi/mpicc-wrapper-data.txt"
sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
$dev/share/openmpi/mpicc-wrapper-data.txt
echo "$dev/share/openmpi/ortecc-wrapper-data.txt"
sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
$dev/share/openmpi/ortecc-wrapper-data.txt
echo "$dev/share/openmpi/mpic++-wrapper-data.txt"
sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++:' \
$dev/share/openmpi/mpic++-wrapper-data.txt
'' + lib.optionalString fortranSupport ''
echo "$dev/share/openmpi/mpifort-wrapper-data.txt"
sed -i 's:compiler=.*:compiler=${gfortran}/bin/${gfortran.targetPrefix}gfortran:' \
$dev/share/openmpi/mpifort-wrapper-data.txt
'';
# The path to the wrapper is hard coded in libopen-pal.so, which we just cleared.
wrapProgram "''${!outputDev}/bin/opal_wrapper" \
--set OPAL_INCLUDEDIR "''${!outputDev}/include" \
--set OPAL_PKGDATADIR "''${!outputDev}/share/openmpi"
'';
doCheck = true;
passthru = {
defaultAvxOptions = {
sse3 = true;
sse41 = true;
avx = true;
avx2 = stdenv.hostPlatform.avx2Support;
avx512 = stdenv.hostPlatform.avx512Support;
};
inherit cudaSupport;
cudatoolkit = cudaPackages.cudatoolkit; # For backward compatibility only
};
meta = with lib; {
meta = {
homepage = "https://www.open-mpi.org/";
description = "Open source MPI-3 implementation";
longDescription = "The Open MPI Project is an open source MPI-3 implementation that is developed and maintained by a consortium of academic, research, and industry partners. Open MPI is therefore able to combine the expertise, technologies, and resources from all across the High Performance Computing community in order to build the best MPI library available. Open MPI offers advantages for system and software vendors, application developers and computer science researchers.";
maintainers = with maintainers; [ markuskowa ];
license = licenses.bsd3;
platforms = platforms.unix;
maintainers = with lib.maintainers; [ markuskowa ];
license = lib.licenses.bsd3;
platforms = lib.platforms.unix;
};
}
})

View File

@ -71,8 +71,9 @@ stdenv.mkDerivation rec {
# Pin the compiler to the current version in a cross compiler friendly way.
# Same pattern as for openmpi (see https://github.com/NixOS/nixpkgs/pull/58964#discussion_r275059427).
sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
$dev/share/pmix/pmixcc-wrapper-data.txt
substituteInPlace $dev/share/pmix/pmixcc-wrapper-data.txt \
--replace-fail compiler=gcc \
compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc
'';
enableParallelBuilding = true;