diff --git a/core/multigrid/amgx_pgm.cpp b/core/multigrid/amgx_pgm.cpp index db02285e90c..4a2f9fdf56a 100644 --- a/core/multigrid/amgx_pgm.cpp +++ b/core/multigrid/amgx_pgm.cpp @@ -67,6 +67,7 @@ GKO_REGISTER_OPERATION(amgx_pgm_generate, amgx_pgm::amgx_pgm_generate); } // namespace amgx_pgm + namespace { diff --git a/core/multigrid/amgx_pgm_kernels.hpp b/core/multigrid/amgx_pgm_kernels.hpp index 68e6f57f857..26031d570fd 100644 --- a/core/multigrid/amgx_pgm_kernels.hpp +++ b/core/multigrid/amgx_pgm_kernels.hpp @@ -55,29 +55,24 @@ namespace amgx_pgm { std::shared_ptr exec, const Array<_itype> &agg, \ const matrix::Dense<_vtype> *b, matrix::Dense<_vtype> *x) - #define GKO_DECLARE_AMGX_PGM_PROLONGATE_APPLY_KERNEL(_vtype, _itype) \ void prolong_applyadd( \ std::shared_ptr exec, const Array<_itype> &agg, \ const matrix::Dense<_vtype> *b, matrix::Dense<_vtype> *x) - #define GKO_DECLARE_AMGX_PGM_INITIAL_KERNEL(_itype) \ void initial(std::shared_ptr exec, \ Array<_itype> &agg) - #define GKO_DECLARE_AMGX_PGM_MATCH_EDGE_KERNEL(_itype) \ void match_edge(std::shared_ptr exec, \ const Array<_itype> &strongest_neighbor, \ Array<_itype> &agg) - #define GKO_DECLARE_AMGX_PGM_COUNT_UNAGG_KERNEL(_itype) \ void count_unagg(std::shared_ptr exec, \ const Array<_itype> &agg, size_type *num_unagg) - #define GKO_DECLARE_AMGX_PGM_RENUMBER_KERNEL(_itype) \ void renumber(std::shared_ptr exec, \ Array<_itype> &agg, size_type *num_agg) @@ -107,7 +102,6 @@ namespace amgx_pgm { const Array &agg, \ matrix::Csr *coarse) - #define GKO_DECLARE_ALL_AS_TEMPLATES \ template \ GKO_DECLARE_AMGX_PGM_RESTRICT_APPLY_KERNEL(ValueType, IndexType); \ diff --git a/core/test/multigrid/amgx_pgm.cpp b/core/test/multigrid/amgx_pgm.cpp index 33e196c11aa..3ffb3d115ab 100644 --- a/core/test/multigrid/amgx_pgm.cpp +++ b/core/test/multigrid/amgx_pgm.cpp @@ -49,7 +49,7 @@ namespace { template -class AmgxPgm : public ::testing::Test { +class AmgxPgmFactory : public ::testing::Test { protected: using value_type = typename std::tuple_element<0, decltype(ValueIndexType())>::type; @@ -59,220 +59,56 @@ class AmgxPgm : public ::testing::Test { using Vec = gko::matrix::Dense; using RestrictProlong = gko::multigrid::AmgxPgm; using T = value_type; - AmgxPgm() + AmgxPgmFactory() : exec(gko::ReferenceExecutor::create()), amgxpgm_factory(RestrictProlong::build() .with_max_iterations(2u) .with_max_unassigned_percentage(0.1) - .on(exec)), - mtx(Mtx::create(exec, gko::dim<2>(5, 5), 15, - std::make_shared())), - agg(exec, 5), - coarse(Mtx::create(exec, gko::dim<2>(2, 2), 4, - std::make_shared())) - - { - this->create_mtx(mtx.get(), &agg, coarse.get()); - rstr_prlg = amgxpgm_factory->generate(mtx); - } - - void create_mtx(Mtx *fine, gko::Array *agg, Mtx *coarse) - { - auto f_vals = fine->get_values(); - auto f_cols = fine->get_col_idxs(); - auto f_rows = fine->get_row_ptrs(); - auto c_vals = coarse->get_values(); - auto c_cols = coarse->get_col_idxs(); - auto c_rows = coarse->get_row_ptrs(); - auto agg_val = agg->get_data(); - /* this matrix is stored: - * 5 -3 -3 0 0 - * -3 5 0 -2 -1 - * -3 0 5 0 -1 - * 0 -3 0 5 0 - * 0 -2 -2 0 5 - */ - f_vals[0] = 5; - f_vals[1] = -3; - f_vals[2] = -3; - f_vals[3] = -3; - f_vals[4] = 5; - f_vals[5] = -2; - f_vals[6] = -1; - f_vals[7] = -3; - f_vals[8] = 5; - f_vals[9] = -1; - f_vals[10] = -3; - f_vals[11] = 5; - f_vals[12] = -2; - f_vals[13] = -2; - f_vals[14] = 5; - - f_rows[0] = 0; - f_rows[1] = 3; - f_rows[2] = 7; - f_rows[3] = 10; - f_rows[4] = 12; - f_rows[5] = 15; - - f_cols[0] = 0; - f_cols[1] = 1; - f_cols[2] = 2; - f_cols[3] = 0; - f_cols[4] = 1; - f_cols[5] = 3; - f_cols[6] = 4; - f_cols[7] = 0; - f_cols[8] = 2; - f_cols[9] = 4; - f_cols[10] = 1; - f_cols[11] = 3; - f_cols[12] = 1; - f_cols[13] = 2; - f_cols[14] = 4; - - agg_val[0] = 0; - agg_val[1] = 1; - agg_val[2] = 0; - agg_val[3] = 1; - agg_val[4] = 0; - /* this coarse is stored: - * 6 -5 - * -4 5 - */ - c_vals[0] = 6; - c_vals[1] = -5; - c_vals[2] = -4; - c_vals[3] = 5; - - c_rows[0] = 0; - c_rows[1] = 2; - c_rows[2] = 4; - - c_cols[0] = 0; - c_cols[1] = 1; - c_cols[2] = 0; - c_cols[3] = 1; - } - - static void assert_same_matrices(const Mtx *m1, const Mtx *m2) - { - ASSERT_EQ(m1->get_size()[0], m2->get_size()[0]); - ASSERT_EQ(m1->get_size()[1], m2->get_size()[1]); - ASSERT_EQ(m1->get_num_stored_elements(), m2->get_num_stored_elements()); - for (gko::size_type i = 0; i < m1->get_size() + 1; i++) { - ASSERT_EQ(m1->get_const_row_ptrs()[i], m2->get_const_row_ptrs()[i]); - } - for (gko::size_type i = 0; i < m1->get_num_stored_elements(); ++i) { - EXPECT_EQ(m1->get_const_values()[i], m2->get_const_values()[i]); - EXPECT_EQ(m1->get_const_col_idxs()[i], m2->get_const_col_idxs()[i]); - } - } - - static void assert_same_agg(const index_type *m1, const index_type *m2, - gko::size_type len) - { - for (gko::size_type i = 0; i < len; ++i) { - EXPECT_EQ(m1[i], m2[i]); - } - } + .with_deterministic(true) + .on(exec)) + + {} std::shared_ptr exec; - std::shared_ptr mtx; - std::shared_ptr coarse; - gko::Array agg; std::unique_ptr amgxpgm_factory; - std::unique_ptr rstr_prlg; }; -TYPED_TEST_CASE(AmgxPgm, gko::test::ValueIndexTypes); +TYPED_TEST_CASE(AmgxPgmFactory, gko::test::ValueIndexTypes); -TYPED_TEST(AmgxPgm, FactoryKnowsItsExecutor) +TYPED_TEST(AmgxPgmFactory, FactoryKnowsItsExecutor) { ASSERT_EQ(this->amgxpgm_factory->get_executor(), this->exec); } -TYPED_TEST(AmgxPgm, CanBeCopied) +TYPED_TEST(AmgxPgmFactory, DefaultSetting) { - using Mtx = typename TestFixture::Mtx; using RestrictProlong = typename TestFixture::RestrictProlong; - auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); - - // copy->copy_from(this->rstr_prlg.get()); - - // auto copy_mtx = - // static_cast(copy.get())->get_system_matrix(); - // auto copy_agg = static_cast(copy.get())->get_const_agg(); auto copy_coarse = - // copy->get_coarse_operator(); + auto factory = RestrictProlong::build().on(this->exec); - // this->assert_same_matrices(static_cast(copy_mtx.get()), - // this->mtx.get()); - // this->assert_same_agg(copy_agg, this->agg.get_data(), - // this->agg.get_num_elems()); this->assert_same_matrices(static_cast(copy_coarse.get()), this->coarse.get()); + ASSERT_EQ(factory->get_parameters().max_iterations, 15u); + ASSERT_EQ(factory->get_parameters().max_unassigned_percentage, 0.05); + ASSERT_EQ(factory->get_parameters().deterministic, false); } -TYPED_TEST(AmgxPgm, CanBeMoved) +TYPED_TEST(AmgxPgmFactory, SetMaxIterations) { - using Mtx = typename TestFixture::Mtx; - using RestrictProlong = typename TestFixture::RestrictProlong; - auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); - - copy->copy_from(std::move(this->rstr_prlg)); - - auto copy_mtx = - static_cast(copy.get())->get_system_matrix(); - auto copy_agg = static_cast(copy.get())->get_const_agg(); - auto copy_coarse = copy->get_coarse_operator(); - - this->assert_same_matrices(static_cast(copy_mtx.get()), - this->mtx.get()); - this->assert_same_agg(copy_agg, this->agg.get_data(), - this->agg.get_num_elems()); - this->assert_same_matrices(static_cast(copy_coarse.get()), - this->coarse.get()); + ASSERT_EQ(this->amgxpgm_factory->get_parameters().max_iterations, 2u); } -TYPED_TEST(AmgxPgm, CanBeCloned) +TYPED_TEST(AmgxPgmFactory, SetMaxUnassignedPercentage) { - using Mtx = typename TestFixture::Mtx; - using RestrictProlong = typename TestFixture::RestrictProlong; - auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); - - auto clone = this->rstr_prlg->clone(); - - auto clone_mtx = - static_cast(clone.get())->get_system_matrix(); - auto clone_agg = - static_cast(clone.get())->get_const_agg(); - auto clone_coarse = clone->get_coarse_operator(); - - this->assert_same_matrices(static_cast(clone_mtx.get()), - this->mtx.get()); - this->assert_same_agg(clone_agg, this->agg.get_data(), - this->agg.get_num_elems()); - this->assert_same_matrices(static_cast(clone_coarse.get()), - this->coarse.get()); + ASSERT_EQ(this->amgxpgm_factory->get_parameters().max_unassigned_percentage, + 0.1); } -TYPED_TEST(AmgxPgm, CanBeCleared) +TYPED_TEST(AmgxPgmFactory, SetDeterministic) { - using RestrictProlong = typename TestFixture::RestrictProlong; - this->rstr_prlg->clear(); - - auto mtx = static_cast(this->rstr_prlg.get()) - ->get_system_matrix(); - auto coarse = this->rstr_prlg->get_coarse_operator(); - auto agg = static_cast(this->rstr_prlg.get())->get_agg(); - ASSERT_EQ(mtx, nullptr); - ASSERT_EQ(coarse, nullptr); - ASSERT_EQ(agg, nullptr); + ASSERT_EQ(this->amgxpgm_factory->get_parameters().deterministic, true); } diff --git a/cuda/test/CMakeLists.txt b/cuda/test/CMakeLists.txt index f2d307391eb..5b180f32c11 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(solver) add_subdirectory(stop) diff --git a/cuda/test/multigrid/CMakeLists.txt b/cuda/test/multigrid/CMakeLists.txt deleted file mode 100644 index 55bea27db18..00000000000 --- a/cuda/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_test_cpp_cuda_header(amgx_pgm_kernels) \ No newline at end of file diff --git a/cuda/test/multigrid/amgx_pgm_kernels.cpp b/cuda/test/multigrid/amgx_pgm_kernels.cpp deleted file mode 100644 index b72889b923f..00000000000 --- a/cuda/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2020, 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 "core/multigrid/amgx_pgm_kernels.hpp" -#include "cuda/test/utils.hpp" - - -namespace {} // namespace diff --git a/hip/test/CMakeLists.txt b/hip/test/CMakeLists.txt index b5201938d72..fd1fa2941d8 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 481c2cc1bf2..00000000000 --- a/hip/test/multigrid/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -ginkgo_create_hip_test_special_linkage(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 13c99bc6a2b..00000000000 --- a/hip/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2020, 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 "core/multigrid/amgx_pgm_kernels.hpp" -#include "hip/test/utils.hip.hpp" - - -namespace {} // namespace diff --git a/include/ginkgo/core/multigrid/amgx_pgm.hpp b/include/ginkgo/core/multigrid/amgx_pgm.hpp index ecac15c6f0b..1925fdbf6a5 100644 --- a/include/ginkgo/core/multigrid/amgx_pgm.hpp +++ b/include/ginkgo/core/multigrid/amgx_pgm.hpp @@ -106,7 +106,7 @@ class AmgxPgm : public EnableRestrictProlong> { /** * The maximum number of iteration. */ - unsigned GKO_FACTORY_PARAMETER(max_iterations, 15); + unsigned GKO_FACTORY_PARAMETER(max_iterations, 15u); /** * The maximum ratio of unassigned number. @@ -125,9 +125,11 @@ class AmgxPgm : public EnableRestrictProlong> { void restrict_apply_impl(const LinOp *b, LinOp *x) const override; void prolong_applyadd_impl(const LinOp *b, LinOp *x) const override; + explicit AmgxPgm(std::shared_ptr exec) : EnableRestrictProlong(std::move(exec)) {} + explicit AmgxPgm(const Factory *factory, std::shared_ptr system_matrix) : EnableRestrictProlong(factory->get_executor()), diff --git a/include/ginkgo/core/multigrid/restrict_prolong.hpp b/include/ginkgo/core/multigrid/restrict_prolong.hpp index 5a7537bddb1..13baa11cdb5 100644 --- a/include/ginkgo/core/multigrid/restrict_prolong.hpp +++ b/include/ginkgo/core/multigrid/restrict_prolong.hpp @@ -37,6 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include + #include #include #include @@ -55,7 +56,6 @@ namespace multigrid { * * @ingroup RestrictProlong */ - class RestrictProlong : public EnableAbstractPolymorphicObject { public: @@ -226,6 +226,7 @@ class RestrictProlongFactory } }; + template @@ -260,7 +261,6 @@ class EnableRestrictProlong return self(); } - ConcreteLinOp *prolong_applyadd(const LinOp *b, LinOp *x) { this->validate_prolong_parameters(b, x); diff --git a/include/ginkgo/ginkgo.hpp b/include/ginkgo/ginkgo.hpp index d8dea7a9f70..63be3bef6a3 100644 --- a/include/ginkgo/ginkgo.hpp +++ b/include/ginkgo/ginkgo.hpp @@ -80,6 +80,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include +#include + #include #include #include diff --git a/omp/test/CMakeLists.txt b/omp/test/CMakeLists.txt index 9be287fa2e1..d746413f53f 100644 --- a/omp/test/CMakeLists.txt +++ b/omp/test/CMakeLists.txt @@ -3,7 +3,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/create_test.cmake) add_subdirectory(components) add_subdirectory(factorization) add_subdirectory(matrix) -add_subdirectory(multigrid) add_subdirectory(preconditioner) add_subdirectory(solver) add_subdirectory(stop) 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 4d2f5ed1fa6..00000000000 --- a/omp/test/multigrid/amgx_pgm_kernels.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2020, 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 "core/multigrid/amgx_pgm_kernels.hpp" -#include "core/test/utils.hpp" - - -namespace {} // namespace diff --git a/reference/test/matrix/csr_kernels.cpp b/reference/test/matrix/csr_kernels.cpp index 8227f19fe62..94b8fa42703 100644 --- a/reference/test/matrix/csr_kernels.cpp +++ b/reference/test/matrix/csr_kernels.cpp @@ -195,7 +195,6 @@ class Csr : public ::testing::Test { cols_u[6] = 0; } - void assert_equal_to_mtx(const Coo *m) { auto v = m->get_const_values(); diff --git a/reference/test/multigrid/amgx_pgm_kernels.cpp b/reference/test/multigrid/amgx_pgm_kernels.cpp index ea16d233de3..bbbdd5b1968 100644 --- a/reference/test/multigrid/amgx_pgm_kernels.cpp +++ b/reference/test/multigrid/amgx_pgm_kernels.cpp @@ -70,7 +70,7 @@ class AmgxPgm : public ::testing::Test { using T = value_type; AmgxPgm() : exec(gko::ReferenceExecutor::create()), - Amgxpgm_factory(RestrictProlong::build() + amgxpgm_factory(RestrictProlong::build() .with_max_iterations(2u) .with_max_unassigned_percentage(0.1) .on(exec)), @@ -92,20 +92,26 @@ class AmgxPgm : public ::testing::Test { exec)), mtx(Mtx::create(exec, gko::dim<2>(5, 5), 15, std::make_shared())), + coarse(Mtx::create(exec, gko::dim<2>(2, 2), 4, + std::make_shared())), mtx_diag(exec, 5), agg(exec, 5) { - this->create_mtx(mtx.get(), &mtx_diag, &agg); + this->create_mtx(mtx.get(), &mtx_diag, &agg, coarse.get()); + rstr_prlg = amgxpgm_factory->generate(mtx); } void create_mtx(Mtx *fine, gko::Array *diag, - gko::Array *agg) + gko::Array *agg, Mtx *coarse) { auto vals = fine->get_values(); auto cols = fine->get_col_idxs(); auto rows = fine->get_row_ptrs(); auto diag_val = diag->get_data(); auto agg_val = agg->get_data(); + auto c_vals = coarse->get_values(); + auto c_cols = coarse->get_col_idxs(); + auto c_rows = coarse->get_row_ptrs(); /* this matrix is stored: * 5 -3 -3 0 0 * -3 5 0 -2 -1 @@ -163,10 +169,51 @@ class AmgxPgm : public ::testing::Test { agg_val[2] = 0; agg_val[3] = 1; agg_val[4] = 0; + + /* this coarse is stored: + * 6 -5 + * -4 5 + */ + c_vals[0] = 6; + c_vals[1] = -5; + c_vals[2] = -4; + c_vals[3] = 5; + + c_rows[0] = 0; + c_rows[1] = 2; + c_rows[2] = 4; + + c_cols[0] = 0; + c_cols[1] = 1; + c_cols[2] = 0; + c_cols[3] = 1; + } + + static void assert_same_matrices(const Mtx *m1, const Mtx *m2) + { + ASSERT_EQ(m1->get_size()[0], m2->get_size()[0]); + ASSERT_EQ(m1->get_size()[1], m2->get_size()[1]); + ASSERT_EQ(m1->get_num_stored_elements(), m2->get_num_stored_elements()); + for (gko::size_type i = 0; i < m1->get_size() + 1; i++) { + ASSERT_EQ(m1->get_const_row_ptrs()[i], m2->get_const_row_ptrs()[i]); + } + for (gko::size_type i = 0; i < m1->get_num_stored_elements(); ++i) { + EXPECT_EQ(m1->get_const_values()[i], m2->get_const_values()[i]); + EXPECT_EQ(m1->get_const_col_idxs()[i], m2->get_const_col_idxs()[i]); + } + } + + static void assert_same_agg(const index_type *m1, const index_type *m2, + gko::size_type len) + { + for (gko::size_type i = 0; i < len; ++i) { + EXPECT_EQ(m1[i], m2[i]); + } } std::shared_ptr exec; std::shared_ptr mtx; + std::shared_ptr coarse; gko::Array mtx_diag; gko::Array agg; std::shared_ptr coarse_b; @@ -174,19 +221,107 @@ class AmgxPgm : public ::testing::Test { std::shared_ptr restrict_ans; std::shared_ptr prolong_ans; std::shared_ptr fine_x; - std::unique_ptr Amgxpgm_factory; + std::unique_ptr amgxpgm_factory; + std::unique_ptr rstr_prlg; }; TYPED_TEST_CASE(AmgxPgm, gko::test::ValueIndexTypes); + +TYPED_TEST(AmgxPgm, CanBeCopied) +{ + using Mtx = typename TestFixture::Mtx; + using RestrictProlong = typename TestFixture::RestrictProlong; + auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); + + copy->copy_from(this->rstr_prlg.get()); + + auto copy_mtx = + static_cast(copy.get())->get_system_matrix(); + auto copy_agg = static_cast(copy.get())->get_const_agg(); + auto copy_coarse = copy->get_coarse_operator(); + + this->assert_same_matrices(static_cast(copy_mtx.get()), + this->mtx.get()); + this->assert_same_agg(copy_agg, this->agg.get_data(), + this->agg.get_num_elems()); + this->assert_same_matrices(static_cast(copy_coarse.get()), + this->coarse.get()); +} + + +TYPED_TEST(AmgxPgm, CanBeMoved) +{ + using Mtx = typename TestFixture::Mtx; + using RestrictProlong = typename TestFixture::RestrictProlong; + auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); + + copy->copy_from(std::move(this->rstr_prlg)); + + auto copy_mtx = + static_cast(copy.get())->get_system_matrix(); + auto copy_agg = static_cast(copy.get())->get_const_agg(); + auto copy_coarse = copy->get_coarse_operator(); + + this->assert_same_matrices(static_cast(copy_mtx.get()), + this->mtx.get()); + this->assert_same_agg(copy_agg, this->agg.get_data(), + this->agg.get_num_elems()); + this->assert_same_matrices(static_cast(copy_coarse.get()), + this->coarse.get()); +} + + +TYPED_TEST(AmgxPgm, CanBeCloned) +{ + using Mtx = typename TestFixture::Mtx; + using RestrictProlong = typename TestFixture::RestrictProlong; + auto copy = this->amgxpgm_factory->generate(Mtx::create(this->exec)); + + auto clone = this->rstr_prlg->clone(); + + auto clone_mtx = + static_cast(clone.get())->get_system_matrix(); + auto clone_agg = + static_cast(clone.get())->get_const_agg(); + auto clone_coarse = clone->get_coarse_operator(); + + this->assert_same_matrices(static_cast(clone_mtx.get()), + this->mtx.get()); + this->assert_same_agg(clone_agg, this->agg.get_data(), + this->agg.get_num_elems()); + this->assert_same_matrices(static_cast(clone_coarse.get()), + this->coarse.get()); +} + + +TYPED_TEST(AmgxPgm, CanBeCleared) +{ + using RestrictProlong = typename TestFixture::RestrictProlong; + + this->rstr_prlg->clear(); + + auto mtx = static_cast(this->rstr_prlg.get()) + ->get_system_matrix(); + auto coarse = this->rstr_prlg->get_coarse_operator(); + auto agg = static_cast(this->rstr_prlg.get())->get_agg(); + + ASSERT_EQ(mtx, nullptr); + ASSERT_EQ(coarse, nullptr); + ASSERT_EQ(agg, nullptr); +} + + TYPED_TEST(AmgxPgm, RestrictApply) { // fine->coarse using Vec = typename TestFixture::Vec; using value_type = typename TestFixture::value_type; auto x = Vec::create_with_config_of(gko::lend(this->coarse_b)); + gko::kernels::reference::amgx_pgm::restrict_apply( this->exec, this->agg, this->fine_b.get(), x.get()); + GKO_ASSERT_MTX_NEAR(x, this->restrict_ans, gko::remove_complex{0}); } @@ -195,8 +330,10 @@ TYPED_TEST(AmgxPgm, ProlongApplyadd) { using value_type = typename TestFixture::value_type; auto x = gko::clone(this->fine_x); + gko::kernels::reference::amgx_pgm::prolong_applyadd( this->exec, this->agg, this->coarse_b.get(), x.get()); + GKO_ASSERT_MTX_NEAR(x, this->prolong_ans, gko::remove_complex{0}); } @@ -269,7 +406,7 @@ TYPED_TEST(AmgxPgm, Renumber) TYPED_TEST(AmgxPgm, Generate) { - auto coarse_fine = this->Amgxpgm_factory->generate(this->mtx); + auto coarse_fine = this->amgxpgm_factory->generate(this->mtx); auto agg_result = coarse_fine->get_const_agg(); @@ -284,7 +421,7 @@ TYPED_TEST(AmgxPgm, Generate) TYPED_TEST(AmgxPgm, CoarseFineRestrictApply) { std::unique_ptr amgx_pgm{ - this->Amgxpgm_factory->generate(this->mtx)}; + this->amgxpgm_factory->generate(this->mtx)}; // fine->coarse using Vec = typename TestFixture::Vec; @@ -298,11 +435,11 @@ TYPED_TEST(AmgxPgm, CoarseFineRestrictApply) TYPED_TEST(AmgxPgm, CoarseFineProlongApplyadd) { - std::unique_ptr amgx_pgm{ - this->Amgxpgm_factory->generate(this->mtx)}; - using value_type = typename TestFixture::value_type; + std::unique_ptr amgx_pgm{ + this->amgxpgm_factory->generate(this->mtx)}; auto x = gko::clone(this->fine_x); + amgx_pgm->prolong_applyadd(this->coarse_b.get(), x.get()); GKO_ASSERT_MTX_NEAR(x, this->prolong_ans, gko::remove_complex{0}); @@ -312,8 +449,8 @@ TYPED_TEST(AmgxPgm, CoarseFineProlongApplyadd) TYPED_TEST(AmgxPgm, ExtractDiag) { using value_type = typename TestFixture::value_type; - gko::Array diag(this->exec, 5); + gko::kernels::reference::amgx_pgm::extract_diag(this->exec, this->mtx.get(), diag); GKO_ASSERT_ARRAY_EQ(diag, this->mtx_diag); @@ -331,8 +468,10 @@ TYPED_TEST(AmgxPgm, FindStrongestNeighbor) snb_vals[i] = -1; agg_vals[i] = -1; } + gko::kernels::reference::amgx_pgm::find_strongest_neighbor( this->exec, this->mtx.get(), this->mtx_diag, agg, strongest_neighbor); + ASSERT_EQ(snb_vals[0], 2); ASSERT_EQ(snb_vals[1], 0); ASSERT_EQ(snb_vals[2], 0); @@ -353,8 +492,10 @@ TYPED_TEST(AmgxPgm, AssignToExistAgg) agg_vals[2] = 0; agg_vals[3] = 1; agg_vals[4] = -1; + gko::kernels::reference::amgx_pgm::assign_to_exist_agg( this->exec, this->mtx.get(), this->mtx_diag, agg, intermediate_agg); + ASSERT_EQ(agg_vals[0], 0); ASSERT_EQ(agg_vals[1], 1); ASSERT_EQ(agg_vals[2], 0); @@ -377,14 +518,15 @@ TYPED_TEST(AmgxPgm, GenerateMtx) agg_vals[3] = 1; agg_vals[4] = 2; auto csr_coarse = mtx_type::create(this->exec, gko::dim<2>{3, 3}, 0); + gko::kernels::reference::amgx_pgm::amgx_pgm_generate( this->exec, this->mtx.get(), agg, csr_coarse.get()); - ASSERT_EQ(csr_coarse->get_size(), gko::dim<2>(3, 3)); - ASSERT_EQ(csr_coarse->get_num_stored_elements(), 9); auto r = csr_coarse->get_const_row_ptrs(); auto c = csr_coarse->get_const_col_idxs(); auto v = csr_coarse->get_const_values(); + ASSERT_EQ(csr_coarse->get_size(), gko::dim<2>(3, 3)); + ASSERT_EQ(csr_coarse->get_num_stored_elements(), 9); ASSERT_EQ(r[0], 0); ASSERT_EQ(r[1], 3); ASSERT_EQ(r[2], 6); diff --git a/test_install/test_install.cpp b/test_install/test_install.cpp index 5df5ed227cb..c2a4345a2b2 100644 --- a/test_install/test_install.cpp +++ b/test_install/test_install.cpp @@ -258,6 +258,11 @@ int main(int, char **) auto test = Mtx::create(refExec, gko::dim<2>{2, 2}); } + // core/multigrid/amgx_pgm.hpp + { + auto test = gko::multigrid::AmgxPgm<>::build().on(refExec); + } + // core/preconditioner/ilu.hpp { auto test = gko::preconditioner::Ilu<>::build().on(refExec); diff --git a/test_install/test_install_cuda.cu b/test_install/test_install_cuda.cu index 3784447fa28..8de2a6de487 100644 --- a/test_install/test_install_cuda.cu +++ b/test_install/test_install_cuda.cu @@ -262,6 +262,11 @@ int main(int, char **) Mtx::create(cudaExec, gko::dim<2>{2, 2}); } + // core/multigrid/amgx_pgm.hpp + { + gko::multigrid::AmgxPgm<>::build().on(cudaExec); + } + // core/preconditioner/ilu.hpp { gko::preconditioner::Ilu<>::build().on(cudaExec);