Skip to content

Commit

Permalink
[lhe] add --upstream option to generateAndCompare.sh and patchMad.sh
Browse files Browse the repository at this point in the history
I have understod the problem: I was still using my old pre-patched version of addmothers.f!
I must go back to vecMLM out of the box as much as possible first...
  • Loading branch information
valassi committed Dec 7, 2022
1 parent bcebb43 commit c5c07d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
18 changes: 10 additions & 8 deletions epochX/cudacpp/CODEGEN/generateAndCompare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function codeGenAndDiff()
# [NB: NEW! these patches are no longer applied to madonly, which is now meant as an out-of-the-box reference]
###if [ "${OUTBCK}" == "madonly" ] || [ "${OUTBCK}" == "mad" ]; then
if [ "${OUTBCK}" == "mad" ]; then
$SCRDIR/patchMad.sh ${OUTDIR}/${proc}.${autosuffix} ${vecsize} ${dir_patches} ${NOPATCH}
$SCRDIR/patchMad.sh ${OUTDIR}/${proc}.${autosuffix} ${vecsize} ${dir_patches} ${PATCHLEVEL}
fi
# Compare the existing generated code to the newly generated code for the specific process
pushd ${OUTDIR} >& /dev/null
Expand Down Expand Up @@ -185,7 +185,7 @@ function usage()
echo "Usage: $0 [--nobrief] <proc>"
else
# NB: all options with $SCRBCK=cudacpp use the 311 branch by default and always disable helicity recycling
echo "Usage: $0 [--nobrief] [--cpp|--gpu|--madonly|--mad|--madgpu] [--nopatch] <proc>"
echo "Usage: $0 [--nobrief] [--cpp|--gpu|--madonly|--mad|--madgpu] [--nopatch|--upstream] <proc>"
echo "(NB: a --madcpp option also exists but code generation fails for it)"
fi
exit 1
Expand Down Expand Up @@ -228,8 +228,8 @@ BRIEF=--brief
# Default for gridpacks: untar gridpack.tar.gz but do not regenerate it (use --nountaronly to regenerate it)
UNTARONLY=1

# Default: apply all patches in patchMad.sh (this is ignored unless --mad is also specified)
NOPATCH=
# Default: apply all patches in patchMad.sh (--nopatch is ignored unless --mad is also specified)
PATCHLEVEL=

# Default for gridpacks: use helicity recycling (use --nohelrec to disable it)
# (export the value to the untarGridpack.sh script)
Expand All @@ -243,8 +243,10 @@ for arg in "$@"; do
usage
elif [ "$arg" == "--nobrief" ]; then
BRIEF=
elif [ "$arg" == "--nopatch" ]; then
NOPATCH=--nopatch
elif [ "$arg" == "--nopatch" ] && [ "${PATCHLEVEL}" == "" ]; then
PATCHLEVEL=--nopatch
elif [ "$arg" == "--upstream" ] && [ "${PATCHLEVEL}" == "" ]; then
PATCHLEVEL=--upstream
elif [ "$arg" == "--nountaronly" ] && [ "${SCRBCK}" == "gridpack" ]; then
UNTARONLY=0
elif [ "$arg" == "--nohelrec" ] && [ "${SCRBCK}" == "gridpack" ]; then
Expand Down Expand Up @@ -350,8 +352,8 @@ echo -e "Current git commit of MG5AMC_HOME is '${commit_mg5amc}'"
if [ "${commit_patches}" != "${commit_mg5amc}" ]; then echo -e "\nERROR! git commit mismatch!"; exit 1; fi
cd - > /dev/null

# Copy MG5AMC ad-hoc patches if any
if [ "${SCRBCK}" == "cudacpp" ]; then
# Copy MG5AMC ad-hoc patches if any (unless --upstream is specified)
if [ "${PATCHLEVEL}" != "--upstream" ] && [ "${SCRBCK}" == "cudacpp" ]; then
###patches=$(cd $SCRDIR/MG5aMC_patches/${dir_patches}; find . -type f -name '*.py')
patches=$(cd $SCRDIR/MG5aMC_patches/${dir_patches}; find . -type f ! -name '*.GIT')
echo -e "Copy MG5aMC_patches/${dir_patches} patches..."
Expand Down
26 changes: 18 additions & 8 deletions epochX/cudacpp/CODEGEN/patchMad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ scrdir=$(cd $(dirname $0); pwd)

function usage()
{
echo "Usage: $0 <process.[madonly|mad]> <vecsize> <patch_dir> [--nopatch]"
echo "Usage: $0 <process.[madonly|mad]> <vecsize> <patch_dir> [--nopatch|--upstream]"
exit 1
}

