Skip to content

Commit

Permalink
move the test to correct place and format
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Jun 19, 2020
1 parent bfa1af4 commit 2227918
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 374 deletions.
1 change: 1 addition & 0 deletions core/multigrid/amgx_pgm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ GKO_REGISTER_OPERATION(amgx_pgm_generate, amgx_pgm::amgx_pgm_generate);

} // namespace amgx_pgm


namespace {


Expand Down
6 changes: 0 additions & 6 deletions core/multigrid/amgx_pgm_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,24 @@ namespace amgx_pgm {
std::shared_ptr<const DefaultExecutor> 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<const DefaultExecutor> 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<const DefaultExecutor> exec, \
Array<_itype> &agg)


#define GKO_DECLARE_AMGX_PGM_MATCH_EDGE_KERNEL(_itype) \
void match_edge(std::shared_ptr<const DefaultExecutor> exec, \
const Array<_itype> &strongest_neighbor, \
Array<_itype> &agg)


#define GKO_DECLARE_AMGX_PGM_COUNT_UNAGG_KERNEL(_itype) \
void count_unagg(std::shared_ptr<const DefaultExecutor> exec, \
const Array<_itype> &agg, size_type *num_unagg)


#define GKO_DECLARE_AMGX_PGM_RENUMBER_KERNEL(_itype) \
void renumber(std::shared_ptr<const DefaultExecutor> exec, \
Array<_itype> &agg, size_type *num_agg)
Expand Down Expand Up @@ -107,7 +102,6 @@ namespace amgx_pgm {
const Array<IndexType> &agg, \
matrix::Csr<ValueType, IndexType> *coarse)


#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_AMGX_PGM_RESTRICT_APPLY_KERNEL(ValueType, IndexType); \
Expand Down
204 changes: 20 additions & 184 deletions core/test/multigrid/amgx_pgm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace {


template <typename ValueIndexType>
class AmgxPgm : public ::testing::Test {
class AmgxPgmFactory : public ::testing::Test {
protected:
using value_type =
typename std::tuple_element<0, decltype(ValueIndexType())>::type;
Expand All @@ -59,220 +59,56 @@ class AmgxPgm : public ::testing::Test {
using Vec = gko::matrix::Dense<value_type>;
using RestrictProlong = gko::multigrid::AmgxPgm<value_type, index_type>;
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<typename Mtx::classical>())),
agg(exec, 5),
coarse(Mtx::create(exec, gko::dim<2>(2, 2), 4,
std::make_shared<typename Mtx::classical>()))

{
this->create_mtx(mtx.get(), &agg, coarse.get());
rstr_prlg = amgxpgm_factory->generate(mtx);
}

void create_mtx(Mtx *fine, gko::Array<index_type> *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<const gko::Executor> exec;
std::shared_ptr<Mtx> mtx;
std::shared_ptr<Mtx> coarse;
gko::Array<index_type> agg;
std::unique_ptr<typename RestrictProlong::Factory> amgxpgm_factory;
std::unique_ptr<RestrictProlong> 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<RestrictProlong *>(copy.get())->get_system_matrix();
// auto copy_agg = static_cast<RestrictProlong
// *>(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<const Mtx *>(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<const
// Mtx *>(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<RestrictProlong *>(copy.get())->get_system_matrix();
auto copy_agg = static_cast<RestrictProlong *>(copy.get())->get_const_agg();
auto copy_coarse = copy->get_coarse_operator();

this->assert_same_matrices(static_cast<const Mtx *>(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<const Mtx *>(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<RestrictProlong *>(clone.get())->get_system_matrix();
auto clone_agg =
static_cast<RestrictProlong *>(clone.get())->get_const_agg();
auto clone_coarse = clone->get_coarse_operator();

this->assert_same_matrices(static_cast<const Mtx *>(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<const Mtx *>(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<RestrictProlong *>(this->rstr_prlg.get())
->get_system_matrix();
auto coarse = this->rstr_prlg->get_coarse_operator();
auto agg = static_cast<RestrictProlong *>(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);
}


Expand Down
1 change: 0 additions & 1 deletion cuda/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cuda/test/multigrid/CMakeLists.txt

This file was deleted.

56 changes: 0 additions & 56 deletions cuda/test/multigrid/amgx_pgm_kernels.cpp

This file was deleted.

1 change: 0 additions & 1 deletion hip/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion hip/test/multigrid/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 2227918

Please sign in to comment.