Skip to content

Commit

Permalink
review updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Sep 23, 2022
1 parent ef2b32f commit 53759b2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 840 deletions.
709 changes: 0 additions & 709 deletions omp/test/stop/residual_norm_kernels.cpp

This file was deleted.

10 changes: 6 additions & 4 deletions reference/test/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,9 @@ TYPED_TEST(Csr, ConvertsToPrecision)
tmp->convert_to(res.get());

GKO_ASSERT_MTX_NEAR(this->mtx2, res, residual);
ASSERT_EQ(typeid(*this->mtx2->get_strategy()),
typeid(*res->get_strategy()));
auto first_strategy = this->mtx2->get_strategy();
auto second_strategy = res->get_strategy();
ASSERT_EQ(typeid(*first_strategy), typeid(*second_strategy));
}


Expand All @@ -624,8 +625,9 @@ TYPED_TEST(Csr, MovesToPrecision)
tmp->move_to(res.get());

GKO_ASSERT_MTX_NEAR(this->mtx2, res, residual);
ASSERT_EQ(typeid(*this->mtx2->get_strategy()),
typeid(*res->get_strategy()));
auto first_strategy = this->mtx2->get_strategy();
auto second_strategy = res->get_strategy();
ASSERT_EQ(typeid(*first_strategy), typeid(*second_strategy));
}


Expand Down
2 changes: 1 addition & 1 deletion test/components/prefix_sum_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TYPED_TEST(PrefixSum, EqualsReference)
{
using gko::size_type;
for (auto size :
{size_type{0}, size_type{1}, size_type{100}, this->total_size}) {
{size_type{0}, size_type{1}, size_type{131}, this->total_size}) {
SCOPED_TRACE(size);
gko::kernels::reference::components::prefix_sum(
this->ref, this->vals.get_data(), size);
Expand Down
6 changes: 2 additions & 4 deletions test/factorization/par_ilu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ class ParIlu : public CommonTestFixture {
std::string file_name(gko::matrices::location_ani4_mtx);
auto input_file = std::ifstream(file_name, std::ios::in);
auto mtx_temp = gko::read<Csr>(input_file, ref);
auto dmtx_temp = gko::clone(exec, mtx_temp);
// Make sure there are diagonal elements present
gko::kernels::reference::factorization::add_diagonal_elements(
ref, mtx_temp.get(), false);
gko::kernels::EXEC_NAMESPACE::factorization::add_diagonal_elements(
exec, dmtx_temp.get(), false);
auto dmtx_temp = gko::clone(exec, mtx_temp);
mtx = gko::give(mtx_temp);
dmtx = gko::give(dmtx_temp);
}
Expand Down Expand Up @@ -143,7 +141,7 @@ class ParIlu : public CommonTestFixture {
initialize_row_ptrs(l_row_ptrs.get_data(), u_row_ptrs.get_data(),
dl_row_ptrs.get_data(), du_row_ptrs.get_data());
// Since `initialize_row_ptrs` was already tested, it is expected that
// `*` and `*d` contain identical values
// `*` and `d*` contain identical values
auto l_nnz = l_row_ptrs.get_const_data()[num_row_ptrs - 1];
auto u_nnz = u_row_ptrs.get_const_data()[num_row_ptrs - 1];

Expand Down
8 changes: 7 additions & 1 deletion test/matrix/csr_kernels2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ TEST_F(Csr, SimpleApplySparseToSparseCsrMatrixIsEquivalentToRef)
}


// TODO: broken in ROCm <= 4.5
#ifndef GKO_COMPILING_HIP


TEST_F(Csr, SimpleApplyToEmptyCsrMatrixIsEquivalentToRef)
{
set_up_apply_data<Mtx::classical>();
Expand All @@ -573,6 +577,9 @@ TEST_F(Csr, SimpleApplyToEmptyCsrMatrixIsEquivalentToRef)
}


#endif


TEST_F(Csr, AdvancedApplyToIdentityMatrixIsEquivalentToRef)
{
set_up_apply_data<Mtx::classical>();
Expand Down Expand Up @@ -1223,7 +1230,6 @@ TEST_F(Csr, CanDetectMissingDiagonalEntry)

TEST_F(Csr, CanDetectWhenAllDiagonalEntriesArePresent)
{
using T = double;
using Csr = Mtx;
auto ref_mtx = gen_mtx<Csr>(103, 98, 10);
gko::utils::ensure_all_diagonal_entries(ref_mtx.get());
Expand Down
6 changes: 0 additions & 6 deletions test/matrix/ell_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef3)
}


#ifndef GKO_COMPILING_OMP


TEST_F(Ell, SimpleApplyByAtomicIsEquivalentToRef)
{
set_up_apply_data(10, 10000);
Expand Down Expand Up @@ -459,9 +456,6 @@ TEST_F(Ell, AdvancedByAtomicToDenseMatrixApplyIsEquivalentToRef)
}


#endif // !defined(GKO_COMPILING_OMP)


TEST_F(Ell, SimpleApplyOnSmallMatrixIsEquivalentToRef)
{
set_up_apply_data(1, 10);
Expand Down
185 changes: 74 additions & 111 deletions test/matrix/fbcsr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,13 @@ TYPED_TEST(Fbcsr, TransposeIsEquivalentToRefSortedBS3)
using Mtx = typename TestFixture::Mtx;
using value_type = typename Mtx::value_type;
using index_type = typename Mtx::index_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto trans_ref_linop = this->rsorted->transpose();
std::unique_ptr<const Mtx> trans_ref =
gko::as<const Mtx>(std::move(trans_ref_linop));
auto drand = gko::clone(this->exec, this->rsorted);

auto trans_cuda_linop = drand->transpose();
std::unique_ptr<const Mtx> trans_cuda =
gko::as<const Mtx>(std::move(trans_cuda_linop));
auto trans = gko::as<Mtx>(this->rsorted->transpose());
auto dtrans = gko::as<Mtx>(drand->transpose());

GKO_ASSERT_MTX_EQ_SPARSITY(trans_ref, trans_cuda);
GKO_ASSERT_MTX_NEAR(trans_ref, trans_cuda, 0.0);
GKO_ASSERT_MTX_EQ_SPARSITY(trans, dtrans);
GKO_ASSERT_MTX_NEAR(trans, dtrans, 0.0);
}


Expand All @@ -148,15 +143,11 @@ TYPED_TEST(Fbcsr, TransposeIsEquivalentToRefSortedBS7)
std::default_random_engine(43));
drand->copy_from(gko::lend(rsorted2));

auto trans_ref_linop = rsorted2->transpose();
std::unique_ptr<const Mtx> trans_ref =
gko::as<const Mtx>(std::move(trans_ref_linop));
auto trans_cuda_linop = drand->transpose();
std::unique_ptr<const Mtx> trans_cuda =
gko::as<const Mtx>(std::move(trans_cuda_linop));
auto trans = gko::as<Mtx>(rsorted2->transpose());
auto dtrans = gko::as<Mtx>(drand->transpose());

GKO_ASSERT_MTX_EQ_SPARSITY(trans_ref, trans_cuda);
GKO_ASSERT_MTX_NEAR(trans_ref, trans_cuda, 0.0);
GKO_ASSERT_MTX_EQ_SPARSITY(trans, dtrans);
GKO_ASSERT_MTX_NEAR(trans, dtrans, 0.0);
}


