29template <
typename AFloat>
30TRandom * TCudnn<AFloat>::fgRandomGen =
nullptr;
32template<
typename AFloat>
33void TCudnn<AFloat>::SetRandomSeed(
size_t seed)
35 if (!fgRandomGen) fgRandomGen =
new TRandom3();
36 fgRandomGen->SetSeed(seed);
38template<
typename AFloat>
39TRandom & TCudnn<AFloat>::GetRandomGenerator()
41 if (!fgRandomGen) fgRandomGen =
new TRandom3(0);
45template<
typename AFloat>
46void TCudnn<AFloat>::InitializeGauss(TCudaTensor<AFloat> & A)
49 size_t n = (A.GetNDim() == 2 && A.GetLayout() == Tensor_t::MemoryLayout::ColumnMajor) ?
50 A.GetShape()[1] : A.GetFirstStride();
52 TRandom & rand = GetRandomGenerator();
56 size_t nelements = A.GetSize();
57 TCudaHostBuffer<AFloat> xhost(nelements);
58 for (
size_t i = 0; i < nelements; i++) {
61 A.GetDeviceBuffer().CopyFrom(xhost);
65template<
typename AFloat>
66void TCudnn<AFloat>::InitializeUniform(TCudaTensor<AFloat> & A)
70 (A.GetNDim() == 2 && A.GetLayout() == Tensor_t::MemoryLayout::ColumnMajor) ?
71 A.GetShape()[1] : A.GetFirstStride();
73 TRandom & rand = GetRandomGenerator();
77 size_t nelements = A.GetSize();
78 TCudaHostBuffer<AFloat> xhost(nelements);
79 for (
size_t i = 0; i < nelements; i++) {
80 xhost[i] = rand.
Uniform(-range, range);
82 A.GetDeviceBuffer().CopyFrom(xhost);
91template<
typename AFloat>
92void TCudnn<AFloat>::InitializeGlorotNormal(TCudaTensor<AFloat> & A)
96 size_t n = A.GetShape()[0];
97 size_t m = A.GetShape()[1];
99 if (A.GetShape().size() > 2) {
101 for (
size_t j = 2; j < A.GetShape().
size(); ++j) {
102 m *= A.GetShape()[j];
103 n *= A.GetShape()[j];
107 TRandom & rand = GetRandomGenerator();
110 size_t nsize = A.GetSize();
111 TCudaHostBuffer<AFloat> xhost(nsize);
112 for (
size_t i = 0; i < nsize; i++) {
119 A.GetDeviceBuffer().CopyFrom(xhost);
127template<
typename AFloat>
128void TCudnn<AFloat>::InitializeGlorotUniform(TCudaTensor<AFloat> & A)
130 size_t n = A.GetShape()[0];
131 size_t m = A.GetShape()[1];
133 if (A.GetShape().size() > 2) {
135 for (
size_t j = 2; j < A.GetShape().
size(); ++j) {
136 m *= A.GetShape()[j];
137 n *= A.GetShape()[j];
141 TRandom & rand = GetRandomGenerator();
144 size_t nsize = A.GetSize();
145 TCudaHostBuffer<AFloat> xhost(nsize);
146 for (
size_t i = 0; i < nsize; i++) {
147 xhost[i] = rand.
Uniform(-range, range);
149 A.GetDeviceBuffer().CopyFrom(xhost);
154template<
typename AFloat>
155void TCudnn<AFloat>::InitializeIdentity(TCudaTensor<AFloat> & A)
158 m = A.GetFirstSize();
159 n = A.GetFirstStride();
163 for (
size_t i = 0; i <
m; i++) {
164 for (
size_t j = 0; j <
n ; j++) {
171 TCudaMatrix<AFloat> mB = B;
172 A.GetDeviceBuffer() = mB.GetDeviceBuffer();
176template<
typename AFloat>
177void TCudnn<AFloat>::InitializeZero(TCudaTensor<AFloat> & A)
180 cudaMemset(A.GetDataPointer(), 0,
sizeof(AFloat) * A.GetSize());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Random number generator class based on M.
This is the base class for the ROOT Random number generators.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
create variable transformations