Skip to content

Commit 7cefc0b

Browse files
committed
Merge remote-tracking branch 'upstream/master' (including PR #809 and previous ones) into patchmad_nofileeeeeeeeeeeeeeeeeeeee
2 parents e6e043d + 073db8f commit 7cefc0b

975 files changed

Lines changed: 25558 additions & 21561 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MG5aMC/mg5amcnlo

Submodule mg5amcnlo updated 172 files

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/MG5aMC_patches/PROD/patch.P1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git b/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/auto_dsig1.f a/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/auto_dsig1.f
2-
index 880769442..5a3da931f 100644
2+
index 0a3dfa449..8f4aaecd6 100644
33
--- b/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/auto_dsig1.f
44
+++ a/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/auto_dsig1.f
55
@@ -484,23 +484,140 @@ C
@@ -77,9 +77,9 @@ index 880769442..5a3da931f 100644
7777
+ STOP
7878
+ ENDIF
7979
+ IF ( FIRST ) THEN ! exclude first pass (helicity filtering) from timers (#461)
80-
+ CALL FBRIDGESEQUENCE(FBRIDGE_PBRIDGE, P_MULTI, ALL_G,
81-
+ & HEL_RAND, COL_RAND, 0, OUT2,
82-
+ & SELECTED_HEL2, SELECTED_COL2 ) ! 0: multi channel disabled for helicity filtering
80+
+ CALL FBRIDGESEQUENCE_NOMULTICHANNEL( FBRIDGE_PBRIDGE, ! multi channel disabled for helicity filtering
81+
+ & P_MULTI, ALL_G, HEL_RAND, COL_RAND, OUT2,
82+
+ & SELECTED_HEL2, SELECTED_COL2 )
8383
+ FIRST = .FALSE.
8484
+c ! This is a workaround for https://github.com/oliviermattelaer/mg5amc_test/issues/22 (see PR #486)
8585
+ IF( FBRIDGE_MODE .EQ. 1 ) THEN ! (CppOnly=1 : SMATRIX1 is not called at all)
@@ -96,9 +96,9 @@ index 880769442..5a3da931f 100644
9696
+ ENDIF
9797
+ call counters_smatrix1multi_start( 0, VECSIZE_USED ) ! cudacpp=0
9898
+ IF ( .NOT. MULTI_CHANNEL ) THEN
99-
+ CALL FBRIDGESEQUENCE(FBRIDGE_PBRIDGE, P_MULTI, ALL_G,
100-
+ & HEL_RAND, COL_RAND, 0, OUT2,
101-
+ & SELECTED_HEL2, SELECTED_COL2 ) ! 0: multi channel disabled
99+
+ CALL FBRIDGESEQUENCE_NOMULTICHANNEL( FBRIDGE_PBRIDGE, ! multi channel disabled
100+
+ & P_MULTI, ALL_G, HEL_RAND, COL_RAND, OUT2,
101+
+ & SELECTED_HEL2, SELECTED_COL2 )
102102
+ ELSE
103103
+ IF( SDE_STRAT.NE.1 ) THEN
104104
+ WRITE(6,*) 'ERROR! The cudacpp bridge requires SDE=1' ! multi channel single-diagram enhancement strategy
@@ -284,7 +284,7 @@ index 71fbf2b25..0f1d199fc 100644
284284
open(unit=lun,file=tempname,status='old',ERR=20)
285285
fopened=.true.
286286
diff --git b/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/matrix1.f a/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/matrix1.f
287-
index 3ac962688..daea73a6d 100644
287+
index 817af778b..0c2ce6ec4 100644
288288
--- b/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/matrix1.f
289289
+++ a/epochX/cudacpp/gg_tt.mad/SubProcesses/P1_gg_ttx/matrix1.f
290290
@@ -72,7 +72,10 @@ C

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/MG5aMC_patches/PROD/patch.common

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ index 617f10b93..00c73099a 100644
3838
+cleanall: cleanSource # THIS IS THE ONE
3939
+ for i in `ls -d ../SubProcesses/P*`; do cd $$i; make cleanavxs; cd -; done;
4040
diff --git b/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile a/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile
41-
index 348c283be..65369d610 100644
41+
index 348c283be..d572486c2 100644
4242
--- b/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile
4343
+++ a/epochX/cudacpp/gg_tt.mad/SubProcesses/makefile
4444
@@ -1,6 +1,28 @@
@@ -297,10 +297,10 @@ index 348c283be..65369d610 100644
297297
+distclean: cleanall # Clean all fortran and cudacpp builds as well as the googletest installation
298298
+ $(MAKE) -f $(CUDACPP_MAKEFILE) distclean
299299
diff --git b/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py a/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py
300-
index ebbc1ac1d..a88d60b28 100755
300+
index fb7efa87c..5fd170d18 100755
301301
--- b/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py
302302
+++ a/epochX/cudacpp/gg_tt.mad/bin/internal/gen_ximprove.py
303-
@@ -385,8 +385,20 @@ class gensym(object):
303+
@@ -391,8 +391,20 @@ class gensym(object):
304304
done = True
305305
if not done:
306306
raise Exception('Parsing error in gensym: %s' % stdout)
@@ -324,7 +324,7 @@ index ebbc1ac1d..a88d60b28 100755
324324
self.submit_to_cluster(job_list)
325325
job_list = {}
326326
diff --git b/epochX/cudacpp/gg_tt.mad/bin/internal/madevent_interface.py a/epochX/cudacpp/gg_tt.mad/bin/internal/madevent_interface.py
327-
index 389b93ab8..d72270289 100755
327+
index 8c509e83f..cb6bf4ca5 100755
328328
--- b/epochX/cudacpp/gg_tt.mad/bin/internal/madevent_interface.py
329329
+++ a/epochX/cudacpp/gg_tt.mad/bin/internal/madevent_interface.py
330330
@@ -3614,8 +3614,20 @@ Beware that this can be dangerous for local multicore runs.""")

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/CurandRandomNumberKernel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cassert>
1111

1212
#ifndef MGONGPU_HAS_NO_CURAND /* clang-format off */
13+
// NB This must come AFTER mgOnGpuConfig.h which contains our definition of __global__ when MGONGPUCPP_GPUIMPL is not defined
1314
#include "curand.h"
1415
#define checkCurand( code ){ assertCurand( code, __FILE__, __LINE__ ); }
1516
inline void assertCurand( curandStatus_t code, const char *file, int line, bool abort = true )
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright (C) 2020-2024 CERN and UCLouvain.
2+
// Licensed under the GNU Lesser General Public License (version 3 or later).
3+
// Created by: A. Valassi (Jan 2024) for the MG5aMC CUDACPP plugin.
4+
// Further modified by: A. Valassi (2024) for the MG5aMC CUDACPP plugin.
5+
6+
#include "mgOnGpuConfig.h"
7+
8+
#include "GpuRuntime.h"
9+
#include "MemoryBuffers.h"
10+
#include "RandomNumberKernels.h"
11+
12+
#include <cassert>
13+
14+
#ifndef MGONGPU_HAS_NO_HIPRAND /* clang-format off */
15+
#ifndef __HIP_PLATFORM_AMD__
16+
#define __HIP_PLATFORM_AMD__ 1 // enable hiprand for AMD (rocrand)
17+
#endif
18+
#include <hiprand/hiprand.h>
19+
#define checkHiprand( code ){ assertHiprand( code, __FILE__, __LINE__ ); }
20+
inline void assertHiprand( hiprandStatus_t code, const char *file, int line, bool abort = true )
21+
{
22+
if ( code != HIPRAND_STATUS_SUCCESS )
23+
{
24+
printf( "HiprandAssert: %s:%d code=%d\n", file, line, code );
25+
if ( abort ) assert( code == HIPRAND_STATUS_SUCCESS );
26+
}
27+
}
28+
#endif /* clang-format on */
29+
30+
#ifdef MGONGPUCPP_GPUIMPL
31+
namespace mg5amcGpu
32+
#else
33+
namespace mg5amcCpu
34+
#endif
35+
{
36+
//--------------------------------------------------------------------------
37+
#ifndef MGONGPU_HAS_NO_HIPRAND
38+
HiprandRandomNumberKernel::HiprandRandomNumberKernel( BufferRndNumMomenta& rnarray, const bool onDevice )
39+
: RandomNumberKernelBase( rnarray )
40+
, m_isOnDevice( onDevice )
41+
{
42+
if( m_isOnDevice )
43+
{
44+
#ifdef MGONGPUCPP_GPUIMPL
45+
if( !m_rnarray.isOnDevice() )
46+
throw std::runtime_error( "HiprandRandomNumberKernel on device with a host random number array" );
47+
#else
48+
throw std::runtime_error( "HiprandRandomNumberKernel does not support HiprandDevice on CPU host" );
49+
#endif
50+
}
51+
else
52+
{
53+
if( m_rnarray.isOnDevice() )
54+
throw std::runtime_error( "HiprandRandomNumberKernel on host with a device random number array" );
55+
}
56+
createGenerator();
57+
}
58+
59+
//--------------------------------------------------------------------------
60+
61+
HiprandRandomNumberKernel::~HiprandRandomNumberKernel()
62+
{
63+
destroyGenerator();
64+
}
65+
66+
//--------------------------------------------------------------------------
67+
68+
void HiprandRandomNumberKernel::seedGenerator( const unsigned int seed )
69+
{
70+
if( m_isOnDevice )
71+
{
72+
destroyGenerator(); // workaround for #429
73+
createGenerator(); // workaround for #429
74+
}
75+
//printf( "seedGenerator: seed %d\n", seed );
76+
checkHiprand( hiprandSetPseudoRandomGeneratorSeed( m_rnGen, seed ) );
77+
}
78+
79+
//--------------------------------------------------------------------------
80+
81+
void HiprandRandomNumberKernel::createGenerator()
82+
{
83+
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_DEFAULT;
84+
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_XORWOW;
85+
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MRG32K3A;
86+
const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MTGP32; // same as curand; not implemented yet (code=1000) in host code
87+
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MT19937;
88+
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_PHILOX4_32_10;
89+
if( m_isOnDevice )
90+
{
91+
checkHiprand( hiprandCreateGenerator( &m_rnGen, type ) );
92+
}
93+
else
94+
{
95+
// See https://github.com/ROCm/hipRAND/issues/76
96+
throw std::runtime_error( "HiprandRandomNumberKernel on host is not supported yet (hiprandCreateGeneratorHost is not implemented yet)" );
97+
//checkHiprand( hiprandCreateGeneratorHost( &m_rnGen, type ) ); // ALWAYS FAILS WITH CODE=1000
98+
}
99+
// FIXME: hiprand ordering is not implemented yet
100+
// See https://github.com/ROCm/hipRAND/issues/75
101+
/*
102+
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_LEGACY ) );
103+
checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_BEST ) );
104+
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_DYNAMIC ) );
105+
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_SEEDED ) );
106+
*/
107+
}
108+
109+
//--------------------------------------------------------------------------
110+
111+
void HiprandRandomNumberKernel::destroyGenerator()
112+
{
113+
checkHiprand( hiprandDestroyGenerator( m_rnGen ) );
114+
}
115+
116+
//--------------------------------------------------------------------------
117+
118+
void HiprandRandomNumberKernel::generateRnarray()
119+
{
120+
#if defined MGONGPU_FPTYPE_DOUBLE
121+
checkHiprand( hiprandGenerateUniformDouble( m_rnGen, m_rnarray.data(), m_rnarray.size() ) );
122+
#elif defined MGONGPU_FPTYPE_FLOAT
123+
checkHiprand( hiprandGenerateUniform( m_rnGen, m_rnarray.data(), m_rnarray.size() ) );
124+
#endif
125+
/*
126+
printf( "\nHiprandRandomNumberKernel::generateRnarray size = %d\n", (int)m_rnarray.size() );
127+
fptype* data = m_rnarray.data();
128+
#ifdef MGONGPUCPP_GPUIMPL
129+
if( m_rnarray.isOnDevice() )
130+
{
131+
data = new fptype[m_rnarray.size()]();
132+
checkCuda( cudaMemcpy( data, m_rnarray.data(), m_rnarray.bytes(), cudaMemcpyDeviceToHost ) );
133+
}
134+
#endif
135+
for( int i = 0; i < ( (int)m_rnarray.size() / 4 ); i++ )
136+
printf( "[%4d] %f %f %f %f\n", i * 4, data[i * 4], data[i * 4 + 2], data[i * 4 + 2], data[i * 4 + 3] );
137+
#ifdef MGONGPUCPP_GPUIMPL
138+
if( m_rnarray.isOnDevice() ) delete[] data;
139+
#endif
140+
*/
141+
}
142+
143+
//--------------------------------------------------------------------------
144+
#endif
145+
}

epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/madgraph/iolibs/template_files/gpu/RandomNumberKernels.h

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
// Copyright (C) 2020-2023 CERN and UCLouvain.
1+
// Copyright (C) 2020-2024 CERN and UCLouvain.
22
// Licensed under the GNU Lesser General Public License (version 3 or later).
33
// Created by: A. Valassi (Dec 2021) for the MG5aMC CUDACPP plugin.
4-
// Further modified by: J. Teig, A. Valassi (2021-2023) for the MG5aMC CUDACPP plugin.
4+
// Further modified by: J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
55

66
#ifndef RANDOMNUMBERKERNELS_H
77
#define RANDOMNUMBERKERNELS_H 1
88

99
#include "mgOnGpuConfig.h"
1010

11-
// NB This must come AFTER mgOnGpuConfig.h which contains our definition of __global__ when MGONGPUCPP_GPUIMPL is not defined
12-
#ifndef MGONGPU_HAS_NO_CURAND
13-
//#include "curand.h"
14-
struct curandGenerator_st; // forward definition from curand.h
15-
#endif
16-
1711
#include "MemoryBuffers.h"
1812

13+
// Forward definition from curand.h (the full header is only needed in CurandRandomKernel.cc)
14+
struct curandGenerator_st;
15+
16+
// Forward definition from hiprand.h (the full header is only needed in HiprandRandomKernel.cc)
17+
struct rocrand_generator_base_type;
18+
typedef rocrand_generator_base_type hiprandGenerator_st;
19+
1920
#ifdef MGONGPUCPP_GPUIMPL
2021
namespace mg5amcGpu
2122
#else
@@ -107,7 +108,6 @@ namespace mg5amcCpu
107108

108109
//--------------------------------------------------------------------------
109110

110-
#ifndef MGONGPU_HAS_NO_CURAND
111111
// A class encapsulating CURAND random number generation on a CPU host or on a GPU device
112112
class CurandRandomNumberKernel final : public RandomNumberKernelBase
113113
{
@@ -142,11 +142,49 @@ namespace mg5amcCpu
142142
const bool m_isOnDevice;
143143

144144
// The curand generator
145-
// (NB: curand.h defines typedef generator_t as a pointer to forward-defined 'struct curandGenerator_st')
145+
// (NB: curand.h defines typedef curandGenerator_t as a pointer to forward-defined 'struct curandGenerator_st')
146146
curandGenerator_st* m_rnGen;
147147
};
148148

149-
#endif
149+
//--------------------------------------------------------------------------
150+
151+
// A class encapsulating HIPRAND random number generation on a CPU host or on a GPU device
152+
class HiprandRandomNumberKernel final : public RandomNumberKernelBase
153+
{
154+
public:
155+
156+
// Constructor from an existing output buffer
157+
HiprandRandomNumberKernel( BufferRndNumMomenta& rnarray, const bool onDevice );
158+
159+
// Destructor
160+
~HiprandRandomNumberKernel();
161+
162+
// Seed the random number generator
163+
void seedGenerator( const unsigned int seed ) override final;
164+
165+
// Generate the random number array
166+
void generateRnarray() override final;
167+
168+
// Is this a host or device kernel?
169+
bool isOnDevice() const override final { return m_isOnDevice; }
170+
171+
private:
172+
173+
// Create the generator (workaround for #429: do this in every seedGenerator call rather than only in the ctor)
174+
void createGenerator();
175+
176+
// Destroy the generator (workaround for #429: do this in every seedGenerator call rather than only in the ctor)
177+
void destroyGenerator();
178+
179+
private:
180+
181+
// Is this a host or device kernel?
182+
const bool m_isOnDevice;
183+
184+
// The hiprand generator
185+
// (NB: hiprand.h defines typedef hiprandGenerator_t as a pointer to forward-defined 'struct hiprandGenerator_st')
186+
hiprandGenerator_st* m_rnGen;
187+
};
150188

151189
//--------------------------------------------------------------------------
152190
}

0 commit comments

Comments
 (0)