Expand All @@ -165,22 +156,20 @@ TYPED_TEST(Fbcsr, SpmvIsEquivalentToRefSorted)
using Mtx = typename TestFixture::Mtx;
using Dense = typename TestFixture::Dense;
using value_type = typename Mtx::value_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto x_ref =
auto drand = gko::clone(this->exec, this->rsorted);
auto x =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[1], 1));
this->generate_sin(x_ref.get());
auto x_cuda = Dense::create(this->exec);
x_cuda->copy_from(x_ref.get());
auto prod_ref =
this->generate_sin(x.get());
auto dx = gko::clone(this->exec, x);
auto prod =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[0], 1));
auto prod_cuda = Dense::create(this->exec, prod_ref->get_size());
auto dprod = Dense::create(this->exec, prod->get_size());

drand->apply(x_cuda.get(), prod_cuda.get());
this->rsorted->apply(x_ref.get(), prod_ref.get());
drand->apply(dx.get(), dprod.get());
this->rsorted->apply(x.get(), prod.get());

const double tol = r<value_type>::value;
GKO_ASSERT_MTX_NEAR(prod_ref, prod_cuda, 5 * tol);
GKO_ASSERT_MTX_NEAR(prod, dprod, 5 * tol);
}


Expand All @@ -189,22 +178,20 @@ TYPED_TEST(Fbcsr, SpmvMultiIsEquivalentToRefSorted)
using Mtx = typename TestFixture::Mtx;
using Dense = typename TestFixture::Dense;
using value_type = typename Mtx::value_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto x_ref =
auto drand = gko::clone(this->exec, this->rsorted);
auto x =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[1], 3));
this->generate_sin(x_ref.get());
auto x_cuda = Dense::create(this->exec);
x_cuda->copy_from(x_ref.get());
auto prod_ref =
this->generate_sin(x.get());
auto dx = gko::clone(this->exec, x);
auto prod =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[0], 3));
auto prod_cuda = Dense::create(this->exec, prod_ref->get_size());
auto dprod = Dense::create(this->exec, prod->get_size());

