28 template<
typename Real>
29 curandStatus_t curandGenerateUniformWrap(curandGenerator_t gen, Real *ptr,
size_t num);
32 curandStatus_t curandGenerateUniformWrap(curandGenerator_t gen,
float *ptr,
size_t num) {
33 return curandGenerateUniform(gen, ptr, num);
36 curandStatus_t curandGenerateUniformWrap(curandGenerator_t gen,
double *ptr,
size_t num) {
37 return curandGenerateUniformDouble(gen, ptr, num);
41 template<
typename Real>
42 curandStatus_t curandGenerateNormalWrap(
43 curandGenerator_t gen, Real *ptr,
size_t num);
46 curandStatus_t curandGenerateNormalWrap<float>(
47 curandGenerator_t gen,
float *ptr,
size_t num) {
48 return curandGenerateNormal(gen, ptr, num, 0.0 , 1.0 );
51 curandStatus_t curandGenerateNormalWrap<double>(
52 curandGenerator_t gen,
double *ptr,
size_t num) {
53 return curandGenerateNormalDouble(gen, ptr, num, 0.0 , 1.0 );
59 template<
typename Real>
62 if (CuDevice::Instantiate().Enabled()) {
71 size_t s =
static_cast<size_t>(tmp.NumRows()) * static_cast<size_t>(tmp.Stride());
72 CURAND_SAFE_CALL(curandGenerateUniformWrap(
73 GetCurandHandle(), tmp.Data(), s));
75 CuDevice::Instantiate().AccuProfile(__func__, tim);
79 tgt->
Mat().SetRandUniform();
83 template<
typename Real>
86 if (CuDevice::Instantiate().Enabled()) {
89 size_t s =
static_cast<size_t>(tgt->
NumRows()) * static_cast<size_t>(tgt->
Stride());
90 CURAND_SAFE_CALL(curandGenerateUniformWrap(
91 GetCurandHandle(), tgt->
Data(), s));
92 CuDevice::Instantiate().AccuProfile(__func__, tim);
96 tgt->
Mat().SetRandUniform();
100 template<
typename Real>
103 if (CuDevice::Instantiate().Enabled()) {
105 CURAND_SAFE_CALL(curandGenerateUniformWrap(
106 GetCurandHandle(), tgt->
Data(), tgt->
Dim()));
107 CuDevice::Instantiate().AccuProfile(__func__, tim);
111 tgt->
Vec().SetRandUniform();
115 template<
typename Real>
118 if (CuDevice::Instantiate().Enabled()) {
131 CURAND_SAFE_CALL(curandGenerateNormalWrap(
132 GetCurandHandle(), tmp.Data(), tmp.NumRows()*tmp.Stride()));
134 CuDevice::Instantiate().AccuProfile(__func__, tim);
138 tgt->
Mat().SetRandn();
142 template<
typename Real>
145 if (CuDevice::Instantiate().Enabled()) {
149 if (0 == (num_elements % 2)) {
150 CURAND_SAFE_CALL(curandGenerateNormalWrap(
151 GetCurandHandle(), tgt->
Data(), num_elements));
160 CURAND_SAFE_CALL(curandGenerateNormalWrap(
161 GetCurandHandle(), tmp.Data(), tmp.NumRows() * tmp.Stride()));
164 CuDevice::Instantiate().AccuProfile(__func__, tim);
168 tgt->
Mat().SetRandn();
172 template<
typename Real>
175 if (CuDevice::Instantiate().Enabled()) {
181 if (0 == (num_elements % 2)) {
182 CURAND_SAFE_CALL(curandGenerateNormalWrap(
183 GetCurandHandle(), tgt->
Data(), tgt->
Dim()));
187 CURAND_SAFE_CALL(curandGenerateNormalWrap(
188 GetCurandHandle(), tmp.
Data(), tmp.
Dim()));
191 CuDevice::Instantiate().AccuProfile(__func__, tim);
195 tgt->
Vec().SetRandn();
200 template<
typename Real>
205 tmp.AddMat(1.0, probs);
210 template<
typename Real>
216 this->RandGaussian(&tmp);
const MatrixBase< Real > & Mat() const
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT Stride() const
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
void RandUniform(CuMatrixBase< Real > *tgt)
Fill with uniform [0..1] floats,.
void BinarizeProbs(const CuMatrix< Real > &probs, CuMatrix< Real > *states)
align probabilities to discrete 0/1 states (use uniform sampling),
void AddMat(Real alpha, const CuMatrixBase< Real > &A, MatrixTransposeType trans=kNoTrans)
*this += alpha * A
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void AddGaussNoise(CuMatrix< Real > *tgt, Real gscale=1.0)
add gaussian noise to each element,
void RandGaussian(CuMatrixBase< Real > *tgt)
Fill with Normal random numbers,.
void CopyFromVec(const CuVectorBase< Real > &src)
Copy functions; these will crash if the dimension do not match.
void Heaviside(const CuMatrixBase< Real > &src)
Set each element to the Heaviside function of the corresponding element of "src", which we define as ...
const Real * Data() const
Return data pointer (const).
CuSubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Matrix for CUDA computing.
MatrixIndexT NumCols() const
const VectorBase< Real > & Vec() const
Real * Data()
Returns a pointer to the start of the vector's data.
MatrixIndexT NumRows() const
Dimensions.
const Matrix< Real > & Mat() const
MatrixIndexT Dim() const
Dimensions.
Vector for CUDA computing.