Skip to content

Commit

Permalink
Support for OFI and UCX
Browse files Browse the repository at this point in the history
* MPICH: Configure --with-device=ch4:ofi,ucx
* Open MPI: Configure --with-ofi --with-ucx
* Reproducible builds
* Strip binaries to reduce size
* Remove unneeded binaries
  • Loading branch information
dalcinl committed Nov 6, 2024
1 parent eaf7bc2 commit 94e0687
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 110 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/cd-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
shell: python
name: 'setup build matrix'
run: |
# setup build matrix # "
keys = ("os", "arch", "runner")
rows = [
("Linux", "aarch64", "ubuntu-22.04"),
Expand All @@ -93,6 +94,7 @@ jobs:
import os, json
with open(os.getenv("GITHUB_OUTPUT"), "w") as out:
print(f"matrix={json.dumps(matrix)}", file=out)
# "
build:
needs: setup
Expand All @@ -117,12 +119,12 @@ jobs:
cd $(brew --prefix)/bin
gfortran=$(ls gfortran-* | sort | head -n 1)
sudo ln -s $gfortran gfortran
# unlink libevent
brew unlink libevent || true
# install autotools
brew install autoconf
brew install automake
brew install libtool
# unlink libevent
brew unlink libevent || true
# install uv
brew install uv
Expand All @@ -142,9 +144,13 @@ jobs:

- id: source-date-epoch
run: |
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
read -r SOURCE_DATE_EPOCH < source-date-epoch || true
SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --pretty=%ct)}
echo SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH >> $GITHUB_ENV
echo $(git log -1 --pretty=%ci) [timestamp=$SOURCE_DATE_EPOCH]
echo [SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH] $(
date -u -d @$SOURCE_DATE_EPOCH 2>/dev/null ||
date -u -r $SOURCE_DATE_EPOCH 2>/dev/null )
working-directory: package/source

- id: build
uses: pypa/[email protected]
Expand Down Expand Up @@ -174,7 +180,7 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
delocate-wheel
--ignore-missing-dependencies
--exclude libmpi --exclude libpmpi
--exclude libmpi --exclude libpmpi --exclude libfabric
--require-archs {delocate_archs}
-w {dest_dir} -v {wheel}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/venv/
*.egg-info/
*.tar.gz
*.tar.bz2
*~
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ lint:
yamllint .github/

