StatMech
Loading...
Searching...
No Matches
GaussianRandomMatrixGenerator_GPU< Derived, > Class Template Reference
Collaboration diagram for GaussianRandomMatrixGenerator_GPU< Derived, >:
Collaboration graph

Public Member Functions

 GaussianRandomMatrixGenerator_GPU (Derived const &opSpace, int seed=0, RealScalar stddev=1.0)
 
 GaussianRandomMatrixGenerator_GPU ()=default
 Default constructor.
 
 GaussianRandomMatrixGenerator_GPU (GaussianRandomMatrixGenerator_GPU const &other)=delete
 Copy constructor.
 
 GaussianRandomMatrixGenerator_GPU (GaussianRandomMatrixGenerator_GPU &&other)=default
 Move constructor.
 
 ~GaussianRandomMatrixGenerator_GPU ()=default
 Destructor.
 
Operator overloads
__host__ __device__ GaussianRandomMatrixGenerator_GPUoperator= (GaussianRandomMatrixGenerator_GPU const &other)=delete
 Copy assignment operator.
 
__host__ __device__ GaussianRandomMatrixGenerator_GPUoperator= (GaussianRandomMatrixGenerator_GPU &&other)=default
 Move assignment operator.
 
void reset ()
 
void discard (unsigned long long num)
 Discards random numbers to advance internal states of the random number generator.
 
ObjectOnGPU< Eigen::MatrixX< Scalar > > operator() ()
 Generates an instance of a random matrix.
 
ObjectOnGPU< Eigen::MatrixX< Scalar > > sample ()
 Generates an instance of a random matrix.
 

Private Types

using Scalar = typename Derived::Scalar
 
using RealScalar = typename Eigen::NumTraits< typename Derived::Scalar >::Real
 

Private Attributes

ObjectOnGPU< Derived > m_opSpace = ObjectOnGPU<Derived>(Derived())
 
int m_seed
 
std::mt19937 mt
 
std::normal_distribution< double > Gaussian
 
unsigned long long count
 

Member Typedef Documentation

◆ RealScalar

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
using GaussianRandomMatrixGenerator_GPU< Derived, >::RealScalar = typename Eigen::NumTraits<typename Derived::Scalar>::Real
private

◆ Scalar

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
using GaussianRandomMatrixGenerator_GPU< Derived, >::Scalar = typename Derived::Scalar
private

Constructor & Destructor Documentation

◆ GaussianRandomMatrixGenerator_GPU() [1/4]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
GaussianRandomMatrixGenerator_GPU< Derived, >::GaussianRandomMatrixGenerator_GPU ( Derived const &  opSpace,
int  seed = 0,
RealScalar  stddev = 1.0 
)
inline
32 : m_opSpace{opSpace}, m_seed(seed), mt(seed), Gaussian{0.0, stddev}, count{0} {}
unsigned long long count
Definition RandomMatrix.cuh:27
std::normal_distribution< double > Gaussian
Definition RandomMatrix.cuh:26
ObjectOnGPU< Derived > m_opSpace
Definition RandomMatrix.cuh:22
std::mt19937 mt
Definition RandomMatrix.cuh:25
int m_seed
Definition RandomMatrix.cuh:24

◆ GaussianRandomMatrixGenerator_GPU() [2/4]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
GaussianRandomMatrixGenerator_GPU< Derived, >::GaussianRandomMatrixGenerator_GPU ( )
default

Default constructor.

◆ GaussianRandomMatrixGenerator_GPU() [3/4]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
GaussianRandomMatrixGenerator_GPU< Derived, >::GaussianRandomMatrixGenerator_GPU ( GaussianRandomMatrixGenerator_GPU< Derived, > const &  other)
delete

Copy constructor.

Parameters
other

◆ GaussianRandomMatrixGenerator_GPU() [4/4]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
GaussianRandomMatrixGenerator_GPU< Derived, >::GaussianRandomMatrixGenerator_GPU ( GaussianRandomMatrixGenerator_GPU< Derived, > &&  other)
default

Move constructor.

Parameters
other

◆ ~GaussianRandomMatrixGenerator_GPU()

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
GaussianRandomMatrixGenerator_GPU< Derived, >::~GaussianRandomMatrixGenerator_GPU ( )
default

Destructor.

Member Function Documentation

◆ discard()

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
void GaussianRandomMatrixGenerator_GPU< Derived, >::discard ( unsigned long long  num)
inline

Discards random numbers to advance internal states of the random number generator.

Parameters
numNumber of random numbers to be discarded
96 {
97 for(auto j = 0; j < num * m_opSpace.dim(); ++j) Gaussian(mt);
98 count += num * m_opSpace.dim();
99 }

◆ operator()()

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
ObjectOnGPU< Eigen::MatrixX< Scalar > > GaussianRandomMatrixGenerator_GPU< Derived, >::operator() ( )
inline

Generates an instance of a random matrix.

