Skip to content

Commit

Permalink
[june24] in gg_tt.mad Bridge*/runTest/check, add useChannelIds argume…
Browse files Browse the repository at this point in the history
…nt in computeMatrixElements in madgraph5#892 - bldall ok but runTest segfaults
valassi committed Jul 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a11f1d2 commit 4162768
Showing 6 changed files with 34 additions and 25 deletions.
12 changes: 7 additions & 5 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/Bridge.h
Original file line number Diff line number Diff line change
@@ -335,18 +335,19 @@ namespace mg5amcCpu
std::copy( rndhel, rndhel + m_nevt, m_hstRndHel.data() );
std::copy( rndcol, rndcol + m_nevt, m_hstRndCol.data() );
}
if( channelIds ) memcpy( m_hstChannelIds.data(), channelIds, m_nevt * sizeof( unsigned int ) );
const bool useChannelIds = ( channelIds != nullptr ) && ( !goodHelOnly );
if( useChannelIds ) memcpy( m_hstChannelIds.data(), channelIds, m_nevt * sizeof( unsigned int ) );
copyDeviceFromHost( m_devGs, m_hstGs );
copyDeviceFromHost( m_devRndHel, m_hstRndHel );
copyDeviceFromHost( m_devRndCol, m_hstRndCol );
if( useChannelIds ) copyDeviceFromHost( m_devChannelIds, m_hstChannelIds );
if( m_nGoodHel < 0 )
{
m_nGoodHel = m_pmek->computeGoodHelicities();
if( m_nGoodHel < 0 ) throw std::runtime_error( "Bridge gpu_sequence: computeGoodHelicities returned nGoodHel<0" );
}
if( goodHelOnly ) return;
copyDeviceFromHost( m_devChannelIds, m_hstChannelIds );
m_pmek->computeMatrixElements();
m_pmek->computeMatrixElements( useChannelIds );
copyHostFromDevice( m_hstMEs, m_devMEs );
flagAbnormalMEs( m_hstMEs.data(), m_nevt );
copyHostFromDevice( m_hstSelHel, m_devSelHel );
@@ -391,14 +392,15 @@ namespace mg5amcCpu
std::copy( rndhel, rndhel + m_nevt, m_hstRndHel.data() );
std::copy( rndcol, rndcol + m_nevt, m_hstRndCol.data() );
}
const bool useChannelIds = ( channelIds != nullptr ) && ( !goodHelOnly );
if( useChannelIds ) memcpy( m_hstChannelIds.data(), channelIds, m_nevt * sizeof( unsigned int ) );
if( m_nGoodHel < 0 )
{
m_nGoodHel = m_pmek->computeGoodHelicities();
if( m_nGoodHel < 0 ) throw std::runtime_error( "Bridge cpu_sequence: computeGoodHelicities returned nGoodHel<0" );
}
if( goodHelOnly ) return;
if( channelIds ) memcpy( m_hstChannelIds.data(), channelIds, m_nevt * sizeof( unsigned int ) );
m_pmek->computeMatrixElements();
m_pmek->computeMatrixElements( useChannelIds );
flagAbnormalMEs( m_hstMEs.data(), m_nevt );
if constexpr( std::is_same_v<FORTRANFPTYPE, fptype> )
{
18 changes: 10 additions & 8 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/BridgeKernels.cc
Original file line number Diff line number Diff line change
@@ -79,17 +79,18 @@ namespace mg5amcCpu
int BridgeKernelHost::computeGoodHelicities()
{
constexpr bool goodHelOnly = true;
constexpr unsigned int* channelId = nullptr; // disable multi-channel for helicity filtering
m_bridge.cpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), channelId, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
constexpr unsigned int* pChannelIds = nullptr; // disable multi-channel for helicity filtering
m_bridge.cpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), pChannelIds, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
return m_bridge.nGoodHel();
}

//--------------------------------------------------------------------------