drand->apply(x_cuda.get(), prod_cuda.get());
this->rsorted->apply(x_ref.get(), prod_ref.get());
drand->apply(dx.get(), dprod.get());
this->rsorted->apply(x.get(), prod.get());

const double tol = r<value_type>::value;
GKO_ASSERT_MTX_NEAR(prod_ref, prod_cuda, 5 * tol);
GKO_ASSERT_MTX_NEAR(prod, dprod, 5 * tol);
}


Expand All @@ -214,34 +201,27 @@ TYPED_TEST(Fbcsr, AdvancedSpmvIsEquivalentToRefSorted)
using Dense = typename TestFixture::Dense;
using value_type = typename TestFixture::value_type;
using real_type = typename TestFixture::real_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto x_ref =
auto drand = gko::clone(this->exec, this->rsorted);
auto x =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[1], 1));
this->generate_sin(x_ref.get());
auto x_cuda = Dense::create(this->exec);
x_cuda->copy_from(x_ref.get());
auto prod_ref =
this->generate_sin(x.get());
auto dx = gko::clone(this->exec, x);
auto prod =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[0], 1));
this->generate_sin(prod_ref.get());
auto prod_cuda = Dense::create(this->exec);
prod_cuda->copy_from(prod_ref.get());
auto alpha_ref = Dense::create(this->ref, gko::dim<2>(1, 1));
alpha_ref->get_values()[0] =
static_cast<real_type>(2.4) + this->get_random_value();
auto beta_ref = Dense::create(this->ref, gko::dim<2>(1, 1));
beta_ref->get_values()[0] = -1.2;
auto alpha = Dense::create(this->exec);
alpha->copy_from(alpha_ref.get());
auto beta = Dense::create(this->exec);
beta->copy_from(beta_ref.get());

drand->apply(alpha.get(), x_cuda.get(), beta.get(), prod_cuda.get());
this->rsorted->apply(alpha_ref.get(), x_ref.get(), beta_ref.get(),
prod_ref.get());
this->generate_sin(prod.get());
auto dprod = gko::clone(this->exec, prod);
auto alpha = Dense::create(this->ref, gko::dim<2>(1, 1));
alpha->at(0, 0) = static_cast<real_type>(2.4) + this->get_random_value();
auto beta = Dense::create(this->ref, gko::dim<2>(1, 1));
beta->at(0, 0) = -1.2;
auto dalpha = gko::clone(this->exec, alpha);
auto dbeta = gko::clone(this->exec, beta);

drand->apply(dalpha.get(), dx.get(), dbeta.get(), dprod.get());
this->rsorted->apply(alpha.get(), x.get(), beta.get(), prod.get());

const double tol = r<value_type>::value;
GKO_ASSERT_MTX_NEAR(prod_ref, prod_cuda, 5 * tol);
GKO_ASSERT_MTX_NEAR(prod, dprod, 5 * tol);
}


Expand All @@ -251,34 +231,27 @@ TYPED_TEST(Fbcsr, AdvancedSpmvMultiIsEquivalentToRefSorted)
using Dense = typename TestFixture::Dense;
using value_type = typename TestFixture::value_type;
using real_type = typename TestFixture::real_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto x_ref =
auto drand = gko::clone(this->exec, this->rsorted);
auto x =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[1], 3));
this->generate_sin(x_ref.get());
auto x_cuda = Dense::create(this->exec);
x_cuda->copy_from(x_ref.get());
auto prod_ref =
this->generate_sin(x.get());
auto dx = gko::clone(this->exec, x);
auto prod =
Dense::create(this->ref, gko::dim<2>(this->rsorted->get_size()[0], 3));
this->generate_sin(prod_ref.get());
auto prod_cuda = Dense::create(this->exec);
prod_cuda->copy_from(prod_ref.get());
auto alpha_ref = Dense::create(this->ref, gko::dim<2>(1, 1));
alpha_ref->get_values()[0] =
static_cast<real_type>(2.4) + this->get_random_value();
auto beta_ref = Dense::create(this->ref, gko::dim<2>(1, 1));
beta_ref->get_values()[0] = -1.2;
auto alpha = Dense::create(this->exec);
alpha->copy_from(alpha_ref.get());
auto beta = Dense::create(this->exec);
beta->copy_from(beta_ref.get());

