From 2b90a146da7a4798581a39447880a683a1677e51 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Thu, 10 Feb 2022 15:57:46 +0100 Subject: [PATCH] move test to common test --- cuda/test/CMakeLists.txt | 1 - cuda/test/multigrid/CMakeLists.txt | 1 - dpcpp/test/CMakeLists.txt | 1 - dpcpp/test/multigrid/CMakeLists.txt | 1 - dpcpp/test/multigrid/amgx_pgm_kernels.cpp | 348 ----------------- hip/test/CMakeLists.txt | 1 - hip/test/multigrid/CMakeLists.txt | 1 - hip/test/multigrid/amgx_pgm_kernels.cpp | 351 ------------------ omp/test/CMakeLists.txt | 1 - omp/test/multigrid/CMakeLists.txt | 1 - omp/test/multigrid/amgx_pgm_kernels.cpp | 343 ----------------- test/CMakeLists.txt | 1 + test/multigrid/CMakeLists.txt | 1 + .../multigrid/amgx_pgm_kernels.cpp | 96 ++--- 14 files changed, 55 insertions(+), 1093 deletions(-) delete mode 100644 cuda/test/multigrid/CMakeLists.txt delete mode 100644 dpcpp/test/multigrid/CMakeLists.txt delete mode 100644 dpcpp/test/multigrid/amgx_pgm_kernels.cpp delete mode 100644 hip/test/multigrid/CMakeLists.txt delete mode 100644 hip/test/multigrid/amgx_pgm_kernels.cpp delete mode 100644 omp/test/multigrid/CMakeLists.txt delete mode 100644 omp/test/multigrid/amgx_pgm_kernels.cpp create mode 100644 test/multigrid/CMakeLists.txt rename {cuda/test => test}/multigrid/amgx_pgm_kernels.cpp (80%) diff --git a/cuda/test/CMakeLists.txt b/cuda/test/CMakeLists.txt index fb66aaf270f..83d7b39f35e 100644 --- a/cuda/test/CMakeLists.txt +++ b/cuda/test/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(base) add_subdirectory(components) add_subdirectory(factorization) add_subdirectory(matrix) -add_subdirectory(multigrid) add_subdirectory(preconditioner) add_subdirectory(reorder) add_subdirectory(solver) diff --git a/cuda/test/multigrid/CMakeLists.txt b/cuda/test/multigrid/CMakeLists.txt deleted file mode 100644 index 8fe8bbeba48..00000000000 --- a/cuda/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_test(amgx_pgm_kernels) diff --git a/dpcpp/test/CMakeLists.txt b/dpcpp/test/CMakeLists.txt index a4bed5d0879..8ccd05b0518 100644 --- a/dpcpp/test/CMakeLists.txt +++ b/dpcpp/test/CMakeLists.txt @@ -4,6 +4,5 @@ set(GINKGO_COMPILING_DPCPP_TEST ON) add_subdirectory(base) add_subdirectory(components) add_subdirectory(matrix) -add_subdirectory(multigrid) add_subdirectory(solver) add_subdirectory(stop) diff --git a/dpcpp/test/multigrid/CMakeLists.txt b/dpcpp/test/multigrid/CMakeLists.txt deleted file mode 100644 index 8fe8bbeba48..00000000000 --- a/dpcpp/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_test(amgx_pgm_kernels) diff --git a/dpcpp/test/multigrid/amgx_pgm_kernels.cpp b/dpcpp/test/multigrid/amgx_pgm_kernels.cpp deleted file mode 100644 index e6c90acbdf1..00000000000 --- a/dpcpp/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2021, the Ginkgo authors -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*************************************************************/ - -#include - - -#include -#include -#include - - -#include - - -#include -#include -#include -#include -#include -#include -#include - - -#include "core/multigrid/amgx_pgm_kernels.hpp" -#include "core/test/utils.hpp" -#include "core/test/utils/matrix_generator.hpp" -#include "core/test/utils/unsort_matrix.hpp" - - -namespace { - - -class AmgxPgm : public ::testing::Test { -protected: -#if GINKGO_DPCPP_SINGLE_MODE - using value_type = float; -#else - using value_type = double; -#endif // GINKGO_DPCPP_SINGLE_MODE - using index_type = gko::int32; - using Mtx = gko::matrix::Dense; - using Csr = gko::matrix::Csr; - using Diag = gko::matrix::Diagonal; - - AmgxPgm() : rand_engine(30) {} - - void SetUp() - { - ASSERT_GT(gko::DpcppExecutor::get_num_devices("all"), 0); - ref = gko::ReferenceExecutor::create(); - dpcpp = gko::DpcppExecutor::create(0, ref); - } - - void TearDown() - { - if (dpcpp != nullptr) { - ASSERT_NO_THROW(dpcpp->synchronize()); - } - } - - std::unique_ptr gen_mtx(int num_rows, int num_cols) - { - return gko::test::generate_random_matrix( - num_rows, num_cols, - std::uniform_int_distribution<>(num_cols, num_cols), - std::normal_distribution(-1.0, 1.0), rand_engine, ref); - } - - gko::Array gen_array(gko::size_type num, index_type min_val, - index_type max_val) - { - return gko::test::generate_random_array( - num, std::uniform_int_distribution<>(min_val, max_val), rand_engine, - ref); - } - - gko::Array gen_agg_array(gko::size_type num, - gko::size_type num_agg) - { - auto agg_array = gen_array(num, 0, num_agg - 1); - auto agg_array_val = agg_array.get_data(); - std::vector select_agg(num); - std::iota(select_agg.begin(), select_agg.end(), 0); - // use the first num_agg item as the aggregated index. - std::shuffle(select_agg.begin(), select_agg.end(), rand_engine); - // the value of agg_array is the i-th of aggregate group - for (gko::size_type i = 0; i < num; i++) { - agg_array_val[i] = select_agg[agg_array_val[i]]; - } - // the aggregated group must contain the identifier-th element - // agg_val[i] == i holds in the aggregated group whose identifier is i - for (gko::size_type i = 0; i < num_agg; i++) { - auto agg_idx = select_agg[i]; - agg_array_val[agg_idx] = agg_idx; - } - return agg_array; - } - - void initialize_data() - { - m = 597; - n = 300; - int nrhs = 3; - - agg = gen_agg_array(m, n); - // only use 0 ~ n-2 and ensure the end isolated and not yet finished - unfinished_agg = gen_array(m, -1, n - 2); - unfinished_agg.get_data()[n - 1] = -1; - strongest_neighbor = gen_array(m, 0, n - 2); - strongest_neighbor.get_data()[n - 1] = n - 1; - coarse_vector = gen_mtx(n, nrhs); - fine_vector = gen_mtx(m, nrhs); - auto weight = gen_mtx(m, m); - make_weight(weight.get()); - weight_csr = Csr::create(ref); - weight->convert_to(weight_csr.get()); - weight_diag = weight_csr->extract_diagonal(); - auto system_dense = gen_mtx(m, m); - gko::test::make_hpd(system_dense.get()); - system_mtx = Csr::create(ref); - system_dense->convert_to(system_mtx.get()); - - d_agg = gko::Array(dpcpp, agg); - d_unfinished_agg = gko::Array(dpcpp, unfinished_agg); - d_strongest_neighbor = - gko::Array(dpcpp, strongest_neighbor); - d_coarse_vector = gko::clone(dpcpp, coarse_vector); - d_fine_vector = gko::clone(dpcpp, fine_vector); - d_weight_csr = gko::clone(dpcpp, weight_csr); - d_weight_diag = gko::clone(dpcpp, weight_diag); - d_system_mtx = gko::clone(dpcpp, system_mtx); - } - - void make_weight(Mtx* mtx) - { - gko::test::make_symmetric(mtx); - // only works for real value cases. - mtx->compute_absolute_inplace(); - gko::test::make_diag_dominant(mtx); - } - - std::shared_ptr ref; - std::shared_ptr dpcpp; - - std::ranlux48 rand_engine; - - gko::Array agg; - gko::Array unfinished_agg; - gko::Array strongest_neighbor; - - gko::Array d_agg; - gko::Array d_unfinished_agg; - gko::Array d_strongest_neighbor; - - std::unique_ptr coarse_vector; - std::unique_ptr fine_vector; - std::unique_ptr weight_diag; - std::unique_ptr weight_csr; - std::shared_ptr system_mtx; - - std::unique_ptr d_coarse_vector; - std::unique_ptr d_fine_vector; - std::unique_ptr d_weight_diag; - std::unique_ptr d_weight_csr; - std::shared_ptr d_system_mtx; - - gko::size_type n; - gko::size_type m; -}; - - -TEST_F(AmgxPgm, MatchEdgeIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - - gko::kernels::reference::amgx_pgm::match_edge(ref, strongest_neighbor, x); - gko::kernels::dpcpp::amgx_pgm::match_edge(dpcpp, d_strongest_neighbor, d_x); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, CountUnaggIsEquivalentToRef) -{ - initialize_data(); - index_type num_unagg; - index_type d_num_unagg; - - gko::kernels::reference::amgx_pgm::count_unagg(ref, unfinished_agg, - &num_unagg); - gko::kernels::dpcpp::amgx_pgm::count_unagg(dpcpp, d_unfinished_agg, - &d_num_unagg); - - ASSERT_EQ(d_num_unagg, num_unagg); -} - - -TEST_F(AmgxPgm, RenumberIsEquivalentToRef) -{ - initialize_data(); - index_type num_agg; - index_type d_num_agg; - - gko::kernels::reference::amgx_pgm::renumber(ref, agg, &num_agg); - gko::kernels::dpcpp::amgx_pgm::renumber(dpcpp, d_agg, &d_num_agg); - - ASSERT_EQ(d_num_agg, num_agg); - GKO_ASSERT_ARRAY_EQ(d_agg, agg); - ASSERT_EQ(num_agg, n); -} - - -TEST_F(AmgxPgm, FindStrongestNeighborIsEquivalentToRef) -{ - initialize_data(); - auto snb = strongest_neighbor; - auto d_snb = d_strongest_neighbor; - - gko::kernels::reference::amgx_pgm::find_strongest_neighbor( - ref, weight_csr.get(), weight_diag.get(), agg, snb); - gko::kernels::dpcpp::amgx_pgm::find_strongest_neighbor( - dpcpp, d_weight_csr.get(), d_weight_diag.get(), d_agg, d_snb); - - GKO_ASSERT_ARRAY_EQ(d_snb, snb); -} - - -TEST_F(AmgxPgm, AssignToExistAggIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - auto intermediate_agg = x; - auto d_intermediate_agg = d_x; - - gko::kernels::reference::amgx_pgm::assign_to_exist_agg( - ref, weight_csr.get(), weight_diag.get(), x, intermediate_agg); - gko::kernels::dpcpp::amgx_pgm::assign_to_exist_agg( - dpcpp, d_weight_csr.get(), d_weight_diag.get(), d_x, - d_intermediate_agg); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, AssignToExistAggUnderteminsticIsEquivalentToRef) -{ - initialize_data(); - auto d_x = d_unfinished_agg; - auto d_intermediate_agg = gko::Array(dpcpp, 0); - index_type d_num_unagg; - - gko::kernels::dpcpp::amgx_pgm::assign_to_exist_agg( - dpcpp, d_weight_csr.get(), d_weight_diag.get(), d_x, - d_intermediate_agg); - gko::kernels::dpcpp::amgx_pgm::count_unagg(dpcpp, d_agg, &d_num_unagg); - - // only test whether all elements are aggregated. - GKO_ASSERT_EQ(d_num_unagg, 0); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRef) -{ - initialize_data(); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(dpcpp); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), - r::value); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), - r::value); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_prolong_op()), - gko::as(mg_level->get_prolong_op()), - r::value); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRefOnUnsortedMatrix) -{ - initialize_data(); - gko::test::unsort_matrix(gko::lend(system_mtx), rand_engine); - d_system_mtx = gko::clone(dpcpp, system_mtx); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(dpcpp); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), - r::value); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), - r::value); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_prolong_op()), - gko::as(mg_level->get_prolong_op()), - r::value); -} - - -} // namespace diff --git a/hip/test/CMakeLists.txt b/hip/test/CMakeLists.txt index a5f126893bf..9c8e39ca4ab 100644 --- a/hip/test/CMakeLists.txt +++ b/hip/test/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(base) add_subdirectory(components) add_subdirectory(factorization) add_subdirectory(matrix) -add_subdirectory(multigrid) add_subdirectory(solver) add_subdirectory(preconditioner) add_subdirectory(stop) diff --git a/hip/test/multigrid/CMakeLists.txt b/hip/test/multigrid/CMakeLists.txt deleted file mode 100644 index 8fe8bbeba48..00000000000 --- a/hip/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_test(amgx_pgm_kernels) diff --git a/hip/test/multigrid/amgx_pgm_kernels.cpp b/hip/test/multigrid/amgx_pgm_kernels.cpp deleted file mode 100644 index e58cda974e4..00000000000 --- a/hip/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2022, the Ginkgo authors -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*************************************************************/ - -#include - - -#include -#include -#include - - -#include - - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "core/multigrid/amgx_pgm_kernels.hpp" -#include "core/test/utils/matrix_generator.hpp" -#include "core/test/utils/unsort_matrix.hpp" -#include "hip/test/utils.hip.hpp" - - -namespace { - - -class AmgxPgm : public ::testing::Test { -protected: - using value_type = gko::default_precision; - using index_type = gko::int32; - using Mtx = gko::matrix::Dense<>; - using Csr = gko::matrix::Csr; - using RowGatherer = gko::matrix::RowGatherer; - using Diag = gko::matrix::Diagonal; - - AmgxPgm() : rand_engine(30) {} - - void SetUp() - { - ASSERT_GT(gko::HipExecutor::get_num_devices(), 0); - ref = gko::ReferenceExecutor::create(); - hip = gko::HipExecutor::create(0, ref); - } - - void TearDown() - { - if (hip != nullptr) { - ASSERT_NO_THROW(hip->synchronize()); - } - } - - std::unique_ptr gen_mtx(int num_rows, int num_cols) - { - return gko::test::generate_random_matrix( - num_rows, num_cols, - std::uniform_int_distribution<>(num_cols, num_cols), - std::normal_distribution<>(-1.0, 1.0), rand_engine, ref); - } - - gko::Array gen_array(gko::size_type num, index_type min_val, - index_type max_val) - { - return gko::test::generate_random_array( - num, std::uniform_int_distribution<>(min_val, max_val), rand_engine, - ref); - } - - gko::Array gen_agg_array(gko::size_type num, - gko::size_type num_agg) - { - auto agg_array = gen_array(num, 0, num_agg - 1); - auto agg_array_val = agg_array.get_data(); - std::vector select_agg(num); - std::iota(select_agg.begin(), select_agg.end(), 0); - // use the first num_agg item as the aggregated index. - std::shuffle(select_agg.begin(), select_agg.end(), rand_engine); - // the value of agg_array is the i-th of aggregate group - for (gko::size_type i = 0; i < num; i++) { - agg_array_val[i] = select_agg[agg_array_val[i]]; - } - // the aggregated group must contain the identifier-th element - // agg_val[i] == i holds in the aggregated group whose identifier is i - for (gko::size_type i = 0; i < num_agg; i++) { - auto agg_idx = select_agg[i]; - agg_array_val[agg_idx] = agg_idx; - } - return agg_array; - } - - void initialize_data() - { - m = 597; - n = 300; - int nrhs = 3; - - agg = gen_agg_array(m, n); - // only use 0 ~ n-2 and ensure the end isolated and not yet finished - unfinished_agg = gen_array(m, -1, n - 2); - unfinished_agg.get_data()[n - 1] = -1; - strongest_neighbor = gen_array(m, 0, n - 2); - strongest_neighbor.get_data()[n - 1] = n - 1; - coarse_vector = gen_mtx(n, nrhs); - fine_vector = gen_mtx(m, nrhs); - auto weight = gen_mtx(m, m); - make_weight(weight.get()); - weight_csr = Csr::create(ref); - weight->convert_to(weight_csr.get()); - weight_diag = weight_csr->extract_diagonal(); - auto system_dense = gen_mtx(m, m); - gko::test::make_hpd(system_dense.get()); - system_mtx = Csr::create(ref); - system_dense->convert_to(system_mtx.get()); - - d_agg = gko::Array(hip, agg); - d_unfinished_agg = gko::Array(hip, unfinished_agg); - d_strongest_neighbor = gko::Array(hip, strongest_neighbor); - d_coarse_vector = gko::clone(hip, coarse_vector); - d_fine_vector = gko::clone(hip, fine_vector); - d_weight_csr = gko::clone(hip, weight_csr); - d_weight_diag = gko::clone(hip, weight_diag); - d_system_mtx = gko::clone(hip, system_mtx); - } - - void make_weight(Mtx* mtx) - { - gko::test::make_symmetric(mtx); - // only works for real value cases - mtx->compute_absolute_inplace(); - gko::test::make_diag_dominant(mtx); - } - - std::shared_ptr ref; - std::shared_ptr hip; - - std::default_random_engine rand_engine; - - gko::Array agg; - gko::Array unfinished_agg; - gko::Array strongest_neighbor; - - gko::Array d_agg; - gko::Array d_unfinished_agg; - gko::Array d_strongest_neighbor; - - std::unique_ptr coarse_vector; - std::unique_ptr fine_vector; - std::unique_ptr weight_diag; - std::unique_ptr weight_csr; - std::shared_ptr system_mtx; - - std::unique_ptr d_coarse_vector; - std::unique_ptr d_fine_vector; - std::unique_ptr d_weight_diag; - std::unique_ptr d_weight_csr; - std::shared_ptr d_system_mtx; - - gko::size_type n; - gko::size_type m; -}; - - -TEST_F(AmgxPgm, MatchEdgeIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - - gko::kernels::reference::amgx_pgm::match_edge(ref, strongest_neighbor, x); - gko::kernels::hip::amgx_pgm::match_edge(hip, d_strongest_neighbor, d_x); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, CountUnaggIsEquivalentToRef) -{ - initialize_data(); - index_type num_unagg; - index_type d_num_unagg; - - gko::kernels::reference::amgx_pgm::count_unagg(ref, unfinished_agg, - &num_unagg); - gko::kernels::hip::amgx_pgm::count_unagg(hip, d_unfinished_agg, - &d_num_unagg); - - ASSERT_EQ(d_num_unagg, num_unagg); -} - - -TEST_F(AmgxPgm, RenumberIsEquivalentToRef) -{ - initialize_data(); - index_type num_agg; - index_type d_num_agg; - - gko::kernels::reference::amgx_pgm::renumber(ref, agg, &num_agg); - gko::kernels::hip::amgx_pgm::renumber(hip, d_agg, &d_num_agg); - - ASSERT_EQ(d_num_agg, num_agg); - GKO_ASSERT_ARRAY_EQ(d_agg, agg); - ASSERT_EQ(num_agg, n); -} - - -TEST_F(AmgxPgm, FindStrongestNeighborIsEquivalentToRef) -{ - initialize_data(); - auto snb = strongest_neighbor; - auto d_snb = d_strongest_neighbor; - - gko::kernels::reference::amgx_pgm::find_strongest_neighbor( - ref, weight_csr.get(), weight_diag.get(), agg, snb); - gko::kernels::hip::amgx_pgm::find_strongest_neighbor( - hip, d_weight_csr.get(), d_weight_diag.get(), d_agg, d_snb); - - GKO_ASSERT_ARRAY_EQ(d_snb, snb); -} - - -TEST_F(AmgxPgm, AssignToExistAggIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - auto intermediate_agg = x; - auto d_intermediate_agg = d_x; - - gko::kernels::reference::amgx_pgm::assign_to_exist_agg( - ref, weight_csr.get(), weight_diag.get(), x, intermediate_agg); - gko::kernels::hip::amgx_pgm::assign_to_exist_agg( - hip, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, AssignToExistAggUnderteminsticIsEquivalentToRef) -{ - initialize_data(); - auto d_x = d_unfinished_agg; - auto d_intermediate_agg = gko::Array(hip, 0); - index_type d_num_unagg; - - gko::kernels::hip::amgx_pgm::assign_to_exist_agg( - hip, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); - gko::kernels::hip::amgx_pgm::count_unagg(hip, d_agg, &d_num_unagg); - - // only test whether all elements are aggregated. - GKO_ASSERT_EQ(d_num_unagg, 0); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRef) -{ - initialize_data(); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(hip); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - auto row_gatherer = gko::as(mg_level->get_prolong_op()); - auto d_row_gatherer = gko::as(d_mg_level->get_prolong_op()); - auto row_gather_view = gko::Array::const_view( - row_gatherer->get_executor(), row_gatherer->get_size()[0], - row_gatherer->get_const_row_idxs()); - auto d_row_gather_view = gko::Array::const_view( - d_row_gatherer->get_executor(), d_row_gatherer->get_size()[0], - d_row_gatherer->get_const_row_idxs()); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); - GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRefOnUnsortedMatrix) -{ - initialize_data(); - gko::test::unsort_matrix(gko::lend(system_mtx), rand_engine); - d_system_mtx = gko::clone(hip, system_mtx); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(hip); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - auto row_gatherer = gko::as(mg_level->get_prolong_op()); - auto d_row_gatherer = gko::as(d_mg_level->get_prolong_op()); - auto row_gather_view = gko::Array::const_view( - row_gatherer->get_executor(), row_gatherer->get_size()[0], - row_gatherer->get_const_row_idxs()); - auto d_row_gather_view = gko::Array::const_view( - d_row_gatherer->get_executor(), d_row_gatherer->get_size()[0], - d_row_gatherer->get_const_row_idxs()); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); - GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); -} - - -} // namespace diff --git a/omp/test/CMakeLists.txt b/omp/test/CMakeLists.txt index 35590c60df1..cf7723a11f1 100644 --- a/omp/test/CMakeLists.txt +++ b/omp/test/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(base) add_subdirectory(components) add_subdirectory(factorization) add_subdirectory(matrix) -add_subdirectory(multigrid) add_subdirectory(preconditioner) add_subdirectory(reorder) add_subdirectory(solver) diff --git a/omp/test/multigrid/CMakeLists.txt b/omp/test/multigrid/CMakeLists.txt deleted file mode 100644 index 8fe8bbeba48..00000000000 --- a/omp/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_test(amgx_pgm_kernels) diff --git a/omp/test/multigrid/amgx_pgm_kernels.cpp b/omp/test/multigrid/amgx_pgm_kernels.cpp deleted file mode 100644 index 9566afb2245..00000000000 --- a/omp/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2022, the Ginkgo authors -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*************************************************************/ - -#include - - -#include -#include -#include - - -#include - - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "core/multigrid/amgx_pgm_kernels.hpp" -#include "core/test/utils.hpp" -#include "core/test/utils/matrix_generator.hpp" -#include "core/test/utils/unsort_matrix.hpp" - - -namespace { - - -class AmgxPgm : public ::testing::Test { -protected: - using value_type = gko::default_precision; - using index_type = gko::int32; - using Mtx = gko::matrix::Dense<>; - using Csr = gko::matrix::Csr; - using RowGatherer = gko::matrix::RowGatherer; - using Diag = gko::matrix::Diagonal; - - AmgxPgm() : rand_engine(30) {} - - void SetUp() - { - ref = gko::ReferenceExecutor::create(); - omp = gko::OmpExecutor::create(); - } - - std::unique_ptr gen_mtx(int num_rows, int num_cols) - { - return gko::test::generate_random_matrix( - num_rows, num_cols, - std::uniform_int_distribution<>(num_cols, num_cols), - std::normal_distribution<>(-1.0, 1.0), rand_engine, ref); - } - - gko::Array gen_array(gko::size_type num, index_type min_val, - index_type max_val) - { - return gko::test::generate_random_array( - num, std::uniform_int_distribution<>(min_val, max_val), rand_engine, - ref); - } - - gko::Array gen_agg_array(gko::size_type num, - gko::size_type num_agg) - { - auto agg_array = gen_array(num, 0, num_agg - 1); - auto agg_array_val = agg_array.get_data(); - std::vector select_agg(num); - std::iota(select_agg.begin(), select_agg.end(), 0); - // use the first num_agg item as the aggregated index. - std::shuffle(select_agg.begin(), select_agg.end(), rand_engine); - // the value of agg_array is the i-th of aggregate group - for (gko::size_type i = 0; i < num; i++) { - agg_array_val[i] = select_agg[agg_array_val[i]]; - } - // the aggregated group must contain the identifier-th element - // agg_val[i] == i holds in the aggregated group whose identifier is i - for (gko::size_type i = 0; i < num_agg; i++) { - auto agg_idx = select_agg[i]; - agg_array_val[agg_idx] = agg_idx; - } - return agg_array; - } - - void initialize_data() - { - m = 597; - n = 300; - int nrhs = 3; - - agg = gen_agg_array(m, n); - // only use 0 ~ n-2 and ensure the end isolated and not yet finished - unfinished_agg = gen_array(m, -1, n - 2); - unfinished_agg.get_data()[n - 1] = -1; - strongest_neighbor = gen_array(m, 0, n - 2); - strongest_neighbor.get_data()[n - 1] = n - 1; - coarse_vector = gen_mtx(n, nrhs); - fine_vector = gen_mtx(m, nrhs); - auto weight = gen_mtx(m, m); - make_weight(weight.get()); - weight_csr = Csr::create(ref); - weight->convert_to(weight_csr.get()); - weight_diag = weight_csr->extract_diagonal(); - auto system_dense = gen_mtx(m, m); - gko::test::make_hpd(system_dense.get()); - system_mtx = Csr::create(ref); - system_dense->convert_to(system_mtx.get()); - - d_agg = gko::Array(omp, agg); - d_unfinished_agg = gko::Array(omp, unfinished_agg); - d_strongest_neighbor = gko::Array(omp, strongest_neighbor); - d_coarse_vector = gko::clone(omp, coarse_vector); - d_fine_vector = gko::clone(omp, fine_vector); - d_weight_csr = gko::clone(omp, weight_csr); - d_weight_diag = gko::clone(omp, weight_diag); - d_system_mtx = gko::clone(omp, system_mtx); - } - - void make_weight(Mtx* mtx) - { - gko::test::make_symmetric(mtx); - // it is only works for real value case. - mtx->compute_absolute_inplace(); - gko::test::make_diag_dominant(mtx); - } - - std::shared_ptr ref; - std::shared_ptr omp; - - std::default_random_engine rand_engine; - - gko::Array agg; - gko::Array unfinished_agg; - gko::Array strongest_neighbor; - - gko::Array d_agg; - gko::Array d_unfinished_agg; - gko::Array d_strongest_neighbor; - - std::unique_ptr coarse_vector; - std::unique_ptr fine_vector; - std::unique_ptr weight_diag; - std::unique_ptr weight_csr; - std::shared_ptr system_mtx; - - std::unique_ptr d_coarse_vector; - std::unique_ptr d_fine_vector; - std::unique_ptr d_weight_diag; - std::unique_ptr d_weight_csr; - std::shared_ptr d_system_mtx; - - gko::size_type n; - gko::size_type m; -}; - - -TEST_F(AmgxPgm, MatchEdgeIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - - gko::kernels::reference::amgx_pgm::match_edge(ref, strongest_neighbor, x); - gko::kernels::omp::amgx_pgm::match_edge(omp, d_strongest_neighbor, d_x); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, CountUnaggIsEquivalentToRef) -{ - initialize_data(); - index_type num_unagg; - index_type d_num_unagg; - - gko::kernels::reference::amgx_pgm::count_unagg(ref, unfinished_agg, - &num_unagg); - gko::kernels::omp::amgx_pgm::count_unagg(omp, d_unfinished_agg, - &d_num_unagg); - - ASSERT_EQ(d_num_unagg, num_unagg); -} - - -TEST_F(AmgxPgm, RenumberIsEquivalentToRef) -{ - initialize_data(); - index_type num_agg; - index_type d_num_agg; - - gko::kernels::reference::amgx_pgm::renumber(ref, agg, &num_agg); - gko::kernels::omp::amgx_pgm::renumber(omp, d_agg, &d_num_agg); - - ASSERT_EQ(d_num_agg, num_agg); - GKO_ASSERT_ARRAY_EQ(d_agg, agg); - ASSERT_EQ(num_agg, n); -} - - -TEST_F(AmgxPgm, FindStrongestNeighborIsEquivalentToRef) -{ - initialize_data(); - auto snb = strongest_neighbor; - auto d_snb = d_strongest_neighbor; - - gko::kernels::reference::amgx_pgm::find_strongest_neighbor( - ref, weight_csr.get(), weight_diag.get(), agg, snb); - gko::kernels::omp::amgx_pgm::find_strongest_neighbor( - omp, d_weight_csr.get(), d_weight_diag.get(), d_agg, d_snb); - - GKO_ASSERT_ARRAY_EQ(d_snb, snb); -} - - -TEST_F(AmgxPgm, AssignToExistAggIsEquivalentToRef) -{ - initialize_data(); - auto x = unfinished_agg; - auto d_x = d_unfinished_agg; - auto intermediate_agg = x; - auto d_intermediate_agg = d_x; - - gko::kernels::reference::amgx_pgm::assign_to_exist_agg( - ref, weight_csr.get(), weight_diag.get(), x, intermediate_agg); - gko::kernels::omp::amgx_pgm::assign_to_exist_agg( - omp, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); - - GKO_ASSERT_ARRAY_EQ(d_x, x); -} - - -TEST_F(AmgxPgm, AssignToExistAggUnderteminsticIsEquivalentToRef) -{ - initialize_data(); - auto d_x = d_unfinished_agg; - auto d_intermediate_agg = gko::Array(omp, 0); - index_type d_num_unagg; - - gko::kernels::omp::amgx_pgm::assign_to_exist_agg( - omp, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); - gko::kernels::omp::amgx_pgm::count_unagg(omp, d_agg, &d_num_unagg); - - // only test whether all elements are aggregated. - GKO_ASSERT_EQ(d_num_unagg, 0); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRef) -{ - initialize_data(); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .with_skip_sorting(true) - .on(omp); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - auto row_gatherer = gko::as(mg_level->get_prolong_op()); - auto d_row_gatherer = gko::as(d_mg_level->get_prolong_op()); - auto row_gather_view = gko::Array::const_view( - row_gatherer->get_executor(), row_gatherer->get_size()[0], - row_gatherer->get_const_row_idxs()); - auto d_row_gather_view = gko::Array::const_view( - d_row_gatherer->get_executor(), d_row_gatherer->get_size()[0], - d_row_gatherer->get_const_row_idxs()); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); - GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); -} - - -TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRefOnUnsortedMatrix) -{ - initialize_data(); - gko::test::unsort_matrix(gko::lend(system_mtx), rand_engine); - d_system_mtx = gko::clone(omp, system_mtx); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() - .with_deterministic(true) - .on(omp); - - auto mg_level = mg_level_factory->generate(system_mtx); - auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); - auto row_gatherer = gko::as(mg_level->get_prolong_op()); - auto d_row_gatherer = gko::as(d_mg_level->get_prolong_op()); - auto row_gather_view = gko::Array::const_view( - row_gatherer->get_executor(), row_gatherer->get_size()[0], - row_gatherer->get_const_row_idxs()); - auto d_row_gather_view = gko::Array::const_view( - d_row_gatherer->get_executor(), d_row_gatherer->get_size()[0], - d_row_gatherer->get_const_row_idxs()); - - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); - GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); - GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); -} - - -} // namespace diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 055a135377f..1c8be7007f3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,4 +4,5 @@ add_subdirectory(base) add_subdirectory(components) add_subdirectory(distributed) add_subdirectory(matrix) +add_subdirectory(multigrid) add_subdirectory(solver) diff --git a/test/multigrid/CMakeLists.txt b/test/multigrid/CMakeLists.txt new file mode 100644 index 00000000000..85d362951f4 --- /dev/null +++ b/test/multigrid/CMakeLists.txt @@ -0,0 +1 @@ +ginkgo_create_common_test(amgx_pgm_kernels) diff --git a/cuda/test/multigrid/amgx_pgm_kernels.cpp b/test/multigrid/amgx_pgm_kernels.cpp similarity index 80% rename from cuda/test/multigrid/amgx_pgm_kernels.cpp rename to test/multigrid/amgx_pgm_kernels.cpp index fc8fe7f0962..11f1efd9b52 100644 --- a/cuda/test/multigrid/amgx_pgm_kernels.cpp +++ b/test/multigrid/amgx_pgm_kernels.cpp @@ -30,7 +30,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *************************************************************/ -#include +#include "core/multigrid/amgx_pgm_kernels.hpp" #include @@ -46,15 +46,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include -#include "core/multigrid/amgx_pgm_kernels.hpp" +#include "core/test/utils.hpp" #include "core/test/utils/matrix_generator.hpp" #include "core/test/utils/unsort_matrix.hpp" -#include "cuda/test/utils.hpp" +#include "test/utils/executor.hpp" namespace { @@ -62,9 +63,13 @@ namespace { class AmgxPgm : public ::testing::Test { protected: - using value_type = gko::default_precision; +#if GINKGO_COMMON_SINGLE_MODE + using value_type = float; +#else + using value_type = double; +#endif // GINKGO_COMMON_SINGLE_MODE using index_type = gko::int32; - using Mtx = gko::matrix::Dense<>; + using Mtx = gko::matrix::Dense; using Csr = gko::matrix::Csr; using RowGatherer = gko::matrix::RowGatherer; using Diag = gko::matrix::Diagonal; @@ -73,15 +78,14 @@ class AmgxPgm : public ::testing::Test { void SetUp() { - ASSERT_GT(gko::CudaExecutor::get_num_devices(), 0); ref = gko::ReferenceExecutor::create(); - cuda = gko::CudaExecutor::create(0, ref); + init_executor(ref, exec); } void TearDown() { - if (cuda != nullptr) { - ASSERT_NO_THROW(cuda->synchronize()); + if (exec != nullptr) { + ASSERT_NO_THROW(exec->synchronize()); } } @@ -90,7 +94,7 @@ class AmgxPgm : public ::testing::Test { return gko::test::generate_random_matrix( num_rows, num_cols, std::uniform_int_distribution<>(num_cols, num_cols), - std::normal_distribution<>(-1.0, 1.0), rand_engine, ref); + std::normal_distribution(-1.0, 1.0), rand_engine, ref); } gko::Array gen_array(gko::size_type num, index_type min_val, @@ -147,14 +151,14 @@ class AmgxPgm : public ::testing::Test { system_mtx = Csr::create(ref); system_dense->convert_to(system_mtx.get()); - d_agg = gko::Array(cuda, agg); - d_unfinished_agg = gko::Array(cuda, unfinished_agg); - d_strongest_neighbor = gko::Array(cuda, strongest_neighbor); - d_coarse_vector = gko::clone(cuda, coarse_vector); - d_fine_vector = gko::clone(cuda, fine_vector); - d_weight_csr = gko::clone(cuda, weight_csr); - d_weight_diag = gko::clone(cuda, weight_diag); - d_system_mtx = gko::clone(cuda, system_mtx); + d_agg = gko::Array(exec, agg); + d_unfinished_agg = gko::Array(exec, unfinished_agg); + d_strongest_neighbor = gko::Array(exec, strongest_neighbor); + d_coarse_vector = gko::clone(exec, coarse_vector); + d_fine_vector = gko::clone(exec, fine_vector); + d_weight_csr = gko::clone(exec, weight_csr); + d_weight_diag = gko::clone(exec, weight_diag); + d_system_mtx = gko::clone(exec, system_mtx); } void make_weight(Mtx* mtx) @@ -166,9 +170,9 @@ class AmgxPgm : public ::testing::Test { } std::shared_ptr ref; - std::shared_ptr cuda; + std::shared_ptr exec; - std::default_random_engine rand_engine; + std::ranlux48 rand_engine; gko::Array agg; gko::Array unfinished_agg; @@ -202,7 +206,8 @@ TEST_F(AmgxPgm, MatchEdgeIsEquivalentToRef) auto d_x = d_unfinished_agg; gko::kernels::reference::amgx_pgm::match_edge(ref, strongest_neighbor, x); - gko::kernels::cuda::amgx_pgm::match_edge(cuda, d_strongest_neighbor, d_x); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::match_edge( + exec, d_strongest_neighbor, d_x); GKO_ASSERT_ARRAY_EQ(d_x, x); } @@ -216,8 +221,8 @@ TEST_F(AmgxPgm, CountUnaggIsEquivalentToRef) gko::kernels::reference::amgx_pgm::count_unagg(ref, unfinished_agg, &num_unagg); - gko::kernels::cuda::amgx_pgm::count_unagg(cuda, d_unfinished_agg, - &d_num_unagg); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::count_unagg(exec, d_unfinished_agg, + &d_num_unagg); ASSERT_EQ(d_num_unagg, num_unagg); } @@ -230,7 +235,7 @@ TEST_F(AmgxPgm, RenumberIsEquivalentToRef) index_type d_num_agg; gko::kernels::reference::amgx_pgm::renumber(ref, agg, &num_agg); - gko::kernels::cuda::amgx_pgm::renumber(cuda, d_agg, &d_num_agg); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::renumber(exec, d_agg, &d_num_agg); ASSERT_EQ(d_num_agg, num_agg); GKO_ASSERT_ARRAY_EQ(d_agg, agg); @@ -246,8 +251,8 @@ TEST_F(AmgxPgm, FindStrongestNeighborIsEquivalentToRef) gko::kernels::reference::amgx_pgm::find_strongest_neighbor( ref, weight_csr.get(), weight_diag.get(), agg, snb); - gko::kernels::cuda::amgx_pgm::find_strongest_neighbor( - cuda, d_weight_csr.get(), d_weight_diag.get(), d_agg, d_snb); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::find_strongest_neighbor( + exec, d_weight_csr.get(), d_weight_diag.get(), d_agg, d_snb); GKO_ASSERT_ARRAY_EQ(d_snb, snb); } @@ -263,8 +268,8 @@ TEST_F(AmgxPgm, AssignToExistAggIsEquivalentToRef) gko::kernels::reference::amgx_pgm::assign_to_exist_agg( ref, weight_csr.get(), weight_diag.get(), x, intermediate_agg); - gko::kernels::cuda::amgx_pgm::assign_to_exist_agg( - cuda, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::assign_to_exist_agg( + exec, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); GKO_ASSERT_ARRAY_EQ(d_x, x); } @@ -274,12 +279,13 @@ TEST_F(AmgxPgm, AssignToExistAggUnderteminsticIsEquivalentToRef) { initialize_data(); auto d_x = d_unfinished_agg; - auto d_intermediate_agg = gko::Array(cuda, 0); + auto d_intermediate_agg = gko::Array(exec, 0); index_type d_num_unagg; - gko::kernels::cuda::amgx_pgm::assign_to_exist_agg( - cuda, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); - gko::kernels::cuda::amgx_pgm::count_unagg(cuda, d_agg, &d_num_unagg); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::assign_to_exist_agg( + exec, d_weight_csr.get(), d_weight_diag.get(), d_x, d_intermediate_agg); + gko::kernels::EXEC_NAMESPACE::amgx_pgm::count_unagg(exec, d_agg, + &d_num_unagg); // only test whether all elements are aggregated. GKO_ASSERT_EQ(d_num_unagg, 0); @@ -289,14 +295,14 @@ TEST_F(AmgxPgm, AssignToExistAggUnderteminsticIsEquivalentToRef) TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRef) { initialize_data(); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() + auto mg_level_factory = gko::multigrid::AmgxPgm::build() .with_deterministic(true) .with_skip_sorting(true) .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() + auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() .with_deterministic(true) .with_skip_sorting(true) - .on(cuda); + .on(exec); auto mg_level = mg_level_factory->generate(system_mtx); auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); @@ -310,9 +316,11 @@ TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRef) d_row_gatherer->get_const_row_idxs()); GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); + gko::as(mg_level->get_restrict_op()), + r::value); GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); + gko::as(mg_level->get_coarse_op()), + r::value); GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); } @@ -321,13 +329,13 @@ TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRefOnUnsortedMatrix) { initialize_data(); gko::test::unsort_matrix(gko::lend(system_mtx), rand_engine); - d_system_mtx = gko::clone(cuda, system_mtx); - auto mg_level_factory = gko::multigrid::AmgxPgm::build() + d_system_mtx = gko::clone(exec, system_mtx); + auto mg_level_factory = gko::multigrid::AmgxPgm::build() .with_deterministic(true) .on(ref); - auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() + auto d_mg_level_factory = gko::multigrid::AmgxPgm::build() .with_deterministic(true) - .on(cuda); + .on(exec); auto mg_level = mg_level_factory->generate(system_mtx); auto d_mg_level = d_mg_level_factory->generate(d_system_mtx); @@ -341,9 +349,11 @@ TEST_F(AmgxPgm, GenerateMgLevelIsEquivalentToRefOnUnsortedMatrix) d_row_gatherer->get_const_row_idxs()); GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_restrict_op()), - gko::as(mg_level->get_restrict_op()), 1e-14); + gko::as(mg_level->get_restrict_op()), + r::value); GKO_ASSERT_MTX_NEAR(gko::as(d_mg_level->get_coarse_op()), - gko::as(mg_level->get_coarse_op()), 1e-14); + gko::as(mg_level->get_coarse_op()), + r::value); GKO_ASSERT_ARRAY_EQ(d_row_gather_view, row_gather_view); }