Skip to content

Commit dcf46e0

Browse files
committed
Add a makefile wrapper to avoid double -f while doing make
Makefile wrapper used in case of madevent to join together both makefile_orig and cudacpp_overlay.mk. This is to avoid doing make -f makefile -f cudacpp.mk, keeping the possibility to just do `make`: - makefile (after code generation by MadGraph) is renamed to makefile_original.mk - makefile_wrapper.mk (copied from cudacpp) is symlinked as makefile The logic is: in each SubProcesses/P* directory we have - makefile -> ../makefile (this is the original makefile) - cudacpp_overlay.mk -> ../cudacpp_overlay.mk While in the SubProcesses directory we had to: - makefile (this is the original makefile) - cudacpp_overlay.mk - makefile_wrapper.mk So, in each SubProcesses/P* we had to (done in model_handling.py) symlink from SubProcesses/P*/makefile_original.mk to SubProcesses/makefile_original.mk (it will be broken initially). While in SubProcesses we had to (done in output.py): - copy makefile to makefile_original.mk (this fixes the previous symlink) - remove makefile - symlink from makefile_wrapper.mk to makefile So that now the situation in each SubProcesses/P* is: - makefile -> ../makefile (this is the makefile_wrapper.mk) - cudacpp_overlay.mk -> ../cudacpp_overlay.mk - makefile_original.mk -> ../makefile_original.mk (this is the original makefile)
1 parent 122c12f commit dcf46e0

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