nopatch=0 # apply patch commands (default)
# Patch level
###patchlevel=0 # [--upstream] out of the box codegen from upstream MG5AMC (do not even copy templates)
###patchlevel=1 # [--nopatch] modify upstream MG5AMC but do not apply patch commands (reference to prepare new patches)
patchlevel=2 # [DEFAULT] complete generation of cudacpp .sa/.mad (copy templates and apply patch commands)

if [ "${1%.madonly}" == "$1" ] && [ "${1%.mad}" == "$1" ]; then
usage
elif [ "$3" == "" ]; then
usage
elif [ "$4" == "--nopatch" ]; then
if [ "$5" != "" ]; then usage; fi
nopatch=1 # skip patch commands (produce a new reference)
patchlevel=1
elif [ "$4" == "--upstream" ]; then
if [ "$5" != "" ]; then usage; fi
patchlevel=0
elif [ "$4" != "" ]; then
usage
fi
Expand All @@ -39,25 +46,28 @@ ${dir}/bin/madevent treatcards param
\rm -f ${dir}/madevent.tar.gz
\rm -rf ${dir}/bin/internal/__pycache__
\rm -rf ${dir}/bin/internal/ufomodel/__pycache__
echo -e "index.html\n.libs\n.cudacpplibs" > ${dir}/.gitignore
touch ${dir}/Events/.keepme
\rm -rf ${dir}/HTML

# Exit here for patchlevel 0 (--upstream)
if [ "${patchlevel}" == "0" ]; then exit $status; fi

# Add global flag '-O3 -ffast-math -fbounds-check' as in previous gridpacks
echo "GLOBAL_FLAG=-O3 -ffast-math -fbounds-check" > ${dir}/Source/make_opts.new
cat ${dir}/Source/make_opts >> ${dir}/Source/make_opts.new
\mv ${dir}/Source/make_opts.new ${dir}/Source/make_opts

# Patch the default Fortran code to provide the integration with the cudacpp plugin
# (1) Process-independent patches
echo -e "index.html\n.libs\n.cudacpplibs" > ${dir}/.gitignore
touch ${dir}/Events/.keepme
\cp -dpr ${scrdir}/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/.clang-format ${dir} # new file
\cp -dpr ${scrdir}/MG5aMC_patches/${dir_patches}/vector.inc ${dir}/Source # replace default
\cp -dpr ${scrdir}/MG5aMC_patches/${dir_patches}/fbridge_common.inc ${dir}/SubProcesses # new file
for file in ${dir}/Source/MODEL/rw_para.f; do cat ${file} | sed "s|include 'coupl.inc'|include 'vector.inc'\n include 'coupl.inc'|" > ${file}.new; \mv ${file}.new ${file}; done
for file in ${dir}/Source/PDF/ElectroweakFlux.inc; do cat ${file} | sed "s|include '../MODEL/coupl.inc'|include 'vector.inc'\n include 'coupl.inc'|" > ${file}.new; \mv ${file}.new ${file}; done
cd ${dir}/SubProcesses
cd - > /dev/null
if [ "${nopatch}" == "0" ]; then
if [ "${patchlevel}" == "2" ]; then
cd ${dir}
if ! patch -p4 -i ${scrdir}/MG5aMC_patches/${dir_patches}/patch.common; then status=1; fi
cd - > /dev/null
Expand All @@ -70,7 +80,7 @@ for p1dir in ${dir}/SubProcesses/P1_*; do
if [ "${dir%.mad}" == "$1" ]; then
\cp -dpr ${scrdir}/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/timer.h . # new file, already present via cudacpp in *.mad
fi
if [ "${nopatch}" == "0" ]; then
if [ "${patchlevel}" == "2" ]; then
if ! patch -p6 -i ${scrdir}/MG5aMC_patches/${dir_patches}/patch.P1; then status=1; fi
fi
cd - > /dev/null
Expand Down Expand Up @@ -110,7 +120,7 @@ for p1dir in ${dir}/SubProcesses/P1_*; do
| sed "s|/NB_PAGE|/NB_PAGE_MAX|" \
> auto_dsig1.f.new
\mv auto_dsig1.f.new auto_dsig1.f
if [ "${nopatch}" == "0" ]; then
if [ "${patchlevel}" == "2" ]; then
if ! patch -p6 -i ${scrdir}/MG5aMC_patches/${dir_patches}/patch.auto_dsig1.f; then status=1; fi
fi
\rm -f *.orig
Expand Down

0 comments on commit c5c07d6

Please sign in to comment.