forked from madgraph5/madgraph4gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestsuite_oneprocess.sh
More file actions
executable file
·290 lines (266 loc) · 11.8 KB
/
testsuite_oneprocess.sh
File metadata and controls
executable file
·290 lines (266 loc) · 11.8 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
# Copyright (C) 2020-2024 CERN and UCLouvain.
# Licensed under the GNU Lesser General Public License (version 3 or later).
# Created by: A. Valassi (Oct 2023) for the MG5aMC CUDACPP plugin.
# Further modified by: A. Valassi (2023-2024) for the MG5aMC CUDACPP plugin.
# Verbose script
###set -x
# Automatic exit on error
###set -e
# Path to the top directory of madgraphgpu
# In the CI this would be simply $(pwd), but allow the script to be run also outside the CI
echo "Executing $0 $*"; echo
topdir=$(cd $(dirname $0)/../..; pwd)
#----------------------------------------------------------------------------------------------------------------------------------
# Code generation stage
function codegen() {
if [ "$1" == "" ] || [ "$2" != "" ]; then echo "Usage: $(basename $0) <process>"; exit 1; fi
proc=$1
if [ "${proc%.mad}" == "${proc}" ] && [ "${proc%.sa}" == "${proc}" ]; then echo "Usage: $(basename $0) <process.mad|process.sa>"; exit 1; fi
# Generate code and check clang formatting
cd ${topdir}/epochX/cudacpp
echo "Current directory is $(pwd)"
echo
echo "*******************************************************************************"
echo "*** code generation for ${proc}"
echo "*******************************************************************************"
if [ "${proc%.mad}" != "${proc}" ]; then
./CODEGEN/generateAndCompare.sh -q ${proc%.mad} --mad
else
./CODEGEN/generateAndCompare.sh -q ${proc%.sa}
fi
# Check if there are any differences to the current repo
###compare=1 # enable comparison to current git repo
compare=0 # disable comparison to current git repo
if [ "${compare}" != "0" ] && [ "$(git ls-tree --name-only HEAD ${proc})" != "" ]; then
echo
echo "Compare newly generated code for ${proc} to that in the madgraph4gpu github repository"
git checkout HEAD ${proc}/CODEGEN*.txt
if [ "${proc%.mad}" != "${proc}" ]; then
git checkout HEAD ${proc}/Cards/me5_configuration.txt
git checkout HEAD ${proc}/Source/make_opts
fi
echo "git diff (start)"
git diff --exit-code
echo "git diff (end)"
else
echo
echo "(SKIP comparison of newly generated code for ${proc} to that in the madgraph4gpu github repository)"
fi
}
#----------------------------------------------------------------------------------------------------------------------------------
function setup_ccache {
# Set up ccache environment
export PATH=${topdir}/BIN:$PATH
export CCACHE_DIR=${topdir}/CCACHE_DIR
}
#----------------------------------------------------------------------------------------------------------------------------------
# Before-build stage (analyse data retrieved from cache, download ccache executable and googletest if not retrieved from cache)
function before_build() {
# Install and configure ccache
if [ -d ${topdir}/DOWNLOADS ]; then
echo "Directory ${topdir}/DOWNLOADS already exists (retrieved from cache)"
else
echo "Directory ${topdir}/DOWNLOADS does not exist: create it"
mkdir ${topdir}/DOWNLOADS
cd ${topdir}/DOWNLOADS
echo "Current directory is $(pwd)"
echo
echo "wget -q https://github.com/ccache/ccache/releases/download/v4.8.3/ccache-4.8.3-linux-x86_64.tar.xz"
wget -q https://github.com/ccache/ccache/releases/download/v4.8.3/ccache-4.8.3-linux-x86_64.tar.xz
echo
echo "tar -xvf ccache-4.8.3-linux-x86_64.tar.xz"
tar -xvf ccache-4.8.3-linux-x86_64.tar.xz
fi
mkdir ${topdir}/BIN
cd ${topdir}/BIN
ln -sf ${topdir}/DOWNLOADS/ccache-4.8.3-linux-x86_64/ccache .
# Set up ccache environment
setup_ccache
# Create the CCACHE_DIR directory if it was not retrieved from the cache
echo
if [ -d ${CCACHE_DIR} ]; then
echo "Directory CCACHE_DIR=${CCACHE_DIR} already exists (retrieved from cache)"
else
echo "Directory CCACHE_DIR=${CCACHE_DIR} does not exist: create it"
mkdir ${CCACHE_DIR}
fi
# Dump ccache status before the builds
echo
echo "ccache --version | head -1"
ccache --version | head -1
echo
echo "CCACHE_DIR=${CCACHE_DIR}"
echo "du -sm ${CCACHE_DIR}"
du -sm ${CCACHE_DIR}
echo
echo "ccache -s (before the builds)"
ccache -s
# Check if googletest has already been installed and configured
echo
if [ -d ${topdir}/test/googletest ]; then
echo "Directory ${topdir}/test/googletest already exists (retrieved from cache)"
echo "ls ${topdir}/test/googletest (start)"
ls ${topdir}/test/googletest
echo "ls ${topdir}/test/googletest (end)"
else
echo "Directory ${topdir}/test/googletest does not exist: it will be created during the build"
fi
}
#----------------------------------------------------------------------------------------------------------------------------------
# Build stage
function build() {
if [ "$1" == "" ] || [ "$2" != "" ]; then echo "Usage: $(basename $0) <process>"; exit 1; fi
proc=$1
if [ "${proc%.mad}" == "${proc}" ] && [ "${proc%.sa}" == "${proc}" ]; then echo "Usage: $(basename $0) <process.mad|process.sa>"; exit 1; fi
# Set up build environment
setup_ccache
export USECCACHE=1 # enable ccache in madgraph4gpu builds
export CXX=g++ # set up CXX that is needed by cudacpp.mk
###echo; echo "$CXX --version"; $CXX --version
export USEBUILDDIR=1
# Iterate over P* directories and build
cd ${topdir}/epochX/cudacpp/${proc}
echo "Current directory is $(pwd)"
gtestlibs=0
pdirs="$(ls -d SubProcesses/P*_*)"
for pdir in ${pdirs}; do
pushd $pdir >& /dev/null
echo
echo "*******************************************************************************"
echo "*** build ${proc} ($(basename $(pwd)))"
echo "*******************************************************************************"
echo
echo "Building in $(pwd)"
if [ "${gtestlibs}" == "0" ]; then
# Build googletest once and for all to avoid issues in parallel builds
gtestlibs=1
make -f cudacpp.mk gtestlibs
fi
# NB: 'make bldall' internally checks if 'which nvcc' and 'which hipcc' succeed before attempting to build cuda and hip
make -j bldall
popd >& /dev/null
done
}
#----------------------------------------------------------------------------------------------------------------------------------
# After-build stage (analyse data to be saved in updated cache)
function after_build() {
# Set up ccache environment
setup_ccache
# Dump ccache status after the builds
echo
echo "CCACHE_DIR=${CCACHE_DIR}"
echo "du -sm ${CCACHE_DIR}"
du -sm ${CCACHE_DIR}
echo
echo "ccache -s (after the builds)"
ccache -s
# Check contents of googletest
echo
echo "ls ${topdir}/test/googletest (start)"
ls ${topdir}/test/googletest
echo "ls ${topdir}/test/googletest (end)"
# Check contents of build directories
echo
echo "ls -d ${topdir}/epochX/cudacpp/*.*/SubProcesses/P*_*/build* (start)"
ls -d ${topdir}/epochX/cudacpp/*.*/SubProcesses/P*_*/build*
echo "ls -d ${topdir}/epochX/cudacpp/*.*/SubProcesses/P*_*/build* (end)"
}
#----------------------------------------------------------------------------------------------------------------------------------
function runExe() {
echo
echo "Execute $*"
if [ -f $1 ]; then $*; else echo "(SKIP missing $1)"; fi
}
# Tput-test stage (runTest.exe, check.exe, gcheck.exe)
function tput_test() {
if [ "$1" == "" ] || [ "$2" != "" ]; then echo "Usage: $(basename $0) <process>"; exit 1; fi
proc=$1
if [ "${proc%.mad}" == "${proc}" ] && [ "${proc%.sa}" == "${proc}" ]; then echo "Usage: $(basename $0) <process.mad|process.sa>"; exit 1; fi
# Iterate over P* directories and run tests
cd ${topdir}/epochX/cudacpp/${proc}
echo "Current directory is $(pwd)"
pdirs="$(ls -d SubProcesses/P*_*)"
for pdir in ${pdirs}; do
pushd $pdir >& /dev/null
echo
echo "*******************************************************************************"
echo "*** tput-test ${proc} ($(basename $(pwd)))"
echo "*******************************************************************************"
echo
echo "Testing in $(pwd)"
# FIXME1: this is just a quick test, eventually port here tput tests from throughputX.sh
# (could move some throughputX.sh functions to a separate script included both here and there)
# FIXME2: enable FPEs
# FIXME3: handle all d/f/m, inl0/1, hrd0/1 etc...
unamep=$(uname -p)
unames=$(uname -s)
for backend in cuda hip cppnone cppsse4 cppavx2 cpp512y cpp512z; do
# Skip GPU tests for NVidia and AMD unless nvcc and hipcc, respectively, are in PATH
if ! nvcc --version &> /dev/null; then
if [ "${backend}" == "cuda" ]; then echo; echo "(SKIP ${backend} because nvcc is missing on this node)"; continue; fi
elif ! hipcc --version &> /dev/null; then
if [ "${backend}" == "hip" ]; then echo; echo "(SKIP ${backend} because hipcc is missing on this node)"; continue; fi
fi
# Skip C++ tests for unsupported simd modes as done in tput tests (prevent illegal instruction crashes #791)
if [ "${unamep}" != "x86_64" ]; then
if [ "${backend}" == "cppavx2" ]; then echo; echo "(SKIP ${backend} which is not supported on ${unamep})"; continue; fi
if [ "${backend}" == "cpp512y" ]; then echo; echo "(SKIP ${backend} which is not supported on ${unamep})"; continue; fi
if [ "${backend}" == "cpp512z" ]; then echo; echo "(SKIP ${backend} which is not supported on ${unamep})"; continue; fi
elif [ "${unames}" == "Darwin" ]; then
if [ "${backend}" == "cpp512y" ]; then echo; echo "(SKIP ${backend} which is not supported on ${unames})"; continue; fi
if [ "${backend}" == "cpp512z" ]; then echo; echo "(SKIP ${backend} which is not supported on ${unames})"; continue; fi
elif [ "$(grep -m1 -c avx512vl /proc/cpuinfo)" != "1" ]; then
if [ "${backend}" == "cpp512y" ]; then echo; echo "(SKIP ${backend} which is not supported - no avx512vl in /proc/cpuinfo)"; continue; fi
if [ "${backend}" == "cpp512z" ]; then echo; echo "(SKIP ${backend} which is not supported - no avx512vl in /proc/cpuinfo)"; continue; fi
fi
if ls -d build.${backend}* > /dev/null 2>&1; then
bdirs="$(ls -d build.${backend}*)"
for bdir in ${bdirs}; do
runExe ${bdir}/runTest.exe
if [ -f ${bdir}/check.exe ]; then
runExe ${bdir}/check.exe -p 1 32 1
elif [ -f ${bdir}/gcheck.exe ]; then
runExe ${bdir}/gcheck.exe -p 1 32 1
else
echo "ERROR! Neither ${bdir}/check.exe nor ${bdir}/gcheck.exe was found?"; exit 1
fi
done
fi
done
popd >& /dev/null
done
}
#----------------------------------------------------------------------------------------------------------------------------------
# Usage
function usage() {
echo "Usage: $(basename $0) <${stages// /|}> <proc.sa|proc.mad>"
exit 1
}
#----------------------------------------------------------------------------------------------------------------------------------
# Valid stages
stages="codegen before_build build after_build tput_test"
# Check input arguments
for astage in $stages; do
if [ "$1" == "$astage" ]; then
stage=$1; proc=$2; shift; shift; break
fi
done
if [ "$stage" == "" ] || [ "$proc" == "" ] || [ "$1" != "" ]; then usage; fi
# Start
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "[testsuite_oneprocess.sh] $stage ($proc) starting at $(date)"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
# Execute stage
( set -e; $stage $proc) # execute this within a subprocess and fail immediately on error
status=$?
# Finish
echo
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
if [ $status -eq 0 ]; then
echo "[testsuite_oneprocess.sh] $stage ($proc) finished with status=$status (OK) at $(date)"
else
echo "[testsuite_oneprocess.sh] $stage ($proc) finished with status=$status (NOT OK) at $(date)"
fi
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
exit $status