Skip to content

Commit fbdacbd

Browse files
authored
Merge pull request #764 from madgraph5/new_interface
New interface
2 parents f75e994 + 87afdc2 commit fbdacbd

File tree

15 files changed

+306
-186
lines changed

15 files changed

+306
-186
lines changed

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

Lines changed: 11 additions & 46 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
@@ -78,12 +81,12 @@ index 348c283be..74db44d84 100644
7881
+CUDACPP_MAKEENV:=$(shell echo '$(.VARIABLES)' | tr " " "\n" | egrep "(USEBUILDDIR|AVX|FPTYPE|HELINL|HRDCOD)")
7982
+###$(info CUDACPP_MAKEENV=$(CUDACPP_MAKEENV))
8083
+###$(info $(foreach v,$(CUDACPP_MAKEENV),$(v)="$($(v))"))
81-
+CUDACPP_BUILDDIR:=$(shell $(MAKE) $(foreach v,$(CUDACPP_MAKEENV),$(v)="$($(v))") -f $(CUDACPP_MAKEFILE) -pn |& awk '/Building/{print $$3}' | sed s/BUILDDIR=//)
82-
+ifeq ($(CUDACPP_BUILDDIR),)
83-
+$(error CUDACPP_BUILDDIR='$(CUDACPP_BUILDDIR)' should not be empty!)
84-
+else
84+
+CUDACPP_BUILDDIR:=$(shell $(MAKE) $(foreach v,$(CUDACPP_MAKEENV),$(v)="$($(v))") -f $(CUDACPP_MAKEFILE) -pn 2>/dev/null | awk '/Building/{print $$3}' | sed s/BUILDDIR=//)
85+
+#ifeq ($(CUDACPP_BUILDDIR),)
86+
+#$(error CUDACPP_BUILDDIR='$(CUDACPP_BUILDDIR)' should not be empty!)
87+
+#else
8588
+$(info CUDACPP_BUILDDIR='$(CUDACPP_BUILDDIR)')
86-
+endif
89+
+#endif
8790
+CUDACPP_COMMONLIB=mg5amc_common
8891
+CUDACPP_CXXLIB=mg5amc_$(processid_short)_cpp
8992
+CUDACPP_CULIB=mg5amc_$(processid_short)_cuda
@@ -110,7 +113,7 @@ index 348c283be..74db44d84 100644
110113

111114
-$(PROG): $(PROCESS) auto_dsig.o $(LIBS) $(MATRIX)
112115
- $(FC) -o $(PROG) $(PROCESS) $(MATRIX) $(LINKLIBS) $(LDFLAGS) $(BIASDEPENDENCIES) -fopenmp
113-
+LDFLAGS+=-Wl,--no-relax # avoid 'failed to convert GOTPCREL relocation' error #458
116+
+#LDFLAGS+=-Wl,--no-relax # avoid 'failed to convert GOTPCREL relocation' error #458 (flag not universal -> skip?)
114117

115118
-$(PROG)_forhel: $(PROCESS) auto_dsig.o $(LIBS) $(MATRIX_HEL)
116119
- $(FC) -o $(PROG)_forhel $(PROCESS) $(MATRIX_HEL) $(LINKLIBS) $(LDFLAGS) $(BIASDEPENDENCIES) -fopenmp
@@ -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}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
import logging
3+
import os
4+
import subprocess
5+
pjoin = os.path.join
6+
logger = logging.getLogger('cmdprint') # for stdout
7+
8+
try:
9+
import madgraph
10+
except ImportError:
11+
import internal.madevent_interface as madevent_interface
12+
import internal.misc as misc
13+
import internal.extended_cmd as extended_cmd
14+
import internal.banner as banner_mod
15+
else:
16+
import madgraph.interface.madevent_interface as madevent_interface
17+
import madgraph.various.misc as misc
18+
import madgraph.interface.extended_cmd as extended_cmd
19+
import madgraph.various.banner as banner_mod
20+
21+
class CPPMEInterface(madevent_interface.MadEventCmdShell):
22+
23+
def compile(self, *args, **opts):
24+
""" """
25+
26+
import multiprocessing
27+
if not self.options['nb_core'] or self.options['nb_core'] == 'None':
28+
self.options['nb_core'] = multiprocessing.cpu_count()
29+
30+
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+
38+
cudacpp_backend = self.run_card['cudacpp_backend'].upper() # the default value is defined in banner.py
39+
logger.info("Building madevent in madevent_interface.py with '%s' matrix elements"%cudacpp_backend)
40+
if cudacpp_backend == 'FORTRAN':
41+
args[0][0] = 'madevent_fortran_link'
42+
elif cudacpp_backend == 'CPP':
43+
args[0][0] = 'madevent_cpp_link'
44+
elif cudacpp_backend == 'CUDA':
45+
args[0][0] = 'madevent_cuda_link'
46+
else:
47+
raise Exception("Invalid cudacpp_backend='%s': only 'FORTRAN', 'CPP', 'CUDA' are supported")
48+
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)
49+
else:
50+
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)
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+
99+
MEINTERFACE = CPPMEInterface
100+
RunCard = CPPRunCard

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/MatrixElementKernels.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,17 @@ namespace mg5amcCpu
112112
// See https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu
113113
bool ok = true; // this is just an assumption!
114114
const std::string tag = "arm neon (128bit as in SSE4.2)";
115-
#else
115+
#elif defined(__x86_64__) || defined(__i386__)
116116
bool known = true;
117117
bool ok = __builtin_cpu_supports( "sse4.2" );
118118
const std::string tag = "nehalem (SSE4.2)";
119+
#else
120+
bool known = false; // __builtin_cpu_supports is not supported
121+
// See https://gcc.gnu.org/onlinedocs/gcc/Basic-PowerPC-Built-in-Functions-Available-on-all-Configurations.html
122+
// See https://stackoverflow.com/q/62783908
123+
// See https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu
124+
bool ok = true; // this is just an assumption!
125+
const std::string tag = "arm neon (128bit as in SSE4.2)";
119126
#endif
120127
#else
121128
bool known = true;

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/cudacpp.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ UNAME_S := $(shell uname -s)
2727
UNAME_P := $(shell uname -p)
2828
###$(info UNAME_P='$(UNAME_P)')
2929