.github/workflows/testsuite_oneprocess.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,7 @@ function build() {
165165
make -f cudacpp.mk gtestlibs
166166
fi
167167
# NB: 'make bldall' internally checks if 'which nvcc' and 'which hipcc' succeed before attempting to build cuda and hip
168-
if [ "${proc##*.}" == "sa" ]; then
169-
# for standalone, just use the makefile (symlinked to cudacpp.mk)
170-
make -j bldall
171-
else
172-
# makefile overlay after removing patches
173-
make -j -f makefile -f cudacpp_overlay.mk bldall
174-
fi
168+
make -j bldall
175169
popd >& /dev/null
176170
done
177171
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def compile(self, *args, **opts):
4040
cudacpp_backend = self.run_card['cudacpp_backend'].lower() # the default value is defined in launch_plugin.py
4141
logger.info("Building madevent in madevent_interface.py with '%s' matrix elements"%cudacpp_backend)
4242
if cudacpp_backend in cudacpp_supported_backends :
43-
new_args = list(args)
44-
new_args[0] = ['-f', 'makefile', '-f', 'cudacpp_overlay.mk', 'madevent_' + cudacpp_backend + '_link'] + new_args[0][1:]
45-
args = tuple(new_args)
43+
args[0][0] = 'madevent_' + cudacpp_backend + '_link'
4644
else:
4745
raise Exception( "Invalid cudacpp_backend='%s': supported backends are %s"%supported_backends )
4846
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
# Based on code originally written by: S. Hageboeck, O. Mattelaer, S. Roiser, J. Teig, A. Valassi (2020-2024)
55

66
# To be used after the project makefile
7-
# Usage: make -f makefile -f cudacpp_overlay.mk ...
87
SHELL := /bin/bash
98

10-
# Recursive-make helper
11-
PRIMARY_MK ?= makefile
12-
OVERLAY_MK ?= cudacpp_overlay.mk
13-
SELF_MF := -f $(PRIMARY_MK) -f $(OVERLAY_MK)
14-
159
# Determine CUDACPP_BUILDDIR based on the user-defined choices of BACKEND, FPTYPE, HELINL, HRDCOD and USEBUILDDIR (#829)
1610
# Stop with an error if BACKEND=cuda and nvcc is missing or if BACKEND=hip and hipcc is missing
1711
include ../../src/cudacpp_config.mk
@@ -205,17 +199,17 @@ madevent_fortran_link: $(PROG)_fortran
205199
ln -s $(PROG)_fortran $(PROG)
206200

207201
madevent_cuda_link:
208-
$(MAKE) $(SELF_MF) USEGTEST=0 BACKEND=cuda $(CUDACPP_BUILDDIR)/$(PROG)_cuda
202+
$(MAKE) USEGTEST=0 BACKEND=cuda $(CUDACPP_BUILDDIR)/$(PROG)_cuda
209203
rm -f $(PROG)
210204
ln -s $(CUDACPP_BUILDDIR)/$(PROG)_cuda $(PROG)
211205

212206
madevent_hip_link:
213-
$(MAKE) $(SELF_MF) USEGTEST=0 BACKEND=hip $(CUDACPP_BUILDDIR)/$(PROG)_hip
207+
$(MAKE) USEGTEST=0 BACKEND=hip $(CUDACPP_BUILDDIR)/$(PROG)_hip
214208
rm -f $(PROG)
215209
ln -s $(CUDACPP_BUILDDIR)/$(PROG)_hip $(PROG)
216210

217211
madevent_cpp_link:
218-
$(MAKE) $(SELF_MF) USEGTEST=0 BACKEND=cppauto $(CUDACPP_BUILDDIR)/$(PROG)_cpp
212+
$(MAKE) USEGTEST=0 BACKEND=cppauto $(CUDACPP_BUILDDIR)/$(PROG)_cpp
219213
rm -f $(PROG)
220214
ln -s $(CUDACPP_BUILDDIR)/$(PROG)_cpp $(PROG)
221215

@@ -224,7 +218,7 @@ override SUPPORTED_AVXS := cppnone cppsse4 cppavx2 cpp512y cpp512z cppauto
224218
madevent_%_link:
225219
@if [ '$(words $(filter $*, $(SUPPORTED_AVXS)))' != '1' ]; then \
226220
echo "ERROR! Invalid target '$@' (supported: $(foreach avx,$(SUPPORTED_AVXS),madevent_$(avx)_link))"; exit 1; fi
227-
$(MAKE) $(SELF_MF) USEGTEST=0 BACKEND=$* $(CUDACPP_BUILDDIR)/$(PROG)_cpp
221+
$(MAKE) USEGTEST=0 BACKEND=$* $(CUDACPP_BUILDDIR)/$(PROG)_cpp
228222
rm -f $(PROG)
229223
ln -s $(CUDACPP_BUILDDIR)/$(PROG)_cpp $(PROG)
230224

@@ -253,31 +247,31 @@ endif
253247

254248
bldcuda: $(PROG)_fortran $(DSIG_cudacpp)
255249
@echo
256-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cuda
250+
$(MAKE) USEBUILDDIR=1 BACKEND=cuda
257251

258252
bldhip: $(PROG)_fortran $(DSIG_cudacpp)
259253
@echo
260-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=hip
254+
$(MAKE) USEBUILDDIR=1 BACKEND=hip
261255

262256
bldnone: $(PROG)_fortran $(DSIG_cudacpp)
263257
@echo
264-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cppnone
258+
$(MAKE) USEBUILDDIR=1 BACKEND=cppnone
265259

266260
bldsse4: $(PROG)_fortran $(DSIG_cudacpp)
267261
@echo
268-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cppsse4
262+
$(MAKE) USEBUILDDIR=1 BACKEND=cppsse4
269263

270264
bldavx2: $(PROG)_fortran $(DSIG_cudacpp)
271265
@echo
272-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cppavx2
266+
$(MAKE) USEBUILDDIR=1 BACKEND=cppavx2
273267

274268
bld512y: $(PROG)_fortran $(DSIG_cudacpp)
275269
@echo
276-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cpp512y
270+
$(MAKE) USEBUILDDIR=1 BACKEND=cpp512y
277271

278272
bld512z: $(PROG)_fortran $(DSIG_cudacpp)
279273
@echo
280-
$(MAKE) $(SELF_MF) USEBUILDDIR=1 BACKEND=cpp512z
274+
$(MAKE) USEBUILDDIR=1 BACKEND=cpp512z
281275

282276
# Clean (NB: 'make clean' in Source calls 'make clean' in all P*)
283277
clean: # Clean builds: fortran in this Pn; cudacpp executables for one AVX in this Pn
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SHELL := /bin/bash
2+
include makefile_original.mk
3+
include cudacpp_overlay.mk

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,8 @@ def generate_process_files(self):
14461446
# NB: symlink of cudacpp.mk to makefile is overwritten by madevent makefile if this exists (#480)
14471447
# NB: this relies on the assumption that cudacpp code is generated before madevent code
14481448
files.ln(pjoin(self.path, 'cudacpp.mk'), self.path, 'makefile')
1449+
# Add link to makefile_original.mk, PR #1052
1450+
files.ln(pjoin(self.path, '..', 'makefile_original.mk'), self.path, 'makefile_original.mk')
14491451
# Add symbolic links in the test directory
14501452
files.ln(pjoin(self.path + '/../../test', 'cudacpp_test.mk'), self.path + '/../../test', 'makefile')
14511453
# Add reference file in the test directory (if it exists for this process)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class PLUGIN_ProcessExporter(PLUGIN_export_cpp.ProcessExporterGPU):
121121
s+'gpu/MadgraphTest.h', s+'gpu/runTest.cc',
122122
s+'gpu/testmisc.cc', s+'gpu/testxxx_cc_ref.txt', s+'gpu/valgrind.h',
123123
s+'gpu/perf.py', s+'gpu/profile.sh',
124-
s+'gpu/cudacpp_overlay.mk',
124+
s+'gpu/cudacpp_overlay.mk', s+'gpu/makefile_wrapper.mk',
125125
s+'CMake/SubProcesses/CMakeLists.txt'],
126126
'test': [s+'gpu/cudacpp_test.mk']}
127127

@@ -239,6 +239,14 @@ def finalize(self, matrix_element, cmdhistory, MG5options, outputflag):
239239
outputflags is a list of options provided when doing the output command"""
240240
###misc.sprint('Entering PLUGIN_ProcessExporter.finalize', self.in_madevent_mode, type(self))
241241
if self.in_madevent_mode:
242+
# Modify makefiles and symlinks to avoid doing
243+
# make -f makefile -f cudacpp_overlay.mk to include the overlay
244+
# and instead just use `make`, see #1052
245+
subprocesses_dir = pjoin(self.dir_path, "SubProcesses")
246+
files.cp(pjoin(subprocesses_dir, "makefile"), pjoin(subprocesses_dir, "makefile_original.mk"))
247+
files.rm(pjoin(subprocesses_dir, "makefile"))
248+
files.ln(pjoin(subprocesses_dir, "makefile_wrapper.mk"), subprocesses_dir, 'makefile')
249+
242250
patch_coupl_write = r"""set -euo pipefail
243251
# Get last fields from lines starting with WRITE(*,2)
244252
gcs=$(awk '$1=="WRITE(*,2)" {print $NF}' coupl_write.inc)

0 commit comments

Comments
 (0)