Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0940c98
[rocrand] in gg_tt.mad, first no-brainer addition of Rocrand support:…
valassi Jan 29, 2024
6ed1a95
[rocrand] in gg_tt.mad cudacpp.mk, clean up (remove extra spaces)
valassi Jan 29, 2024
7e7110b
[rocrand] in gg_tt.mad cudacpp_src.mk, replace RNDGEN by HASCURAND an…
valassi Jan 29, 2024
8bfd3d1
[rocrand] in gg_tt.mad cudacpp.mk, replace RNDGEN by two separate HAS…
valassi Jan 29, 2024
90dc350
[rocrand] in gg_tt.mad check_sa.cc add rocrand support (and the --ror…
valassi Jan 29, 2024
3968e2e
[rocrand] in gg_tt.mad cudacpp.mk, add RNDCXXFLAGS to runTest, fsampl…
valassi Jan 29, 2024
7378926
[rocrand] revert the previous commit in cudacpp.mk, as the issue can …
valassi Jan 29, 2024
f3fe636
[rocrand] in gg_tt.mad RandomNumberKernels.h, add a forward definitio…
valassi Jan 29, 2024
576eb65
[rocrand] in gg_tt.mad, replace rocrand by horand and add other fixes…
valassi Jan 29, 2024
79c9a6b
[rocrand] in gg_tt.mad cudacpp.mk, link also RocrandRandomNumberKerne…
valassi Jan 29, 2024
fdfb335
[rocrand] in gg_tt.mad, add symlink of RocrandRandomNumberKernel.cc t…
valassi Jan 29, 2024
6ae85c8
[rocrand] in gg_tt.mad cudacpp.mk, add HIPINC when compiling RocrandR…
valassi Jan 29, 2024
465624e
[rocrand] in gg_tt.mad RocrandRandomNumberKernel.cc, do not set gener…
valassi Jan 29, 2024
94124a1
[rocrand] in gg_tt.mad cudacpp.mk, add -lhiprand if HASROCRAND=hasRoc…
valassi Jan 29, 2024
7949054
[rocrand] in gg_tt.mad mgOnGpuConfig.h and RocrandRandomNumberKernel.…
valassi Jan 29, 2024
ff3afb0
[rocrand] in gg_tt.mad, fix check_sa.cc to allow RocrandDevice on AMD…
valassi Jan 29, 2024
3539ced
[rocrand] in gg_tt.mad check_sa.cc, BUG FIX that removes the nan's al…
valassi Jan 30, 2024
fb8d6fe
[rocrand] in gg_tt.mad RocrandRandomNumberKernel.cc, clarify that hip…
valassi Feb 2, 2024
ef359a9
[rocrand] in gg_tt.mad RocrandRandomNumberKernel.cc, clarify that hip…
valassi Feb 2, 2024
bd7395d
[rocrand] in gg_tt.mad check_sa.cc, clarify that RocrandHost is not y…
valassi Feb 2, 2024
3b3b654
[rocrand] in gg_tt.mad, rename rocrand as hiprand in all files names …
valassi Feb 2, 2024
8941a64
[jt774] in tput scripts, add -rorhst and -hip flags
valassi Jan 30, 2024
a16495b
[rocrand] in tput scripts, rename -rorhst as -hirhst (hiprand host in…
valassi Feb 2, 2024
755020d
[rocrand] in tput scripts, use common random for HIP instead of hipra…
valassi Feb 2, 2024
a515606
[rocrand] fix clang formatting for itscrd80 in CODEGEN runTest.cc
valassi Feb 2, 2024
7a29e44
[rocrand] in CODEGEN, backport from gg_tt.mad the changes adding hipr…
valassi Feb 2, 2024
987da65
[rocrand] in CODEGEN check_sa.cc, fix clang formatting
valassi Feb 2, 2024
21c4eea
[rocrand] regenerate gg_tt.mad - all ok except for additional formatt…
valassi Feb 2, 2024
86ed395
Merge remote-tracking branch 'upstream/master' (including HIP PR #801…
valassi Feb 2, 2024
5f7cf12
[rocrand] generate gg_tt.mad
valassi Feb 2, 2024
ea6035a
[rocrand] regenerate all processes - add HiprandRandomNumberKernel.cc…
valassi Feb 2, 2024
b6029cb
[rocrand] rerun 78 tput tests on itscrd80 (not 90), all ok
valassi Feb 3, 2024
495d4cf
[rocrand] rerun 18 tmad tests on itscrd80 (not 90), all ok
valassi Feb 3, 2024
1d6289a
[rocrand] rerun 78 (actually, 72!) tput tests on LUMI - all as expect…
valassi Feb 5, 2024
0e9020e
[rocrand] rerun 18 tmad tests on LUMI worker nodes - all ok
valassi Feb 5, 2024
3272a4b
[rocrand] improve debug printouts in tput/allTees.sh
valassi Feb 5, 2024
0ec10a1
[rocrand] improve tput/allTees.sh to only run the -common tests once …
valassi Feb 5, 2024
6c4a1a6
[rocrand] ** COMPLETE ROCRAND (still need to merge other PRS) ** go b…
valassi Feb 5, 2024
64bb526
[rocrand] prepare to merge upstream/master - checkout generated code …
valassi Feb 5, 2024
3548fbd
Merge remote-tracking branch 'upstream/master' (including PR #368 add…
valassi Feb 5, 2024
61cf075
[rocrand] in CODEGEN, bug fix in my previous conflict fix after mergi…
valassi Feb 5, 2024
c54f1f8
[rocrand] regenerate gg_tt.mad after merging the gXXX.cu PR into rocrand
valassi Feb 5, 2024
43936ae
[rocrand] rerun one tput and one tmad test for ggtt, all ok
valassi Feb 5, 2024
fa9c516
[rocrand] rerun one tput and one tmad test for ggtt also on LUMI, all ok
valassi Feb 5, 2024
a691879
[rocrand] regenerate all processes (NB all gHiprandRandomNumberKernel…
valassi Feb 5, 2024
c27cb7e
[rocrand] rerun 78 tput tests on itscrd90, all ok
valassi Feb 6, 2024
04e31d7
[rocrand] rerun 18 tmad tests on itscrd90, all ok
valassi Feb 6, 2024
c62e3a0
[rocrand] rerun 72 tput tests for HIP on LUMI (as good as it gets, us…
valassi Feb 8, 2024
a177a03
[rocrand] rerun 18 tmad tests on LUMI worker nodes
valassi Feb 9, 2024
fc299af
[rocrand] ** COMPLETE ROCRAND ** Merge remote-tracking branch 'upstre…
valassi Feb 9, 2024
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 @@ -10,6 +10,7 @@
#include <cassert>

#ifndef MGONGPU_HAS_NO_CURAND /* clang-format off */
// NB This must come AFTER mgOnGpuConfig.h which contains our definition of __global__ when MGONGPUCPP_GPUIMPL is not defined
#include "curand.h"
#define checkCurand( code ){ assertCurand( code, __FILE__, __LINE__ ); }
inline void assertCurand( curandStatus_t code, const char *file, int line, bool abort = true )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (C) 2020-2024 CERN and UCLouvain.
// Licensed under the GNU Lesser General Public License (version 3 or later).
// Created by: A. Valassi (Jan 2024) for the MG5aMC CUDACPP plugin.
// Further modified by: A. Valassi (2024) for the MG5aMC CUDACPP plugin.

#include "mgOnGpuConfig.h"

#include "GpuRuntime.h"
#include "MemoryBuffers.h"
#include "RandomNumberKernels.h"

#include <cassert>

#ifndef MGONGPU_HAS_NO_HIPRAND /* clang-format off */
#ifndef __HIP_PLATFORM_AMD__
#define __HIP_PLATFORM_AMD__ 1 // enable hiprand for AMD (rocrand)
#endif
#include <hiprand/hiprand.h>
#define checkHiprand( code ){ assertHiprand( code, __FILE__, __LINE__ ); }
inline void assertHiprand( hiprandStatus_t code, const char *file, int line, bool abort = true )
{
if ( code != HIPRAND_STATUS_SUCCESS )
{
printf( "HiprandAssert: %s:%d code=%d\n", file, line, code );
if ( abort ) assert( code == HIPRAND_STATUS_SUCCESS );
}
}
#endif /* clang-format on */

#ifdef MGONGPUCPP_GPUIMPL
namespace mg5amcGpu
#else
namespace mg5amcCpu
#endif
{
//--------------------------------------------------------------------------
#ifndef MGONGPU_HAS_NO_HIPRAND
HiprandRandomNumberKernel::HiprandRandomNumberKernel( BufferRndNumMomenta& rnarray, const bool onDevice )
: RandomNumberKernelBase( rnarray )
, m_isOnDevice( onDevice )
{
if( m_isOnDevice )
{
#ifdef MGONGPUCPP_GPUIMPL
if( !m_rnarray.isOnDevice() )
throw std::runtime_error( "HiprandRandomNumberKernel on device with a host random number array" );
#else
throw std::runtime_error( "HiprandRandomNumberKernel does not support HiprandDevice on CPU host" );
#endif
}
else
{
if( m_rnarray.isOnDevice() )
throw std::runtime_error( "HiprandRandomNumberKernel on host with a device random number array" );
}
createGenerator();
}

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

HiprandRandomNumberKernel::~HiprandRandomNumberKernel()
{
destroyGenerator();
}

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

void HiprandRandomNumberKernel::seedGenerator( const unsigned int seed )
{
if( m_isOnDevice )
{
destroyGenerator(); // workaround for #429
createGenerator(); // workaround for #429
}
//printf( "seedGenerator: seed %d\n", seed );
checkHiprand( hiprandSetPseudoRandomGeneratorSeed( m_rnGen, seed ) );
}

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

void HiprandRandomNumberKernel::createGenerator()
{
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_DEFAULT;
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_XORWOW;
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MRG32K3A;
const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MTGP32; // same as curand; not implemented yet (code=1000) in host code
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_MT19937;
//const hiprandRngType_t type = HIPRAND_RNG_PSEUDO_PHILOX4_32_10;
if( m_isOnDevice )
{
checkHiprand( hiprandCreateGenerator( &m_rnGen, type ) );
}
else
{
// See https://github.com/ROCm/hipRAND/issues/76
throw std::runtime_error( "HiprandRandomNumberKernel on host is not supported yet (hiprandCreateGeneratorHost is not implemented yet)" );
//checkHiprand( hiprandCreateGeneratorHost( &m_rnGen, type ) ); // ALWAYS FAILS WITH CODE=1000
}
// FIXME: hiprand ordering is not implemented yet
// See https://github.com/ROCm/hipRAND/issues/75
/*
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_LEGACY ) );
checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_BEST ) );
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_DYNAMIC ) );
//checkHiprand( hiprandSetGeneratorOrdering( *&m_rnGen, HIPRAND_ORDERING_PSEUDO_SEEDED ) );
*/
}

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

void HiprandRandomNumberKernel::destroyGenerator()
{
checkHiprand( hiprandDestroyGenerator( m_rnGen ) );
}

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

void HiprandRandomNumberKernel::generateRnarray()
{
#if defined MGONGPU_FPTYPE_DOUBLE
checkHiprand( hiprandGenerateUniformDouble( m_rnGen, m_rnarray.data(), m_rnarray.size() ) );
#elif defined MGONGPU_FPTYPE_FLOAT
checkHiprand( hiprandGenerateUniform( m_rnGen, m_rnarray.data(), m_rnarray.size() ) );
#endif
/*
printf( "\nHiprandRandomNumberKernel::generateRnarray size = %d\n", (int)m_rnarray.size() );
fptype* data = m_rnarray.data();
#ifdef MGONGPUCPP_GPUIMPL
if( m_rnarray.isOnDevice() )
{
data = new fptype[m_rnarray.size()]();
checkCuda( cudaMemcpy( data, m_rnarray.data(), m_rnarray.bytes(), cudaMemcpyDeviceToHost ) );
}
#endif
for( int i = 0; i < ( (int)m_rnarray.size() / 4 ); i++ )
printf( "[%4d] %f %f %f %f\n", i * 4, data[i * 4], data[i * 4 + 2], data[i * 4 + 2], data[i * 4 + 3] );
#ifdef MGONGPUCPP_GPUIMPL
if( m_rnarray.isOnDevice() ) delete[] data;
#endif
*/
}

//--------------------------------------------------------------------------
#endif
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// Copyright (C) 2020-2023 CERN and UCLouvain.
// Copyright (C) 2020-2024 CERN and UCLouvain.
// Licensed under the GNU Lesser General Public License (version 3 or later).
// Created by: A. Valassi (Dec 2021) for the MG5aMC CUDACPP plugin.
// Further modified by: J. Teig, A. Valassi (2021-2023) for the MG5aMC CUDACPP plugin.
// Further modified by: J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.

#ifndef RANDOMNUMBERKERNELS_H
#define RANDOMNUMBERKERNELS_H 1

#include "mgOnGpuConfig.h"

// NB This must come AFTER mgOnGpuConfig.h which contains our definition of __global__ when MGONGPUCPP_GPUIMPL is not defined
#ifndef MGONGPU_HAS_NO_CURAND
//#include "curand.h"
struct curandGenerator_st; // forward definition from curand.h
#endif

#include "MemoryBuffers.h"

// Forward definition from curand.h (the full header is only needed in CurandRandomKernel.cc)
struct curandGenerator_st;

// Forward definition from hiprand.h (the full header is only needed in HiprandRandomKernel.cc)
struct rocrand_generator_base_type;
typedef rocrand_generator_base_type hiprandGenerator_st;

#ifdef MGONGPUCPP_GPUIMPL
namespace mg5amcGpu
#else
Expand Down Expand Up @@ -107,7 +108,6 @@ namespace mg5amcCpu

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

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

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

#endif
//--------------------------------------------------------------------------

// A class encapsulating HIPRAND random number generation on a CPU host or on a GPU device
class HiprandRandomNumberKernel final : public RandomNumberKernelBase
{
public:

// Constructor from an existing output buffer
HiprandRandomNumberKernel( BufferRndNumMomenta& rnarray, const bool onDevice );

// Destructor
~HiprandRandomNumberKernel();

// Seed the random number generator
void seedGenerator( const unsigned int seed ) override final;

// Generate the random number array
void generateRnarray() override final;

// Is this a host or device kernel?
bool isOnDevice() const override final { return m_isOnDevice; }

private:

// Create the generator (workaround for #429: do this in every seedGenerator call rather than only in the ctor)
void createGenerator();

// Destroy the generator (workaround for #429: do this in every seedGenerator call rather than only in the ctor)
void destroyGenerator();

private:

// Is this a host or device kernel?
const bool m_isOnDevice;

// The hiprand generator
// (NB: hiprand.h defines typedef hiprandGenerator_t as a pointer to forward-defined 'struct hiprandGenerator_st')
hiprandGenerator_st* m_rnGen;
};

//--------------------------------------------------------------------------
}
Expand Down
Loading