Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spack configuration #271

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Workflow to build the development Docker image
name: Periodic Docker build

# Controls when the workflow will run
on:
# Triggers the workflow on pushes to open pull requests with changes to the Spack or Docker configuration
pull_request:
paths:
- .github/workflows/docker.yml
- docker/Dockerfile.devenv
- spack.yaml

# Triggers the workflow at 00:00 on the first day of every 3 months
schedule:
- cron: '0 0 1 */3 *'

# Cancel jobs running if new commits are pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

# Workflow run - one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "docker"
docker:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout the repo
with:
persist-credentials: false
uses: actions/checkout@v4

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

- name: Log into GitHub Container Repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true

- name: Build container and push to ghcr
uses: docker/build-push-action@v5
with:
push: true
file: docker/Dockerfile.devenv
tags: ghcr.io/cambridge-iccs/ftorch-dev-env:latest
56 changes: 23 additions & 33 deletions .github/workflows/test_suite_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
matrix:
std: ["f2008", "f2018"]

# The Docker container that the job will use
container:
image: ghcr.io/cambridge-iccs/ftorch-dev-env:latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -50,61 +54,47 @@ jobs:
persist-credentials: false
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install PyTorch
- name: Create virtual environment
run: |
python -m pip install --upgrade pip
. /opt/spack-environment/activate.sh
python -m venv ftorch
. ftorch/bin/activate
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu

# MPI is required by pFUnit
- name: Install an MPI distribution
run: |
sudo apt update
sudo apt install mpich

- name: Install pFUnit
run: |
export FC=/usr/bin/gfortran
export MPIF90=/usr/bin/mpif90
# TODO: Avoid version pinning (needed because version appears in install path)
git clone -b v4.10.0 https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git
mkdir pFUnit/build
cd pFUnit/build
cmake ..
make -j 4 install
# tmate can be used to get an interactive ssh session to the github runner
# for debugging actions. See
# [here](https://github.com/mxschmitt/action-tmate) for more information.
# Uncomment these lines to debug the FTorch build.
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3

- name: Build FTorch
run: |
. /opt/spack-environment/activate.sh
. ftorch/bin/activate
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
export Torch_DIR=${VIRTUAL_ENV}/lib/python${VN}/site-packages
export BUILD_DIR=$(pwd)/build
# NOTE: The pFUnit version (pinned during installation above) is used in the install path.
export PFUNIT_DIR=$(pwd)/pFUnit/build/installed/PFUNIT-4.10
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
VN="$(python -c 'import sys; print(".".join(sys.version.split(".")[:2]))')"
export Torch_DIR="/opt/view/lib/python${VN}/site-packages"
export PFUNIT_DIR="/opt/view/$(ls /opt/view | grep PFUNIT)"
export BUILD_DIR="$(pwd)/build"
mkdir "${BUILD_DIR}"
cd "${BUILD_DIR}"
cmake .. \
-DPython_EXECUTABLE="$(which python)" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
-DCMAKE_INSTALL_PREFIX="${BUILD_DIR}" \
-DCMAKE_BUILD_TESTS=TRUE \
-DCMAKE_PREFIX_PATH="${PFUNIT_DIR};${Torch_DIR}" \
-DCMAKE_PREFIX_PATH="/opt/view;${PFUNIT_DIR};${Torch_DIR}" \
-DCMAKE_Fortran_FLAGS="-std=${{ matrix.std }}"
cmake --build .
cmake --install .

- name: Run unit tests
run: |
. /opt/spack-environment/activate.sh
. ftorch/bin/activate
./run_test_suite.sh --verbose --unit-only

- name: Run integration tests
run: |
. /opt/spack-environment/activate.sh
. ftorch/bin/activate
./run_test_suite.sh --verbose --integration-only
52 changes: 52 additions & 0 deletions docker/Dockerfile.devenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Build stage with Spack pre-installed and ready to be used
FROM spack/ubuntu-jammy:0.21 AS builder

# Install software from spack.yaml
RUN mkdir /opt/spack-environment
COPY spack.yaml /opt/spack-environment/spack.yaml
RUN cd /opt/spack-environment \
&& spack env activate . \
&& spack install --fail-fast \
&& spack gc -y

# Install perl URI lib
RUN apt update \
&& apt install -y --no-install-recommends libany-uri-escape-perl \
&& rm -rf /var/lib/apt/lists/*

# Strip all the binaries
RUN find -L /opt/views/view/* -type f -exec readlink -f '{}' \; | \
xargs file -i | \
grep 'charset=binary' | \
grep 'x-executable\|x-archive\|x-sharedlib' | \
awk -F: '{print $1}' | xargs strip

# Modifications to the environment that are necessary to run
RUN cd /opt/spack-environment \
&& spack env activate --sh -d . > activate.sh

# Bare OS image to run the installed executables
FROM ubuntu:22.04

# Copy necessary files from the builder stage
COPY --from=builder /opt/spack-environment /opt/spack-environment
COPY --from=builder /opt/software /opt/software
COPY --from=builder /usr /usr
# paths.view is a symlink, so copy the parent to avoid dereferencing and duplicating it
COPY --from=builder /opt/views /opt/views

# Create entrypoint script
RUN { \
echo '#!/bin/sh'; \
echo '. /opt/spack-environment/activate.sh'; \
echo 'exec "$@"'; \
} > /entrypoint.sh \
&& chmod a+x /entrypoint.sh \
&& ln -s /opt/views/view /opt/view \
&& apt update \
&& apt install -y --no-install-recommends ca-certificates cpp m4 \
&& rm -rf /var/lib/apt/lists/*

# Set entrypoint and default command
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]
15 changes: 15 additions & 0 deletions spack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spack:
packages:
all:
compiler: [gcc@11:]
specs:
- cmake
- pfunit~mpi~openmp
- py-torch~cuda~mpi~openmp~mkldnn
- py-torchvision
- py-pip
concretizer:
unify: true
config:
install_tree: /opt/software
view: /opt/views/view
Loading