Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
! Copyright (C) 2020-2024 CERN and UCLouvain.
! Licensed under the GNU Lesser General Public License (version 3 or later).
! Modified by: O. Mattelaer (Mar 2020) for the MG5aMC CUDACPP plugin.
! Further modified by: O. Mattelaer, A. Valassi (2020-2024) for the MG5aMC CUDACPP plugin.
! Further modified by: O. Mattelaer, A. Valassi, Z. Wettersten (2020-2025) for the MG5aMC CUDACPP plugin.
!==========================================================================
//--------------------------------------------------------------------------

Expand Down Expand Up @@ -194,7 +194,8 @@
if( pp == 0. )
{
// NB: Do not use "abs" for floats! It returns an integer with no build warning! Use std::abs!
fptype sqm[2] = { fpsqrt( std::abs( fmass ) ), 0. }; // possibility of negative fermion masses
// Aliased abs to allow __float128
fptype sqm[2] = { fpsqrt( fpabs( fmass ) ), 0. }; // possibility of negative fermion masses
//sqm[1] = ( fmass < 0. ? -abs( sqm[0] ) : abs( sqm[0] ) ); // AV: why abs here?
sqm[1] = ( fmass < 0. ? -sqm[0] : sqm[0] ); // AV: removed an abs here
fi[2] = cxmake( ip * sqm[ip], 0 );
Expand All @@ -220,7 +221,8 @@
#else
// Branch A: pp == 0.
// NB: Do not use "abs" for floats! It returns an integer with no build warning! Use std::abs!
fptype sqm[2] = { fpsqrt( std::abs( fmass ) ), 0 }; // possibility of negative fermion masses (NB: SCALAR!)
// Aliased abs to allow __float128 (irrelevant in SIMD but kept for consistency)
fptype sqm[2] = { fpsqrt( fpabs( fmass ) ), 0 }; // possibility of negative fermion masses (NB: SCALAR!)
sqm[1] = ( fmass < 0 ? -sqm[0] : sqm[0] ); // AV: removed an abs here (as above)
const cxtype fiA_2 = ip * sqm[ip]; // scalar cxtype: real part initialised from fptype, imag part = 0
const cxtype fiA_3 = im * nsf * sqm[ip]; // scalar cxtype: real part initialised from fptype, imag part = 0
Expand Down Expand Up @@ -436,8 +438,8 @@
vc[1] = cxmake( pvec1 * (fptype)nsv, pvec2 * (fptype)nsv );
if( vmass != 0. )
{
const int nsvahl = nsv * std::abs( hel );
const fptype hel0 = 1. - std::abs( hel );
const int nsvahl = nsv * fpabs( hel );
const fptype hel0 = 1. - fpabs( hel );
#ifndef MGONGPU_CPPSIMD
const fptype_sv pt2 = ( pvec1 * pvec1 ) + ( pvec2 * pvec2 );
const fptype_sv pp = fpmin( pvec0, fpsqrt( pt2 + ( pvec3 * pvec3 ) ) );
Expand Down Expand Up @@ -604,7 +606,8 @@
if( pp == 0. )
{
// NB: Do not use "abs" for floats! It returns an integer with no build warning! Use std::abs!
fptype sqm[2] = { fpsqrt( std::abs( fmass ) ), 0. }; // possibility of negative fermion masses
// Aliased abs to allow __float128
fptype sqm[2] = { fpsqrt( fpabs( fmass ) ), 0. }; // possibility of negative fermion masses
//sqm[1] = ( fmass < 0. ? -abs( sqm[0] ) : abs( sqm[0] ) ); // AV: why abs here?
sqm[1] = ( fmass < 0. ? -sqm[0] : sqm[0] ); // AV: removed an abs here
const int ip = -( ( 1 - nh ) / 2 ) * nhel; // NB: Fortran sqm(0:1) also has indexes 0,1 as in C++
Expand Down Expand Up @@ -637,7 +640,8 @@
const fptype_sv pp = fpmin( pvec0, fpsqrt( p2 ) );
// Branch A: pp == 0.
// NB: Do not use "abs" for floats! It returns an integer with no build warning! Use std::abs!
fptype sqm[2] = { fpsqrt( std::abs( fmass ) ), 0 }; // possibility of negative fermion masses
// Aliased abs to allow __float128 (irrelevant in SIMD, but for consistency)
fptype sqm[2] = { fpsqrt( fpabs( fmass ) ), 0 }; // possibility of negative fermion masses
sqm[1] = ( fmass < 0 ? -sqm[0] : sqm[0] ); // AV: removed an abs here (as above)
const int ipA = -( ( 1 - nh ) / 2 ) * nhel;
const int imA = ( 1 + nh ) / 2 * nhel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ def compile(self, *args, **opts):
{'override FPTYPE': self.run_card['floating_type'] })
misc.sprint('FPTYPE checked')
cudacpp_supported_backends = [ 'fortran', 'cuda', 'hip', 'cpp', 'cppnone', 'cppsse4', 'cppavx2', 'cpp512y', 'cpp512z', 'cppauto' ]

if args and args[0][0] == 'madevent' and hasattr(self, 'run_card'):
cudacpp_backend = self.run_card['cudacpp_backend'].lower() # the default value is defined in launch_plugin.py
if self.run_card['floating_type'] == 'q':
if cudacpp_backend not in [ 'fortran', 'cppnone' ]:
misc.sprint("WARNING: cudacpp_backend='%s' does not support quad precision. Switching to 'cppnone' backend."%cudacpp_backend)
cudacpp_backend = 'cppnone'
logger.info("Building madevent in madevent_interface.py with '%s' matrix elements"%cudacpp_backend)
if cudacpp_backend in cudacpp_supported_backends :
args[0][0] = 'madevent_' + cudacpp_backend + '_link'
Expand Down Expand Up @@ -86,7 +91,7 @@ def default_setup(self):
super().default_setup()
self.add_param('floating_type', 'm', include=False, hidden=True,
fct_mod=(self.reset_makeopts,(),{}),
allowed=['m','d','f'],
allowed=['m','d','f', 'q'],
comment='floating point precision: f (single), d (double), m (mixed: double for amplitudes, single for colors)'
)
cudacpp_supported_backends = [ 'fortran', 'cuda', 'hip', 'cpp', 'cppnone', 'cppsse4', 'cppavx2', 'cpp512y', 'cpp512z', 'cppauto' ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2020-2024 CERN and UCLouvain.
// Licensed under the GNU Lesser General Public License (version 3 or later).
// Created by: A. Valassi (Jan 2022) for the MG5aMC CUDACPP plugin.
// Further modified by: J. Teig, A. Valassi (2022-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: J. Teig, A. Valassi, Z. Wettersten (2022-2025) for the MG5aMC CUDACPP plugin.

#include "CrossSectionKernels.h"

Expand All @@ -18,18 +18,15 @@
// *** NB: Attempts with __attribute__((optimize("-fno-fast-math"))) were unsatisfactory ***
// ******************************************************************************************

inline bool
fp_is_nan( const fptype& fp )
{
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wtautological-compare" // for icpx2021/clang13 (https://stackoverflow.com/a/15864661)
return std::isnan( fp ); // always false for clang in fast math mode (tautological compare)?
//#pragma clang diagnostic pop
}

inline bool
fp_is_abnormal( const fptype& fp )
{
#ifdef MGONGPUCPP_GPUIMPL
using namespace mg5amcGpu;
#else
using namespace mg5amcCpu;
#endif
if( fp_is_nan( fp ) ) return true;
if( fp != fp ) return true;
return false;
Expand All @@ -46,6 +43,9 @@ fp_is_zero( const fptype& fp )
inline const char*
fp_show_class( const fptype& fp )
{
#ifdef MGONGPU_FPTYPE_QUAD // not bothering to implement the full fpclassify for quad
return "quad";
#else
switch( std::fpclassify( fp ) )
{
case FP_INFINITE: return "Inf";
Expand All @@ -55,24 +55,30 @@ fp_show_class( const fptype& fp )
case FP_ZERO: return "zero";
default: return "unknown";
}
#endif
}

inline void
debug_me_is_abnormal( const fptype& me, size_t ievtALL )
{
#ifdef MGONGPUCPP_GPUIMPL
using namespace mg5amcGpu;
#else
using namespace mg5amcCpu;
#endif
std::cout << "DEBUG[" << ievtALL << "]"
<< " ME=" << me
<< " fpisabnormal=" << fp_is_abnormal( me )
<< " fpclass=" << fp_show_class( me )
<< " (me==me)=" << ( me == me )
<< " (me==me+1)=" << ( me == me + 1 )
<< " isnan=" << fp_is_nan( me )
<< " isfinite=" << std::isfinite( me )
<< " isnormal=" << std::isnormal( me )
<< " isfinite=" << fp_is_infinite( me )
<< " isnormal=" << fp_is_normal( me )
<< " is0=" << ( me == 0 )
<< " is1=" << ( me == 1 )
<< " abs(ME)=" << std::abs( me )
<< " isnan=" << fp_is_nan( std::abs( me ) )
<< " abs(ME)=" << fpabs( me )
<< " isnan=" << fp_is_nan( fpabs( me ) )
<< std::endl;
}

Expand Down Expand Up @@ -172,8 +178,8 @@ namespace mg5amcCpu
const fptype& me = MemoryAccessMatrixElements::ieventAccessConst( m_matrixElements.data(), ievt );
const fptype& wg = MemoryAccessWeights::ieventAccessConst( m_samplingWeights.data(), ievt );
if( fp_is_abnormal( me ) ) continue;
stats.sqsMEdiff += std::pow( me - stats.refME, 2 );
stats.sqsWGdiff += std::pow( wg - stats.refWG, 2 );
stats.sqsMEdiff += (double)fppow( me - stats.refME, 2 );
stats.sqsWGdiff += (double)fppow( wg - stats.refWG, 2 );
}
// FOURTH PASS: UPDATE THE OVERALL STATS BY ADDING THE NEW STATS
m_stats += stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (C) 2020-2024 CERN and UCLouvain.
// Licensed under the GNU Lesser General Public License (version 3 or later).
// Modified by: O. Mattelaer (Nov 2020) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Hageboeck, O. Mattelaer, S. Roiser, J. Teig, A. Valassi (2020-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Hageboeck, O. Mattelaer, S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2020-2025) for the MG5aMC CUDACPP plugin.
//==========================================================================

#include "mgOnGpuConfig.h"
Expand Down Expand Up @@ -704,17 +704,22 @@ main( int argc, char** argv )
{
if( verbose )
{
#ifdef MGONGPU_FPTYPE_QUAD
size_t width = 42;
#else
size_t width = 14;
#endif
// Display momenta
std::cout << "Momenta:" << std::endl;
for( int ipar = 0; ipar < CPPProcess::npar; ipar++ )
{
// NB: 'setw' affects only the next field (of any type)
std::cout << std::scientific // fixed format: affects all floats (default precision: 6)
<< std::setw( 4 ) << ipar + 1
<< std::setw( 14 ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 0, ipar )
<< std::setw( 14 ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 1, ipar )
<< std::setw( 14 ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 2, ipar )
<< std::setw( 14 ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 3, ipar )
<< std::setw( width ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 0, ipar )
<< std::setw( width ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 1, ipar )
<< std::setw( width ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 2, ipar )
<< std::setw( width ) << MemoryAccessMomenta::ieventAccessIp4IparConst( hstMomenta.data(), ievt, 3, ipar )
<< std::endl
<< std::defaultfloat; // default format: affects all floats
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2020-2025 CERN and UCLouvain.
# Licensed under the GNU Lesser General Public License (version 3 or later).
# Created by: S. Roiser (Feb 2020) for the MG5aMC CUDACPP plugin.
# Further modified by: S. Hageboeck, D. Massaro, O. Mattelaer, S. Roiser, J. Teig, A. Valassi (2020-2025) for the MG5aMC CUDACPP plugin.
# Further modified by: S. Hageboeck, D. Massaro, O. Mattelaer, S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2020-2025) for the MG5aMC CUDACPP plugin.

#=== Determine the name of this makefile (https://ftp.gnu.org/old-gnu/Manuals/make-3.80/html_node/make_17.html)
#=== NB: use ':=' to ensure that the value of CUDACPP_MAKEFILE is not modified further down after including make_opts
Expand All @@ -14,6 +14,17 @@ override CUDACPP_SRC_MAKEFILE = cudacpp_src.mk

#-------------------------------------------------------------------------------

#=== Include the common MG5aMC Makefile options

# OM: including make_opts is crucial for MG5aMC flag consistency/documentation
# AV: disable the inclusion of make_opts if the file has not been generated (standalone cudacpp)
# ZW: need to include make_opts prior to cudacpp_config.mk to pass flags for quadmath
ifneq ($(wildcard ../../Source/make_opts),)
include ../../Source/make_opts
endif

#-------------------------------------------------------------------------------

#=== Include cudacpp_config.mk

# Check that the user-defined choices of BACKEND, FPTYPE, HELINL, HRDCOD are supported (and configure defaults if no user-defined choices exist)
Expand Down Expand Up @@ -44,16 +55,6 @@ UNAME_P := $(shell uname -p)

#-------------------------------------------------------------------------------

#=== Include the common MG5aMC Makefile options

# OM: including make_opts is crucial for MG5aMC flag consistency/documentation
# AV: disable the inclusion of make_opts if the file has not been generated (standalone cudacpp)
ifneq ($(wildcard ../../Source/make_opts),)
include ../../Source/make_opts
endif

#-------------------------------------------------------------------------------

#=== Redefine BACKEND if the current value is 'cppauto'

# Set the default BACKEND choice corresponding to 'cppauto' (the 'best' C++ vectorization available: eventually use native instead?)
Expand Down Expand Up @@ -577,8 +578,10 @@ else ifeq ($(FPTYPE),f)
else ifeq ($(FPTYPE),m)
CXXFLAGS += -DMGONGPU_FPTYPE_DOUBLE -DMGONGPU_FPTYPE2_FLOAT
GPUFLAGS += -DMGONGPU_FPTYPE_DOUBLE -DMGONGPU_FPTYPE2_FLOAT
else
$(error Unknown FPTYPE='$(FPTYPE)': only 'd', 'f' and 'm' are supported)
else ifeq ($(FPTYPE),q)
CXXFLAGS += -DMGONGPU_FPTYPE_QUAD
else ifeq
$(error Unknown FPTYPE='$(FPTYPE)': only 'd', 'f', 'm' and 'q' are supported)
endif

# Set the build flags appropriate to each HELINL choice (example: "make HELINL=1")
Expand Down Expand Up @@ -811,7 +814,7 @@ endif
# (NB do not include CUDA_INC here! add it only for NVTX or curand #679)
$(BUILDDIR)/%%_cpp.o : %%.cc *.h ../../src/*.h $(BUILDDIR)/.build.$(TAG)
@if [ ! -d $(BUILDDIR) ]; then echo "mkdir -p $(BUILDDIR)"; mkdir -p $(BUILDDIR); fi
$(CXX) $(CPPFLAGS) $(INCFLAGS) $(CXXFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) $(INCFLAGS) $(CXXFLAGS) -c $< -o $@ $(QUADFLAG)

# Generic target and build rules: objects from CUDA or HIP compilation
ifneq ($(GPUCC),)
Expand Down Expand Up @@ -847,7 +850,7 @@ endif
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: $(BUILDDIR)/fbridge_cpp.o
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: cxx_objects_lib += $(BUILDDIR)/fbridge_cpp.o
$(LIBDIR)/lib$(MG5AMC_CXXLIB).so: $(LIBDIR)/lib$(MG5AMC_COMMONLIB).so $(cxx_objects_lib)
$(CXX) -shared -o $@ $(cxx_objects_lib) $(CXXLIBFLAGSRPATH2) -L$(LIBDIR) -l$(MG5AMC_COMMONLIB)
$(CXX) -shared -o $@ $(cxx_objects_lib) $(CXXLIBFLAGSRPATH2) -L$(LIBDIR) -l$(MG5AMC_COMMONLIB) $(QUADFLAG)

ifneq ($(GPUCC),)
$(LIBDIR)/lib$(MG5AMC_GPULIB).so: $(BUILDDIR)/fbridge_$(GPUSUFFIX).o
Expand Down Expand Up @@ -875,7 +878,7 @@ endif
###$(cxx_checkmain): LIBFLAGS += $(CXXLIBFLAGSASAN)
$(cxx_checkmain): LIBFLAGS += $(CXXLIBFLAGSRPATH) # avoid the need for LD_LIBRARY_PATH
$(cxx_checkmain): $(BUILDDIR)/check_sa_cpp.o $(LIBDIR)/lib$(MG5AMC_CXXLIB).so $(cxx_objects_exe) $(BUILDDIR)/CurandRandomNumberKernel_cpp.o $(BUILDDIR)/HiprandRandomNumberKernel_cpp.o
$(CXX) -o $@ $(BUILDDIR)/check_sa_cpp.o $(OMPFLAGS) -ldl -pthread $(LIBFLAGS) -L$(LIBDIR) -l$(MG5AMC_CXXLIB) $(cxx_objects_exe) $(BUILDDIR)/CurandRandomNumberKernel_cpp.o $(BUILDDIR)/HiprandRandomNumberKernel_cpp.o $(RNDLIBFLAGS)
$(CXX) -o $@ $(BUILDDIR)/check_sa_cpp.o $(OMPFLAGS) -ldl -pthread $(LIBFLAGS) -L$(LIBDIR) -l$(MG5AMC_CXXLIB) $(cxx_objects_exe) $(BUILDDIR)/CurandRandomNumberKernel_cpp.o $(BUILDDIR)/HiprandRandomNumberKernel_cpp.o $(RNDLIBFLAGS) $(QUADFLAG)

ifneq ($(GPUCC),)
###$(gpu_checkmain): LIBFLAGS += $(GPULIBFLAGSASAN)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Copyright (C) 2020-2024 CERN and UCLouvain.
# Licensed under the GNU Lesser General Public License (version 3 or later).
# Created by: A. Valassi (Mar 2024) for the MG5aMC CUDACPP plugin.
# Further modified by: A. Valassi (2024) for the MG5aMC CUDACPP plugin.
# Further modified by: A. Valassi, Z. Wettersten (2024-2025) for the MG5aMC CUDACPP plugin.

#-------------------------------------------------------------------------------

#=== Check that the user-defined choices of BACKEND, FPTYPE, HELINL, HRDCOD are supported
#=== Configure default values for these variables if no user-defined choices exist

# Include libquadmath if FPTYPE=quad and set backend to cppnone
ifeq ($(FPTYPE),q)
override QUADFLAG = -lquadmath
override BACKEND = cppnone
else
override QUADFLAG =
endif

# Set the default BACKEND (CUDA, HIP or C++/SIMD) choice
ifeq ($(BACKEND),)
override BACKEND = cppauto
Expand Down Expand Up @@ -39,7 +47,7 @@ ifneq ($(words $(filter $(BACKEND), $(SUPPORTED_BACKENDS))),1)
$(error Invalid backend BACKEND='$(BACKEND)': supported backends are $(foreach backend,$(SUPPORTED_BACKENDS),'$(backend)'))
endif

override SUPPORTED_FPTYPES = d f m
override SUPPORTED_FPTYPES = d f m q
ifneq ($(words $(filter $(FPTYPE), $(SUPPORTED_FPTYPES))),1)
$(error Invalid fptype FPTYPE='$(FPTYPE)': supported fptypes are $(foreach fptype,$(SUPPORTED_FPTYPES),'$(fptype)'))
endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2020-2024 CERN and UCLouvain.
# Licensed under the GNU Lesser General Public License (version 3 or later).
# Created by: S. Roiser (Feb 2020) for the MG5aMC CUDACPP plugin.
# Further modified by: S. Hageboeck, O. Mattelaer, S. Roiser, J. Teig, A. Valassi (2020-2024) for the MG5aMC CUDACPP plugin.
# Further modified by: S. Hageboeck, O. Mattelaer, S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2020-2025) for the MG5aMC CUDACPP plugin.

#=== Determine the name of this makefile (https://ftp.gnu.org/old-gnu/Manuals/make-3.80/html_node/make_17.html)
#=== NB: assume that the same name (e.g. cudacpp.mk, Makefile...) is used in the Subprocess and src directories
Expand Down Expand Up @@ -132,7 +132,7 @@ $(LIBDIR)/.build.$(TAG):
# Generic target and build rules: objects from C++ compilation
$(BUILDDIR)/%%_cpp.o : %%.cc *.h $(BUILDDIR)/.build.$(TAG)
@if [ ! -d $(BUILDDIR) ]; then echo "mkdir -p $(BUILDDIR)"; mkdir -p $(BUILDDIR); fi
$(CXX) $(CPPFLAGS) $(INCFLAGS) $(CXXFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) $(INCFLAGS) $(CXXFLAGS) -c $< -o $@ $(QUADFLAG)

# Generic target and build rules: objects from CUDA compilation
ifneq ($(GPUCC),)
Expand All @@ -154,7 +154,7 @@ endif
ifeq ($(GPUCC),)
$(LIBDIR)/lib$(MG5AMC_COMMONLIB).so : $(cxx_objects)
@if [ ! -d $(LIBDIR) ]; then echo "mkdir -p $(LIBDIR)"; mkdir -p $(LIBDIR); fi
$(CXX) -shared -o $@ $(cxx_objects) $(LDFLAGS)
$(CXX) -shared -o $@ $(cxx_objects) $(LDFLAGS) $(QUADFLAG)
else
$(LIBDIR)/lib$(MG5AMC_COMMONLIB).so : $(cxx_objects) $(gpu_objects)
@if [ ! -d $(LIBDIR) ]; then echo "mkdir -p $(LIBDIR)"; mkdir -p $(LIBDIR); fi
Expand Down
Loading
Loading