From 3a5b2c89dfcbeca604ee5a88969e4e154c6b813e Mon Sep 17 00:00:00 2001 From: shizhibao Date: Wed, 11 Nov 2020 17:31:39 +0800 Subject: [PATCH] UT: fix ucg ut framework --- test/gtest/ucg/test_builtin.cc | 67 +++++- test/gtest/ucg/test_cb.cc | 6 - test/gtest/ucg/test_coll_algorithm.cc | 323 +++++++++++++------------- test/gtest/ucg/test_collective.cc | 63 +++-- test/gtest/ucg/test_group.cc | 17 +- test/gtest/ucg/test_op.cc | 77 ++++-- test/gtest/ucg/test_op.h | 20 +- test/gtest/ucg/test_plan.cc | 56 +++-- test/gtest/ucg/test_step.cc | 6 + test/gtest/ucg/test_ucg_context.cc | 4 +- test/gtest/ucg/ucg_plan_test.h | 43 ++-- test/gtest/ucg/ucg_test.cc | 85 ++++--- test/gtest/ucg/ucg_test.h | 34 ++- 13 files changed, 458 insertions(+), 343 deletions(-) diff --git a/test/gtest/ucg/test_builtin.cc b/test/gtest/ucg/test_builtin.cc index f709eea0f86..f4a8144b289 100644 --- a/test/gtest/ucg/test_builtin.cc +++ b/test/gtest/ucg/test_builtin.cc @@ -10,7 +10,50 @@ extern "C" { #include "ucg_plan_test.h" -TEST_F(ucg_plan_test, ucg_plan_1_test) { +ucg_plan_test::ucg_plan_test() +{ + m_builtin_ctx = NULL; + m_planc = NULL; + m_group_params = NULL; + m_coll_params = NULL; + m_group = NULL; + m_all_rank_infos.clear(); +} + +ucg_plan_test::ucg_plan_test(size_t node_cnt, size_t ppn, unsigned myrank) +{ + m_planc = NULL; + m_all_rank_infos.clear(); + m_resource_factory->create_balanced_rank_info(m_all_rank_infos, node_cnt, ppn); + m_group_params = m_resource_factory->create_group_params(m_all_rank_infos[myrank], m_all_rank_infos); + m_group = m_resource_factory->create_group(m_group_params, m_ucg_worker); + m_coll_params = m_resource_factory->create_collective_params(UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, + 0, NULL, 1, NULL, 4, NULL, NULL); + m_coll_type.modifiers = UCG_GROUP_COLLECTIVE_MODIFIER_AGGREGATE; + m_coll_type.root = 0; + ucg_plan_select(m_group, NULL, m_coll_params, &m_planc); + m_builtin_ctx = (ucg_builtin_group_ctx_t *)UCG_GROUP_TO_COMPONENT_CTX(ucg_builtin_component, m_group); +} + +ucg_plan_test::~ucg_plan_test() +{ + if (m_coll_params != NULL) { + delete m_coll_params; + m_coll_params = NULL; + } + + ucg_group_destroy(m_group); + + if (m_group_params != NULL) { + delete m_group_params; + m_group_params = NULL; + } + + m_all_rank_infos.clear(); +} + + +TEST(ucg_plan_test, ucg_plan_1_test) { ucg_plan_test example(4, 8, 0); size_t msg_size = UCG_GROUP_MED_MSG_SIZE - 1024; @@ -24,7 +67,7 @@ TEST_F(ucg_plan_test, ucg_plan_1_test) { } -TEST_F(ucg_plan_test, ucg_plan_2_test) { +TEST(ucg_plan_test, ucg_plan_2_test) { ucg_plan_test example(4, 8, 0); size_t msg_size = UCG_GROUP_MED_MSG_SIZE + 1024; @@ -37,7 +80,7 @@ TEST_F(ucg_plan_test, ucg_plan_2_test) { EXPECT_EQ(UCS_OK, ret); } -TEST_F(ucg_plan_test, ucg_plan_3_test) { +TEST(ucg_plan_test, ucg_plan_3_test) { ucg_plan_test example(4, 8, 0); size_t msg_size = UCG_GROUP_MED_MSG_SIZE - 1024; @@ -50,7 +93,7 @@ TEST_F(ucg_plan_test, ucg_plan_3_test) { EXPECT_EQ(UCS_OK, ret); } /* -TEST_F(ucg_plan_test, ucg_plan_4_test) { +TEST(ucg_plan_test, ucg_plan_4_test) { ucg_plan_test example(4, 8, 0); size_t msg_size = UCG_GROUP_MED_MSG_SIZE + 1024; @@ -63,7 +106,7 @@ TEST_F(ucg_plan_test, ucg_plan_4_test) { EXPECT_EQ(UCS_OK, ret); } */ -TEST_F(ucg_plan_test, algorithm_selection) { +TEST(ucg_plan_test, algorithm_selection) { ucs_status_t ret; unsigned idx; for (idx = 0; idx < UCG_ALGORITHM_ALLREDUCE_LAST; idx++) { @@ -83,7 +126,7 @@ TEST_F(ucg_plan_test, algorithm_selection) { } -TEST_F(ucg_plan_test, topo_level) { +TEST(ucg_plan_test, topo_level) { ucs_status_t ret; ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_NODE; enum ucg_group_member_distance domain_distance = UCG_GROUP_MEMBER_DISTANCE_SELF; @@ -97,7 +140,7 @@ TEST_F(ucg_plan_test, topo_level) { ASSERT_EQ(UCS_OK, ret); } -TEST_F(ucg_plan_test, check_continus_number) { +TEST(ucg_plan_test, check_continus_number) { ucg_group_params_t group_params; group_params.member_count = 4; group_params.topo_map = (char **)malloc(sizeof(char *) * group_params.member_count); @@ -120,7 +163,7 @@ TEST_F(ucg_plan_test, check_continus_number) { ASSERT_EQ(1u, discount); } -TEST_F(ucg_plan_test, choose_type) { +TEST(ucg_plan_test, choose_type) { enum ucg_collective_modifiers flags[] = \ { UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_DESTINATION, \ @@ -166,7 +209,7 @@ TEST_F(ucg_plan_test, choose_type) { /* TODO: add verification to below functions */ /* -TEST_F(ucg_plan_test, plan_decision_in_discontinuous_case) { +TEST(ucg_plan_test, plan_decision_in_discontinuous_case) { ucg_plan_test example(2, 2, 0); unsigned op_num = 3; enum ucg_collective_modifiers modifiers[op_num] = { (enum ucg_collective_modifiers ) (UCG_GROUP_COLLECTIVE_MODIFIER_BROADCAST | UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE), \ @@ -181,7 +224,7 @@ TEST_F(ucg_plan_test, plan_decision_in_discontinuous_case) { } } */ -TEST_F(ucg_plan_test, plan_decision_fixed) { +TEST(ucg_plan_test, plan_decision_fixed) { ucg_plan_test example(2, 2, 0); unsigned op_num = 3; enum ucg_collective_modifiers modifiers[op_num] = { (enum ucg_collective_modifiers ) (UCG_GROUP_COLLECTIVE_MODIFIER_BROADCAST | UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE), \ @@ -204,7 +247,7 @@ TEST_F(ucg_plan_test, plan_decision_fixed) { } } -TEST_F(ucg_plan_test, plan_chooose_ops) { +TEST(ucg_plan_test, plan_chooose_ops) { ucg_plan_test example(2, 2, 0); unsigned op_num = 3; enum ucg_collective_modifiers modifiers[op_num] = { (enum ucg_collective_modifiers ) (UCG_GROUP_COLLECTIVE_MODIFIER_BROADCAST | UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE), \ @@ -216,7 +259,7 @@ TEST_F(ucg_plan_test, plan_chooose_ops) { } } -TEST_F(ucg_plan_test, test_algorithm_decision) { +TEST(ucg_plan_test, test_algorithm_decision) { ucg_plan_test example(2, 2, 0); ucs_status_t ret = ucg_builtin_algorithm_decision(&(example.m_coll_type), 1024, example.m_group_params, example.m_coll_params, example.m_planc); ASSERT_EQ(UCS_OK, ret); diff --git a/test/gtest/ucg/test_cb.cc b/test/gtest/ucg/test_cb.cc index 144e195fb77..ea5006c5703 100644 --- a/test/gtest/ucg/test_cb.cc +++ b/test/gtest/ucg/test_cb.cc @@ -101,9 +101,6 @@ TEST_F(ucg_cb_test, test_op_cb_init) { params->send.buf = MPI_IN_PLACE; ucg_builtin_init_reduce((ucg_builtin_op_t *)op); ASSERT_EQ(recv_buf[0], recv_buf[0]); - - ucg_builtin_component.destroy(group); - delete group; } TEST_F(ucg_cb_test, test_op_cb_final) { @@ -688,7 +685,4 @@ TEST_F(ucg_cb_test, test_op_consider_optimization) { ret = ucg_builtin_op_consider_optimization((ucg_builtin_op_t*)op, (ucg_builtin_config_t*)plan->planner->plan_config); ASSERT_EQ(UCS_OK, ret); - - ucg_builtin_component.destroy(group); - delete group; } diff --git a/test/gtest/ucg/test_coll_algorithm.cc b/test/gtest/ucg/test_coll_algorithm.cc index eda1075e8e8..73cd37046bc 100644 --- a/test/gtest/ucg/test_coll_algorithm.cc +++ b/test/gtest/ucg/test_coll_algorithm.cc @@ -14,184 +14,177 @@ extern "C" { #include "ucg_test.h" #include "ucg_plan_test.h" -TEST_F(ucg_plan_test, test_ring) { - - ucg_plan_test example1(4, 8, 0); - ucg_builtin_plan_t *plan; - ucs_status_t ret = ucg_builtin_ring_create(example1.m_builtin_ctx, UCG_PLAN_RING, - (ucg_builtin_config_t *) example1.m_planc->plan_config, - example1.m_group_params, &example1.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - - ucg_plan_test example2(4, 7, 0); - ret = ucg_builtin_ring_create(example2.m_builtin_ctx, UCG_PLAN_RING, - (ucg_builtin_config_t *) example2.m_planc->plan_config, example2.m_group_params, - &example2.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example3(1, 2, 0); - ret = ucg_builtin_ring_create(example3.m_builtin_ctx, UCG_PLAN_RING, - (ucg_builtin_config_t *) example3.m_planc->plan_config, example3.m_group_params, - &example3.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); +TEST(ucg_plan_test, test_ring) { + ucs_status_t ret; + ucg_plan_test *obj = NULL; + ucg_builtin_plan_t *plan = NULL; + ucg_plan_test_data_t data[] = { + {4, 8, 0}, + {4, 7, 0}, + {1, 2, 0}, + }; + + for (unsigned i = 0; i < sizeof(data) / sizeof(data[0]); i++) { + obj = new ucg_plan_test(data[i].node_cnt, data[i].ppn, data[i].myrank); + ret = ucg_builtin_ring_create(obj->m_builtin_ctx, UCG_PLAN_RING, + (ucg_builtin_config_t *)obj->m_planc->plan_config, + obj->m_group_params, &obj->m_coll_type, &plan); + delete obj; + ASSERT_EQ(UCS_OK, ret); + } } -TEST_F(ucg_plan_test, test_recursive) { - - size_t node_cnt = 2; - size_t ppn = 2; - ucg_builtin_plan_t *plan; +TEST(ucg_plan_test, test_recursive) { ucs_status_t ret; - unsigned idx; + ucg_plan_test *obj = NULL; + ucg_builtin_plan_t *plan = NULL; + ucg_plan_test_data_t data[] = { + {2, 2, 0}, {2, 2, 1}, {2, 2, 2}, {2, 2, 3}, + {1, 3, 0}, {1, 3, 1}, {1, 3, 2}, + }; + + for (unsigned i = 0; i < sizeof(data) / sizeof(data[0]); i++) { + obj = new ucg_plan_test(data[i].node_cnt, data[i].ppn, data[i].myrank); + ret = ucg_builtin_recursive_create(obj->m_builtin_ctx, UCG_PLAN_RECURSIVE, + (ucg_builtin_config_t *)obj->m_planc->plan_config, + obj->m_group_params, &obj->m_coll_type, &plan); + delete obj; - for (idx = 0; idx < (node_cnt * ppn); idx++) { - ucg_plan_test example1(node_cnt, ppn, idx); - ret = ucg_builtin_recursive_create(example1.m_builtin_ctx, UCG_PLAN_RECURSIVE, - (ucg_builtin_config_t *) example1.m_planc->plan_config, - example1.m_group_params, &example1.m_coll_type, &plan); ASSERT_EQ(UCS_OK, ret); } +} - node_cnt = 1; - ppn = 3; - for (idx = 0; idx < (node_cnt * ppn); idx++) { - ucg_plan_test example1(node_cnt, ppn, idx); - ret = ucg_builtin_recursive_create(example1.m_builtin_ctx, UCG_PLAN_RECURSIVE, - (ucg_builtin_config_t *) example1.m_planc->plan_config, - example1.m_group_params, &example1.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); +static void ucg_algo_set(int option) +{ + switch (option) { + case 0: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 1; + ucg_algo.kmtree = 1; + return; + + case 1: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 0; + ucg_algo.kmtree = 1; + return; + + case 2: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 0; + ucg_algo.kmtree = 0; + ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_NODE; + return; + + case 3: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 0; + ucg_algo.kmtree = 0; + return; + + case 4: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 0; + ucg_algo.kmtree = 0; + ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; + return; + + case 5: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 1; + ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; + return; + + case 6: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 1; + ucg_algo.kmtree = 1; + ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; + return; + + case 7: + ucg_algo.topo = 1; + return; + + case 8: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 1; + return; + + case 9: + ucg_algo.topo = 1; + ucg_algo.bmtree = 1; + ucg_algo.recursive = 0; + ucg_algo.kmtree_intra = 1; + ucg_algo.kmtree = 1; + return; + + default: + return; } - } -TEST_F(ucg_plan_test, test_binomial_tree) { - - ucg_plan_test example1(4, 8, 0); - ucg_builtin_plan_t *plan; - ucs_status_t ret = ucg_builtin_binomial_tree_create(example1.m_builtin_ctx, UCG_PLAN_TREE_FANOUT, - (ucg_builtin_config_t *) example1.m_planc->plan_config, - example1.m_group_params, &example1.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - size_t node_cnt = 1; - size_t ppn = 3; - for (unsigned idx = 0; idx < (node_cnt * ppn); idx++) { - ucg_plan_test example(node_cnt, ppn, idx); - ret = ucg_builtin_binomial_tree_create(example.m_builtin_ctx, UCG_PLAN_TREE_FANOUT, - (ucg_builtin_config_t *) example.m_planc->plan_config, - example.m_group_params, &example.m_coll_type, &plan); +TEST(ucg_plan_test, test_binomial_tree) { + unsigned i; + ucs_status_t ret; + ucg_plan_test *obj = NULL; + ucg_builtin_plan_t *plan = NULL; + ucg_plan_test_data_algo_t fanout[] = { + {{4, 8, 0}, -1}, + {{1, 3, 0}, -1}, + {{1, 3, 1}, -1}, + {{1, 3, 2}, -1}, + {{4, 8, 0}, 0}, + {{4, 8, 0}, 1}, + {{2, 1, 0}, 2}, + }; + ucg_plan_test_data_algo_t fanin_out[] = { + {{3, 8, 0}, 3}, + {{4, 8, 0}, 4}, + {{4, 8, 0}, 5}, + {{4, 8, 0}, 6}, + {{4, 7, 0}, 7}, + {{4, 8, 0}, 8}, + {{4, 8, 0}, 9}, + }; + + for (i = 0; i < sizeof(fanout) / sizeof(fanout[0]); i++) { + obj = new ucg_plan_test(fanout[i].data.node_cnt, fanout[i].data.ppn, fanout[i].data.myrank); + ucg_algo_set(fanout[i].algo_id); + ret = ucg_builtin_binomial_tree_create(obj->m_builtin_ctx, UCG_PLAN_TREE_FANOUT, + (ucg_builtin_config_t *)obj->m_planc->plan_config, + obj->m_group_params, &obj->m_coll_type, &plan); + delete obj; + ASSERT_EQ(UCS_OK, ret); } - ucg_plan_test example2(4, 7, 0); - ucg_algo.topo = 1; - ret = ucg_builtin_binomial_tree_create(example2.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example2.m_planc->plan_config, - example2.m_group_params, &example2.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example3(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 1; - ret = ucg_builtin_binomial_tree_create(example3.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example3.m_planc->plan_config, - example3.m_group_params, &example3.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example4(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 1; - ucg_algo.kmtree = 1; - ret = ucg_builtin_binomial_tree_create(example4.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example4.m_planc->plan_config, - example4.m_group_params, &example4.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example5(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 1; - ucg_algo.kmtree = 1; - ret = ucg_builtin_binomial_tree_create(example5.m_builtin_ctx, UCG_PLAN_TREE_FANOUT, - (ucg_builtin_config_t *) example5.m_planc->plan_config, - example5.m_group_params, &example5.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example6(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 0; - ucg_algo.kmtree = 1; - ret = ucg_builtin_binomial_tree_create(example6.m_builtin_ctx, UCG_PLAN_TREE_FANOUT, - (ucg_builtin_config_t *) example6.m_planc->plan_config, - example6.m_group_params, &example6.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example7(3, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 0; - ucg_algo.kmtree = 0; - ret = ucg_builtin_binomial_tree_create(example7.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example7.m_planc->plan_config, - example7.m_group_params, &example7.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example8(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 0; - ucg_algo.kmtree = 0; - ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; - ret = ucg_builtin_binomial_tree_create(example8.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example8.m_planc->plan_config, - example8.m_group_params, &example8.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example9(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 1; - ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; - ret = ucg_builtin_binomial_tree_create(example9.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example9.m_planc->plan_config, - example9.m_group_params, &example9.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example10(4, 8, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 1; - ucg_algo.kmtree = 1; - ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_SOCKET; - ret = ucg_builtin_binomial_tree_create(example10.m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, - (ucg_builtin_config_t *) example10.m_planc->plan_config, - example10.m_group_params, &example10.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); - - ucg_plan_test example11(2, 1, 0); - ucg_algo.topo = 1; - ucg_algo.bmtree = 1; - ucg_algo.recursive = 0; - ucg_algo.kmtree_intra = 0; - ucg_algo.kmtree = 0; - ucg_algo.topo_level = UCG_GROUP_HIERARCHY_LEVEL_NODE; - ret = ucg_builtin_binomial_tree_create(example11.m_builtin_ctx, UCG_PLAN_TREE_FANOUT, - (ucg_builtin_config_t *) example11.m_planc->plan_config, - example11.m_group_params, &example11.m_coll_type, &plan); - ASSERT_EQ(UCS_OK, ret); -} + for (i = 0; i < sizeof(fanin_out) / sizeof(fanin_out[0]); i++) { + obj = new ucg_plan_test(fanin_out[i].data.node_cnt, fanin_out[i].data.ppn, fanin_out[i].data.myrank); + ucg_algo_set(fanin_out[i].algo_id); + ret = ucg_builtin_binomial_tree_create(obj->m_builtin_ctx, UCG_PLAN_TREE_FANIN_FANOUT, + (ucg_builtin_config_t *)obj->m_planc->plan_config, + obj->m_group_params, &obj->m_coll_type, &plan); + delete obj; + ASSERT_EQ(UCS_OK, ret); + } +} diff --git a/test/gtest/ucg/test_collective.cc b/test/gtest/ucg/test_collective.cc index ea0d4562eeb..39255f3de13 100644 --- a/test/gtest/ucg/test_collective.cc +++ b/test/gtest/ucg/test_collective.cc @@ -8,35 +8,61 @@ using namespace std; class ucg_collective_test : public ucg_test { +public: + ucg_collective_test(); + + virtual ~ucg_collective_test(); + protected: - ucg_collective_test() { - init(); - } + vector m_all_rank_infos; + ucg_group_params_t *m_group_params; + ucg_group_params_t *m_group2_params; + ucg_collective_params_t *m_coll_params; + ucg_group_h m_group; + ucg_group_h m_group2; +}; + +ucg_collective_test::ucg_collective_test() +{ + m_all_rank_infos.clear(); + m_resource_factory->create_balanced_rank_info(m_all_rank_infos, 2, 2); + m_group_params = m_resource_factory->create_group_params(m_all_rank_infos[0], m_all_rank_infos); + m_group2_params = m_resource_factory->create_group_params(m_all_rank_infos[1], m_all_rank_infos); + m_group = m_resource_factory->create_group(m_group_params, m_ucg_worker); + m_group2 = m_resource_factory->create_group(m_group2_params, m_ucg_worker); + m_coll_params = m_resource_factory->create_collective_params( + UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, + 0, NULL, 1, NULL, 4, NULL, NULL); +} - ~ucg_collective_test() {} +ucg_collective_test::~ucg_collective_test() +{ + if (m_coll_params != NULL) { + delete m_coll_params; + m_coll_params = NULL; + } - void init() { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(2, 2); + ucg_group_destroy(m_group2); + ucg_group_destroy(m_group); - m_group = m_resource_factory->create_group(all_rank_infos[0], all_rank_infos, m_ucg_worker); - m_group2 = m_resource_factory->create_group(all_rank_infos[1], all_rank_infos, m_ucg_worker); + if (m_group2_params != NULL) { + delete m_group2_params; + m_group2_params = NULL; + } - m_coll_params = m_resource_factory->create_collective_params( - UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, 0, NULL, 1, - NULL, 4, NULL, NULL); + if (m_group_params != NULL) { + delete m_group_params; + m_group_params = NULL; } -protected: - ucg_group_h m_group; - ucg_group_h m_group2; - ucg_collective_params_t *m_coll_params; -}; + m_all_rank_infos.clear(); +} + TEST_F(ucg_collective_test, test_collective_create) { ucg_coll_h coll = NULL; ucs_status_t ret = ucg_collective_create(m_group, m_coll_params, &coll); - ucg_collective_destroy(coll); ASSERT_EQ(UCS_OK, ret); } @@ -48,7 +74,6 @@ TEST_F(ucg_collective_test, test_collective_start_nb) { EXPECT_EQ(UCS_OK, retC); ucs_status_ptr_t retP = ucg_collective_start_nb(coll); - ucg_collective_destroy(coll); ASSERT_TRUE(retP != NULL); } @@ -61,7 +86,6 @@ TEST_F(ucg_collective_test, test_collective_start_nbr) { EXPECT_EQ(UCS_OK, retC); ucg_collective_start_nbr(coll, req); - ucg_collective_destroy(coll); //ASSERT_EQ(UCS_OK, retS); } @@ -72,7 +96,6 @@ TEST_F(ucg_collective_test, test_collective_destroy) { ucs_status_t ret = ucg_collective_create(m_group, m_coll_params, &coll); EXPECT_EQ(UCS_OK, ret); - ucg_collective_destroy(coll); //TODO ASSERT_TRUE(true); } diff --git a/test/gtest/ucg/test_group.cc b/test/gtest/ucg/test_group.cc index e6b710e3bfa..551194d6106 100644 --- a/test/gtest/ucg/test_group.cc +++ b/test/gtest/ucg/test_group.cc @@ -8,16 +8,23 @@ using namespace std; class ucg_group_test : public ucg_test { -protected: +public: ucg_group_test() { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(2, 2); - - m_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); + m_all_rank_infos.clear(); + m_resource_factory->create_balanced_rank_info(m_all_rank_infos, 2, 2); + m_params = m_resource_factory->create_group_params(m_all_rank_infos[0], m_all_rank_infos); } - ~ucg_group_test() {} + ~ucg_group_test() { + if (m_params != NULL) { + delete m_params; + m_params = NULL; + } + m_all_rank_infos.clear(); + } protected: + vector m_all_rank_infos; ucg_group_params_t *m_params; }; diff --git a/test/gtest/ucg/test_op.cc b/test/gtest/ucg/test_op.cc index 4426d4e3afb..8331b8bfde2 100644 --- a/test/gtest/ucg/test_op.cc +++ b/test/gtest/ucg/test_op.cc @@ -7,10 +7,28 @@ using namespace std; -ucg_builtin_plan_phase_t *ucg_op_test::create_phase(ucg_builtin_plan_method_type method) const { +ucg_op_test::ucg_op_test() +{ + num_procs = 4; +}; + +ucg_op_test::~ucg_op_test() +{ +}; + +ucg_builtin_plan_phase_t *ucg_op_test::create_phase(ucg_builtin_plan_method_type method) +{ ucg_builtin_plan_phase_t *phase = new ucg_builtin_plan_phase_t(); + init_phase(method, phase); + + return phase; +} + +void ucg_op_test::init_phase(ucg_builtin_plan_method_type method, ucg_builtin_plan_phase_t *phase) +{ uct_md_attr_t *md_attr = new uct_md_attr_t(); + md_attr->cap.max_reg = 8128; phase->md_attr = md_attr; @@ -34,28 +52,37 @@ ucg_builtin_plan_phase_t *ucg_op_test::create_phase(ucg_builtin_plan_method_type phase->recv_thresh.max_bcopy_max = phase->send_thresh.max_bcopy_max; phase->recv_thresh.max_zcopy_one = phase->send_thresh.max_zcopy_one; phase->recv_thresh.md_attr_cap_max_reg = 8128; +} - return phase; +void ucg_op_test::destroy_phase(ucg_builtin_plan_phase_t *phase) +{ + if (phase != NULL) { + if (phase->md_attr != NULL) { + delete phase->md_attr; + phase->md_attr = NULL; + } + + delete phase; + } } -ucg_plan_t *ucg_op_test::create_plan(unsigned phs_cnt, ucg_collective_params_t *params, ucg_group_h group) const { - ucg_plan_t *plan = new ucg_plan_t(); +ucg_plan_t *ucg_op_test::create_plan(unsigned phs_cnt, ucg_collective_params_t *params, ucg_group_h group) +{ + ucg_builtin_plan_t *builtin_plan = (ucg_builtin_plan_t *)malloc(sizeof(ucg_builtin_plan_t) + + phs_cnt * sizeof(ucg_builtin_plan_phase_t)); + ucg_plan_t *plan = &builtin_plan->super; + ucg_plan_component_t *planc = NULL; + plan->group_id = 1; plan->my_index = 0; plan->group = group; - - ucg_plan_component_t *planc = NULL; ucg_plan_select(group, NULL, params, &planc); plan->planner = planc; - - size_t alloc_size = sizeof(ucg_builtin_plan_t) + - (phs_cnt * sizeof(ucg_builtin_plan_phase_t)); - ucg_builtin_plan_t *builtin_plan = (ucg_builtin_plan_t*)malloc(alloc_size); - builtin_plan->super = *plan; builtin_plan->am_id = 1; builtin_plan->resend = NULL; builtin_plan->slots = NULL; builtin_plan->phs_cnt = phs_cnt; + ucs_mpool_ops_t ops = { ucs_mpool_chunk_malloc, ucs_mpool_chunk_free, @@ -63,44 +90,52 @@ ucg_plan_t *ucg_op_test::create_plan(unsigned phs_cnt, ucg_collective_params_t * NULL }; size_t op_size = sizeof(ucg_builtin_op_t) + builtin_plan->phs_cnt * sizeof(ucg_builtin_op_step_t); + ucs_mpool_init(&builtin_plan->op_mp, 0, op_size, 0, UCS_SYS_CACHE_LINE_SIZE, 1, UINT_MAX, &ops, "ucg_builtin_plan_mp"); ucs_mpool_grow(&builtin_plan->op_mp, 1); for (unsigned i = 0; i < phs_cnt; i++) { - ucg_builtin_plan_phase_t *phase = create_phase(UCG_PLAN_METHOD_RECV_TERMINAL); - builtin_plan->phss[i] = *phase; + init_phase(UCG_PLAN_METHOD_RECV_TERMINAL, &builtin_plan->phss[i]); } - return (ucg_plan_t *) builtin_plan; + return (ucg_plan_t *)builtin_plan; } -ucg_builtin_plan_t *ucg_op_test::create_method_plan(ucg_builtin_plan_method_type method) const { - ucg_builtin_plan_t *builtin_plan = new ucg_builtin_plan_t; - builtin_plan->phss[0] = *create_phase(method); +ucg_builtin_plan_t *ucg_op_test::create_method_plan(ucg_builtin_plan_method_type method) +{ + ucg_builtin_plan_t *builtin_plan = (ucg_builtin_plan_t *)malloc(sizeof(ucg_builtin_plan_t) + + sizeof(ucg_builtin_plan_phase_t)); + + init_phase(method, &builtin_plan->phss[0]); return builtin_plan; } -ucg_group_h ucg_op_test::create_group() const { +ucg_group_h ucg_op_test::create_group() +{ ucg_rank_info my_rank_info = {.rank = 0, .nodex_idx = 0, .socket_idx = 0}; ucg_rank_info other_rank_info = {.rank = 1, .nodex_idx = 0, .socket_idx = 0}; vector all_rank_infos; all_rank_infos.push_back(my_rank_info); all_rank_infos.push_back(other_rank_info); + ucg_group_params_t *group_params = m_resource_factory->create_group_params(my_rank_info, all_rank_infos); - return m_resource_factory->create_group(my_rank_info, all_rank_infos, m_ucg_worker); + return m_resource_factory->create_group(group_params, m_ucg_worker); } -static ucs_status_t mem_reg_mock(uct_md_h md, void *address, size_t length, unsigned flags, uct_mem_h *memh_p) { +ucs_status_t mem_reg_mock(uct_md_h md, void *address, size_t length, unsigned flags, uct_mem_h *memh_p) +{ // do nothing return UCS_OK; } -uct_md_h ucg_op_test::create_md() const { +uct_md_h ucg_op_test::create_md() +{ uct_md_h md = new uct_md; uct_md_ops_t *ops = new uct_md_ops_t; + ops->mem_reg = mem_reg_mock; md->ops = ops; return md; diff --git a/test/gtest/ucg/test_op.h b/test/gtest/ucg/test_op.h index 7c785c4e60a..eba921a1b3e 100644 --- a/test/gtest/ucg/test_op.h +++ b/test/gtest/ucg/test_op.h @@ -12,22 +12,24 @@ class ucg_op_test : public ucg_test { public: - ucg_op_test() { - num_procs = 4; - }; + ucg_op_test(); - ~ucg_op_test() {}; + virtual ~ucg_op_test(); protected: - ucg_builtin_plan_phase_t *create_phase(ucg_builtin_plan_method_type method) const; + ucg_builtin_plan_phase_t *create_phase(ucg_builtin_plan_method_type method); - ucg_group_h create_group() const; + void init_phase(ucg_builtin_plan_method_type method, ucg_builtin_plan_phase_t *phase); - ucg_plan_t *create_plan(unsigned phs_cnt, ucg_collective_params_t *params, ucg_group_h group) const; + void destroy_phase(ucg_builtin_plan_phase_t *phase); - ucg_builtin_plan_t *create_method_plan(ucg_builtin_plan_method_type method) const; + ucg_group_h create_group(); - uct_md_h create_md() const; + ucg_plan_t *create_plan(unsigned phs_cnt, ucg_collective_params_t *params, ucg_group_h group); + + ucg_builtin_plan_t *create_method_plan(ucg_builtin_plan_method_type method); + + uct_md_h create_md(); }; #endif diff --git a/test/gtest/ucg/test_plan.cc b/test/gtest/ucg/test_plan.cc index 83aa3aa14c3..743fd5a0418 100644 --- a/test/gtest/ucg/test_plan.cc +++ b/test/gtest/ucg/test_plan.cc @@ -9,19 +9,24 @@ using namespace std; TEST_F(ucg_test, select_plan_component) { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(4, 8); - ucg_group_h group = m_resource_factory->create_group(all_rank_infos[0], all_rank_infos, m_ucg_worker); + vector all_rank_infos; + + m_resource_factory->create_balanced_rank_info(all_rank_infos, 4, 8); + ucg_group_params_t *group_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); + ucg_group_h group = m_resource_factory->create_group(group_params, m_ucg_worker); ucg_collective_params_t *params = m_resource_factory->create_collective_params( - UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, - 0, NULL, 1, NULL, 4, NULL, NULL); - ucg_plan_component_t *planc; + UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, + 0, NULL, 1, NULL, 4, NULL, NULL); + ucg_plan_component_t *planc = NULL; ucs_status_t ret = ucg_plan_select(group, NULL, params, &planc); ASSERT_EQ(UCS_OK, ret); ASSERT_TRUE(planc != NULL); delete params; - delete group; + ucg_group_destroy(group); + delete group_params; + all_rank_infos.clear(); } TEST_F(ucg_test, create_plan) { @@ -39,38 +44,51 @@ TEST_F(ucg_test, create_plan) { } TEST_F(ucg_test, create_plan_component) { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(4, 8); - ucg_group_h group = m_resource_factory->create_group(all_rank_infos[0], all_rank_infos, m_ucg_worker); + vector all_rank_infos; + + m_resource_factory->create_balanced_rank_info(all_rank_infos, 4, 8); + ucg_group_params_t *group_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); + ucg_group_h group = m_resource_factory->create_group(group_params, m_ucg_worker); unsigned base_am_id = 23; ucg_group_id_t group_id = 0; - ucg_group_params_t *group_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); - ucs_status_t ret = ucg_builtin_component.create(&ucg_builtin_component, m_ucg_worker, group, base_am_id, group_id, - NULL, group_params); + ucs_status_t ret = ucg_builtin_component.create(&ucg_builtin_component, m_ucg_worker, group, + base_am_id, group_id, NULL, group_params); ASSERT_EQ(UCS_OK, ret); - delete group; + ucg_group_destroy(group); delete group_params; + all_rank_infos.clear(); } TEST_F(ucg_test, destroy_group) { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(4, 8); - ucg_group_h group = m_resource_factory->create_group(all_rank_infos[0], all_rank_infos, m_ucg_worker); - ucg_builtin_component.destroy(group); + vector all_rank_infos; + m_resource_factory->create_balanced_rank_info(all_rank_infos, 4, 8); + ucg_group_params_t *group_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); + ucg_group_h group = m_resource_factory->create_group(group_params, m_ucg_worker); + ucg_builtin_component.destroy(group); ASSERT_TRUE(true); - delete group; + + ucg_group_destroy(group); + delete group_params; + all_rank_infos.clear(); } TEST_F(ucg_test, progress_group) { - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(4, 8); - ucg_group_h group = m_resource_factory->create_group(all_rank_infos[0], all_rank_infos, m_ucg_worker); + vector all_rank_infos; + + m_resource_factory->create_balanced_rank_info(all_rank_infos, 4, 8); + ucg_group_params_t *group_params = m_resource_factory->create_group_params(all_rank_infos[0], all_rank_infos); + ucg_group_h group = m_resource_factory->create_group(group_params, m_ucg_worker); unsigned ret = ucg_builtin_component.progress(group); //TODO how to judge progress result? cout << "ucg_builtin_component.progress return: " << ret << endl; - delete group; + ucg_group_destroy(group); + delete group_params; + all_rank_infos.clear(); } TEST_F(ucg_test, query_plan) { diff --git a/test/gtest/ucg/test_step.cc b/test/gtest/ucg/test_step.cc index 701e7221e47..c20f0c102ab 100644 --- a/test/gtest/ucg/test_step.cc +++ b/test/gtest/ucg/test_step.cc @@ -303,6 +303,8 @@ TEST_F(ucg_step_test, test_step_execute_short) { step->flags |= UCG_BUILTIN_OP_STEP_FLAG_FRAGMENTED; step->fragment_length = sizeof(int); ret = ucg_builtin_step_execute(&slot->req, NULL); + delete iface; + step->uct_iface = NULL; ASSERT_EQ(UCS_OK, ret); } @@ -334,6 +336,8 @@ TEST_F(ucg_step_test, test_step_execute_bcopy) { step->flags |= UCG_BUILTIN_OP_STEP_FLAG_FRAGMENTED; step->fragment_length = sizeof(int); ret = ucg_builtin_step_execute(&slot->req, NULL); + delete iface; + step->uct_iface = NULL; ASSERT_EQ(UCS_OK, ret); } @@ -377,6 +381,8 @@ TEST_F(ucg_step_test, test_step_execute_zcopy) { step->zcopy.num_store = 0; ret = ucg_builtin_step_execute(&slot->req, NULL); + delete iface; + step->uct_iface = NULL; ASSERT_EQ(UCS_OK, ret); ASSERT_EQ((unsigned)0, step->zcopy.num_store); } diff --git a/test/gtest/ucg/test_ucg_context.cc b/test/gtest/ucg/test_ucg_context.cc index 2872d884517..6803a7fa306 100644 --- a/test/gtest/ucg/test_ucg_context.cc +++ b/test/gtest/ucg/test_ucg_context.cc @@ -24,7 +24,7 @@ class ucg_context_test : public ucg_test { } }; -TEST_F(ucg_context_test, minimal_field_mask) { +TEST(ucg_context_test, minimal_field_mask) { ucs::handle config; UCS_TEST_CREATE_HANDLE(ucg_config_t *, config, ucg_config_release, ucg_config_read, NULL, NULL); @@ -37,7 +37,7 @@ TEST_F(ucg_context_test, minimal_field_mask) { ucg_params_t params; VALGRIND_MAKE_MEM_UNDEFINED(¶ms, sizeof(params)); params.field_mask = UCS_BIT(0); - params.features = get_ctx_params().features; + params.features = ucg_context_test::get_ctx_params().features; UCS_TEST_CREATE_HANDLE(ucg_context_h, ucgh, ucg_cleanup, ucg_init, ¶ms, config.get()); diff --git a/test/gtest/ucg/ucg_plan_test.h b/test/gtest/ucg/ucg_plan_test.h index f8d04bfb666..fddac3816f5 100644 --- a/test/gtest/ucg/ucg_plan_test.h +++ b/test/gtest/ucg/ucg_plan_test.h @@ -10,40 +10,21 @@ using namespace std; -class ucg_plan_resource_factory; - /** * UCG_PLAN test. */ -class ucg_plan_test : public ::ucg_test { - +class ucg_plan_test : public ucg_test { public: - ucg_plan_test() {} - - ucg_plan_test(size_t node_cnt, size_t ppn, unsigned myrank) { - - vector all_rank_infos = m_resource_factory->create_balanced_rank_info(node_cnt, ppn); - - m_group = m_resource_factory->create_group(all_rank_infos[myrank], all_rank_infos, m_ucg_worker); - m_coll_params = m_resource_factory->create_collective_params(UCG_GROUP_COLLECTIVE_MODIFIER_SINGLE_SOURCE, - 0, NULL, 1, NULL, 4, NULL, NULL); + ucg_plan_test(); - m_group_params = m_resource_factory->create_group_params(all_rank_infos[myrank], all_rank_infos); + ucg_plan_test(size_t node_cnt, size_t ppn, unsigned myrank); - m_coll_type.modifiers = UCG_GROUP_COLLECTIVE_MODIFIER_AGGREGATE; - m_coll_type.root = 0; - - ucg_plan_select(m_group, NULL, m_coll_params, &m_planc); - m_builtin_ctx = (ucg_builtin_group_ctx_t *) UCG_GROUP_TO_COMPONENT_CTX(ucg_builtin_component, m_group); - } - - ~ucg_plan_test() {} + virtual ~ucg_plan_test(); virtual void TestBody() {} -protected: - public: + vector m_all_rank_infos; ucg_builtin_group_ctx_t *m_builtin_ctx; ucg_plan_component_t *m_planc; ucg_group_params_t *m_group_params; @@ -52,11 +33,17 @@ class ucg_plan_test : public ::ucg_test { ucg_group_h m_group; }; -class ucg_plan_resource_factory { -public:; -}; -#endif +typedef struct { + size_t node_cnt; + size_t ppn; + unsigned myrank; +} ucg_plan_test_data_t; +typedef struct { + ucg_plan_test_data_t data; + int algo_id; +} ucg_plan_test_data_algo_t; +#endif \ No newline at end of file diff --git a/test/gtest/ucg/ucg_test.cc b/test/gtest/ucg/ucg_test.cc index 59422035a0a..19c914bfad3 100644 --- a/test/gtest/ucg/ucg_test.cc +++ b/test/gtest/ucg/ucg_test.cc @@ -10,22 +10,38 @@ using namespace std; -ucg_test::ucg_test() { - init_ucg_component(); +static class ucg_resource_factory g_ucg_resource_factory; + +ucg_resource_factory *ucg_test::m_resource_factory = &g_ucg_resource_factory; + +ucg_test::ucg_test() +{ + m_ucg_context = NULL; + m_ucg_worker = NULL; - m_resource_factory = new ucg_resource_factory(); + init_ucg_component(); } -ucg_test::~ucg_test() { - delete m_resource_factory; +ucg_test::~ucg_test() +{ + if (m_ucg_worker != NULL) { + ucg_worker_destroy(m_ucg_worker); + m_ucg_worker = NULL; + } + + if (m_ucg_context != NULL) { + ucg_cleanup(m_ucg_context); + m_ucg_context = NULL; + } } -void ucg_test::init_ucg_component() { +void ucg_test::init_ucg_component() +{ ucg_params_t params; ucg_config_t *config = NULL; /* Read options */ - (void) ucg_config_read("MPI", NULL, &config); + (void)ucg_config_read("MPI", NULL, &config); /* Initialize UCX context */ params.field_mask = UCP_PARAM_FIELD_FEATURES | @@ -47,8 +63,7 @@ void ucg_test::init_ucg_component() { since it will be protected by worker */ params.estimated_num_eps = 0; - ucg_context_h ucg_context; - (void) ucg_init(¶ms, config, &ucg_context); + (void)ucg_init(¶ms, config, &m_ucg_context); ucg_worker_params_t work_params; @@ -57,8 +72,7 @@ void ucg_test::init_ucg_component() { work_params.thread_mode = UCS_THREAD_MODE_SINGLE; work_params.thread_mode = UCS_THREAD_MODE_SINGLE; - (void) ucg_worker_create(ucg_context, &work_params, - &m_ucg_worker); + (void)ucg_worker_create(m_ucg_context, &work_params, &m_ucg_worker); } ucg_collective_type_t ucg_test::create_allreduce_coll_type() const { @@ -115,8 +129,9 @@ ucg_collective_params_t *ucg_test::create_bcast_params() const { 0, send_buf, count, recv_buf, sizeof(int), NULL, NULL); } -ucg_builtin_config_t * -ucg_resource_factory::create_config(unsigned bcast_alg, unsigned allreduce_alg, unsigned barrier_alg) const { +ucg_builtin_config_t *ucg_resource_factory::create_config( + unsigned bcast_alg, unsigned allreduce_alg, unsigned barrier_alg) +{ ucg_builtin_config_t *config = new ucg_builtin_config_t; config->super.ft = UCG_PLAN_FT_IGNORE; @@ -141,14 +156,16 @@ ucg_resource_factory::create_config(unsigned bcast_alg, unsigned allreduce_alg, return config; } -ucs_status_t -resolve_address_callback(void *cb_group_obj, ucg_group_member_index_t index, ucg_address_t **addr, size_t *addr_len) { +ucs_status_t resolve_address_callback(void *cb_group_obj, ucg_group_member_index_t index, + ucg_address_t **addr, size_t *addr_len) +{ *addr_len = 0; return UCS_OK; } -ucg_group_params_t *ucg_resource_factory::create_group_params(const ucg_rank_info my_rank_info, - const std::vector &rank_infos) const { +ucg_group_params_t *ucg_resource_factory::create_group_params( + ucg_rank_info my_rank_info, const std::vector &rank_infos) +{ ucg_group_params_t *args = new ucg_group_params_t(); args->member_count = rank_infos.size(); args->cid = 0; @@ -179,22 +196,17 @@ ucg_group_params_t *ucg_resource_factory::create_group_params(const ucg_rank_inf return args; } -ucg_group_h -ucg_resource_factory::create_group(const ucg_rank_info my_rank_info, const std::vector &rank_infos, - ucg_worker_h ucg_worker) const { - ucg_group_params_t *params = create_group_params(my_rank_info, rank_infos); - +ucg_group_h ucg_resource_factory::create_group(const ucg_group_params_t *params, ucg_worker_h ucg_worker) +{ ucg_group_h group; ucg_group_create(ucg_worker, params, &group); return group; } -ucg_collective_params_t *ucg_resource_factory::create_collective_params(const ucg_collective_modifiers modifiers, - const ucg_group_member_index_t root, - void *send_buffer, const int count, - void *recv_buffer, - const size_t dt_len, void *dt_ext, - void *op_ext) const { +ucg_collective_params_t *ucg_resource_factory::create_collective_params( + ucg_collective_modifiers modifiers, ucg_group_member_index_t root, + void *send_buffer, int count, void *recv_buffer, size_t dt_len, void *dt_ext, void *op_ext) +{ ucg_collective_params_t *params = new ucg_collective_params_t(); params->type.modifiers = modifiers; params->type.root = root; @@ -213,13 +225,14 @@ ucg_collective_params_t *ucg_resource_factory::create_collective_params(const uc return params; } -std::vector -ucg_resource_factory::create_balanced_rank_info(const size_t nodes, const size_t ppn, const bool map_by_socket) const { - vector ret; +void ucg_resource_factory::create_balanced_rank_info(std::vector &rank_infos, + size_t nodes, size_t ppn, bool map_by_socket) +{ int rank = 0; + ucg_rank_info info; + for (size_t i = 0; i < nodes; i++) { for (size_t j = 0; j < ppn; j++) { - ucg_rank_info info; info.rank = rank++; info.nodex_idx = i; if (map_by_socket) { @@ -228,14 +241,12 @@ ucg_resource_factory::create_balanced_rank_info(const size_t nodes, const size_t info.socket_idx = 0; } - ret.push_back(info); + rank_infos.push_back(info); } } - - return ret; } - -int ucg_resource_factory::ompi_op_is_commute(void *op) { +int ompi_op_is_commute(void *op) +{ return (int) ((ucg_ompi_op *) op)->commutative; } diff --git a/test/gtest/ucg/ucg_test.h b/test/gtest/ucg/ucg_test.h index daaf85f2a50..a732d19d535 100644 --- a/test/gtest/ucg/ucg_test.h +++ b/test/gtest/ucg/ucg_test.h @@ -30,13 +30,13 @@ class ucg_test : public ::testing::Test { public: ucg_test(); - ~ucg_test(); + virtual ~ucg_test(); + ucg_context_h m_ucg_context; ucg_worker_h m_ucg_worker; protected: void SetUp() override { - //init_ucg_component(); } void TearDown() override { @@ -54,7 +54,7 @@ class ucg_test : public ::testing::Test { ucg_collective_params_t *create_bcast_params() const; - ucg_resource_factory *m_resource_factory; + static ucg_resource_factory *m_resource_factory; }; struct ucg_rank_info { @@ -69,27 +69,23 @@ struct ucg_ompi_op { class ucg_resource_factory { public: - ucg_builtin_config_t *create_config(unsigned bcast_alg, unsigned allreduce_alg, unsigned barrier_alg) const; + ucg_builtin_config_t *create_config(unsigned bcast_alg, unsigned allreduce_alg, unsigned barrier_alg); - ucg_group_h create_group(const ucg_rank_info my_rank_info, const std::vector &rank_infos, - ucg_worker_h ucg_worker) const; + ucg_group_h create_group(const ucg_group_params_t *params, ucg_worker_h ucg_worker); - ucg_group_params_t * - create_group_params(const ucg_rank_info my_rank_info, const std::vector &rank_infos) const; + ucg_group_params_t *create_group_params(ucg_rank_info my_rank_info, const std::vector &rank_infos); - ucg_collective_params_t * - create_collective_params(const ucg_collective_modifiers modifiers, const ucg_group_member_index_t root, - void *send_buffer, const int count, void *recv_buffer, const size_t dt_len, void *dt_ext, - void *op_ext) const; + ucg_collective_params_t *create_collective_params(ucg_collective_modifiers modifiers, + ucg_group_member_index_t root, + void *send_buffer, int count, + void *recv_buffer, size_t dt_len, + void *dt_ext, void *op_ext); - std::vector - create_balanced_rank_info(const size_t nodes, const size_t ppn, const bool map_by_socket = false) const; - -private: - static int ompi_op_is_commute(void *op); + void create_balanced_rank_info(std::vector &rank_infos, + size_t nodes, size_t ppn, bool map_by_socket = false); }; - -#endif +int ompi_op_is_commute(void *op); +#endif \ No newline at end of file