29 using namespace kaldi;
33 template<
typename Real>
41 std::vector<int32> idx(row);
43 for (
int i = 0;
i < row; ++
i) {
44 idx[
i] =
Rand() % col;
45 weights(
i) =
Rand() % 100;
81 template <
typename Real>
91 std::vector<int32> idx(row + col);
92 for (
auto && e : idx) {
112 cusp_selected_trans.
NumCols());
113 cusp_selected_trans.
CopyToMat(&cu_selected_trans);
121 AssertEqual(cu_selected_trans, cu_selected2_trans, 0.00001);
125 template <
typename Real>
159 template <
typename Real>
174 Real sum1 = cu_smat.
Sum();
175 Real sum2 = mat.
Sum();
180 template <
typename Real>
201 template <
typename Real>
225 template <
typename Real>
247 cu_smat1.
Swap(&smat1);
258 cu_smat2.
Swap(&cu_smat1);
270 template <
typename Real>
272 UnitTestCuSparseMatrixConstructFromIndexes<Real>();
273 UnitTestCuSparseMatrixSelectRowsAndTranspose<Real>();
274 UnitTestCuSparseMatrixTraceMatSmat<Real>();
275 UnitTestCuSparseMatrixSum<Real>();
276 UnitTestCuSparseMatrixFrobeniusNorm<Real>();
277 UnitTestCuSparseMatrixCopyToSmat<Real>();
278 UnitTestCuSparseMatrixSwap<Real>();
288 for (; loop < 2; loop++) {
289 CuDevice::Instantiate().SetDebugStrideMode(
true);
291 CuDevice::Instantiate().SelectGpuId(
"no");
293 CuDevice::Instantiate().SelectGpuId(
"yes");
296 kaldi::CudaSparseMatrixUnitTest<float>();
299 if (CuDevice::Instantiate().DoublePrecisionSupported()) {
300 kaldi::CudaSparseMatrixUnitTest<double>();
302 KALDI_WARN <<
"Double precision not supported";
305 kaldi::CudaSparseMatrixUnitTest<double>();
309 KALDI_LOG <<
"Tests without GPU use succeeded.";
311 KALDI_LOG <<
"Tests with GPU use (if available) succeeded.";
315 CuDevice::Instantiate().PrintProfile();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumRows() const
static void UnitTestCuSparseMatrixSwap()
void SelectRows(const std::vector< int32 > &row_indexes, const SparseMatrix< Real > &smat_other)
Select a subset of the rows of a SparseMatrix.
void CopyToMat(CuMatrixBase< OtherReal > *dest, MatrixTransposeType trans=kNoTrans) const
void Swap(SparseMatrix< Real > *smat)
Swap with CPU-based matrix.
static void UnitTestCuSparseMatrixFrobeniusNorm()
Real FrobeniusNorm() const
void CudaSparseMatrixUnitTest()
void SelectRows(const CuArray< int32 > &row_indexes, const CuSparseMatrix< Real > &smat_other)
Select a subset of the rows of a CuSparseMatrix.
static void UnitTestCuSparseMatrixSum()
static void UnitTestCuSparseMatrixSelectRowsAndTranspose()
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 CopyToMat(MatrixBase< OtherReal > *other, MatrixTransposeType t=kNoTrans) const
Copy to matrix. It must already have the correct size.
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
MatrixIndexT NumCols() const
static void UnitTestCuSparseMatrixTraceMatSmat()
static void UnitTestCuSparseMatrixConstructFromIndexes()
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
int Rand(struct RandomState *state)
void CopyToSmat(SparseMatrix< OtherReal > *smat) const
Copy to CPU-based matrix.
A class representing a vector.
void SetRandn(BaseFloat zero_prob)
Sets up to a pseudo-randomly initialized matrix, with each element zero with probability zero_prob an...
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Real FrobeniusNorm() const
static void UnitTestCuSparseMatrixCopyToSmat()
Real TraceMatSmat(const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType trans)
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
MatrixIndexT NumCols() const