Skip to content

Commit

Permalink
uncommented debug statements but set default debug flags to false and…
Browse files Browse the repository at this point in the history
… added some additional compile time debug flags
  • Loading branch information
zeniheisser committed Nov 6, 2024
1 parent 63bbbfc commit d9fefe6
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 34 deletions.
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: O. Mattelaer (Sep 2021) for the MG5aMC CUDACPP plugin.
# Further modified by: O. Mattelaer, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
# Further modified by: O. Mattelaer, A. Valassi, Z. Wettersten (2021-2024) for the MG5aMC CUDACPP plugin.

# AV - Rename the plugin as CUDACPP_OUTPUT (even if the madgraph4gpu directory is still called CUDACPP_SA_OUTPUT)
# This can be used in mg5amcnlo in one of two ways:
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 (Nov 2021) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Roiser, J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2021-2024) for the MG5aMC CUDACPP plugin.

#ifndef BRIDGE_H
#define BRIDGE_H 1
Expand Down Expand Up @@ -255,19 +255,22 @@ namespace mg5amcCpu
throw std::logic_error( "Bridge constructor: FIXME! cannot choose gputhreads" ); // this should never happen!
m_gpublocks = m_nevt / m_gputhreads;
}
//std::cout << "WARNING! Instantiate device Bridge (nevt=" << m_nevt << ", gpublocks=" << m_gpublocks << ", gputhreads=" << m_gputhreads
// << ", gpublocks*gputhreads=" << m_gpublocks * m_gputhreads << ")" << std::endl;
#ifdef MGONGPU_VERBOSE_BRIDGE
std::cout << "WARNING! Instantiate device Bridge (nevt=" << m_nevt << ", gpublocks=" << m_gpublocks << ", gputhreads=" << m_gputhreads
<< ", gpublocks*gputhreads=" << m_gpublocks * m_gputhreads << ")" << std::endl;
#endif
m_pmek.reset( new MatrixElementKernelDevice( m_devMomentaC, m_devGs, m_devRndHel, m_devRndCol, m_devChannelIds, m_devMEs, m_devSelHel, m_devSelCol, m_gpublocks, m_gputhreads ) );
#else
//std::cout << "WARNING! Instantiate host Bridge (nevt=" << m_nevt << ")" << std::endl;
#ifdef MGONGPU_VERBOSE_BRIDGE
std::cout << "WARNING! Instantiate host Bridge (nevt=" << m_nevt << ")" << std::endl;
#endif
m_pmek.reset( new MatrixElementKernelHost( m_hstMomentaC, m_hstGs, m_hstRndHel, m_hstRndCol, m_hstChannelIds, m_hstMEs, m_hstSelHel, m_hstSelCol, m_nevt ) );
#endif // MGONGPUCPP_GPUIMPL
// Create a process object, read param card and set parameters
// FIXME: the process instance can happily go out of scope because it is only needed to read parameters?
// FIXME: the CPPProcess should really be a singleton? what if fbridgecreate is called from several Fortran threads?
CPPProcess process( /*verbose=*/false );
std::string paramCard = "../../Cards/param_card.dat";
std::string paramCardTrex = "../Cards/param_card.dat";
std::string paramCard = "../Cards/param_card.dat"; // ZW: change default param_card.dat location to one dir down
/*
#ifdef __HIPCC__
if( !std::experimental::filesystem::exists( paramCard ) ) paramCard = "../" + paramCard;
Expand All @@ -279,8 +282,12 @@ namespace mg5amcCpu
//if( !( stat( paramCard.c_str(), &dummyBuffer ) == 0 ) ) paramCard = "../" + paramCard; //
auto fileExists = []( std::string& fileName )
{ struct stat buffer; return stat( fileName.c_str(), &buffer ) == 0; };
if( fileExists( paramCardTrex ) ) paramCard = paramCardTrex; // ZW: override param_card.dat to be one dir down since trex runs from the SubProcesses dir directory
if( !fileExists( paramCard ) ) paramCard = "../" + paramCard; // bypass std::filesystem #803
size_t paramCardCheck = 2; // ZW: check for paramCard up to 2 directories up
for( size_t k = 0 ; k < paramCardCheck ; ++k )
{
if( fileExists( paramCard ) ) break; // bypass std::filesystem #803
paramCard = "../" + paramCard;
}
process.initProc( paramCard );
}

Expand Down Expand Up @@ -349,7 +356,9 @@ namespace mg5amcCpu
if( goodHelOnly ) return;
m_pmek->computeMatrixElements( useChannelIds );
copyHostFromDevice( m_hstMEs, m_devMEs );
//flagAbnormalMEs( m_hstMEs.data(), m_nevt );
#ifdef MGONGPU_VERBOSE_BRIDGE
flagAbnormalMEs( m_hstMEs.data(), m_nevt );
#endif
copyHostFromDevice( m_hstSelHel, m_devSelHel );
copyHostFromDevice( m_hstSelCol, m_devSelCol );
if constexpr( std::is_same_v<FORTRANFPTYPE, fptype> )
Expand Down Expand Up @@ -402,7 +411,9 @@ namespace mg5amcCpu
}
if( goodHelOnly ) return;
m_pmek->computeMatrixElements( useChannelIds );
//flagAbnormalMEs( m_hstMEs.data(), m_nevt );
#ifdef MGONGPU_VERBOSE_BRIDGE
flagAbnormalMEs( m_hstMEs.data(), m_nevt );
#endif
if constexpr( std::is_same_v<FORTRANFPTYPE, fptype> )
{
memcpy( mes, m_hstMEs.data(), m_hstMEs.bytes() );
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: J. Teig (Jun 2023, based on earlier work by S. Roiser) for the MG5aMC CUDACPP plugin.
// Further modified by: O. Mattelaer, S. Roiser, J. Teig, A. Valassi (2020-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: O. Mattelaer, S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2020-2024) for the MG5aMC CUDACPP plugin.

#ifndef MG5AMC_GPURUNTIME_H
#define MG5AMC_GPURUNTIME_H 1
Expand Down Expand Up @@ -38,7 +38,7 @@ namespace mg5amcGpu
// *** FIXME! This will all need to be designed differently when going to multi-GPU nodes! ***
struct GpuRuntime final
{
GpuRuntime( const bool debug = false )
GpuRuntime( const bool debug = false ) // ZW: default debug to false
: m_debug( debug ) { setUp( m_debug ); }
~GpuRuntime() { tearDown( m_debug ); }
GpuRuntime( const GpuRuntime& ) = delete;
Expand All @@ -50,7 +50,7 @@ namespace mg5amcGpu
// Set up CUDA application
// ** NB: strictly speaking this is not needed when using the CUDA runtime API **
// Calling cudaSetDevice on startup is useful to properly book-keep the time spent in CUDA initialization
static void setUp( const bool debug = false )
static void setUp( const bool debug = false ) // ZW: default debug to false
{
// ** NB: it is useful to call cudaSetDevice, or cudaFree, to properly book-keep the time spent in CUDA initialization
// ** NB: otherwise, the first CUDA operation (eg a cudaMemcpyToSymbol in CPPProcess ctor) appears to take much longer!
Expand All @@ -71,7 +71,7 @@ namespace mg5amcGpu
// ** NB: strictly speaking this is not needed when using the CUDA runtime API **
// Calling cudaDeviceReset on shutdown is only needed for checking memory leaks in cuda-memcheck
// See https://docs.nvidia.com/cuda/cuda-memcheck/index.html#leak-checking
static void tearDown( const bool debug = false )
static void tearDown( const bool debug = false ) // ZW: default debug to false
{
if( debug ) std::cout << "__GpuRuntime: calling GpuDeviceReset()" << std::endl;
checkGpu( gpuDeviceReset() );
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-2024) for the MG5aMC CUDACPP plugin.

#include "MatrixElementKernels.h"

Expand Down Expand Up @@ -60,7 +60,9 @@ namespace mg5amcCpu
#ifdef MGONGPU_CHANNELID_DEBUG
MatrixElementKernelBase::dumpNevtProcessedByChannel();
#endif
// MatrixElementKernelBase::dumpSignallingFPEs();
#ifdef MGONGPU_VERBOSE_FPES
MatrixElementKernelBase::dumpSignallingFPEs();
#endif
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -130,7 +132,9 @@ namespace mg5amcCpu
if( std::fetestexcept( FE_OVERFLOW ) ) fpes += " FE_OVERFLOW";
if( std::fetestexcept( FE_UNDERFLOW ) ) fpes += " FE_UNDERFLOW";
//if( std::fetestexcept( FE_INEXACT ) ) fpes += " FE_INEXACT"; // do not print this out: this would almost always signal!
if( fpes != "" )
if( fpes == "" )
std::cout << "INFO: No Floating Point Exceptions have been reported" << std::endl;
else
std::cerr << "INFO: The following Floating Point Exceptions have been reported:" << fpes << std::endl;
}

Expand Down Expand Up @@ -272,14 +276,15 @@ namespace mg5amcCpu
#endif
if( verbose )
{
if( tag != "none" ){
//std::cout << "INFO: The application does not require the host to support any AVX feature" << std::endl;
if( ok && !known )
if( tag == "none" )
std::cout << "INFO: The application does not require the host to support any AVX feature" << std::endl;
else if( ok && known )
std::cout << "INFO: The application is built for " << tag << " and the host supports it" << std::endl;
else if( ok )
std::cout << "WARNING: The application is built for " << tag << " but it is unknown if the host supports it" << std::endl;
else if ( !ok && known )
else
std::cout << "ERROR! The application is built for " << tag << " but the host does not support it" << std::endl;
}
}
return ok;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace mg5amcCpu

// Does this host system support the SIMD used in the matrix element calculation?
// [NB: this is private, SIMD vectorization in mg5amc C++ code is currently only used in the ME calculations below MatrixElementKernelHost!]
static bool hostSupportsSIMD( const bool verbose = true );
static bool hostSupportsSIMD( const bool verbose = false ); // ZW: set verbose to false by default

private:

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 (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) for the MG5aMC CUDACPP plugin.

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

Expand All @@ -13,7 +13,8 @@ ifeq ($(BACKEND),)
override BACKEND = gpucpp
endif

# Stop immediately if BACKEND=cuda but nvcc is missing
# ZW: gpucpp backend checks if there is a GPU backend available before going to SIMD
# prioritises CUDA over HIP
ifeq ($(BACKEND),gpucpp)
ifeq ($(shell which nvcc 2>/dev/null),)
ifeq ($(shell which hipcc 2>/dev/null),)
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-2024) 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
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ endif
#-------------------------------------------------------------------------------

# Target (and build rules): C++ rwgt libraries
# ZW: the -Bsymbolic flag ensures that function calls will be handled internally by the library, rather than going to global context
cxx_rwgtfiles := $(BUILDDIR)/rwgt_runner_cpp.o $(LIBDIR)/lib$(MG5AMC_COMMONLIB).so $(BUILDDIR)/fbridge_cpp.o $(cxx_objects_lib) $(cxx_objects_exe) $(BUILDDIR)/CurandRandomNumberKernel_cpp.o $(BUILDDIR)/HiprandRandomNumberKernel_cpp.o
$(cxx_rwgtlib): LIBFLAGS += $(CXXLIBFLAGSRPATH)
$(cxx_rwgtlib): $(LIBDIR)/lib$(MG5AMC_COMMONLIB).so $(cxx_rwgtfiles) $(cxx_objects_lib)
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 (Oct 2021) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Roiser, J. Teig, A. Valassi, Z. Wettersten (2021-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: S. Roiser, J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.

#include "Bridge.h"
#include "CPPProcess.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ fpeEnable()
//std::cout << "fpeEnable: FE_INVALID is" << ( ( fpes & FE_INVALID ) ? " " : " NOT " ) << "enabled" << std::endl;
//std::cout << "fpeEnable: FE_OVERFLOW is" << ( ( fpes & FE_OVERFLOW ) ? " " : " NOT " ) << "enabled" << std::endl;
//std::cout << "fpeEnable: FE_UNDERFLOW is" << ( ( fpes & FE_UNDERFLOW ) ? " " : " NOT " ) << "enabled" << std::endl;
constexpr bool enableFPE = true; // this is hardcoded and no longer controlled by getenv( "CUDACPP_RUNTIME_ENABLEFPE" )
constexpr bool enableFPE = false; // this is hardcoded and no longer controlled by getenv( "CUDACPP_RUNTIME_ENABLEFPE" )
// ZW: hardcode enableFPE to false
if( enableFPE )
{
//std::cout << "INFO: The following Floating Point Exceptions will cause SIGFPE program aborts: FE_DIVBYZERO, FE_INVALID, FE_OVERFLOW" << std::endl;
std::cout << "INFO: The following Floating Point Exceptions will cause SIGFPE program aborts: FE_DIVBYZERO, FE_INVALID, FE_OVERFLOW" << std::endl;
feenableexcept( FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW ); // new strategy #831 (do not enable FE_UNDERFLOW)
//fpes = fegetexcept();
//std::cout << "fpeEnable: analyse fegetexcept()=" << fpes << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace mg5amcCpu
#else
memcpy( cHel, tHel, ncomb * npar * sizeof( short ) );
#endif
//fpeEnable(); // enable SIGFPE traps for Floating Point Exceptions
fpeEnable(); // enable SIGFPE traps for Floating Point Exceptions
}

//--------------------------------------------------------------------------
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: O. Mattelaer (Sep 2021) for the MG5aMC CUDACPP plugin.
# Further modified by: O. Mattelaer, J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
# Further modified by: O. Mattelaer, J. Teig, A. Valassi, Z. Wettersten (2021-2024) for the MG5aMC CUDACPP plugin.

import os
import sys
Expand Down
4 changes: 2 additions & 2 deletions tools/REX/rwgt_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// A class for reweighting matrix elements for
%(process_lines)s
//--------------------------------------------------------------------------
#ifndef _LIBCOMP_
#define _LIBCOMP_
#ifndef _TREX_
#define _TREX_
#endif
#include "rwgt_instance.h"
#include "fbridge.h"
Expand Down

0 comments on commit d9fefe6

Please sign in to comment.