Skip to content

Commit 8f8f7a0

Browse files
committed
Implement backend detection and logging for cppauto before compiling
1 parent 0677cef commit 8f8f7a0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,27 @@ def compile(self, *args, **opts):
3838
cudacpp_supported_backends = [ 'fortran', 'cuda', 'hip', 'cpp', 'cppnone', 'cppsse4', 'cppavx2', 'cpp512y', 'cpp512z', 'cppauto' ]
3939
if args and args[0][0] == 'madevent' and hasattr(self, 'run_card'):
4040
cudacpp_backend = self.run_card['cudacpp_backend'].lower() # the default value is defined in launch_plugin.py
41-
logger.info("Building madevent in madevent_interface.py with '%s' matrix elements"%cudacpp_backend)
41+
if cudacpp_backend in ['cpp', 'cppauto']:
42+
backend_log = pjoin(opts["cwd"], ".resolved-backend")
43+
# try to remove old file if present
44+
breakpoint()
45+
try:
46+
os.remove(backend_log)
47+
except FileNotFoundError:
48+
pass
49+
misc.compile(["-f", "cudacpp.mk", f"BACKEND=cppauto", f"BACKEND_LOG={backend_log}", "detect-backend"], **opts)
50+
try:
51+
with open(backend_log, "r") as f:
52+
resolved_backend = f.read().strip()
53+
logger.info(f"Backend '{cudacpp_backend}' resolved as '{resolved_backend}'")
54+
cudacpp_backend = resolved_backend
55+
except FileNotFoundError:
56+
raise RuntimeError("Could not resolve cudacpp_backend=cppauto|cpp; ensure Makefile detection runs properly.")
57+
logger.info(f"Building madevent in madevent_interface.py with '{cudacpp_backend}' matrix elements")
4258
if cudacpp_backend in cudacpp_supported_backends :
4359
args[0][0] = 'madevent_' + cudacpp_backend + '_link'
4460
else:
45-
raise Exception( "Invalid cudacpp_backend='%s': supported backends are %s"%supported_backends )
61+
raise Exception(f"Invalid cudacpp_backend='{cudacpp_backend}': supported backends are [ '" + "', '".join(cudacpp_supported_backends) + "' ]")
4662
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)
4763
else:
4864
return misc.compile(nb_core=self.options['nb_core'], *args, **opts)

0 commit comments

Comments
 (0)