diff --git a/.github/workflows/python-package-tests-and-deploy.yml b/.github/workflows/python-package-tests-and-deploy.yml index 497f9758e..1bff47318 100644 --- a/.github/workflows/python-package-tests-and-deploy.yml +++ b/.github/workflows/python-package-tests-and-deploy.yml @@ -11,7 +11,10 @@ on: jobs: build: - runs-on: ubuntu-latest + # TODO: go back to ubuntu-latest once the gridtools-base images are rebuilt on a newer + # Ubuntu. On ubuntu-latest (26.04) setup-python uses the runner's preinstalled Python + # (3.11), built for 26.04, whose ssl module does not work inside the older container. + runs-on: ubuntu-24.04 container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} strategy: matrix: @@ -83,7 +86,10 @@ jobs: test-wheel: needs: build - runs-on: ubuntu-latest + # TODO: go back to ubuntu-latest once the gridtools-base images are rebuilt on a newer + # Ubuntu. On ubuntu-latest (26.04) setup-python uses the runner's preinstalled Python + # (3.11), built for 26.04, whose ssl module does not work inside the older container. + runs-on: ubuntu-24.04 container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} strategy: matrix: diff --git a/ci/base.Dockerfile b/ci/base.Dockerfile index b3e015784..fd682b271 100644 --- a/ci/base.Dockerfile +++ b/ci/base.Dockerfile @@ -27,6 +27,8 @@ RUN apt-get update -qq && \ xz-utils \ tk-dev \ libffi-dev \ + libevent-dev \ + libhwloc-dev \ liblzma-dev \ libreadline-dev \ python3-dev \ @@ -36,20 +38,45 @@ RUN apt-get update -qq && \ htop && \ rm -rf /var/lib/apt/lists/* -ARG MPICH_VERSION=3.3.2 -ARG MPICH_PATH=/usr/local -RUN wget -q https://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VERSION}.tar.gz && \ - tar -xzf mpich-${MPICH_VERSION}.tar.gz && \ - cd mpich-${MPICH_VERSION} && \ +# CUDA-aware Open MPI, similar to icon4py (.cscs-ci/docker/base.Dockerfile) but without +# the Slingshot stack (libfabric/cxi, xpmem, gdrcopy): the MPI tests run on a single node, +# launched with the container's own mpiexec, so the shared-memory transport is enough. +# CUDA support lives in run-time loadable components (accelerator-cuda, btl-smcuda, ...), +# so libmpi does not depend on the CUDA driver, which is not available at image build time +# (the driver stubs are only used to build those components). +ARG OMPI_VERSION=5.0.10 +ARG MPI_PATH=/usr/local +RUN set -eux; \ + curl -fsSL "https://download.open-mpi.org/release/open-mpi/v${OMPI_VERSION%.*}/openmpi-${OMPI_VERSION}.tar.gz" -o /tmp/ompi.tar.gz; \ + tar -C /tmp -xzf /tmp/ompi.tar.gz; \ + cd "/tmp/openmpi-${OMPI_VERSION}"; \ ./configure \ - --disable-fortran \ - --prefix=$MPICH_PATH && \ - make install -j32 && \ - rm -rf /root/mpich-${MPICH_VERSION}.tar.gz /root/mpich-${MPICH_VERSION} -RUN echo "${MPICH_PATH}/lib" >> /etc/ld.so.conf.d/cscs.conf && ldconfig + --prefix=${MPI_PATH} \ + --disable-mpi-fortran \ + --with-libevent=external \ + --with-hwloc=external \ + --with-pmix=internal \ + --with-prrte=internal \ + --with-cuda=/usr/local/cuda \ + --with-cuda-libdir=/usr/local/cuda/lib64/stubs; \ + make -j"$(nproc)" install; \ + cd /; \ + rm -rf "/tmp/openmpi-${OMPI_VERSION}" /tmp/ompi.tar.gz; \ + ldconfig; \ + # fail the image build if the CUDA component was not built (it is only loadable on + # GPU nodes, so the run-time check with ompi_info is done in the test job) + test -f ${MPI_PATH}/lib/openmpi/mca_accelerator_cuda.so; \ + # libmpi must not depend on driver libraries that only exist as stubs at build time + if readelf -d ${MPI_PATH}/lib/libmpi.so | grep -E 'libcuda|libnvidia-ml'; then \ + echo "libmpi depends on NVIDIA driver libraries" >&2; exit 1; \ + fi; \ + ompi_info --version -ENV CXX=${MPICH_PATH}/bin/mpicxx -ENV CC=${MPICH_PATH}/bin/mpicc +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility + +ENV CXX=${MPI_PATH}/bin/mpicxx +ENV CC=${MPI_PATH}/bin/mpicc ENV CUDA_HOME /usr/local/cuda ENV CUDA_ARCH=${CUDA_ARCH} diff --git a/ci/build.Dockerfile b/ci/build.Dockerfile index 624441968..88de8b3c0 100644 --- a/ci/build.Dockerfile +++ b/ci/build.Dockerfile @@ -10,7 +10,7 @@ ENV GTCMAKE_GT_TESTS_REQUIRE_FORTRAN_COMPILER=ON ENV GTCMAKE_GT_TESTS_REQUIRE_C_COMPILER=ON ENV GTCMAKE_GT_TESTS_REQUIRE_OpenMP=ON ENV GTCMAKE_GT_TESTS_REQUIRE_GPU=ON -ENV GTCMAKE_GT_TESTS_MPI_WITH_MPI_EXECUTABLE=OFF +ENV GTCMAKE_GT_TESTS_MPI_WITH_MPI_EXECUTABLE=ON ENV GTCMAKE_GT_TESTS_REQUIRE_Python=ON ENV GT_ENABLE_STENCIL_DUMP=ON ENV GTCMAKE_CMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON diff --git a/ci/cscs.yml b/ci/cscs.yml index 8e01c9efa..c9b52cfcc 100644 --- a/ci/cscs.yml +++ b/ci/cscs.yml @@ -33,7 +33,8 @@ build_baseimage_aarch64: CUDA_VERSION: 12.6.2 CUDA_ARCH: sm_90 UBUNTU_VERSION: 24.04 - SLURM_TIMELIMIT: 10 + # building Open MPI from source does not fit in 10 minutes + SLURM_TIMELIMIT: 60 .build_image: @@ -68,14 +69,22 @@ test_aarch64: test_aarch64_mpi: extends: [.container-runner-daint-gh200, .test_helper] script: - - export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH - - export LD_PRELOAD=/usr/lib64/libmpi_gtl_cuda.so + # fail early if Open MPI's CUDA support is not usable on the GPU node + - ompi_info --parsable --all | grep 'mpi_built_with_cuda_support:value:true' + # show the GPU used by each rank (logged by tests/src/mpi_test_driver.cpp) + - cd /build && ctest -R '^test_distributed_boundaries_gpu$' -V | grep '\[mpi_test_driver\]' - cd /build && ctest -L mpi --output-on-failure variables: + # a single Slurm task runs ctest, each MPI test is launched with `mpiexec -n 4` + # (GT_TESTS_MPI_WITH_MPI_EXECUTABLE=ON) on the local node + SLURM_NTASKS: 1 + SLURM_GPUS_PER_NODE: 4 NVIDIA_VISIBLE_DEVICES: all - SLURM_NTASKS: 4 - SLURM_GPUS_PER_TASK: 1 - MPICH_GPU_SUPPORT_ENABLED: 1 USE_MPI: "YES" - SLURM_MPI_TYPE: cray_shasta - CSCS_ADDITIONAL_MOUNTS: '["/opt/cray/pe/mpich/8.1.28/ofi/gnu/12.3/lib/libmpi.so:/usr/local/lib/libmpi.so.12.1.8", "/opt/cray/pe/lib64/libpmi.so.0:/usr/lib64/libpmi.so.0", "/opt/cray/pe/lib64/libpmi2.so.0:/usr/lib64/libpmi2.so.0", "/opt/cray/pals/1.4/lib/libpals.so.0:/usr/lib64/libpals.so.0", "/usr/lib64/libgfortran.so.5:/usr/lib64/libgfortran.so.5", "/opt/cray/pe/mpich/8.1.28/gtl/lib/libmpi_gtl_cuda.so:/usr/lib64/libmpi_gtl_cuda.so"]' + # PRRTE detects Slurm (SLURM_JOBID) and would take the allocation (1 task => 1 slot) + # from it and try to use srun, which is not available inside the container: ignore + # Slurm and run all ranks on the local node, without binding (the task's cpuset is + # managed by Slurm) + PRTE_MCA_ras: ^slurm + PRTE_MCA_plm: ^slurm + PRTE_MCA_hwloc_default_binding_policy: none diff --git a/tests/src/mpi_test_driver.cpp b/tests/src/mpi_test_driver.cpp index af5363b12..a14f0f8b0 100644 --- a/tests/src/mpi_test_driver.cpp +++ b/tests/src/mpi_test_driver.cpp @@ -16,17 +16,27 @@ #ifdef GT_HAS_CUDA +#include #include #include #include namespace { + // name of the environment variable providing the node-local rank, nullptr if none is set + char const *local_rank_var() { + // Open MPI, MPICH (hydra), MVAPICH2, Slurm (ranks started by srun). The MPI launchers' + // variables come first: when the ranks are started by mpiexec inside a single Slurm task, + // all of them inherit the same SLURM_LOCALID. + for (auto var : {"OMPI_COMM_WORLD_LOCAL_RANK", "MPI_LOCALRANKID", "MV2_COMM_WORLD_LOCAL_RANK", "SLURM_LOCALID"}) + if (std::getenv(var)) + return var; + return nullptr; + } + int get_local_rank() { - for (auto var : {"MV2_COMM_WORLD_LOCAL_RANK", "SLURM_LOCALID"}) - if (auto *str = std::getenv(var)) - return std::atoi(str); - return 0; + auto *var = local_rank_var(); + return var ? std::atoi(std::getenv(var)) : 0; } int dev_device_count() { @@ -48,6 +58,31 @@ int main(int argc, char **argv) { gridtools::gcl::init(argc, argv); +#ifdef GT_HAS_CUDA + { + // log the GPU used by each rank, to check that the ranks are spread over the GPUs + int rank, size, device, count; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + GT_CUDA_CHECK(cudaGetDevice(&device)); + GT_CUDA_CHECK(cudaGetDeviceCount(&count)); + cudaDeviceProp prop; + GT_CUDA_CHECK(cudaGetDeviceProperties(&prop, device)); + auto *var = local_rank_var(); + std::fprintf(stderr, + "[mpi_test_driver] rank %d/%d: local rank %d (%s), GPU %d of %d, PCI %04x:%02x:%02x\n", + rank, + size, + get_local_rank(), + var ? var : "unset", + device, + count, + prop.pciDomainID, + prop.pciBusID, + prop.pciDeviceID); + } +#endif + // initialize google test environment testing::InitGoogleTest(&argc, argv);