Skip to content

Commit

Permalink
[june24] in CODEGEN (backport gg_tt.mad) CPPProcess.cc, replace 'chan…
Browse files Browse the repository at this point in the history
…nelIds[0] != 0' by 'channelIds != nullptr' (fix segfault madgraph5#892)

Also add the missing fix for computeMatrixElements (I just added -Wunused-parameter otherwise this is not spotted)

Also replace 0 by nullptr for clarity on the channelIDs array

Now both the SIMD and cuda runTest.exe pass without crashing and with success results
valassi committed Jul 10, 2024
1 parent 322d7f7 commit 229efdf
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -269,7 +269,8 @@ namespace mg5amcGpu
constexpr unsigned int sharedMemSize = ntpbMAX * sizeof( float );
#endif
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
gpuLaunchKernelSharedMem( sigmaKin, m_gpublocks, m_gputhreads, sharedMemSize, m_momenta.data(), m_couplings.data(), m_rndhel.data(), m_rndcol.data(), m_matrixElements.data(), m_channelIds.data(), m_numerators.data(), m_denominators.data(), m_selhel.data(), m_selcol.data() );
const unsigned int* pChannelIds = ( useChannelIds ? m_channelIds.data() : nullptr );
gpuLaunchKernelSharedMem( sigmaKin, m_gpublocks, m_gputhreads, sharedMemSize, m_momenta.data(), m_couplings.data(), m_rndhel.data(), m_rndcol.data(), m_matrixElements.data(), pChannelIds, m_numerators.data(), m_denominators.data(), m_selhel.data(), m_selcol.data() );
#else
gpuLaunchKernelSharedMem( sigmaKin, m_gpublocks, m_gputhreads, sharedMemSize, m_momenta.data(), m_couplings.data(), m_rndhel.data(), m_rndcol.data(), m_matrixElements.data(), m_selhel.data(), m_selcol.data() );
#endif
Original file line number Diff line number Diff line change
@@ -308,8 +308,8 @@ namespace mg5amcCpu
// NB: calculate_wavefunctions ADDS |M|^2 for a given ihel to the running sum of |M|^2 over helicities for the given event(s)
constexpr fptype_sv* jamp2_sv = nullptr; // no need for color selection during helicity filtering
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
constexpr unsigned int* channelId = nullptr; // disable multichannel single-diagram enhancement
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, channelId, allNumerators, allDenominators, jamp2_sv );
constexpr unsigned int* channelIds = nullptr; // disable multichannel single-diagram enhancement
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, channelIds, allNumerators, allDenominators, jamp2_sv );
#else
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, jamp2_sv );
#endif
@@ -372,8 +372,8 @@ namespace mg5amcCpu
constexpr fptype_sv* jamp2_sv = nullptr; // no need for color selection during helicity filtering
//std::cout << "sigmaKin_getGoodHel ihel=" << ihel << ( isGoodHel[ihel] ? " true" : " false" ) << std::endl;
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
constexpr unsigned int* channelId = nullptr; // disable multichannel single-diagram enhancement
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, channelId, allNumerators, allDenominators, jamp2_sv, ievt00 );
constexpr unsigned int* channelIds = nullptr; // disable multichannel single-diagram enhancement
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, channelIds, allNumerators, allDenominators, jamp2_sv, ievt00 );
#else
calculate_wavefunctions( ihel, allmomenta, allcouplings, allMEs, jamp2_sv, ievt00 );
#endif
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@
}
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
// Event-by-event random choice of color #402
if( channelIds[0] != 0 ) // no event-by-event choice of color if channelId == 0 (fix FPE #783)
if( channelIds != nullptr ) // no event-by-event choice of color if channelIds == nullptr (fix FPE #783, fix segfault #892)
{
const unsigned int iconfigC = mgOnGpu::channelId_to_iconfigC[CID_ACCESS::kernelAccessConst( channelIds )]; // coloramps.h uses a channel ordering not the diagram id
fptype targetamp[ncolor] = { 0 };
@@ -185,7 +185,7 @@
}
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL // multichannel enabled (random color choice)
// Event-by-event random choice of color #402
if( channelIds[0] != 0 ) // no event-by-event choice of color if channelId == 0 (fix FPE #783)
if( channelIds != nullptr ) // no event-by-event choice of color if channelIds == nullptr (fix FPE #783, fix segfault #892)
{
uint_sv ichannelIds = CID_ACCESS::kernelAccessConst( channelIds ); // coloramps.h uses a channel ordering not the diagram id
fptype_sv targetamp[ncolor] = { 0 };
@@ -271,7 +271,7 @@
#ifdef MGONGPUCPP_GPUIMPL
allMEs[ievt] /= helcolDenominators[0];
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
if( channelIds[0] != 0 ) allMEs[ievt] *= allNumerators[ievt] / allDenominators[ievt];
if( channelIds != nullptr ) allMEs[ievt] *= allNumerators[ievt] / allDenominators[ievt]; // fix segfault #892 (not 'channelIds[0] != 0')
#endif
#else
for( int ipagV = 0; ipagV < npagV; ++ipagV )
@@ -281,7 +281,7 @@
fptype_sv& MEs_sv = E_ACCESS::kernelAccess( MEs );
MEs_sv /= helcolDenominators[0];
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
if( channelIds[0] != 0 )
if( channelIds != nullptr ) // fix segfault #892 (not 'channelIds[0] != 0')
{
fptype* numerators = NUM_ACCESS::ieventAccessRecord( allNumerators, ievt0 );
fptype* denominators = DEN_ACCESS::ieventAccessRecord( allDenominators, ievt0 );
Original file line number Diff line number Diff line change
@@ -1915,8 +1915,8 @@ def super_get_matrix_element_calls(self, matrix_element, color_amplitudes, multi
// Numerators and denominators for the current event (CUDA) or SIMD event page (C++)
fptype_sv& numerators_sv = NUM_ACCESS::kernelAccess( numerators );
fptype_sv& denominators_sv = DEN_ACCESS::kernelAccess( denominators );
uint_sv channelids_sv; // this is only filled (and used) if channelIds != 0
if( channelIds != 0 )
uint_sv channelids_sv; // this is only filled (and used) if channelIds != nullptr
if( channelIds != nullptr )
channelids_sv = CID_ACCESS::kernelAccessConst( channelIds ); // fix #895
#endif""")
diagrams = matrix_element.get('diagrams')
@@ -1948,7 +1948,7 @@ def super_get_matrix_element_calls(self, matrix_element, color_amplitudes, multi
###res.append("if( channelId == %i ) numerators_sv += cxabs2( amp_sv[0] );" % diag_to_config[id_amp]) # BUG #472
###res.append("if( channelId == %i ) numerators_sv += cxabs2( amp_sv[0] );" % id_amp) # wrong fix for BUG #472
res.append("#ifdef MGONGPU_SUPPORTS_MULTICHANNEL")
res.append("if( channelIds != 0 )")
res.append("if( channelIds != nullptr )")
res.append("{")
res.append("#if defined __CUDACC__ or !defined MGONGPU_CPPSIMD")
res.append(" if( channelids_sv == %i ) numerators_sv += cxabs2( amp_sv[0] );" % diagram.get('number'))

0 comments on commit 229efdf

Please sign in to comment.