Parameters
[out]matMatrix to which the generated matrix is assigned
105{ return this->sample(); }
ObjectOnGPU< Eigen::MatrixX< Scalar > > sample()
Generates an instance of a random matrix.
Definition RandomMatrix.cuh:112

◆ operator=() [1/2]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
__host__ __device__ GaussianRandomMatrixGenerator_GPU & GaussianRandomMatrixGenerator_GPU< Derived, >::operator= ( GaussianRandomMatrixGenerator_GPU< Derived, > &&  other)
default

Move assignment operator.

Parameters
other

◆ operator=() [2/2]

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
__host__ __device__ GaussianRandomMatrixGenerator_GPU & GaussianRandomMatrixGenerator_GPU< Derived, >::operator= ( GaussianRandomMatrixGenerator_GPU< Derived, > const &  other)
delete

Copy assignment operator.

Parameters
other

◆ reset()

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
void GaussianRandomMatrixGenerator_GPU< Derived, >::reset ( )
inline
89{ mt = std::mt19937(m_seed); }

◆ sample()

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
ObjectOnGPU< Eigen::MatrixX< Scalar > > GaussianRandomMatrixGenerator_GPU< Derived, >::sample ( )
inline

Generates an instance of a random matrix.

Returns
ObjectOnGPU< Eigen::MatrixX<Scalar> >
112 {
113 using Scalar = typename Derived::Scalar;
114 using RealScalar = typename Eigen::NumTraits<typename Derived::Scalar>::Real;
115
117 Eigen::VectorX<RealScalar> coeff = Eigen::VectorXd::NullaryExpr(m_opSpace.dim(), [&]() {
118 return Gaussian(mt);
119 }).template cast<RealScalar>();
120 ObjectOnGPU< decltype(coeff) > dCoeff(coeff);
121
122 //
123 // Configure Threads and Grids here
124 //
125 constexpr void (*kernel)(
126 Eigen::MatrixBase< std::remove_reference_t<decltype(*sample.ptr())> >*,
127 Eigen::DenseBase< std::remove_reference_t<decltype(*dCoeff.ptr())> > const*,
128 OperatorSpaceBase< std::remove_reference_t<decltype(*m_opSpace.ptr())> > const*)
130 struct cudaFuncAttributes attr;
131 cuCHECK(cudaFuncGetAttributes(&attr, kernel));
132 dim3 nThread;
133 nThread.x = min((size_t)m_opSpace.dim(), (size_t)sqrt(attr.maxThreadsPerBlock));
134 nThread.y = min((size_t)m_opSpace.baseDim(), (size_t)sqrt(attr.maxThreadsPerBlock));
135 auto upperQuotient
136 = [](size_t const& x, size_t const& y) { return (x % y == 0 ? x / y : x / y + 1); };
137 dim3 nBlock;
138 nBlock.x = upperQuotient(m_opSpace.dim(), nThread.x);
139 nBlock.y = upperQuotient(m_opSpace.baseDim(), nThread.y);
140
141 kernel<<<nBlock, nThread>>>(sample.ptr(), dCoeff.ptr(), m_opSpace.ptr());
142 cuCHECK(cudaDeviceSynchronize());
143 return sample;
144 };
Real_t RealScalar
Definition Ensemble.cuh:14
__global__ void RandomMatrixGenerator_sample_kernel(Eigen::MatrixBase< Derived1 > *samplePtr, Eigen::DenseBase< Derived2 > const *coeffPtr, OperatorSpaceBase< Derived3 > const *opSpacePtr)
Definition RandomMatrix.cuh:149
Definition mytypes.hpp:147
Object_t * ptr() const
Definition ObjectOnGPU.cuh:144
Definition ObjectOnGPU.cuh:149
Definition OperatorSpace.hpp:12
cuCHECK(cudaFuncGetAttributes(&attr, MatrixElementsInSector))
struct cudaFuncAttributes attr
Definition getAttributesOfMatrixElementsInSector.cpp:2
Integer_t const nBlock
Definition getAttributesOfMatrixElementsInSector.cpp:5
Integer_t const nThread
Definition getAttributesOfMatrixElementsInSector.cpp:4

Member Data Documentation

◆ count

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
unsigned long long GaussianRandomMatrixGenerator_GPU< Derived, >::count
mutableprivate

◆ Gaussian

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
std::normal_distribution<double> GaussianRandomMatrixGenerator_GPU< Derived, >::Gaussian
private

◆ m_opSpace

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
ObjectOnGPU<Derived> GaussianRandomMatrixGenerator_GPU< Derived, >::m_opSpace = ObjectOnGPU<Derived>(Derived())
private

◆ m_seed

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
int GaussianRandomMatrixGenerator_GPU< Derived, >::m_seed
private

◆ mt

template<class Derived , typename std::enable_if_t< std::is_convertible_v< Derived, OperatorSpaceBase< Derived > > > * = nullptr>
std::mt19937 GaussianRandomMatrixGenerator_GPU< Derived, >::mt
private

The documentation for this class was generated from the following file: