-
Notifications
You must be signed in to change notification settings - Fork 39
243 lines (216 loc) · 8.06 KB
/
test_suite_ubuntu_cpu_gnu.yml
File metadata and controls
243 lines (216 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Workflow to run the FTorch test suite using jobs for GNU compiler
name: Test suite (Ubuntu CPU GNU)
# Controls when the workflow will run
on:
# Triggers the workflow on pushes to the "main" branch, i.e., PR merges
push:
branches: [ "main" ]
# Triggers the workflow on pushes to open pull requests with code changes
pull_request:
paths:
# This workflow
- '.github/workflows/test_suite_ubuntu_cpu_gnu.yml'
# Source files
- '**.c'
- '**.cpp'
- '**.fypp'
- '**.f90'
- '**.F90'
- '**.py'
# Unit tests
- '**.pf'
# Build system
- '**CMakeLists.txt'
- '**requirements.txt'
# Data
- '**data/*'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Cancel jobs running if new commits are pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# Write permissions are not required
permissions: {}
# Workflow run - one or more jobs that can run sequentially or in parallel
jobs:
# Dynamically build matrix for GNU job
setup-matrix:
name: setup matrix
runs-on: ubuntu-latest
# Terminate the job if it runs for more than 5 minutes
timeout-minutes: 5
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
env:
EVENT_NAME: ${{ github.event_name }}
steps:
- id: set-matrix
run: |
if [[ "$EVENT_NAME" == 'push' ]]
then
# Include GCC 9–13 for PRs to main
MATRIX_JSON='
{
"toolchain": [
{"compiler": "gcc", "version": 13},
{"compiler": "gcc", "version": 12},
{"compiler": "gcc", "version": 11},
{"compiler": "gcc", "version": 10},
{"compiler": "gcc", "version": 9}
],
"std": ["f2008"],
"include": [
{"toolchain": {"compiler": "gcc", "version": 13}, "std": "f2018"}
]
}'
else
# Only GCC 13 for everything else
MATRIX_JSON='
{
"toolchain": [
{"compiler": "gcc", "version": 13}
],
"std": ["f2008", "f2018"]
}'
fi
# Convert json to compact line expected by github action
MATRIX_JSON=$(echo "$MATRIX_JSON" | jq -c .)
echo "matrix=${MATRIX_JSON}" >> $GITHUB_OUTPUT
test-suite:
name: test suite
needs: setup-matrix
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }}
# Terminate the job if it runs for more than 15 minutes
timeout-minutes: 15
# 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 FTorch repository
with:
persist-credentials: true
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Fortran
uses: fortran-lang/setup-fortran@d2ba6ea44297a24407def2f6e117954d844a5368 # v1
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Setup Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6
with:
python-version: '3.13'
- name: Install ftorch_utils
run: |
python -m pip install --upgrade pip
python -m venv ftorch
. ftorch/bin/activate
pip install . --extra-index-url https://download.pytorch.org/whl/cpu
- name: Install OpenMPI
run: |
sudo apt update
sudo apt install -y openmpi-bin openmpi-common libopenmpi-dev
- name: Install pFUnit
run: |
# TODO: Avoid version pinning (needed because version appears in install path)
git clone -b v4.12.0 https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git
mkdir pFUnit/build
cd pFUnit/build
cmake ..\
-DCMAKE_Fortran_COMPILER=gfortran\
-DMPI_Fortran_COMPILER=mpif90
make -j 4 install
- name: Build FTorch
env:
FORTRAN_STANDARD: ${{ matrix.std }}
run: |
. 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
mkdir -p ${BUILD_DIR}
# Install to /tmp/ to ensure independent from the CMake build in standalone check.
export INSTALL_DIR=/tmp/ftorch-install
mkdir -p ${INSTALL_DIR}
# NOTE: The pFUnit version (pinned during installation above) is used in the install path.
export PFUNIT_DIR=$(pwd)/pFUnit/build/installed/PFUNIT-4.12
cd ${BUILD_DIR}
cmake .. \
-DPython_EXECUTABLE="$(which python)" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_Fortran_COMPILER=gfortran \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DCMAKE_BUILD_TESTS=TRUE \
-DCMAKE_PREFIX_PATH="${PFUNIT_DIR};${Torch_DIR}" \
-DCMAKE_Fortran_FLAGS="-std=${FORTRAN_STANDARD}"
cmake --build .
cmake --install .
- name: Check pkg-config file
run: |
# pkg-config looks in the `build` directory for libraries
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:build
libs=$(pkg-config --libs ftorch)
cflags=$(pkg-config --cflags ftorch)
# Assert linker flags not empty
if [[ -z "${libs}" ]]
then
echo "::error ::pkg-config --libs ftorch returned empty output"
exit 1
fi
# Assert expected linker flags
lib_dir=$(grep -oE "\-L.*/lib" <<< ${libs})
lib=$(grep -oE "\-lftorch" <<< ${libs})
if [[ -z "${lib_dir}" || -z "${lib}" ]]
then
echo "::error ::pkg-config --libs ftorch do not contain expected linker flags"
exit 1
fi
# Assert compiler flags not empty
if [[ -z "${cflags}" ]]
then
echo "::error ::pkg-config --cflags ftorch returned empty output"
exit 1
fi
# Assert expected compiler flags
include_dir=$(grep -oE "/include " <<< ${cflags})
module_dir=$(grep -oE "/include/ftorch" <<< ${cflags})
if [[ -z ${include_dir} || -z ${module_dir} ]]
then
echo "::error ::pkg-config --cflags ftorch do not contain expected compiler flags"
exit 1
fi
- name: Run unit tests
run: |
. ftorch/bin/activate
cd build
ctest --verbose --tests-regex unit
- name: Run integration tests
run: |
. ftorch/bin/activate
cd build
ctest --verbose --tests-regex example
# Check that we can successfully build and run an example outside the main FTorch build process
- name: Standalone SimpleNet example
env:
FORTRAN_STANDARD: ${{ matrix.std }}
run: |
. ftorch/bin/activate
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
export Torch_DIR="${VIRTUAL_ENV}/lib/python${VN}/site-packages/torch"
export FTORCH_INSTALL_DIR="/tmp/ftorch-install"
export EXAMPLE_BUILD_DIR="examples/02_SimpleNet/build"
mkdir "${EXAMPLE_BUILD_DIR}"
cd "${EXAMPLE_BUILD_DIR}"
cmake .. \
-DPython_EXECUTABLE="$(which python)" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="${FTORCH_INSTALL_DIR};${Torch_DIR}" \
-DCMAKE_BUILD_TESTS=TRUE \
-DCMAKE_Fortran_FLAGS="-std=${FORTRAN_STANDARD}"
cmake --build .
ctest -V