36 using namespace kaldi;
43 template<
typename Real>
72 template<
typename Real>
81 for (
int32 j = 0;
j < 20;
j++, threshold *= 1.3) {
82 bool b1 = A.ApproxEqual(B, threshold);
85 bool b2 = (diff.
FrobeniusNorm() < threshold * std::max(A.FrobeniusNorm(),
95 template<
typename Real>
109 template<
typename Real>
131 template<
typename Real>
145 KALDI_ERR <<
"Matrices differ, A = " << A <<
", B2 = " << B2 <<
", B3(CUDA) = " << B3;
151 template<
typename Real>
182 template<
typename Real>
205 template<
typename Real>
218 const Real alpha = 2.0;
219 const Real beta = 3.0;
231 template<
typename Real>
244 const Real alpha = 2.0;
256 template<
typename Real,
typename OtherReal>
274 template<
typename Real>
278 if (
i % 5 == 0) dim = 0;
292 KALDI_LOG <<
"S1 norm is " << S1.FrobeniusNorm();
293 KALDI_LOG <<
"S2 norm is " << S2.FrobeniusNorm();
305 if (
i % 5 == 0) { dimM = 0; }
308 std::ostringstream os;
309 bool binary = (
i % 4 < 2);
310 mat.
Write(os, binary);
313 std::istringstream is(os.str());
314 mat2.
Read(is, binary);
322 template<
typename Real,
typename OtherReal>
343 UnitTestCuSpMatrixIO<Real>();
344 UnitTestCuSpMatrixConstructor<Real>();
345 UnitTestCuSpMatrixOperator<Real>();
346 UnitTestCuSpMatrixApproxEqual<Real>();
347 UnitTestCuSpMatrixInvert<Real>();
348 UnitTestCuSpMatrixCopyFromMat<Real>();
349 UnitTestCuSpMatrixAddVec2<Real>();
350 UnitTestCuSpMatrixAddMat2<Real>();
351 UnitTestCuSpMatrixAddSp<Real>();
352 UnitTestCuSpMatrixAddToDiag<Real>();
353 UnitTestCuSpMatrixSetUnit<Real>();
357 UnitTestCuSpMatrixTraceSpSp<Real, OtherReal>();
365 using namespace kaldi;
369 for (; loop < 2; loop++) {
370 CuDevice::Instantiate().SetDebugStrideMode(
true);
372 CuDevice::Instantiate().SelectGpuId(
"no");
374 CuDevice::Instantiate().SelectGpuId(
"yes");
377 kaldi::CudaSpMatrixUnitTest<float>();
378 kaldi::CudaSpMatrixUnitTest<float, float>();
380 if (CuDevice::Instantiate().DoublePrecisionSupported()) {
381 kaldi::CudaSpMatrixUnitTest<double>();
382 kaldi::CudaSpMatrixUnitTest<float, double>();
383 kaldi::CudaSpMatrixUnitTest<double, float>();
384 kaldi::CudaSpMatrixUnitTest<double, double>();
386 KALDI_WARN <<
"Double precision not supported";
389 kaldi::CudaSpMatrixUnitTest<float, double>();
390 kaldi::CudaSpMatrixUnitTest<double, float>();
391 kaldi::CudaSpMatrixUnitTest<double, double>();
395 KALDI_LOG <<
"Tests without GPU use succeeded.";
397 KALDI_LOG <<
"Tests with GPU use (if available) succeeded.";
400 CuDevice::Instantiate().PrintProfile();
void AddMat2(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const Real beta)
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTr...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool IsUnit(Real cutoff=1.0e-05) const
Packed symetric matrix class.
void CudaSpMatrixUnitTest()
static void UnitTestCuSpMatrixConstructor()
static void UnitTestCuSpMatrixAddMat2()
Real FrobeniusNorm() const
sqrt of sum of square elements.
void AddToDiag(Real r)
< Set the diagonal value to alpha
float RandGauss(struct RandomState *state=NULL)
A class for storing matrices.
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void Invert()
Note: the CuMatrix version of the Invert() function will only work for positive definite matrices; it...
void SetUnit()
< Set to zero
MatrixIndexT NumRows() const
void SetRandn()
< Set to unit matrix.
static void UnitTestCuSpMatrixIO()
bool IsUnit(Real tol=0.001) const
void SetRandn()
< Set to unit matrix.
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
static void UnitTestCuSpMatrixOperator()
void AddToDiag(const Real r)
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v'
void Read(std::istream &in, bool binary)
void UnitTestCuSpMatrixSetUnit()
void AddSp(const Real alpha, const SpMatrix< Real > &Ma)
void SetDiag(const Real alpha)
void SetRandn()
Sets to random values of a normal distribution.
double TraceSpSp(const SpMatrix< double > &A, const SpMatrix< double > &B)
void AddMatMat(Real alpha, const CuMatrixBase< Real > &A, MatrixTransposeType transA, const CuMatrixBase< Real > &B, MatrixTransposeType transB, Real beta)
C = alpha * A(^T)*B(^T) + beta * C.
static void UnitTestCuSpMatrixTraceSpSp()
int Rand(struct RandomState *state)
void SetRandn()
Set vector to random normally-distributed noise.
static void UnitTestCuSpMatrixApproxEqual()
void CopyToSp(SpMatrix< Real > *dst) const
void CopyFromSp(const CuSpMatrix< Real > &other)
void AddSp(const Real alpha, const CuSpMatrix< Real > &Ma)
static void UnitTestCuSpMatrixAddVec2()
A class representing a vector.
static void UnitTestCuSpMatrixAddSp()
#define KALDI_ASSERT(cond)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
static void UnitTestCuSpMatrixInvert(int32 dim)
static void UnitTestCuSpMatrixCopyFromMat(int32 dim, SpCopyType copy_type)
void Write(std::ostream &out, bool binary) const
void Invert(Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true)
matrix inverse.
static void UnitTestCuSpMatrixAddToDiag()
void AddMat2(const Real alpha, const CuMatrixBase< Real > &M, MatrixTransposeType transM, const Real beta)
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
void AddVec2(const Real alpha, const CuVectorBase< Real > &v)