Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/cudamatrix/cu-vector-speed-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ template<typename Real> void TestCuVectorAddDiagMatMat(int32 dim,
}


template<typename Real> void TestCuVectorAddDiagMat2OnVariousShapes(
int32 dim, MatrixTransposeType trans) {
BaseFloat time_in_secs = 0.02;
int32 size = 1024 * 32;
CuVector<Real> v(trans == kNoTrans ? size / dim : dim);
v.SetRandn();
CuMatrix<Real> N(size / dim, dim);
N.SetRandn();

Timer tim;
int32 iter = 0;

for (; tim.Elapsed() < time_in_secs; iter++) {
v.AddDiagMat2(1.0, N, trans, 0.0);
}

BaseFloat fdim = size;
BaseFloat gflops = (fdim * iter) / (tim.Elapsed() * 1.0e+09);
KALDI_LOG << "For CuVector::AddDiagMat2Shapes" << NameOf<Real>()
<< (trans == kTrans ? "[trans]" : "[no-trans]") << ", for dim = ("
<< size / dim << ", " << dim << "), speed was " << gflops << " gigaflops.";
}



template<typename Real> void TestCuVectorAddDiagMat2(int32 dim, MatrixTransposeType trans) {
BaseFloat time_in_secs = 0.02;
CuVector<Real> v(dim);
Expand Down Expand Up @@ -343,7 +368,6 @@ template<typename Real> void TestCuVectorApplyCeilingNoCount(int32 dim) {

template<typename Real> void CudaVectorSpeedTest() {
std::vector<int32> sizes;
sizes.push_back(16);
sizes.push_back(32);
sizes.push_back(64);
sizes.push_back(128);
Expand All @@ -369,6 +393,10 @@ template<typename Real> void CudaVectorSpeedTest() {
TestCuVectorAddDiagMatMat<Real>(sizes[s], kTrans, kNoTrans);
TestCuVectorAddDiagMatMat<Real>(sizes[s], kTrans, kTrans);
}
for (int32 s = 0; s < ns; s++) {
TestCuVectorAddDiagMat2OnVariousShapes<Real>(sizes[s], kNoTrans);
TestCuVectorAddDiagMat2OnVariousShapes<Real>(sizes[s], kTrans);
}
for (int32 s = 0; s < ns; s++) {
TestCuVectorAddDiagMat2<Real>(sizes[s], kNoTrans);
TestCuVectorAddDiagMat2<Real>(sizes[s], kTrans);
Expand Down Expand Up @@ -415,4 +443,3 @@ int main() {
#endif
KALDI_LOG << "Tests succeeded.";
}

9 changes: 7 additions & 2 deletions src/cudamatrix/cu-vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,13 @@ void CuVectorBase<Real>::AddDiagMat2(Real alpha, const CuMatrixBase<Real> &M,
if (CuDevice::Instantiate().Enabled()) {
if (dim_ == 0) return;
MatrixTransposeType other_trans = (trans == kTrans ? kNoTrans : kTrans);
this->AddDiagMatMat(alpha, M, trans,
M, other_trans, beta);
KALDI_ASSERT(dim_ == (trans == kNoTrans ? M.NumRows() : M.NumCols()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. Would you mind adding the check, in this branch, that the dim is correct? Like in my PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel that, I see that you did that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line above your comment is checking 'dim_'. Do you mean something else?

if (trans == kTrans && M.NumCols() < 512 && M.NumRows() > 8192) {
CuMatrix<Real> MT(M, kTrans);
this->AddDiagMatMat(alpha, MT, other_trans, MT, trans, beta);
} else {
this->AddDiagMatMat(alpha, M, trans, M, other_trans, beta);
}
} else
#endif
{
Expand Down