Skip to content

Commit bcec0af

Browse files
committed
Merge commit 'fbdacbd54' into oct23av
This adds the following commits by Olivier (final part of PR madgraph5#764, I had already merged individually previous commits) fbdacbd Stefan Roiser Fri Sep 15 09:36:36 2023 +0200 Merge pull request madgraph5#764 from madgraph5/new_interface 87afdc2 Olivier Mattelaer Thu Sep 14 09:13:25 2023 +0200 change default gpu size to 16k f27f44d Olivier Mattelaer Tue Sep 12 23:33:24 2023 +0200 adding shortcut for the SIMD/GPU mode 22fd349 Olivier Mattelaer Tue Sep 12 16:53:39 2023 +0200 allowing run_card to not include the vector_size (then use the value defined at output time) 5b594c7 Olivier Mattelaer Tue Sep 12 16:08:42 2023 +0200 fix compilation issue 0dd8542 oliviermattelaer Tue Sep 12 15:29:00 2023 +0200 Merge branch 'master' into new_interface c839c47 Olivier Mattelaer Tue Sep 12 15:07:03 2023 +0200 update to version supporting vector_size to be setup via the run_card Fix conflicts: epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/patchMad.sh
2 parents 06d970e + fbdacbd commit bcec0af

6 files changed

Lines changed: 120 additions & 54 deletions

File tree

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/MG5aMC_patches/PROD/patch.common

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ index 617f10b93..dbe08b846 100644
2525
$(RM) *.o $(LIBRARIES) $(BINARIES)
2626
cd PDF; make clean; cd ..
2727
cd PDF/gammaUPC; make clean; cd ../../
28-
@@ -132,4 +132,9 @@ clean:
28+
@@ -132,4 +132,11 @@ clean:
2929
cd BIAS/ptj_bias; make clean; cd ../..
3030
if [ -d $(CUTTOOLSDIR) ]; then cd $(CUTTOOLSDIR); make clean; cd ..; fi
3131
if [ -d $(IREGIDIR) ]; then cd $(IREGIDIR); make clean; cd ..; fi
3232
+
3333
+clean: cleanSource
3434
for i in `ls -d ../SubProcesses/P*`; do cd $$i; make clean; cd -; done;
3535
+
36-
+cleanall: cleanSource
36+
+cleanavx:
3737
+ for i in `ls -d ../SubProcesses/P*`; do cd $$i; make cleanavxs; cd -; done;
38+
+cleanall: cleanSource # THIS IS THE ONE
39+
+ for i in `ls -d ../SubProcesses/P*`; do cd $$i; make cleanavxs; cd -; done;
40+
+
3841
diff --git b/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile a/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile
3942
index 348c283be..74db44d84 100644
4043
--- b/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile
@@ -283,44 +286,6 @@ index 348c283be..74db44d84 100644
283286
+
284287
+distclean: cleanall # Clean all fortran and cudacpp builds as well as the googletest installation
285288
+ $(MAKE) -f $(CUDACPP_MAKEFILE) distclean
286-
diff --git b/epochX/cudacpp/gg_tt.mad/Source/make_opts a/epochX/cudacpp/gg_tt.mad/Source/make_opts
287-
index 57f5f7bb9..bd3c24228 100644
288-
--- b/epochX/cudacpp/gg_tt.mad/Source/make_opts
289-
+++ a/epochX/cudacpp/gg_tt.mad/Source/make_opts
290-
@@ -1,12 +1,17 @@
291-
+pdlabel1=
292-
+pdlabel2=
293-
+lhapdf=
294-
+PYTHIA8_PATH=NotInstalled
295-
+MG5AMC_VERSION=3.5.0_lo_vect
296-
GLOBAL_FLAG=-O3 -ffast-math -fbounds-check
297-
+ALOHA_FLAG=
298-
+MATRIX_FLAG=
299-
DEFAULT_CPP_COMPILER=g++
300-
MACFLAG=
301-
STDLIB=-lstdc++
302-
STDLIB_FLAG=
303-
DEFAULT_F_COMPILER=gfortran
304-
DEFAULT_F2PY_COMPILER=f2py3
305-
-MG5AMC_VERSION=SpecifiedByMG5aMCAtRunTime
306-
-PYTHIA8_PATH=NotInstalled
307-
#end_of_make_opts_variables
308-
309-
BIASLIBDIR=../../../lib/
310-
diff --git b/epochX/cudacpp/gg_tt.mad/bin/internal/banner.py a/epochX/cudacpp/gg_tt.mad/bin/internal/banner.py
311-
index 8f8df219d..7624b9f55 100755
312-
--- b/epochX/cudacpp/gg_tt.mad/bin/internal/banner.py
313-
+++ a/epochX/cudacpp/gg_tt.mad/bin/internal/banner.py
314-
@@ -4187,7 +4187,8 @@ class RunCardLO(RunCard):
315-
self.add_param('mxxmin4pdg',[-1.], system=True)
316-
self.add_param('mxxpart_antipart', [False], system=True)
317-
318-
-
319-
+ # CUDACPP parameters
320-
+ self.add_param('cudacpp_backend', 'CPP', include=False, hidden=False)
321-
322-
def check_validity(self):
323-
""" """
324289
diff --git b/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py a/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py
325290
index 4dd71db86..3b8ec3121 100755
326291
--- b/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
# allows the command "output myformat PATH" in madgraph.
3333
# MYCLASS should inherit from class madgraph.iolibs.export_v4.VirtualExporter
3434
import PLUGIN.CUDACPP_OUTPUT.output as output
35-
new_output = { 'standalone_cudacpp' : output.PLUGIN_ProcessExporter }
35+
new_output = { 'madevent_simd' : output.SIMD_ProcessExporter,
36+
'madevent_gpu' : output.GPU_ProcessExporter,
37+
'standalone_cudacpp' : output.PLUGIN_ProcessExporter,
38+
'standalone_simd' : output.SIMD_ProcessExporter,
39+
'standalone_cuda' : output.GPU_ProcessExporter,
40+
}
3641

3742
# 2. Define new way to handle the cluster.
3843
# Example: new_cluster = {'mycluster': MYCLUSTERCLASS}

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/launch_plugin.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
import logging
3-
3+
import os
4+
import subprocess
5+
pjoin = os.path.join
46
logger = logging.getLogger('cmdprint') # for stdout
57

68
try:
@@ -9,20 +11,30 @@
911
import internal.madevent_interface as madevent_interface
1012
import internal.misc as misc
1113
import internal.extended_cmd as extended_cmd
14+
import internal.banner as banner_mod
1215
else:
1316
import madgraph.interface.madevent_interface as madevent_interface
1417
import madgraph.various.misc as misc
1518
import madgraph.interface.extended_cmd as extended_cmd
19+
import madgraph.various.banner as banner_mod
1620

1721
class CPPMEInterface(madevent_interface.MadEventCmdShell):
1822

1923
def compile(self, *args, **opts):
2024
""" """
25+
2126
import multiprocessing
2227
if not self.options['nb_core'] or self.options['nb_core'] == 'None':
2328
self.options['nb_core'] = multiprocessing.cpu_count()
2429

2530
if args and args[0][0] == 'madevent' and hasattr(self, 'run_card'):
31+
import pathlib
32+
import os
33+
pjoin = os.path.join
34+
35+
36+
37+
2638
cudacpp_backend = self.run_card['cudacpp_backend'].upper() # the default value is defined in banner.py
2739
logger.info("Building madevent in madevent_interface.py with '%s' matrix elements"%cudacpp_backend)
2840
if cudacpp_backend == 'FORTRAN':
@@ -36,5 +48,53 @@ def compile(self, *args, **opts):
3648
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)
3749
else:
3850
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)
39-
51+
52+
class CPPRunCard(banner_mod.RunCardLO):
53+
54+
def reset_simd(self, old_value, new_value, name):
55+
if not hasattr(self, 'path'):
56+
raise Exception
57+
58+
if name == "vector_size" and new_value <= int(old_value):
59+
# code can handle the new size -> do not recompile
60+
return
61+
62+
Sourcedir = pjoin(os.path.dirname(os.path.dirname(self.path)), 'Source')
63+
subprocess.call(['make', 'cleanavx'], cwd=Sourcedir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
64+
65+
def plugin_input(self, finput):
66+
return
67+
68+
def default_setup(self):
69+
super().default_setup()
70+
self.add_param('cudacpp_backend', 'CPP', include=False, hidden=False)
71+
72+
73+
def write_one_include_file(self, output_dir, incname, output_file=None):
74+
"""write one include file at the time"""
75+
76+
if incname == "vector.inc" and 'vector_size' not in self.user_set:
77+
return
78+
super().write_one_include_file(output_dir, incname, output_file)
79+
80+
81+
def check_validity(self):
82+
"""ensure that PLUGIN information are consistent"""
83+
84+
super().check_validity()
85+
86+
if self['SDE_strategy'] != 1:
87+
logger.warning('SDE_strategy different of 1 is not supported with SMD/GPU mode')
88+
self['sde_strategy'] = 1
89+
90+
if self['hel_recycling']:
91+
self['hel_recycling'] = False
92+
93+
class GPURunCard(CPPRunCard):
94+
95+
def default_setup(self):
96+
super(CPPRunCard, self).default_setup()
97+
self.add_param('cudacpp_backend', 'CUDA', include=False, hidden=False)
98+
4099
MEINTERFACE = CPPMEInterface
100+
RunCard = CPPRunCard

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,30 +203,33 @@ def finalize(self, matrix_element, cmdhistory, MG5options, outputflag):
203203
cmdhistory is the list of command used so far.
204204
MG5options are all the options of the main interface
205205
outputflags is a list of options provided when doing the output command"""
206-
misc.sprint('Entering PLUGIN_ProcessExporter.finalize', self.in_madevent_mode)
206+
misc.sprint('Entering PLUGIN_ProcessExporter.finalize', self.in_madevent_mode, type(self))
207207
if self.in_madevent_mode:
208208
self.add_input_for_banner()
209209
if 'CUDACPP_CODEGEN_PATCHLEVEL' in os.environ: patchlevel = os.environ['CUDACPP_CODEGEN_PATCHLEVEL']
210210
else: patchlevel = ''
211+
<<<<<<< HEAD
211212
# OLDEST implementation (AV)
212213
#path = os.path.realpath(os.curdir + os.sep + 'PLUGIN' + os.sep + 'CUDACPP_OUTPUT')
213214
#misc.sprint(path)
214215
#if os.system(path + os.sep + 'patchMad.sh ' + self.dir_path + ' PROD ' + patchlevel) != 0:
215216
# logger.debug("####### \n stdout is \n %s", stdout)
216217
# logger.info("####### \n stderr is \n %s", stderr)
217218
# raise Exception('ERROR! the O/S call to patchMad.sh failed')
218-
# OLD implementation (OM)
219-
#plugin_path = os.path.dirname(os.path.realpath( __file__ ))
220-
#p = subprocess.Popen([pjoin(plugin_path, 'patchMad.sh'), self.dir_path , 'PROD', str(patchlevel)])
221-
#stdout, stderr = p.communicate()
222-
#if not p.returncode:
219+
# OLD implementation (SH PR #762)
220+
#if os.system(PLUGINDIR + os.sep + 'patchMad.sh ' + self.dir_path + ' PROD ' + patchlevel) != 0:
223221
# logger.debug("####### \n stdout is \n %s", stdout)
224222
# logger.info("####### \n stderr is \n %s", stderr)
225-
# raise Exception('ERROR! the O/S call to patchMad.sh failed')
226-
# NEW implementation (SH)
227-
if os.system(PLUGINDIR + os.sep + 'patchMad.sh ' + self.dir_path + ' PROD ' + patchlevel) != 0:
223+
# raise Exception('ERROR! the O/S call to patchMad.sh failed')
224+
# NEW implementation (OM PR #764)
225+
plugin_path = os.path.dirname(os.path.realpath( __file__ ))
226+
p = subprocess.Popen([pjoin(plugin_path, 'patchMad.sh'), self.dir_path , 'PROD', str(patchlevel)],
227+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
228+
stdout, stderr = p.communicate()
229+
if p.returncode != 0:
228230
logger.debug("####### \n stdout is \n %s", stdout)
229231
logger.info("####### \n stderr is \n %s", stderr)
232+
logger.info("return code is %s\n", p.returncode)
230233
raise Exception('ERROR! the O/S call to patchMad.sh failed')
231234
# Additional patching (OM)
232235
self.add_madevent_plugin_fct() # Added by OM
@@ -267,3 +270,36 @@ def add_madevent_plugin_fct(self):
267270
files.ln( pjoin(self.dir_path, 'lib'), pjoin(self.dir_path, 'SubProcesses'))
268271

269272
#------------------------------------------------------------------------------------
273+
class SIMD_ProcessExporter(PLUGIN_ProcessExporter):
274+
275+
def change_output_args(args, cmd):
276+
""" """
277+
cmd._export_format = "madevent"
278+
args.append('--hel_recycling=False')
279+
args.append('--me_exporter=standalone_simd')
280+
if 'vector_size' not in ''.join(args):
281+
args.append('--vector_size=16')
282+
return args
283+
284+
285+
286+
class GPU_ProcessExporter(PLUGIN_ProcessExporter):
287+
288+
def change_output_args(args, cmd):
289+
""" """
290+
cmd._export_format = "madevent"
291+
args.append('--hel_recycling=False')
292+
args.append('--me_exporter=standalone_cuda')
293+
if 'vector_size' not in ''.join(args):
294+
args.append('--vector_size=16384')
295+
return args
296+
297+
def finalize(self, matrix_element, cmdhistory, MG5options, outputflag):
298+
299+
misc.sprint("enter dedicated function")
300+
out = super().finalize(matrix_element, cmdhistory, MG5options, outputflag)
301+
#change RunCard class to have default for GPU
302+
text = open(pjoin(self.dir_path, 'bin', 'internal', 'launch_plugin.py'), 'r').read()
303+
text = text.replace('RunCard = CPPRunCard', 'RunCard = GPURunCard')
304+
open(pjoin(self.dir_path, 'bin', 'internal', 'launch_plugin.py'), 'w').write(text)
305+
return out

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/patchMad.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fi
8181
# Patch the default Fortran code to provide the integration with the cudacpp plugin
8282
# (1) Process-independent patches
8383
touch ${dir}/Events/.keep # this file should already be present (mg5amcnlo copies it from Template/LO/Events/.keep)
84-
cp -pr ${scrdir}/MG5aMC_patches/${dir_patches}/fbridge_common.inc ${dir}/SubProcesses # new file
84+
\cp -pr ${scrdir}/MG5aMC_patches/${dir_patches}/fbridge_common.inc ${dir}/SubProcesses # new file
8585
if [ "${tmadmode}" != "0" ]; then
8686
sed -i 's/2 = sde_strategy/1 = sde_strategy/' ${dir}/Cards/run_card.dat # use strategy SDE=1 in multichannel mode (see #419)
8787
sed -i 's/SDE_STRAT = 2/SDE_STRAT = 1/' ${dir}/Source/run_card.inc # use strategy SDE=1 in multichannel mode (see #419)

0 commit comments

Comments
 (0)