Skip to content

Commit 54a6643

Browse files
committed
adds github action kernel tests (with GPU HIP test)
1 parent 247a673 commit 54a6643

File tree

4 files changed

+232
-3
lines changed

4 files changed

+232
-3
lines changed

.github/scripts/run_build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ else
7070
hdf=()
7171
fi
7272

73+
## HIP
74+
if [ "${HIP}" == "true" ]; then
75+
echo
76+
echo "enabling HIP"
77+
echo
78+
hip=(--with-hip HIPCC=g++ HIP_FLAGS="-O2 -g -std=c++17" HIP_PLATFORM=cpu HIP_INC=./external_libs/ROCm-HIP-CPU/include HIP_LIBS="-ltbb -lpthread -lstdc++")
79+
else
80+
hip=()
81+
fi
82+
7383
## special testflags
7484
if [ "${TESTFLAGS}" == "check-mcmodel-medium" ]; then
7585
# note: this is a work-around as using the 'env:' parameter in the workflow 'CI.yml' with TESTFLAGS: FLAGS_CHECK=".."
@@ -94,6 +104,7 @@ set -- ${TESTFLAGS}
94104
"${adios[@]}" \
95105
"${netcdf[@]}" \
96106
"${hdf[@]}" \
107+
"${hip[@]}" \
97108
"${petsc[@]}" \
98109
"${flags[@]}" \
99110
FC=gfortran MPIFC=mpif90 CC=gcc "$@"
@@ -112,10 +123,12 @@ sed -i "s:IMAIN .*:IMAIN = ISTANDARD_OUTPUT:" setup/constants.h
112123
# compilation
113124
echo
114125
echo "clean:"
126+
echo
115127
make clean
116128

117129
echo
118130
echo "compilation:"
131+
echo
119132
make -j4 all
120133

121134
# checks

.github/scripts/run_install.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ if [ "${PETSC}" == "true" ]; then
6565
echo; echo "done PETSc"; echo
6666
fi
6767

68+
## HIP
69+
if [ "${HIP}" == "true" ]; then
70+
echo
71+
echo "HIP additionals installation:"
72+
echo
73+
sudo apt-get install -yq --no-install-recommends libtbb-dev
74+
fi
75+
76+
# checks exit code
77+
if [[ $? -ne 0 ]]; then exit 1; fi
78+
echo
79+
6880
# python3 pip upgrade might complain: "ERROR: launchpadlib 1.10.13 requires testresources"
6981
sudo apt-get install -yq --no-install-recommends python3-testresources
7082
# checks exit code

.github/scripts/run_tests.sh

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,85 @@ echo
2222

2323
# bash function for checking seismogram output with reference solutions
2424
my_test(){
25-
echo "testing seismograms:"
25+
echo "######################################################################################################################"
26+
echo "testing seismograms"
2627
ln -s $WORKDIR/utils/scripts/compare_seismogram_correlations.py
2728
./compare_seismogram_correlations.py REF_SEIS/ OUTPUT_FILES/
2829
if [[ $? -ne 0 ]]; then exit 1; fi
2930
./compare_seismogram_correlations.py REF_SEIS/ OUTPUT_FILES/ | grep min/max | cut -d \| -f 3 | awk '{print "correlation:",$1; if ($1 < 0.999 ){print $1,"failed"; exit 1;}else{ print $1,"good"; exit 0;}}'
3031
if [[ $? -ne 0 ]]; then exit 1; fi
32+
echo "######################################################################################################################"
3133
}
3234