30+
include ../../Source/make_opts
3031
#-------------------------------------------------------------------------------
3132

3233
#=== Configure common compiler flags for C++ and CUDA
@@ -220,7 +221,7 @@ else ifneq ($(shell $(CXX) --version | egrep '^(clang)'),)
220221
override OMPFLAGS = -fopenmp
221222
###override OMPFLAGS = # disable OpenMP MT on clang (was not ok without or with nvcc before #578)
222223
else ifneq ($(shell $(CXX) --version | egrep '^(Apple clang)'),)
223-
override OMPFLAGS = # disable OpenMP MT on Apple clang (builds fail in the CI #578)
224+
override OMPFLAGS = -fopenmp # disable OpenMP MT on Apple clang (builds fail in the CI #578)
224225
else
225226
override OMPFLAGS = -fopenmp
226227
###override OMPFLAGS = # disable OpenMP MT (default before #575)
@@ -554,7 +555,7 @@ endif
554555
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: $(BUILDDIR)/fbridge.o
555556
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: cxx_objects_lib += $(BUILDDIR)/fbridge.o
556557
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: $(LIBDIR)/lib$(MG5AMC_COMMONLIB).so $(cxx_objects_lib)
557-
$(CXX) -shared -o $@ $(cxx_objects_lib) $(CXXLIBFLAGSRPATH2) -L$(LIBDIR) -l$(MG5AMC_COMMONLIB)
558+
$(CXX) -shared -o $@ $(cxx_objects_lib) $(CXXLIBFLAGSRPATH2) -L$(LIBDIR) -l$(MG5AMC_COMMONLIB) $(LIBFLAGS) -fopenmp
558559

559560
ifneq ($(NVCC),)
560561
$(LIBDIR)/lib$(MG5AMC_CULIB).so: $(BUILDDIR)/fbridge_cu.o

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/process_function_definitions.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ namespace mg5amcCpu
405405
{
406406
// nprocesses>1 was last observed for "mirror processes" in uux_ttx in the 270 branch (see issue #343 and PRs #360 and #396)
407407
constexpr int nprocesses = %(nproc)i;
408-
static_assert( nprocesses == 1, "Assume nprocesses == 1" );
409-
// process_id corresponds to the index of DSIG1 Fortran functions (must be 1 because cudacpp is unable to handle DSIG2)
408+
static_assert( nprocesses == 1 || nprocesses == 2, "Assume nprocesses == 1 or 2" );
410409
constexpr int process_id = %(proc_id)i; // code generation source: %(proc_id_source)s
411410
static_assert( process_id == 1, "Assume process_id == 1" );
412411
}

0 commit comments

Comments
 (0)