Skip to content

Commit

Permalink
Fix test problem in gpumatixtests.cpp
Browse files Browse the repository at this point in the history
enforce same datatype (float) for boundary values in testcase (avoid double datatype)
do similar changes in other places I found
cleanup of epsilon constant usage
  • Loading branch information
wolfma61 committed Nov 27, 2015
1 parent f40a012 commit 2688029
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Tests/UnitTests/MathTests/CPUSparseMatrixTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Microsoft
DenseMatrix dm1 = dm0.ColumnSlice(start, numCols);
DenseMatrix dm2 = sm0.ColumnSlice(start, numCols).CopyColumnSliceToDense(0, numCols);

BOOST_CHECK(dm1.IsEqualTo(dm2, 0.0001));
BOOST_CHECK(dm1.IsEqualTo(dm2, c_epsilonFloatE4));
}

BOOST_AUTO_TEST_CASE(CPUSparseMatrixCopyColumnSliceToDense)
Expand All @@ -63,7 +63,7 @@ namespace Microsoft
DenseMatrix dm1 = dm0.ColumnSlice(start, numCols);
DenseMatrix dm2 = sm0.CopyColumnSliceToDense(start, numCols);

BOOST_CHECK(dm1.IsEqualTo(dm2, 0.0001));
BOOST_CHECK(dm1.IsEqualTo(dm2, c_epsilonFloatE4));
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down
31 changes: 14 additions & 17 deletions Tests/UnitTests/MathTests/GPUMatrixCudaBlasTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,55 @@ namespace Microsoft
{
namespace Test
{
const int deviceId = 0;
const float epsilon = 0.0001f;

BOOST_AUTO_TEST_SUITE(GPUMatrixSuite)

BOOST_AUTO_TEST_CASE(GPUBlasMultiplyAndWeightedAdd)
{
const float alpha = 2.0f;
const float beta = 0.42f;
GPUMatrix<float> m0(12, 5, deviceId);
GPUMatrix<float> m0(12, 5, c_deviceIdZero);
m0.SetValue(1);
GPUMatrix<float> m1(5, 11, deviceId);
GPUMatrix<float> m1(5, 11, c_deviceIdZero);
m1.SetValue(1);
GPUMatrix<float> m2(12, 11, deviceId);
GPUMatrix<float> m2(12, 11, c_deviceIdZero);
m2.SetValue(1);

// m2 = alpha * m0 * m1 + beta * m2
GPUMatrix<float>::MultiplyAndWeightedAdd(alpha, m0, false, m1, false, beta, m2);

GPUMatrix<float> mr(12, 11, deviceId);
GPUMatrix<float> mr(12, 11, c_deviceIdZero);
mr.SetValue(10.42f);
BOOST_CHECK(m2.IsEqualTo(mr, epsilon));
BOOST_CHECK(m2.IsEqualTo(mr, c_epsilonFloatE4));
}

BOOST_AUTO_TEST_CASE(GPUBlasScale)
{
const float scale = 0.5f;
GPUMatrix<float> m0(12, 53, deviceId);
GPUMatrix<float> m0(12, 53, c_deviceIdZero);
m0.SetValue(4.2f);
GPUMatrix<float>::Scale(scale, m0);

GPUMatrix<float> mr(12, 53, deviceId);
GPUMatrix<float> mr(12, 53, c_deviceIdZero);
mr.SetValue(2.1f);
BOOST_CHECK(m0.IsEqualTo(mr, epsilon));
BOOST_CHECK(m0.IsEqualTo(mr, c_epsilonFloatE4));
}

BOOST_AUTO_TEST_CASE(GPUBlasInnerProduct)
{
GPUMatrix<float> m0(10, 10, deviceId);
GPUMatrix<float> m1(10, 10, deviceId);
GPUMatrix<float> m2(1, 10, deviceId);
GPUMatrix<float> m0(10, 10, c_deviceIdZero);
GPUMatrix<float> m1(10, 10, c_deviceIdZero);
GPUMatrix<float> m2(1, 10, c_deviceIdZero);
m0.SetValue(2);
m1.SetValue(2);
m2.SetValue(2);

GPUMatrix<float>::InnerProduct(m0, m1, m2, true);
GPUMatrix<float> mr(1, 10, deviceId);
GPUMatrix<float> mr(1, 10, c_deviceIdZero);
mr.SetValue(40);
BOOST_CHECK(m2.IsEqualTo(mr, epsilon));
BOOST_CHECK(m2.IsEqualTo(mr, c_epsilonFloatE4));

GPUMatrix<float>::InnerProduct(m0, m1, m2, false);
BOOST_CHECK(m2.IsEqualTo(mr.Transpose(), epsilon));
BOOST_CHECK(m2.IsEqualTo(mr.Transpose(), c_epsilonFloatE4));
}

// TODO: add tests for other CUDA BLAS methods?
Expand Down
Loading

0 comments on commit 2688029

Please sign in to comment.