35+
my_kernel_test(){
36+
# kernel value test - checks rho/kappa/mu kernel value outputs
37+
echo "######################################################################################################################"
38+
echo "testing kernel values"
39+
file_ref=REF_KERNEL/output_solver.txt
40+
file_out=output.log # captures the OUTPUT_FILES/output_solver.txt when running solver since IMAIN was set to standard out
41+
if [ ! -e $file_ref ]; then echo "Please check if file $file_ref exists..."; ls -alR ./; exit 1; fi
42+
if [ ! -e $file_out ]; then echo "Please check if file $file_out exists..."; ls -alR ./; exit 1; fi
43+
# gets reference expected kernel values from REF_KERNEL/ folder
44+
RHO=`grep -E 'maximum value of rho[[:space:]]+kernel' $file_ref | cut -d = -f 2 | tr -d ' '`
45+
KAPPA=`grep -E 'maximum value of kappa[[:space:]]+kernel' $file_ref | cut -d = -f 2 | tr -d ' '`
46+
MU=`grep -E 'maximum value of mu[[:space:]]+kernel' $file_ref | cut -d = -f 2 | tr -d ' '`
47+
KAPPAV=`grep -E 'maximum value of kappav[[:space:]]+kernel' $file_ref | cut -d = -f 2 | tr -d ' '`
48+
MUV=`grep -E 'maximum value of muv[[:space:]]+kernel' $file_ref | cut -d = -f 2 | tr -d ' '`
49+
50+
# need at least rho & kappa (for acoustic kernels)
51+
if [ "$RHO" == "" ]; then
52+
echo " missing reference kernel values: RHO=$RHO | KAPPA=$KAPPA KAPPAV=$KAPPAV | MU=$MU MUV=$MUV"
53+
echo
54+
exit 1
55+
else
56+
echo " reference kernel values: RHO=$RHO | KAPPA=$KAPPA KAPPAV=$KAPPAV | MU=$MU MUV=$MUV"
57+
fi
58+
# compares with test output - using a relative tolerance of 0.001 (1 promille) with respect to expected value
59+
# final test result
60+
PASSED=0
61+
# checks rho kernel value
62+
if [ "$RHO" != "" ]; then
63+
VAL=`grep -E 'maximum value of rho[[:space:]]+kernel' $file_out | cut -d = -f 2 | tr -d ' '`
64+
echo "kernel rho : $VAL"
65+
echo "" | awk '{diff=ex-val;diff_abs=(diff >= 0)? diff:-diff;diff_rel=diff_abs/ex;print " value: expected = "ex" gotten = "val" - difference absolute = "diff_abs" relative = "diff_rel; if (diff_rel>0.001){print " failed"; exit 1;}else{print " good"; exit 0;} }' ex=$RHO val=$VAL
66+
if [[ $? -ne 0 ]]; then PASSED=1; fi
67+
fi
68+
# checks kappa kernel value
69+
if [ "$KAPPA" != "" ]; then
70+
VAL=`grep -E 'maximum value of kappa[[:space:]]+kernel' $file_out | cut -d = -f 2 | tr -d ' '`
71+
echo "kernel kappa : $VAL"
72+
echo "" | awk '{diff=ex-val;diff_abs=(diff >= 0)? diff:-diff;diff_rel=diff_abs/ex;print " value: expected = "ex" gotten = "val" - difference absolute = "diff_abs" relative = "diff_rel; if (diff_rel>0.001){print " failed"; exit 1;}else{print " good"; exit 0;} }' ex=$KAPPA val=$VAL
73+
if [[ $? -ne 0 ]]; then PASSED=1; fi
74+
fi
75+
# checks kappav kernel value (if anisotropic kernels)
76+
if [ "$KAPPAV" != "" ]; then
77+
VAL=`grep -E 'maximum value of kappav[[:space:]]+kernel' $file_out | cut -d = -f 2 | tr -d ' '`
78+
echo "kernel kappav: $VAL"
79+
echo "" | awk '{diff=ex-val;diff_abs=(diff >= 0)? diff:-diff;diff_rel=diff_abs/ex;print " value: expected = "ex" gotten = "val" - difference absolute = "diff_abs" relative = "diff_rel; if (diff_rel>0.001){print " failed"; exit 1;}else{print " good"; exit 0;} }' ex=$KAPPAV val=$VAL
80+
if [[ $? -ne 0 ]]; then PASSED=1; fi
81+
fi
82+
# checks mu kernel value
83+
if [ "$MU" != "" ]; then
84+
VAL=`grep -E 'maximum value of mu[[:space:]]+kernel' $file_out | cut -d = -f 2 | tr -d ' '`
85+
echo "kernel mu : $VAL"
86+
echo "" | awk '{diff=ex-val;diff_abs=(diff >= 0)? diff:-diff;diff_rel=diff_abs/ex;print " value: expected = "ex" gotten = "val" - difference absolute = "diff_abs" relative = "diff_rel; if (diff_rel>0.001){print " failed"; exit 1;}else{print " good"; exit 0;} }' ex=$MU val=$VAL
87+
if [[ $? -ne 0 ]]; then PASSED=1; fi
88+
fi
89+
# checks muv kernel value (if anisotropic kernels)
90+
if [ "$MUV" != "" ]; then
91+
VAL=`grep -E 'maximum value of muv[[:space:]]+kernel' $file_out | cut -d = -f 2 | tr -d ' '`
92+
echo "kernel muv : $VAL"
93+
echo "" | awk '{diff=ex-val;diff_abs=(diff >= 0)? diff:-diff;diff_rel=diff_abs/ex;print " value: expected = "ex" gotten = "val" - difference absolute = "diff_abs" relative = "diff_rel; if (diff_rel>0.001){print " failed"; exit 1;}else{print " good"; exit 0;} }' ex=$MUV val=$VAL
94+
if [[ $? -ne 0 ]]; then PASSED=1; fi
95+
fi
96+
# overall pass
97+
if [[ $PASSED -ne 0 ]]; then
98+
echo "testing kernel values: failed"; exit 1;
99+
else
100+
echo "testing kernel values: all good"
101+
fi
102+
echo "######################################################################################################################"
103+
}
33104
# test example
34105
cd $dir
35106