void BridgeKernelHost::computeMatrixElements()
void BridgeKernelHost::computeMatrixElements( const bool useChannelIds )
{
constexpr bool goodHelOnly = false;
m_bridge.cpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), m_channelIds.data(), m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
const unsigned int* pChannelIds = ( useChannelIds ? m_channelIds.data() : nullptr );
m_bridge.cpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), pChannelIds, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
}

//--------------------------------------------------------------------------
@@ -137,17 +138,18 @@ namespace mg5amcGpu
int BridgeKernelDevice::computeGoodHelicities()
{
constexpr bool goodHelOnly = true;
constexpr unsigned int* channelId = nullptr;
m_bridge.gpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), channelId, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
constexpr unsigned int* pChannelIds = nullptr; // disable multi-channel for helicity filtering
m_bridge.gpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), pChannelIds, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
return m_bridge.nGoodHel();
}

//--------------------------------------------------------------------------

void BridgeKernelDevice::computeMatrixElements()
void BridgeKernelDevice::computeMatrixElements( const bool useChannelIds )
{
constexpr bool goodHelOnly = false;
m_bridge.gpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), m_channelIds.data(), m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
const unsigned int* pChannelIds = ( useChannelIds ? m_channelIds.data() : nullptr );
m_bridge.gpu_sequence( m_fortranMomenta.data(), m_gs.data(), m_rndhel.data(), m_rndcol.data(), pChannelIds, m_matrixElements.data(), m_selhel.data(), m_selcol.data(), goodHelOnly );
}

//--------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/BridgeKernels.h
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ namespace mg5amcCpu
int computeGoodHelicities() override final;

// Compute matrix elements
void computeMatrixElements() override final;
void computeMatrixElements( const bool useChannelIds ) override final;

// Is this a host or device kernel?
bool isOnDevice() const override final { return false; }
@@ -119,7 +119,7 @@ namespace mg5amcCpu
int computeGoodHelicities() override final;

// Compute matrix elements
void computeMatrixElements() override final;
void computeMatrixElements( const bool useChannelIds ) override final;

// Is this a host or device kernel?
bool isOnDevice() const override final { return true; }
4 changes: 2 additions & 2 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/CPPProcess.cc
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ namespace mg5amcCpu
const fptype* allcouplings, // input: couplings[nevt*ndcoup*2]
fptype* allMEs, // output: allMEs[nevt], |M|^2 running_sum_over_helicities
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
const unsigned int* channelIds, // input: multichannel channel id (1 to #diagrams); 0 to disable single-diagram enhancement
const unsigned int* channelIds, // input: multichannel channel id (1 to #diagrams); nullptr to disable single-diagram enhancement
fptype* allNumerators, // output: multichannel numerators[nevt], running_sum_over_helicities
fptype* allDenominators, // output: multichannel denominators[nevt], running_sum_over_helicities
#endif
@@ -919,7 +919,7 @@ namespace mg5amcCpu
const fptype* allrndcol, // input: random numbers[nevt] for color selection
fptype* allMEs, // output: allMEs[nevt], |M|^2 final_avg_over_helicities
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
const unsigned int* channelIds, // input: multichannel channel id (1 to #diagrams); 0 to disable single-diagram enhancement
const unsigned int* channelIds, // input: multichannel channel id (1 to #diagrams); nullptr to disable single-diagram enhancement
fptype* allNumerators, // output: multichannel numerators[nevt], running_sum_over_helicities
fptype* allDenominators, // output: multichannel denominators[nevt], running_sum_over_helicities
#endif
11 changes: 7 additions & 4 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/check_sa.cc
Original file line number Diff line number Diff line change
@@ -369,7 +369,9 @@ main( int argc, char** argv )
DeviceBufferGs devGs( nevt );
#endif

// Memory buffer for channelIDs
// Memory buffer for channelIDs
// [AV: channelId arrays are needed to keep a simpler signature for MatrixElementKernel constructors]
// [but they are not used internally (fix #892) as long as check.exe uses no-multichannel (see #896)]
#ifndef MGONGPUCPP_GPUIMPL
HostBufferChannelIds hstChannelIds( nevt );
#else
@@ -379,12 +381,12 @@ main( int argc, char** argv )

