cu-rand.h
Go to the documentation of this file.
1 // cudamatrix/cu-rand.h
2 
3 // Copyright 2016 Brno University of Technology (author: Karel Vesely)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_CUDAMATRIX_CU_RAND_H_
21 #define KALDI_CUDAMATRIX_CU_RAND_H_
22 
23 #include "cudamatrix/cu-device.h"
24 #include "cudamatrix/cu-matrix.h"
25 #include "cudamatrix/cu-vector.h"
26 #include "base/kaldi-math.h"
27 
28 namespace kaldi {
29 
30 template<typename Real>
31 class CuRand {
32  public:
33 
34  void SeedGpu() {
35  #if HAVE_CUDA == 1
36  CuDevice::Instantiate().SeedGpu();
37  #endif
38  }
39 
40  // CAUTION.
41  // For the versions of these functions that output to a CuMatrix (as opposed to
42  // CuMatrixBase), the random numbers depend on the stride, and the stride
43  // is not guaranteed to be consistent for the same dimension of matrix
44  // (it usually will be, but not when memory is nearly exhausted). So
45  // for applications where consistency is essential, either use the versions
46  // of these function that accept CuMatrixBase, or initialize your matrix
47  // with the kStrideEqualNumCols argument to ensure consistent stride.
48 
51  void RandUniform(CuMatrix<Real> *tgt);
55  void RandGaussian(CuMatrix<Real> *tgt);
57 
59  void BinarizeProbs(const CuMatrix<Real> &probs, CuMatrix<Real> *states);
61  void AddGaussNoise(CuMatrix<Real> *tgt, Real gscale = 1.0);
62 };
63 
64 } // namsepace
65 
66 #endif // KALDI_CUDAMATRIX_CU_RAND_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void SeedGpu()
Definition: cu-rand.h:34
void RandUniform(CuMatrixBase< Real > *tgt)
Fill with uniform [0..1] floats,.
Definition: cu-rand.cc:60
void BinarizeProbs(const CuMatrix< Real > &probs, CuMatrix< Real > *states)
align probabilities to discrete 0/1 states (use uniform sampling),
Definition: cu-rand.cc:201
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
void AddGaussNoise(CuMatrix< Real > *tgt, Real gscale=1.0)
add gaussian noise to each element,
Definition: cu-rand.cc:211
void RandGaussian(CuMatrixBase< Real > *tgt)
Fill with Normal random numbers,.
Definition: cu-rand.cc:116
Matrix for CUDA computing.
Definition: matrix-common.h:69
Vector for CUDA computing.
Definition: matrix-common.h:72