Skip to content

Commit 9288951

Browse files
committed
ci: Add composite actions and test in core-mpi
1 parent 7aae8d9 commit 9288951

4 files changed

Lines changed: 205 additions & 85 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Docker build action
2+
description: Composite action for building Devito Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
file:
8+
description: "Dockerfile containing build instructions"
9+
required: true
10+
default: Dockerfile
11+
tag:
12+
description: "Tag to add to the built image"
13+
required: true
14+
base:
15+
description: "Base docker image to build on top of"
16+
required: true
17+
18+
outputs:
19+
unique:
20+
description: "Unique identifier for the CI run"
21+
value: ${{ steps.uniquetag.outputs.unique }}
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- id: uniquetag
27+
name: "Generate unique CI tag"
28+
shell: bash
29+
run: |
30+
UNIQUE=$(echo "${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" | cksum | cut -f 1 -d " ")
31+
echo "Unique ID: ${UNIQUE}"
32+
echo "unique=${UNIQUE}" >> "$GITHUB_OUTPUT"
33+
34+
- id: dockerbuild
35+
name: "Build docker container"
36+
shell: bash
37+
run: |
38+
docker build \
39+
--pull \
40+
--file ${{ inputs.file }} \
41+
--tag ${{ inputs.tag }}_${{ steps.uniquetag.outputs.unique }} \
42+
--build-arg base=${{ inputs.base }} \
43+
.
44+
45+
# Do we need to be more specific?
46+
#~ docker buildx build . \
47+
#~ --builder "${RUNNER_NAME// /_}" \
48+
#~ --load \
49+
#~ --label ci-run="$GITHUB_RUN_ID" \
50+
#~ --rm --pull \
51+
#~ --file docker/Dockerfile.devito \
52+
#~ --tag "${DOCKER_IMAGE}" \
53+
#~ --build-arg base="${{ matrix.base }}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Docker cleanup action
2+
description: Composite action for removing Docker images
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
uid:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
tag:
11+
description: "Tag of the built image to use"
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- id: dockerclean
18+
name: "Cleanup docker image"
19+
shell: bash
20+
run: |
21+
docker image rm -f "${{ inputs.tag }}_${{ inputs.uid }}"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker run action
2+
description: Composite action for running commands in Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
uid:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
args:
11+
description: "Arguments to pass to `docker run`"
12+
required: true
13+
default: ""
14+
env:
15+
description: "Environment variables to set inside the docker container"
16+
required: true
17+
default: Dockerfile
18+
tag:
19+
description: "Tag of the built image to use"
20+
required: true
21+
command:
22+
description: "Command to execute inside of the docker container"
23+
required: true
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- id: processenv
29+
name: Process environment variable list
30+
shell: bash
31+
env:
32+
ENV_INPUT: ${{ inputs.env }}
33+
run: |
34+
ENV_STRING=""
35+
# Read line by line with here string, safely handling spaces within the values
36+
while IFS= read -r LINE; do
37+
if [[ -n "$LINE" ]]; then
38+
ENV_STRING="$ENV_STRING --env $LINE"
39+
fi
40+
done <<< "$ENV_INPUT"
41+
# Remove the leading space from the first concatenation
42+
ENV_STRING="${ENV_STRING# }"
43+
echo "env=$ENV_STRING" >> "$GITHUB_OUTPUT"
44+
45+
- id: dockerrun
46+
name: "Run command ${{ inputs.command }} in ${{ inputs.tag }} docker container"
47+
shell: bash
48+
run: |
49+
docker run \
50+
--init -t --rm \
51+
${{ inputs.args }} \
52+
--name "ci-${{ inputs.name }}-${{ inputs.uid }}" \
53+
${{ steps.processenv.outputs.env }} \
54+
"${{ inputs.tag }}_${{ inputs.uid }}" \
55+
${{ inputs.command }}

.github/workflows/pytest-core-mpi.yaml

Lines changed: 76 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
# but only for the main branch
1313
push:
1414
branches:
15-
- main
15+
- main
1616
pull_request:
1717
branches:
18-
- main
18+
- main
1919

2020
jobs:
2121
test-mpi-basic:
@@ -63,86 +63,77 @@ jobs:
6363
name: pytest-mpi
6464