@@ -68,7 +139,7 @@ fi
68139
# hdf5 i/o example
69140
if [ "${HDF5}" == "true" ]; then
70141
echo
71-
echo "HDF5 enabled test run"
142+
echo "test run w/ HDF5"
72143
echo
73144
sed -i "s:^HDF5_ENABLED .*:HDF5_ENABLED = .true.:" DATA/Par_file
74145
#sed -i "s:^HDF5_FOR_MOVIES .*:HDF5_FOR_MOVIES = .true.:" DATA/Par_file
@@ -80,13 +151,24 @@ fi
80151
# adios
81152
if [ "${ADIOS2}" == "true" ]; then
82153
# turns on ADIOS
154+
echo "turning on ADIOS"
83155
sed -i "s:^ADIOS_ENABLED .*:ADIOS_ENABLED = .true.:" DATA/Par_file
84156
fi
85157

158+
## GPU
159+
if [ "${GPU}" == "true" ]; then
160+
# turns on GPU
161+
echo "turning on GPU"
162+
sed -i "s:^GPU_MODE .*:GPU_MODE = .true.:" DATA/Par_file
163+
fi
164+
165+
# save Par_file state
166+
cp -v DATA/Par_file DATA/Par_file.bak
167+
86168
# use kernel script
87169
if [ "${RUN_KERNEL}" == "true" ]; then
88170
# use kernel script
89-
./run_this_example.kernel.sh
171+
./run_this_example_kernel.sh | tee output.log
90172
else
91173
# default script
92174
./run_this_example.sh
@@ -107,9 +189,48 @@ if [ "${DEBUG}" == "true" ] || [ "${FULL_GRAVITY}" == "true" ] || [ "${RUN_KERNE
107189
else
108190
my_test
109191
fi
192+
# checks exit code
193+
if [[ $? -ne 0 ]]; then exit 1; fi
194+
195+
# kernel test
196+
if [ "${RUN_KERNEL}" == "true" ]; then
197+
# check kernel values
198+
my_kernel_test
199+
# checks exit code
200+
if [[ $? -ne 0 ]]; then exit 1; fi
201+
# clean up
202+
rm -rf OUTPUT_FILES/ SEM/ output.log
203+
204+
# re-run kernel test w/ UNDO_ATT
205+
UNDO_ATT=`grep ^UNDO_ATTENUATION DATA/Par_file | cut -d = -f 2 | tr -d ' '`
206+
if [[ ${UNDO_ATT} == *"false"* ]]; then
207+
echo
208+
echo "*****************************************"
209+
echo "run kernel w/ UNDO_ATTENUATION"
210+
echo "*****************************************"
211+
echo
212+
213+
# turns on UNDO_ATTENUATION
214+
echo "turning on UNDO_ATTENUATION"
215+
sed -i "s:^UNDO_ATTENUATION .*:UNDO_ATTENUATION = .true.:" DATA/Par_file
216+
217+
# use kernel script
218+
./run_this_example_kernel.sh | tee output.log
219+
# checks exit code
220+
if [[ $? -ne 0 ]]; then exit 1; fi
221+
# kernel test
222+
my_kernel_test
223+
# checks exit code
224+
if [[ $? -ne 0 ]]; then exit 1; fi
225+
fi
226+
fi
227+
228+
# restore original Par_file
229+
cp -v DATA/Par_file.bak DATA/Par_file
110230

111231
# cleanup
112232
rm -rf OUTPUT_FILES* DATABASES_MPI*
233+
if [ -e SEM ]; then rm -rf SEM/; fi
113234

114235
echo
115236
echo "all good"

.github/workflows/CI.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,86 @@ jobs:
575575
HDF5: true
576576
run: ./.github/scripts/run_tests.sh
577577
shell: bash
578+
579+
linuxTest_12:
580+
name: Test 12 - regional_EMC_model netCDF
581+
runs-on: ubuntu-latest
582+
needs: [linuxCheck]
583+
584+
steps:
585+
- uses: actions/checkout@v4
586+
587+
- name: Install packages
588+
env:
589+
NETCDF: true
590+
run: ./.github/scripts/run_install.sh
591+
shell: bash
592+
593+
- name: Run build
594+
env:
595+
NETCDF: true
596+
run: ./.github/scripts/run_build.sh
597+
shell: bash
598+
599+
- name: Run test
600+
env:
601+
TESTDIR: EXAMPLES/regional_EMC_model
602+
run: ./.github/scripts/run_tests.sh
603+
shell: bash
604+
605+
linuxTest_13:
606+
name: Test 13 - regional_EMC_model kernel netCDF
607+
runs-on: ubuntu-latest
608+
needs: [linuxCheck]
609+
610+
steps:
611+
- uses: actions/checkout@v4
612+
613+
- name: Install packages
614+
env:
615+
NETCDF: true
616+
run: ./.github/scripts/run_install.sh
617+
shell: bash
618+
619+
- name: Run build
620+
env:
621+
NETCDF: true
622+
run: ./.github/scripts/run_build.sh
623+
shell: bash
624+
625+
- name: Run test kernel
626+
env:
627+
TESTDIR: EXAMPLES/regional_EMC_model
628+
RUN_KERNEL: true
629+
run: ./.github/scripts/run_tests.sh
630+
shell: bash
631+
632+
linuxTest_14:
633+
name: Test 14 - regional_EMC_model kernel netCDF GPU HIP
634+
runs-on: ubuntu-latest
635+
needs: [linuxCheck]
636+
637+
steps:
638+
- uses: actions/checkout@v4
639+
640+
- name: Install packages
641+
env:
642+
NETCDF: true
643+
HIP: true
644+
run: ./.github/scripts/run_install.sh
645+
shell: bash
646+
647+
- name: Run build
648+
env:
649+
NETCDF: true
650+
HIP: true
651+
run: ./.github/scripts/run_build.sh
652+
shell: bash
653+
654+
- name: Run test kernel
655+
env:
656+
TESTDIR: EXAMPLES/regional_EMC_model
657+
RUN_KERNEL: true
658+
GPU: true
659+
run: ./.github/scripts/run_tests.sh
660+
shell: bash

0 commit comments

Comments
 (0)