Skip to content

Commit

Permalink
wip refactor everything again, add HostMatrix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Nov 25, 2024
1 parent d37325c commit fca9279
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 51 deletions.
12 changes: 7 additions & 5 deletions unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ find_package(MPI REQUIRED)

# generate unit test based on a test case
macro(ogl_unit_test_case TEST CASE)
add_executable(${TEST}_${CASE} ${TEST}_${CASE}.cpp)
add_executable(${TEST}_${CASE} ${TEST}.cpp)
target_link_libraries(
${TEST}_${CASE}
OpenFOAM
Expand All @@ -31,7 +31,7 @@ macro(ogl_unit_test_case TEST CASE)
add_test(
NAME ${TEST}_${CASE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unitTests/${CASE}
COMMAND mpirun -np 4 ${CMAKE_CURRENT_BINARY_DIR}/${TEST}_${CASE} -parallel)
COMMAND mpirun -np 4 ${CMAKE_CURRENT_BINARY_DIR}/${TEST} -parallel)
endmacro()

# generate default unit test
Expand All @@ -56,8 +56,10 @@ macro(ogl_unit_test TEST)
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${TEST})
endmacro()

ogl_unit_test_case(CommunicationPattern l2d)
ogl_unit_test_case(Repartitioner1D l2d)
ogl_unit_test_case(Repartitioner2D l2d)
# ogl_unit_test_case(CommunicationPattern l2d)
#
# ogl_unit_test_case(Repartitioner1D l2d)
#
# ogl_unit_test_case(Repartitioner2D l2d)

add_subdirectory(MatrixWrapper)
9 changes: 5 additions & 4 deletions unitTests/MatrixWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

ogl_unit_test_case(HostMatrix l2d)
ogl_unit_test_case(HostMatrix p2d)
ogl_unit_test_case(HostMatrix p2ds2x2)
# ogl_unit_test_case(HostMatrix l2d)

# ogl_unit_test_case(HostMatrix p2d) ogl_unit_test_case(HostMatrix p2ds2x2)
ogl_unit_test_case(HostMatrix channels1x2x2)
ogl_unit_test_case(Distributed l2d)

# ogl_unit_test_case(Distributed l2d)

# ogl_unit_test_case(Distributed p2d)
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ TEST(HostMatrixP2D, canGenerateLocalSparsityPattern)
auto [localSparsity, nonLocalSparsity] =
hostMatrix->compute_sparsity_patterns(partition);

std::cout << __FILE__ << localSparsity->get_map()[1] << "\n";
EXPECT_EQ(localSparsity->get_nnz(), exp_local_nnz[name]);
EXPECT_EQ(localSparsity->get_rows(), exp_local_rows[name]);
EXPECT_EQ(localSparsity->get_cols(), exp_local_cols[name]);
Expand All @@ -164,27 +163,19 @@ TEST(HostMatrixP2D, canGenerateNonLocalSparsityPattern)
auto exec = ((HostMatrixEnvironment *)global_env)->exec;
auto comm = exec->get_gko_mpi_device_comm();
auto rank = exec->get_rank();
label size = 24;
auto partition{gko::share(
gko::experimental::distributed::build_partition_from_local_size<label,
label>(
exec->get_ref_exec(), *exec->get_communicator().get(), size))};
auto name = ((HostMatrixEnvironment *)global_env)->name_;
auto partition = ((HostMatrixEnvironment *)global_env)->partition_;

auto [localSparsity, nonLocalSparsity] =
hostMatrix->compute_sparsity_patterns(partition);


// we dont test the cols expected for now,
// as they are in compressed format
std::vector<label> exp_send_idx_size{30, 30, 30, 30};
EXPECT_EQ(nonLocalSparsity->get_nnz(), exp_send_idx_size[rank]);

// auto rows_res = convert_to_vector(nonLocalSparsity->row_idxs);
// EXPECT_EQ(rows_expected[rank], rows_res);
// auto mapping_res = convert_to_vector(nonLocalSparsity->ldu_mapping);
// EXPECT_EQ(mapping_expected[rank], mapping_res);
// auto cols_res = convert_to_vector(nonLocalSparsity->col_idxs);
// EXPECT_EQ(cols_expected[comm->rank()], cols_res);
EXPECT_EQ(nonLocalSparsity->get_rows(), exp_non_local_rows[name][rank]);
EXPECT_EQ(nonLocalSparsity->get_cols(), exp_non_local_cols[name][rank]);
EXPECT_EQ(nonLocalSparsity->get_map(), exp_non_local_map[name][rank]);
}


Expand Down
72 changes: 44 additions & 28 deletions unitTests/MatrixWrapper/HostMatrixData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,47 @@ std::map<std::string, std::vector<std::vector<label>>> exp_local_map{
{0, 1, 2, 3, 4, 5, 6, 7},
{0, 1, 2, 3, 4, 5, 6, 7}}}};

std::map<std::string, std::vector<std::vector<label>>> exp_non_local_rows{
{"channels1x2x2",
{{0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13,
13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 22},
{1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10, 11,
11, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18,
19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{2, 5, 8, 11, 14, 17, 20, 23},
{0, 3, 6, 9, 12, 15, 18, 21}}}};

std::map<std::string, std::vector<std::vector<label>>> exp_non_local_cols{
{"channels1x2x2",
{{1, 3, 12, 2, 4, 13, 5, 14, 4, 6, 15, 5, 7, 16, 8, 17,
7, 9, 18, 8, 10, 19, 11, 20, 10, 21, 11, 22, 23, 13, 15, 14,
16, 17, 16, 18, 17, 19, 20, 19, 21, 20, 22, 23, 22, 23},
{0, 1, 0, 1, 3, 2, 4, 3, 4, 6, 5, 7, 6, 7, 9, 8,
10, 0, 1, 12, 2, 13, 3, 12, 4, 13, 15, 5, 14, 16, 6, 15,
7, 16, 18, 8, 17, 19, 9, 18, 10, 19, 21, 11, 20, 22},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{0, 3, 6, 9, 12, 15, 18, 21},
{2, 5, 8, 11, 14, 17, 20, 23}}}};

std::map<std::string, std::vector<std::vector<label>>> exp_non_local_map{
{"channels1x2x2", {{}, {}, {}, {}, {}}}};
std::map<std::string, std::vector<std::vector<std::vector<label>>>>
exp_non_local_rows{{"channels1x2x2",
{{{9, 10, 11, 21, 22, 23},
{12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}},
{{0, 1, 2, 12, 13, 14},
{12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{12, 15, 18, 21, 13, 16, 19, 22, 14, 17, 20, 23},
{9, 10, 11, 21, 22, 23}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{12, 15, 18, 21, 13, 16, 19, 22, 14, 17, 20, 23},
{0, 1, 2, 12, 13, 14}}}}};

std::map<std::string, std::vector<std::vector<std::vector<label>>>>
exp_non_local_cols{{"channels1x2x2",
{{{9, 10, 11, 21, 22, 23},
{12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}},
{{0, 1, 2, 12, 13, 14},
{12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
{0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{12, 15, 18, 21, 13, 16, 19, 22, 14, 17, 20, 23},
{9, 10, 11, 21, 22, 23}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{12, 15, 18, 21, 13, 16, 19, 22, 14, 17, 20, 23},
{0, 1, 2, 12, 13, 14}}}}};

std::map<std::string, std::vector<std::vector<std::vector<label>>>>
exp_non_local_map{{"channels1x2x2",
{{{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}},
{{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5}}}}};

0 comments on commit fca9279

Please sign in to comment.