drand->apply(alpha.get(), x_cuda.get(), beta.get(), prod_cuda.get());
this->rsorted->apply(alpha_ref.get(), x_ref.get(), beta_ref.get(),
prod_ref.get());
this->generate_sin(prod.get());
auto dprod = gko::clone(this->exec, prod);
auto alpha = Dense::create(this->ref, gko::dim<2>(1, 1));
alpha->at(0, 0) = static_cast<real_type>(2.4) + this->get_random_value();
auto beta = Dense::create(this->ref, gko::dim<2>(1, 1));
beta->at(0, 0) = -1.2;
auto dalpha = gko::clone(this->exec, alpha);
auto dbeta = gko::clone(this->exec, beta);

drand->apply(dalpha.get(), dx.get(), dbeta.get(), dprod.get());
this->rsorted->apply(alpha.get(), x.get(), beta.get(), prod.get());

const double tol = r<value_type>::value;
GKO_ASSERT_MTX_NEAR(prod_ref, prod_cuda, 5 * tol);
GKO_ASSERT_MTX_NEAR(prod, dprod, 5 * tol);
}


Expand All @@ -287,26 +260,20 @@ TYPED_TEST(Fbcsr, ConjTransposeIsEquivalentToRefSortedBS3)
using Mtx = typename TestFixture::Mtx;
using value_type = typename Mtx::value_type;
using index_type = typename Mtx::index_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto trans_ref_linop = this->rsorted->conj_transpose();
std::unique_ptr<const Mtx> trans_ref =
gko::as<const Mtx>(std::move(trans_ref_linop));
auto drand = gko::clone(this->exec, this->rsorted);

auto trans_cuda_linop = drand->conj_transpose();
std::unique_ptr<const Mtx> trans_cuda =
gko::as<const Mtx>(std::move(trans_cuda_linop));
auto trans = gko::as<Mtx>(this->rsorted->conj_transpose());
auto dtrans = gko::as<Mtx>(drand->conj_transpose());

GKO_ASSERT_MTX_EQ_SPARSITY(trans_ref, trans_cuda);
GKO_ASSERT_MTX_NEAR(trans_ref, trans_cuda, 0.0);
GKO_ASSERT_MTX_EQ_SPARSITY(trans, dtrans);
GKO_ASSERT_MTX_NEAR(trans, dtrans, 0.0);
}


TYPED_TEST(Fbcsr, RecognizeSortedMatrix)
{
using Mtx = typename TestFixture::Mtx;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto drand = gko::clone(this->exec, this->rsorted);

ASSERT_TRUE(drand->is_sorted_by_column_index());
}
Expand All @@ -319,36 +286,32 @@ TYPED_TEST(Fbcsr, RecognizeUnsortedMatrix)
auto mat = this->rsorted->clone();
index_type* const colinds = mat->get_col_idxs();
std::swap(colinds[0], colinds[1]);
auto unsrt_cuda = Mtx::create(this->exec);
unsrt_cuda->copy_from(gko::lend(mat));
auto dunsrt = gko::clone(this->exec, mat);

ASSERT_FALSE(unsrt_cuda->is_sorted_by_column_index());
ASSERT_FALSE(dunsrt->is_sorted_by_column_index());
}


TYPED_TEST(Fbcsr, InplaceAbsoluteMatrixIsEquivalentToRef)
{
using Mtx = typename TestFixture::Mtx;
using value_type = typename Mtx::value_type;
auto rand_ref = Mtx::create(this->ref);
rand_ref->copy_from(this->rsorted.get());
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto rand = gko::clone(this->ref, this->rsorted);
auto drand = gko::clone(this->exec, this->rsorted);

rand_ref->compute_absolute_inplace();
rand->compute_absolute_inplace();
drand->compute_absolute_inplace();

const double tol = r<value_type>::value;
GKO_ASSERT_MTX_NEAR(rand_ref, drand, tol);
GKO_ASSERT_MTX_NEAR(rand, drand, tol);
}


TYPED_TEST(Fbcsr, OutplaceAbsoluteMatrixIsEquivalentToRef)
{
using Mtx = typename TestFixture::Mtx;
using value_type = typename Mtx::value_type;
auto drand = Mtx::create(this->exec);
drand->copy_from(gko::lend(this->rsorted));
auto drand = gko::clone(this->exec, this->rsorted);

auto abs_mtx = this->rsorted->compute_absolute();
auto dabs_mtx = drand->compute_absolute();
Expand Down
Loading

0 comments on commit 53759b2

Please sign in to comment.