Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Oct 10, 2024
1 parent 53689cc commit 30947e3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/MatrixWrapper/Distributed.C
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ void update_fused_impl(
non_local_sparsity->ldu_mapping.get_executor(), non_local_elements,
non_local_sparsity->ldu_mapping.get_data());

auto non_lcoal_vals = gko::array<scalar>::view(non_local_mtx->get_executor(),

Check warning on line 310 in src/MatrixWrapper/Distributed.C

View workflow job for this annotation

GitHub Actions / Spell check

"lcoal" should be "local" or "coal".
non_local_elements, non_local_ptr);
auto non_local_dense_vec = non_local_row_collection->clone();
non_local_dense_vec->row_gather(&non_local_mapping_view,
non_local_row_collection.get());
Expand Down
150 changes: 93 additions & 57 deletions unitTests/MatrixWrapper/Distributed.C
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ public:
2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, // 50-64
3, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 3, // 65-78
1, 2, 1, 1, 2, 1, 2, 1, 1, 3, 1, 2, 1, 1, // 80-92
1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, // 93
1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 3, //
1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 3, 1, 2, 1, //
2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, //
3, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2 };
1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, // 93
1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 3, //
1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 3, 1, 2, 1, //
2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, //
3, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2};
std::map<bool, std::map<label, vec_vec_s>> exp_local_coeffs{
{true,
{{1,
Expand All @@ -215,6 +215,59 @@ public:
{2, {exp_local_coeff_2_nf, {}, exp_local_coeff_2_nf, {}}},
{4, {exp_local_coeff_4, {}, {}, {}}}}}};

std::vector<scalar> non_local_coeffs{1, 2, 3, 1, 2, 3};
std::map<bool, std::map<label, vec_vec_s>> exp_non_local_coeffs{
{true,
{{1,
{{1, 2, 1, 2, 3, 3},
{1, 2, 3, 1, 2, 3},
{1, 2, 3, 1, 2, 3},
{1, 1, 2, 3, 2, 3}}},
{2, {non_local_coeffs, {}, non_local_coeffs, {}}},
{4, {{}, {}, {}, {}}}}},
{false,
{{1,
{non_local_coeffs, non_local_coeffs, non_local_coeffs,
non_local_coeffs}},
{2, {{1, 2, 3, 1, 2, 3}, {}, {1, 2, 3, 1, 2, 3}, {}}},
{4, {{}, {}, {}, {}}}}}};

std::map<bool, std::map<label, vec_vec>> exp_non_local_rows{
{true,
{{1,
{{2, 5, 6, 7, 8, 8},
{0, 3, 6, 6, 7, 8},
{0, 1, 2, 2, 5, 8},
{0, 0, 1, 2, 3, 6}}},
{2, {{6, 7, 8, 15, 16, 17}, {}, {0, 1, 2, 9, 10, 11}, {}}},
{4, {{}, {}, {}, {}}}}},
{false,
{{1,
{{2, 5, 8, 6, 7, 8},
{0, 3, 6, 6, 7, 8},
{0, 1, 2, 2, 5, 8},
{0, 1, 2, 0, 3, 6}}},
{2, {{6, 7, 8, 15, 16, 17}, {}, {0, 1, 2, 9, 10, 11}, {}}},
{4, {{}, {}, {}, {}}}}}};

std::map<bool, std::map<label, vec_vec>> exp_non_local_cols{
{true,
{{1,
{{0, 1, 3, 4, 2, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 3, 1, 2, 4, 5}}},
{2, {{0, 1, 2, 3, 4, 5}, {}, {0, 1, 2, 3, 4, 5}, {}}},
{4, {{}, {}, {}, {}}}}},
{false,
{{1,
{{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5}}},
{2, {{0, 1, 2, 3, 4, 5}, {}, {0, 1, 2, 3, 4, 5}, {}}},
{4, {{}, {}, {}, {}}}}}};

/*
* The mesh has the following structure
* local ids
Expand Down Expand Up @@ -314,6 +367,27 @@ public:
{{1, {local_cols_1, local_cols_1, local_cols_1, local_cols_1}},
{2, {local_cols_2, {}, local_cols_2, {}}},
{4, {local_cols_4, {}, {}, {}}}}}};

vec_vec_s x_1{{4, 5, 5, 5, 6, 7, 5, 7, 10},
{5, 5, 4, 7, 6, 5, 8, 7, 7},
{5, 7, 8, 5, 6, 7, 4, 5, 7},
{6, 7, 7, 7, 6, 5, 7, 5, 4}};
std::vector<scalar> exp_x_2_1 = {4, 5, 5, 5, 6, 7, 5, 7, 10,
5, 5, 4, 7, 6, 5, 8, 7, 7};
std::vector<scalar> exp_x_2_2 = {5, 7, 8, 5, 6, 7, 4, 5, 7,
6, 7, 7, 7, 6, 5, 7, 5, 4};
std::vector<scalar> exp_x_4 = {4, 5, 5, 5, 6, 7, 5, 7, 10, 5, 5, 4,
7, 6, 5, 8, 7, 7, 5, 7, 8, 5, 6, 7,
4, 5, 7, 6, 7, 7, 7, 6, 5, 7, 5, 4};
std::map<bool, std::map<label, vec_vec_s>> exp_x{
{true,
{{1, x_1},
{2, {exp_x_2_1, {}, exp_x_2_2, {}}},
{4, {exp_x_4, {}, {}, {}}}}},
{false,
{{1, x_1},
{2, {exp_x_2_1, {}, exp_x_2_2, {}}},
{4, {exp_x_4, {}, {}, {}}}}}};
};


Expand Down Expand Up @@ -438,44 +512,25 @@ TEST_P(DistributedMatrixFixtureFormat, hasCorrectNonLocalMatrix)
auto distributed =
create_distributed(exec, repartitioner, hostMatrix, matrix_format);

auto non_local = detail::convert_combination_to_coo(
exec.get_ref_exec(), distributed->get_non_local_matrix());

auto res_non_local_values = convert_to_vector(get_val(non_local));

std::map<label, vec_vec_s> exp_non_local_values;
std::vector<scalar> exp_non_local{1.0, 2.0, 3.0, 1.0, 2.0, 3.0};
exp_non_local_values.emplace(1, vec_vec_s(4, exp_non_local));
exp_non_local_values.emplace(
2, vec_vec_s{exp_non_local, {}, exp_non_local, {}});
exp_non_local_values.emplace(4, vec_vec_s{{}, {}, {}, {}});
auto non_local =
(fused) ? gko::as<gko::matrix::Coo<scalar, label>>(
distributed->get_non_local_matrix())
: detail::convert_combination_to_coo(
exec.get_ref_exec(), distributed->get_non_local_matrix());

auto res_non_local_coeffs = convert_to_vector(get_val(non_local));
auto res_non_local_cols = convert_to_vector(get_col(non_local));
std::map<label, vec_vec> exp_non_local_cols;
exp_non_local_cols.emplace(1, vec_vec{{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5}});
exp_non_local_cols.emplace(
2, vec_vec{{0, 1, 2, 3, 4, 5}, {}, {0, 1, 2, 3, 4, 5}, {}});
exp_non_local_cols.emplace(4, vec_vec{{}, {}, {}, {}});

auto res_non_local_rows = convert_to_vector(get_row(non_local));
std::map<label, vec_vec> exp_non_local_rows;
exp_non_local_rows.emplace(1, vec_vec{{2, 5, 8, 6, 7, 8},
{0, 3, 6, 6, 7, 8},
{0, 1, 2, 2, 5, 8},
{0, 1, 2, 0, 3, 6}});
exp_non_local_rows.emplace(
2, vec_vec{{6, 7, 8, 15, 16, 17}, {}, {0, 1, 2, 9, 10, 11}, {}});
exp_non_local_rows.emplace(4, vec_vec{{}, {}, {}, {}});

ASSERT_EQ(distributed->get_non_local_matrix()->get_size()[1],
exp_non_local_size[ranks_per_gpu][rank]);

ASSERT_EQ(res_non_local_values, exp_non_local_values[ranks_per_gpu][rank]);
ASSERT_EQ(res_non_local_rows, exp_non_local_rows[ranks_per_gpu][rank]);
ASSERT_EQ(res_non_local_cols, exp_non_local_cols[ranks_per_gpu][rank]);
ASSERT_EQ(res_non_local_coeffs,
exp_non_local_coeffs[fused][ranks_per_gpu][rank]);
ASSERT_EQ(res_non_local_rows,
exp_non_local_rows[fused][ranks_per_gpu][rank]);
ASSERT_EQ(res_non_local_cols,
exp_non_local_cols[fused][ranks_per_gpu][rank]);
}

TEST_P(DistributedMatrixFixtureFormat, canApplyCorrectly)
Expand All @@ -501,32 +556,13 @@ TEST_P(DistributedMatrixFixtureFormat, canApplyCorrectly)
exec.get_ref_exec(), comm, global_vec_dim, local_vec_dim, 1));
x->fill(0);

std::map<int, vec_vec_s> exp_x_local;


exp_x_local.emplace(1, vec_vec_s{{4, 5, 5, 5, 6, 7, 5, 7, 10},
{5, 5, 4, 7, 6, 5, 10, 7, 5},
{5, 7, 10, 5, 6, 7, 4, 5, 8},
{6, 6, 5, 6, 6, 5, 5, 5, 4}});

std::vector<scalar> exp_x_local_2_1 = {4, 5, 5, 5, 6, 6, 5, 6, 6,
5, 5, 4, 6, 6, 5, 6, 6, 5};
std::vector<scalar> exp_x_local_2_2 = {5, 6, 6, 5, 6, 6, 4, 5, 5,
6, 6, 5, 6, 6, 5, 5, 5, 4};
exp_x_local.emplace(2, vec_vec_s{exp_x_local_2_1, {}, exp_x_local_2_2, {}});

std::vector<scalar> exp_x_local_4 = {4, 5, 5, 5, 6, 6, 5, 6, 6, 5, 5, 4,
6, 6, 5, 6, 6, 5, 5, 6, 6, 5, 6, 6,
4, 5, 5, 6, 6, 5, 6, 6, 5, 5, 5, 4};
exp_x_local.emplace(4, vec_vec_s{exp_x_local_4, {}, {}, {}});

// Act
distributed->apply(b, x);
auto x_local = std::vector<scalar>(
auto res_x = std::vector<scalar>(
x->get_local_vector()->get_const_values(),
x->get_local_vector()->get_const_values() + local_vec_dim[0]);

ASSERT_EQ(x_local, exp_x_local[ranks_per_gpu][rank]);
ASSERT_EQ(res_x, exp_x[fused][ranks_per_gpu][rank]);
}

int main(int argc, char *argv[])
Expand Down

0 comments on commit 30947e3

Please sign in to comment.