Skip to content

Commit

Permalink
Merge pull request #8 from kmturbulenz/hakostra/llvm-mpich-image
Browse files Browse the repository at this point in the history
Added image for llvm-mpich workflow
  • Loading branch information
hakostra authored Aug 29, 2024
2 parents f052b7b + c8e4cb4 commit dfdce30
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 92 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build-all-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build all docker images

on:
workflow_dispatch:
inputs:
push_image:
type: boolean
description: Push image to package registry
required: true
default: true

jobs:
build-all-images:
strategy:
matrix:
image: ["intel-impi-image", "gnu-ompi-image", "llvm-mpich-image"]
uses: ./.github/workflows/build-single-image.yml
with:
image: ${{ matrix.image }}
push_image: ${{ inputs.push_image }}
secrets: inherit
81 changes: 0 additions & 81 deletions .github/workflows/build-image.yml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/build-single-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Docker image build

on:
workflow_call:
inputs:
image:
description: Which image to build
required: true
type: string
push_image:
description: Push image to package registry
required: true
type: boolean
default: true

workflow_dispatch:
inputs:
image:
type: choice
description: Which image to build
required: true
default: "intel-impi-image"
options:
- "intel-impi-image"
- "gnu-ompi-image"
- "llvm-mpich-image"
push_image:
type: boolean
description: Push image to package registry
required: true
default: true

jobs:
build-single-image:

runs-on: ubuntu-latest
timeout-minutes: 300

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- uses: docker/setup-buildx-action@v3
name: Set up Docker Buildx
id: buildx

- name: Create tag with current date
id: date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/kmturbulenz/${{ inputs.image }}
tags: |
type=sha
type=raw,prefix=date-,value=${{ steps.date.outputs.date }}
- uses: docker/login-action@v3
name: Login to Github Packages
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/build-push-action@v6
name: Build image and push to GitHub Container Registry
with:
context: .
target: ${{ inputs.image }}
tags: ${{ steps.meta.outputs.tags }}
push: ${{ inputs.push_image }}
65 changes: 57 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ RUN dnf check-update ; \
oracle-epel-release-el8 \
patch \
procps-ng \
python3.11 \
python3.11-devel \
python3.11-pip \
python3.11-pip-wheel \
python3.12 \
python3.12-devel \
python3.12-pip \
python3.12-pip-wheel \
rsync \
time \
unzip \
Expand All @@ -37,10 +37,13 @@ RUN dnf check-update ; \
zstd && \
dnf -y install patchelf the_silver_searcher && \
dnf clean all && \
alternatives --set python3 /usr/bin/python3.11
alternatives --set python3 /usr/bin/python3.12

# Install numpy, scipy, matplotlib, h5py for running MGLET testcases
RUN python3 -m pip install --no-cache-dir numpy scipy matplotlib h5py

# Fetch and install updated CMake in /usr/local
ENV CMAKE_VER="3.29.2"
ENV CMAKE_VER="3.30.2"
ARG CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-linux-x86_64.tar.gz"
RUN mkdir /tmp/cmake-install && \
cd /tmp/cmake-install && \
Expand All @@ -50,15 +53,15 @@ RUN mkdir /tmp/cmake-install && \
rm -rf /tmp/cmake-install

# Fetch and install updated Ninja-build in /usr/local
ARG NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-linux.zip"
ARG NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip"
RUN mkdir /tmp/ninja-install && \
cd /tmp/ninja-install && \
wget --no-verbose $NINJA_URL && \
unzip ninja-linux.zip -d /usr/local/bin && \
cd / && \
rm -rf /tmp/ninja-install

ENV HDF5_VER="1.14.4-2"
ENV HDF5_VER="1.14.4-3"
COPY build-hdf5.sh /opt/


Expand Down Expand Up @@ -138,3 +141,49 @@ ENV PATH="${HDF5_ROOT}/bin:${PATH}"

# Update bashrc file
RUN echo "source scl_source enable gcc-toolset-13" >> /opt/bashrc


# ---------------------------------------------------------------------------- #
# LLVM compilers (clang, clang++, flang-new), MPICH image
FROM build-base-image AS llvm-mpich-image
LABEL description="LLVM compilers with MPICH and HDF5 image for building Fortran applications"

# We do not install UCX - MPICH builds embedded UCX instead.
RUN dnf -y install gcc gcc-c++ && \
dnf clean all

# Build LLVM compilers (clang, clang++, flang-new)
COPY build-llvm.sh /opt/
RUN /opt/build-llvm.sh

# CPU architecture for optimizations and default compiler flags
ENV CC="clang"
ENV CXX="clang++"
ENV FC="flang-new"

