From c4438354d660d5bb87c12de76421987c94d557ba Mon Sep 17 00:00:00 2001 From: Terry Cojean Date: Thu, 23 Jan 2020 19:13:17 +0100 Subject: [PATCH] Add multiprecision tests for the new parilu tests and prefix_sum. --- omp/test/components/prefix_sum.cpp | 13 ++++-- reference/test/components/prefix_sum.cpp | 16 +++++-- .../test/factorization/par_ilu_kernels.cpp | 45 +++++++++++-------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/omp/test/components/prefix_sum.cpp b/omp/test/components/prefix_sum.cpp index b0c24ab7a63..1f4af44f0c2 100644 --- a/omp/test/components/prefix_sum.cpp +++ b/omp/test/components/prefix_sum.cpp @@ -44,12 +44,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + + namespace { +template class PrefixSum : public ::testing::Test { protected: - using index_type = gko::int32; + using index_type = T; PrefixSum() : ref(gko::ReferenceExecutor::create()), exec(gko::OmpExecutor::create()), @@ -84,10 +88,13 @@ class PrefixSum : public ::testing::Test { }; -TEST_F(PrefixSum, SmallEqualsReference) { test(100); } +TYPED_TEST_CASE(PrefixSum, gko::test::IndexTypes); + + +TYPED_TEST(PrefixSum, SmallEqualsReference) { this->test(100); } -TEST_F(PrefixSum, BigEqualsReference) { test(total_size); } +TYPED_TEST(PrefixSum, BigEqualsReference) { this->test(this->total_size); } } // namespace diff --git a/reference/test/components/prefix_sum.cpp b/reference/test/components/prefix_sum.cpp index 2dfa31d5330..75a643df1a9 100644 --- a/reference/test/components/prefix_sum.cpp +++ b/reference/test/components/prefix_sum.cpp @@ -41,12 +41,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + + namespace { +template class PrefixSum : public ::testing::Test { protected: - using index_type = gko::int32; + using index_type = T; PrefixSum() : exec(gko::ReferenceExecutor::create()), vals{3, 5, 6, 7, 1, 5, 9, 7, 2, 0, 5}, @@ -59,11 +63,15 @@ class PrefixSum : public ::testing::Test { }; -TEST_F(PrefixSum, Works) +TYPED_TEST_CASE(PrefixSum, gko::test::IndexTypes); + + +TYPED_TEST(PrefixSum, Works) { - gko::kernels::reference::prefix_sum(exec, vals.data(), vals.size()); + gko::kernels::reference::prefix_sum(this->exec, this->vals.data(), + this->vals.size()); - ASSERT_EQ(vals, expected); + ASSERT_EQ(this->vals, this->expected); } diff --git a/reference/test/factorization/par_ilu_kernels.cpp b/reference/test/factorization/par_ilu_kernels.cpp index 909cbd32e83..1fba54bb436 100644 --- a/reference/test/factorization/par_ilu_kernels.cpp +++ b/reference/test/factorization/par_ilu_kernels.cpp @@ -216,20 +216,22 @@ TYPED_TEST(ParIlu, KernelInitializeRowPtrsLU) } -TEST_F(ParIlu, KernelInitializeRowPtrsLUZeroMatrix) +TYPED_TEST(ParIlu, KernelInitializeRowPtrsLUZeroMatrix) { - auto empty_csr_l_expected = Csr::create(ref); - identity->convert_to(gko::lend(empty_csr_l_expected)); - auto empty_csr_u_expected = Csr::create(ref); - identity->convert_to(gko::lend(empty_csr_u_expected)); - auto num_row_ptrs = empty_csr->get_size()[0] + 1; + using Csr = typename TestFixture::Csr; + using index_type = typename TestFixture::index_type; + auto empty_csr_l_expected = Csr::create(this->ref); + this->identity->convert_to(gko::lend(empty_csr_l_expected)); + auto empty_csr_u_expected = Csr::create(this->ref); + this->identity->convert_to(gko::lend(empty_csr_u_expected)); + auto num_row_ptrs = this->empty_csr->get_size()[0] + 1; std::vector l_row_ptrs_vector(num_row_ptrs); std::vector u_row_ptrs_vector(num_row_ptrs); auto l_row_ptrs = l_row_ptrs_vector.data(); auto u_row_ptrs = u_row_ptrs_vector.data(); gko::kernels::reference::par_ilu_factorization::initialize_row_ptrs_l_u( - ref, gko::lend(empty_csr), l_row_ptrs, u_row_ptrs); + this->ref, gko::lend(this->empty_csr), l_row_ptrs, u_row_ptrs); ASSERT_TRUE(std::equal(l_row_ptrs, l_row_ptrs + num_row_ptrs, empty_csr_l_expected->get_const_row_ptrs())); @@ -243,6 +245,7 @@ TYPED_TEST(ParIlu, KernelInitializeLU) using Dense = typename TestFixture::Dense; using Csr = typename TestFixture::Csr; using index_type = typename TestFixture::index_type; + using value_type = typename TestFixture::value_type; // clang-format off auto expected_l = gko::initialize({{1., 0., 0.}, @@ -266,23 +269,26 @@ TYPED_TEST(ParIlu, KernelInitializeLU) this->ref, gko::lend(this->mtx_csr_small), gko::lend(actual_l), gko::lend(actual_u)); - GKO_ASSERT_MTX_NEAR(actual_l, expected_l, 1e-14); - GKO_ASSERT_MTX_NEAR(actual_u, expected_u, 1e-14); + GKO_ASSERT_MTX_NEAR(actual_l, expected_l, r::value); + GKO_ASSERT_MTX_NEAR(actual_u, expected_u, r::value); } -TEST_F(ParIlu, KernelInitializeLUZeroMatrix) +TYPED_TEST(ParIlu, KernelInitializeLUZeroMatrix) { - auto actual_l = Csr::create(ref); - auto actual_u = Csr::create(ref); - actual_l->copy_from(identity.get()); - actual_u->copy_from(identity.get()); + using Csr = typename TestFixture::Csr; + using value_type = typename TestFixture::value_type; + auto actual_l = Csr::create(this->ref); + auto actual_u = Csr::create(this->ref); + actual_l->copy_from(this->identity.get()); + actual_u->copy_from(this->identity.get()); gko::kernels::reference::par_ilu_factorization::initialize_l_u( - ref, gko::lend(empty_csr), gko::lend(actual_l), gko::lend(actual_u)); + this->ref, gko::lend(this->empty_csr), gko::lend(actual_l), + gko::lend(actual_u)); - GKO_ASSERT_MTX_NEAR(actual_l, identity, 1e-14); - GKO_ASSERT_MTX_NEAR(actual_u, identity, 1e-14); + GKO_ASSERT_MTX_NEAR(actual_l, this->identity, r::value); + GKO_ASSERT_MTX_NEAR(actual_u, this->identity, r::value); } @@ -291,6 +297,7 @@ TYPED_TEST(ParIlu, KernelComputeLU) using Dense = typename TestFixture::Dense; using Coo = typename TestFixture::Coo; using Csr = typename TestFixture::Csr; + using value_type = typename TestFixture::value_type; // clang-format off auto l_dense = gko::initialize({{1., 0., 0.}, @@ -319,8 +326,8 @@ TYPED_TEST(ParIlu, KernelComputeLU) this->ref, iterations, gko::lend(mtx_coo), gko::lend(l_csr), gko::lend(u_csr)); - GKO_ASSERT_MTX_NEAR(l_csr, this->small_l_expected, 1e-14); - GKO_ASSERT_MTX_NEAR(u_csr, u_expected, 1e-14); + GKO_ASSERT_MTX_NEAR(l_csr, this->small_l_expected, r::value); + GKO_ASSERT_MTX_NEAR(u_csr, u_expected, r::value); }