Skip to content

Commit

Permalink
add cuda matrix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattldawson committed Dec 31, 2024
1 parent c8842a0 commit 57b461d
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/unit/cuda/util/test_cuda_dense_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,62 @@ TEST(CudaDenseMatrix, CopyFunction)
EXPECT_EQ(matrix2[i][j], matrix[i][j]);
}
}
}

TEST(CudaDenseMatrix, TestMax)
{
micm::CudaDenseMatrix<double,4> matrix{ 2, 3, 0.0 };
matrix.CopyToDevice();
matrix.Max(2.0);
matrix.CopyToHost();

for (auto& elem : matrix.AsVector())
{
EXPECT_EQ(elem, 2.0);
}

for (auto &elem : matrix.AsVector())
{
elem = 1.0;
}
matrix[1][1] = 3.0;
matrix.CopyToDevice();
matrix.Max(2.0);
matrix.CopyToHost();

EXPECT_EQ(matrix[0][0], 2.0);
EXPECT_EQ(matrix[0][1], 2.0);
EXPECT_EQ(matrix[0][2], 2.0);
EXPECT_EQ(matrix[1][0], 2.0);
EXPECT_EQ(matrix[1][1], 3.0);
EXPECT_EQ(matrix[1][2], 2.0);
}

TEST(CudaDenseMatrix, TestMin)
{
micm::CudaDenseMatrix<double,4> matrix{ 2, 3, 0.0 };
matrix.CopyToDevice();
matrix.Min(2.0);
matrix.CopyToHost();

for (auto& elem : matrix.AsVector())
{
EXPECT_EQ(elem, 0.0);
}

for (auto &elem : matrix.AsVector())
{
elem = 1.0;
}
matrix[1][1] = 3.0;
matrix.CopyToDevice();
matrix.Min(2.0);
matrix.CopyToHost();

EXPECT_EQ(matrix[0][0], 2.0);
EXPECT_EQ(matrix[0][1], 2.0);
EXPECT_EQ(matrix[0][2], 2.0);
EXPECT_EQ(matrix[1][0], 2.0);
EXPECT_EQ(matrix[1][1], 2.0);
EXPECT_EQ(matrix[1][2], 2.0);
}

0 comments on commit 57b461d

Please sign in to comment.