ENV CPU_ARCH="x86-64-v2"
ENV CFLAGS="-march=${CPU_ARCH}"
ENV CXXFLAGS="-march=${CPU_ARCH}"
ENV FFLAGS="-march=${CPU_ARCH}"
ENV FCFLAGS=$FFLAGS

ENV LLVM_ROOT="/opt/llvm/install"
ENV PATH="${LLVM_ROOT}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${LLVM_ROOT}:${LD_LIBRARY_PATH}"

# Download and build MPICH
# The FCFLAGS are required until this is resolved:
# https://github.com/llvm/llvm-project/issues/95990
ENV MPICH_VER="4.2.2"
COPY build-mpich.sh /opt/
RUN FCFLAGS="$FCFLAGS -mmlir -allow-assumed-rank" /opt/build-mpich.sh
ENV MPI_HOME="/opt/mpich/${MPICH_VER}/install"
ENV PATH="${MPI_HOME}/bin:${PATH}"

# Download and build HDF5
RUN /opt/build-hdf5.sh
ENV HDF5_ROOT="/opt/hdf5/${HDF5_VER}/install"
ENV PATH="${HDF5_ROOT}/bin:${PATH}"

# Update bashrc file
RUN echo "" >> /opt/bashrc
14 changes: 11 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
Fortran compilation tools image
###############################

This image contains recent versions of Intel compilers, MPI and HDF5 along with
basic build tools (CMake, Ninja). This image can then be used to compile
This image contains recent versions of compilers, MPI and HDF5 libraries along
with basic build tools (CMake, Ninja). These images can then be used to compile
Fortran applications that depend on MPI and HDF5.

Two images for different workflows are built:
Three images for different workflows are defined:

1. ``intel-impi-image``: Intel Compilers and Intel MPI
2. ``gnu-openmpi-image``: GNU Compilers and OpenMPI
3. ``llvm-mpich-image``: LLVM Compilers (clang, clang++, flang-new) and MPICH

Images are automatically build with Github Actions and are published at the
Github container registry.
Expand All @@ -18,3 +19,10 @@ If you want to build the images yourself locally, the commands are::

docker build --target intel-impi-image -t intel-impi-image:latest .
docker build --target gnu-ompi-image -t gnu-ompi-image:latest .
docker build --target llvm-mpich-image -t llvm-mpich-image:latest .

The ``llvm-mpich-image`` build the latest ``main`` branch of the LLVM
compilers ``clang``, ``clang++`` and ``flang-new`` from sources. The build time
of this image is thus very large (hours) compared to the two others. The
reason this builds from source is that the ``flang-new`` receive very frequent
updates and this allows us to have the very latest compilers available.
27 changes: 27 additions & 0 deletions build-llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Fetch and build LLVM from Github
set -o errexit
set -o pipefail

LLVM_ROOT_DIR="/opt/llvm"

mkdir -p $LLVM_ROOT_DIR/install
cd $LLVM_ROOT_DIR

git clone --depth 1 https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -GNinja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_INSTALL_PREFIX="$LLVM_ROOT_DIR/install" \
-DLLVM_ENABLE_PROJECTS="clang;lld;flang;openmp" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_RTTI="ON" \
../llvm 2>&1 | tee cmake.log
ninja -j 2 install 2>&1 | tee ninja.log

# To reduce the size of the image, only the installed files are kept, the
# checked out and compiled sources are deleted.
cd $LLVM_ROOT_DIR
rm -rf llvm-project
31 changes: 31 additions & 0 deletions build-mpich.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# This script require environment variable MPICH_VER to be set

set -o errexit
set -o pipefail

MPICH_URL="https://github.com/pmodels/mpich/releases/download/v${MPICH_VER}/mpich-${MPICH_VER}.tar.gz"
MPICH_ROOT_DIR="/opt/mpich/${MPICH_VER}"

mkdir -p $MPICH_ROOT_DIR
cd $MPICH_ROOT_DIR

wget --no-verbose $MPICH_URL
tar -xf mpich-${MPICH_VER}.tar.gz
rm mpich-${MPICH_VER}.tar.gz

mv mpich-${MPICH_VER} source
mkdir install
cd source

./configure \
--prefix=$MPICH_ROOT_DIR/install \
--with-pic \
--with-device=ch4:ucx \
2>&1 | tee configure.log
make -j install 2>&1 | tee make.log

# To reduce the size of the image, only the installed files are kept, the
# checked out and compiled sources are deleted.
cd $MPICH_ROOT_DIR
rm -rf source

0 comments on commit dfdce30

Please sign in to comment.