6565
test-mpi-docker:
66-
name: pytest-mpi
67-
runs-on: ${{ matrix.os }}
68-
outputs:
69-
unique : ${{ steps.uniquetag.outputs.unique }}
70-
strategy:
71-
matrix:
72-
name: [gcc, gcc-arm, icx]
73-
include:
74-
- name: gcc
75-
arch: gcc
76-
os: ubuntu-latest
77-
mpiflag: ""
78-
79-
- name: gcc-arm
80-
arch: gcc
81-
os: ubuntu-24.04-arm
82-
mpiflag: ""
83-
84-
- name: icx
85-
arch: icx
86-
os: ubuntu-latest
87-
# Need safe math for icx due to inaccuracy with mpi+sinc interpolation
88-
mpiflag: "-e DEVITO_SAFE_MATH=1"
89-
90-
steps:
91-
- name: Checkout devito
92-
uses: actions/checkout@v6
93-
94-
- name: Generate unique CI tag
95-
id: uniquetag
96-
run: |
97-
UNIQUE=$(echo "${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" | cksum | cut -f 1 -d " ")
98-
echo "Unique ID: ${UNIQUE}"
99-
echo "unique=${UNIQUE}" >> "$GITHUB_OUTPUT"
100-
101-
- name: Build docker image
102-
env:
103-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
104-
run: |
105-
docker build \
106-
--file docker/Dockerfile.devito \
107-
--tag "devito_img${UNIQUE}" \
108-
--build-arg base=devitocodes/bases:cpu-${{ matrix.arch }} \
109-
.
110-
111-
- name: Test with pytest
112-
env:
113-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
114-
run: |
115-
docker run \
116-
--init -t --rm \
117-
--env CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \
118-
--env OMP_NUM_THREADS=1 \
119-
--name testrun \
120-
"devito_img${UNIQUE}" \
121-
pytest tests/test_mpi.py
122-
123-
- name: Test examples with MPI
124-
env:
125-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
126-
run: |
127-
docker run \
128-
--init -t --rm \
129-
${{ matrix.mpiflag }} \
130-
--env DEVITO_MPI=1 \
131-
--env OMP_NUM_THREADS=1 \
132-
--name examplerun \
133-
"devito_img${UNIQUE}" \
134-
mpiexec -n 2 pytest examples/seismic/acoustic
135-
#
136-
docker run \
137-
--init -t --rm \
138-
--env DEVITO_MPI=1 \
139-
--env OMP_NUM_THREADS=1 \
140-
--name examplerun \
141-
"devito_img${UNIQUE}" \
142-
mpiexec -n 2 pytest examples/seismic/tti
143-
144-
- name: Cleanup
145-
env:
146-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
147-
run: |
148-
docker image rm -f "devito_img${UNIQUE}"
66+
name: pytest-mpi
67+
runs-on: ${{ matrix.os }}
68+
strategy:
69+
matrix:
70+
name: [gcc, gcc-arm, icx]
71+
include:
72+
- name: gcc
73+
arch: gcc
74+
os: ubuntu-latest
75+
mpiflag: ""
76+
77+
- name: gcc-arm
78+
arch: gcc
79+
os: ubuntu-24.04-arm
80+
mpiflag: ""
81+
82+
- name: icx
83+
arch: icx
84+
os: ubuntu-latest
85+
# Need safe math for icx due to inaccuracy with mpi+sinc interpolation
86+
# (Only on acoustic)
87+
mpiflag: "-e DEVITO_SAFE_MATH=1"
88+
89+
steps:
90+
- name: Checkout devito
91+
uses: actions/checkout@v6
92+
93+
- id: build
94+
name: Build docker image
95+
uses: ./.github/actions/docker-build
96+
with:
97+
file: docker/Dockerfile.devito
98+
tag: devito_img
99+
base: devitocodes/bases:cpu-${{ matrix.arch }}
100+
101+
- name: Test with pytest
102+
uses: ./.github/actions/docker-run
103+
with:
104+
uid: ${{ steps.build.outputs.unique }}
105+
env: |
106+
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
107+
OMP_NUM_THREADS=1
108+
tag: devito_img
109+
command: "pytest tests/test_mpi.py"
110+
111+
- name: Test acoustic example with MPI
112+
uses: ./.github/actions/docker-run
113+
with:
114+
uid: ${{ steps.build.outputs.unique }}
115+
args: ${{ matrix.mpiflag }}
116+
env: |
117+
DEVITO_MPI=1
118+
OMP_NUM_THREADS=1
119+
tag: devito_img
120+
command: "mpiexec -n 2 pytest examples/seismic/acoustic"
121+
122+
- name: Test tti example with MPI
123+
uses: ./.github/actions/docker-run
124+
with:
125+
# --name examplerun
126+
uid: ${{ steps.build.outputs.unique }}
127+
args: ${{ matrix.mpiflag }}
128+
env: |
129+
DEVITO_MPI=1
130+
OMP_NUM_THREADS=1
131+
tag: devito_img
132+
command: "mpiexec -n 2 pytest examples/seismic/tti"
133+
134+
- name: Cleanup docker image
135+
if: always()
136+
uses: ./.github/actions/docker-clean
137+
with:
138+
uid: ${{ steps.build.outputs.unique }}
139+
tag: devito_img

0 commit comments

Comments
 (0)