// Hardcode Gs for now (eventually they should come from Fortran MadEvent)
// Hardcode channelID to 0
constexpr unsigned int channelId = 0; // TEMPORARY? disable multi-channel in check.exe and gcheck.exe #466
//constexpr unsigned int channelId = 0; // TEMPORARY? disable multi-channel in check.exe and gcheck.exe #466
for( unsigned int i = 0; i < nevt; ++i )
{
constexpr fptype fixedG = 1.2177157847767195; // fixed G for aS=0.118 (hardcoded for now in check_sa.cc, fcheck_sa.f, runTest.cc)
hstGs[i] = fixedG;
hstChannelIds[i] = channelId;
//hstChannelIds[i] = channelId; // AV ChannelId arrays are not needed in check.exe (fix #892) as long as check.exe uses no-multichannel (see #896)
//if ( i > 0 ) hstGs[i] = 0; // try hardcoding G only for event 0
//hstGs[i] = i;
}
@@ -658,7 +660,8 @@ main( int argc, char** argv )
// --- 3a. SigmaKin
const std::string skinKey = "3a SigmaKin";
timermap.start( skinKey );
pmek->computeMatrixElements();
constexpr bool useChannelIds = false; // TEMPORARY? disable multi-channel in check.exe and gcheck.exe #466
pmek->computeMatrixElements( useChannelIds );

// *** STOP THE NEW OLD-STYLE TIMER FOR MATRIX ELEMENTS (WAVEFUNCTIONS) ***
wv3atime += timermap.stop(); // calc only
10 changes: 6 additions & 4 deletions epochX/cudacpp/gg_tt.mad/SubProcesses/runTest.cc
Original file line number Diff line number Diff line change
@@ -103,8 +103,10 @@ struct CPUTest : public CUDA_CPU_TestBase
{
constexpr fptype fixedG = 1.2177157847767195; // fixed G for aS=0.118 (hardcoded for now in check_sa.cc, fcheck_sa.f, runTest.cc)
for( unsigned int i = 0; i < nevt; ++i ) hstGs[i] = fixedG;
// [AV: there is no need to fill channelId arrays if runTest.exe uses no-multichannel]
if( iiter == 0 ) pmek->computeGoodHelicities();
pmek->computeMatrixElements();
constexpr bool useChannelIds = false; // TEMPORARY? disable multi-channel in runTest.exe #466
pmek->computeMatrixElements( useChannelIds );
}

fptype getMomentum( std::size_t ievt, unsigned int ipar, unsigned int ip4 ) const override
@@ -196,8 +198,6 @@ struct CUDATest : public CUDA_CPU_TestBase
// 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?
process.initProc( "../../Cards/param_card.dat" );
std::fill_n( hstChannelIds.data(), nevt, 0 );
copyDeviceFromHost( devChannelIds, hstChannelIds );
}

virtual ~CUDATest() {}
@@ -229,8 +229,10 @@ struct CUDATest : public CUDA_CPU_TestBase
constexpr fptype fixedG = 1.2177157847767195; // fixed G for aS=0.118 (hardcoded for now in check_sa.cc, fcheck_sa.f, runTest.cc)
for( unsigned int i = 0; i < nevt; ++i ) hstGs[i] = fixedG;
copyDeviceFromHost( devGs, hstGs ); // BUG FIX #566
// [AV: there is no need to fill channelId arrays if runTest.exe uses no-multichannel]
if( iiter == 0 ) pmek->computeGoodHelicities();
pmek->computeMatrixElements();
constexpr bool useChannelIds = false; // TEMPORARY? disable multi-channel in runTest.exe #466
pmek->computeMatrixElements( useChannelIds );
copyHostFromDevice( hstMatrixElements, devMatrixElements );
}

0 comments on commit 4162768

Please sign in to comment.