clean:
$(RM) -r package/METADATA
$(RM) -r package/LICENSE*
$(RM) -r package/build
$(RM) -r package/LICENSE
$(RM) -r package/install
$(RM) -r package/source
$(RM) -r package/workdir
$(RM) -r package/install
$(RM) -r package/*.egg-info
$(RM) -r .*_cache
116 changes: 109 additions & 7 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ case "$mpiname" in
esac
version=${VERSION:-$version}

ucxversion=1.15.0
ofiversion=1.21.1
ucxversion=${UCXVERSION:-$ucxversion}
ofiversion=${OFIVERSION:-$ofiversion}

PROJECT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PACKAGE=$PROJECT/package
SOURCE=$PACKAGE/source
Expand All @@ -27,21 +32,49 @@ fi
if test ! -d "$SOURCE"; then
if test ! -f "$tarball"; then
echo downloading "$urlbase"/"$tarball"...
curl -fsO "$urlbase"/"$tarball"
curl -fsSLO "$urlbase"/"$tarball"
else
echo reusing "$tarball"...
fi
echo extracting "$tarball" to "$SOURCE"...
echo extracting "$tarball"...
tar xf "$tarball"
mv "$mpiname-$version" "$SOURCE"
patch="$PROJECT/patches/$mpiname-$version"
if test -f "$patch"; then
patch -p1 -i "$patch" -d "$SOURCE"
fi
if test "$mpiname-$(uname)" = "openmpi-Darwin"; then
if test -d "$SOURCE"/3rd-party; then
cd "$SOURCE"/3rd-party
tar xf libevent-*.tar.gz && cd libevent-*
if test "$mpiname" = "mpich"; then
if test "${version}" \> "4.2.2" && test "$(uname)" = "Linux"; then
conf_args='s/\(ofi_subdir_args\)=\("--enable-embedded"\)/\1=""/'
configure="$SOURCE"/configure
sed -i.orig "$conf_args" "$configure"
fi
if test "${version}" \< "4.2.0"; then
disable_doc='s/^\(install-data-local:\s\+\)\$/\1#\$/'
Makefile="$SOURCE"/Makefile.in
sed -i.orig "$disable_doc" "$Makefile"
fi
fi
if test "$mpiname" = "openmpi"; then
for deptarball in "$SOURCE"/3rd-party/*.tar.*; do
test -f "$deptarball" || continue
echo extracting "$(basename "$deptarball")"
tar xf "$deptarball" -C "$(dirname "$deptarball")"
done
makefiles=(
"$SOURCE"/3rd-party/openpmix/src/util/keyval/Makefile.in
"$SOURCE"/3rd-party/prrte/src/mca/rmaps/rank_file/Makefile.in
"$SOURCE"/3rd-party/prrte/src/util/hostfile/Makefile.in
)
for makefile in "${makefiles[@]}"; do
test -f "$makefile" || continue
echo "PMIX_CFLAGS_BEFORE_PICKY = @CFLAGS@" >> "$makefile"
echo "PRTE_CFLAGS_BEFORE_PICKY = @CFLAGS@" >> "$makefile"
done
fi
if test "$mpiname" = "openmpi" && test "${version}" \< "5.0.5"; then
if test "$(uname)" = "Darwin"; then
cd "$SOURCE"/3rd-party/libevent-*
echo running autogen.sh on "$(basename "$(pwd)")"
./autogen.sh
cd "$PROJECT"
Expand All @@ -50,5 +83,74 @@ if test ! -d "$SOURCE"; then
else
echo reusing directory "$SOURCE"...
fi
echo copying license file...

if test "$(uname)" = "Linux"; then
if test "$mpiname" = "mpich"; then
ofidestdir="$SOURCE"/modules/libfabric
ucxdestdir="$SOURCE"/modules/ucx
fi
if test "$mpiname" = "openmpi"; then
ofigithub="https://github.com/ofiwg/libfabric"
ofiurlbase="$ofigithub/releases/download/v$ofiversion"
ofitarball="libfabric-$ofiversion.tar.bz2"
ofidestdir="$SOURCE"/3rd-party/"${ofitarball%%.tar.bz2}"
if test ! -d "$ofidestdir"; then
if test ! -f "$ofitarball"; then
echo downloading "$ofiurlbase"/"$ofitarball"...
curl -fsSLO "$ofiurlbase"/"$ofitarball"
else
echo reusing "$ofitarball"...
fi
echo extracting "$ofitarball"...
tar xf "$ofitarball"
mkdir -p "$(dirname "$ofidestdir")"
mv "$(basename "$ofidestdir")" "$ofidestdir"
else
echo reusing directory "$ofidestdir"...
fi
ucxgithub="https://github.com/openucx/ucx"
ucxurlbase="$ucxgithub/releases/download/v$ucxversion"
ucxtarball="ucx-$ucxversion.tar.gz"
ucxdestdir="$SOURCE"/3rd-party/"${ucxtarball%%.tar.gz}"
if test ! -d "$ucxdestdir"; then
if test ! -f "$ucxtarball"; then
echo downloading "$ucxurlbase"/"$ucxtarball"...
curl -fsSLO "$ucxurlbase"/"$ucxtarball"
else
echo reusing "$ucxtarball"...
fi
echo extracting "$ucxtarball"...
tar xf "$ucxtarball"
mkdir -p "$(dirname "$ucxdestdir")"
mv "$(basename "$ucxdestdir")" "$ucxdestdir"
else
echo reusing directory "$ucxdestdir"...
fi
fi
fi

if test "$mpiname" = "mpich"; then
mpidate=$(sed -nE "s/MPICH_RELEASE_DATE=\"(.*)\"/\1/p" "$SOURCE/configure")
fi
if test "$mpiname" = "openmpi"; then
mpidate=$(sed -nE "s/date=\"(.*)\"/\1/p" "$SOURCE/VERSION")
fi
if test -n "${mpidate:-}"; then
echo writing source-date-epoch ...
date -d "$mpidate" +%s > "$SOURCE/source-date-epoch"
fi

echo writing package metadata ...
echo "Name: $mpiname" > "$PACKAGE/METADATA"
echo "Version: $version" >> "$PACKAGE/METADATA"

echo copying MPI license file...
cp "$SOURCE"/"$license" "$PACKAGE/LICENSE"
if test -n "${ofidestdir:-}"; then
echo copying OFI license file...
cp "$ofidestdir/COPYING" "$PACKAGE/LICENSE.ofi"
fi
if test -n "${ucxdestdir:-}"; then
echo copying UCX license file...
cp "$ucxdestdir/LICENSE" "$PACKAGE/LICENSE.ucx"
fi
9 changes: 6 additions & 3 deletions build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ WORKDIR=package/workdir
DESTDIR=package/install
ARCHLIST=${ARCHLIST:-$(uname -m)}

read -r SOURCE_DATE_EPOCH < "$SOURCE"/source-date-epoch
export SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH

export CIBW_BUILD_FRONTEND='build'
export CIBW_BUILD='cp313-*'
export CIBW_SKIP='*musllinux*'
export CIBW_ARCHS=$ARCHLIST
export CIBW_BEFORE_ALL='bash {project}/cibw-build-mpi.sh'
export CIBW_TEST_COMMAND='bash {project}/cibw-check-mpi.sh'
export CIBW_ENVIRONMENT_PASS='MPINAME RELEASE SOURCE WORKDIR DESTDIR'
export CIBW_REPAIR_WHEEL_COMMAND_MACOS='delocate-wheel --ignore-missing-dependencies --exclude libmpi --exclude libpmpi --require-archs {delocate_archs -w {dest_dir} -v {wheel}'
export CIBW_REPAIR_WHEEL_COMMAND_MACOS='delocate-wheel --ignore-missing-dependencies --exclude libmpi --exclude libpmpi --exclude libfabric --require-archs {delocate_archs -w {dest_dir} -v {wheel}'

if test "$(uname)" = Linux; then
containerengine=$(basename "$(command -v podman || command -v docker)")
export CIBW_CONTAINER_ENGINE=$containerengine
export SOURCE="/project/$SOURCE"
export WORKDIR="/host/$PWD/$WORKDIR"
export DESTDIR="/host/$PWD/$DESTDIR"
export WORKDIR="/host$PWD/$WORKDIR"
export DESTDIR="/host$PWD/$DESTDIR"
platform=linux
fi
if test "$(uname)" = Darwin; then
Expand Down
55 changes: 44 additions & 11 deletions check-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ unzip -qq "$wheelfile" -d "$workdir"
cd "$workdir"

whlname=$(basename "$wheelfile")
pkgname=${whlname%%-*}
whlinfo=${whlname%%-py*}
pkgname=${whlinfo%%-*}
version=${whlinfo##*-}
mpiname=${pkgname}

data=$(ls -d "$pkgname"-*.data/data)
Expand All @@ -29,9 +31,12 @@ if test "$(uname)" = Linux; then
libsdir=.libs
print-runpath() { patchelf --print-rpath "$1"; }
print-needed() { patchelf --print-needed "$1"; }
if test -f "$data"/lib/libucp.so; then
if test -f "$data"/lib/*/libucp.so.*; then
runlibs=$runlibs'|libuc(m|p|s|t)'$soregex
fi
if test -f "$data"/lib/*/libfabric.so.*; then
runlibs=$runlibs'|libfabric'$soregex
fi
fi
if test "$(uname)" = Darwin; then
runpath='@executable_path/../lib/|@loader_path/'
Expand All @@ -41,9 +46,12 @@ if test "$(uname)" = Darwin; then
libsdir=.dylibs
print-runpath() { otool -l "$1" | sed -n '/RPATH/{n;n;p;}'; }
print-needed() { otool -L "$1" | sed 1,1d; }
if test -f "$data"/lib/libucp.dylib; then
if test -f "$data"/lib/libucp.*.dylib; then
runlibs=$runlibs'|libuc(m|p|s|t)'$soregex
fi
if test -f "$data"/lib/libfabric.*.dylib; then
runlibs=$runlibs'|libfabric'$soregex
fi
fi

if test "$mpiname" = "mpich"; then
Expand All @@ -65,12 +73,17 @@ if test "$mpiname" = "mpich"; then
"$data"/bin/hydra_*
)
libraries=(
"$data"/lib/libmpi.*
"$data"/lib/lib*mpi.*
)
if test -d "$data"/lib/ucx; then
if ls "$data"/lib/*/libfabric.* > /dev/null 2>&1; then
libraries+=(
"$data"/lib/*/libfabric.*
)
fi
if ls "$data"/lib/*/libucp.* > /dev/null 2>&1; then
libraries+=(
"$data"/lib/libuc[mpst]*.*
"$data"/lib/ucx/libuc*.*
"$data"/lib/*/libuc[mpst]*.*
"$data"/lib/*/ucx/libuc[mpst]*.*
)
fi
fi
Expand All @@ -96,33 +109,53 @@ if test "$mpiname" = "openmpi"; then
"$data"/lib/libmpi.*
"$data"/lib/libopen-*.*
)
if test "${version%%.*}" -ge 5; then
libraries+=(
"$data"/lib/libevent*.*
"$data"/lib/libhwloc.*
"$data"/lib/libpmix.*
"$data"/lib/libprrte.*
)
fi
if ls "$data"/lib/*/libucp.* > /dev/null 2>&1; then
libraries+=(
"$data"/lib/*/libuc[mpst]*.*
"$data"/lib/*/ucx/libuc[mpst]*.*
)
fi
if ls "$data"/lib/*/libfabric.* > /dev/null 2>&1; then
libraries+=(
"$data"/lib/*/libfabric.*
)
fi
runlibs+='|lib(z|util|event.*|hwloc)'$soregex
runlibs+='|lib(open-(pal|rte)|pmix|prrte)'$soregex
fi

check-binary() {
local dso=$1 out1="" out2=""
echo checking "$dso"...
test -f "$dso" || printf "ERROR: file not found\n"
test -f "$dso" || (printf "ERROR: file not found\n"; exit 1)
out1="$(print-runpath "$dso" | grep -vE "$runpath" || true)"
test -z "$out1" || printf "ERROR: RUNPATH\n%s\n" "$out1"
out2="$(print-needed "$dso" | grep -vE "$runlibs" || true)"
test -z "$out2" || printf "ERROR: NEEDED\n%s\n" "$out2"
test -z "$out1" -a -z "$out2"
test -z "$out1"
test -z "$out2"
}

for header in "${headers[@]-}"; do
test -n "$header" || break
echo checking "$header"...
test -f "$header"
test -f "$header" || (printf "ERROR: file not found\n"; exit 1)
out=$(grep -E '^#include\s+"mpicxx\.h"' "$header" || true)
test -z "$out" || printf "ERROR: include\n%s\n" "$out"
test -z "$out"
done
for script in "${scripts[@]-}"; do
test -n "$script" || break
echo checking "$script"...
test -f "$script"
test -f "$script" || (printf "ERROR: file not found\n"; exit 1)
out=$(grep -E "/opt/$mpiname" "$script" || true)
test -z "$out" || printf "ERROR: prefix\n%s\n" "$out"
test -z "$out"
Expand Down
Loading

0 comments on commit 94e0687

Please sign in to comment.