Skip to content

Commit e240d51

Browse files
committed
Unify task namespaces and refactor common functionality.
Replaced per-implementation task namespaces with a unified namespace `nesterov_a_test_task`. Introduced a common header to centralize shared definitions. Standardized task inheritance by introducing `BaseTask` and refactored related boilerplate for consistency.
1 parent 84cc083 commit e240d51

18 files changed

Lines changed: 161 additions & 120 deletions

File tree

modules/core/perf/include/perf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ struct PerfResults {
2424
template <typename InType, typename OutType>
2525
class Perf {
2626
public:
27-
// Init performance analysis with initialized task and initialized data
27+
// Init performance analysis with an initialized task and initialized data
2828
explicit Perf(const TaskPtr<InType, OutType>& task_ptr) : task_(task_ptr) {
29-
task_ptr->GetStateOfTesting() = Task<InType, OutType>::StateOfTesting::kPerf;
29+
task_ptr->GetStateOfTesting() = StateOfTesting::kPerf;
3030
}
3131
// Check performance of full task's pipeline: PreProcessing() ->
3232
// Validation() -> Run() -> PostProcessing()

modules/core/task/include/task.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ using namespace std::chrono;
1717

1818
namespace ppc::core {
1919

20-
// Memory of inputs and outputs need to be initialized before create object of
20+
enum TypeOfTask : uint8_t { kALL, kMPI, kOMP, kSEQ, kSTL, kTBB, kUnknown };
21+
enum StateOfTesting : uint8_t { kFunc, kPerf };
22+
23+
// Memory of inputs and outputs need to be initialized before create an object of
2124
// Task class
2225
template <typename InType, typename OutType>
2326
class Task {
2427
public:
25-
enum StateOfTesting : uint8_t { kFunc, kPerf };
26-
2728
explicit Task(StateOfTesting /*state_of_testing*/ = StateOfTesting::kFunc) {
2829
auto custom_terminate = []() {
2930
std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT! \n"
@@ -67,6 +68,9 @@ class Task {
6768
// get state of testing
6869
StateOfTesting &GetStateOfTesting() { return state_of_testing_; }
6970

71+
// get a type of task
72+
static constexpr TypeOfTask GetTypeOfTask() { return TypeOfTask::kUnknown; }
73+
7074
InType &GetInput() { return input_; }
7175

7276
OutType &GetOutput() { return output_; }

modules/core/util/include/test_util.hpp

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace ppc::util {
99

10-
enum TestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
10+
enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
1111

1212
inline std::string GetStringParamName(ppc::core::PerfResults::TypeOfRunning type_of_running) {
1313
if (type_of_running == core::PerfResults::kTaskRun) {
@@ -19,6 +19,28 @@ inline std::string GetStringParamName(ppc::core::PerfResults::TypeOfRunning type
1919
return "none";
2020
}
2121

22+
inline std::string GetStringTaskType(ppc::core::TypeOfTask type_of_task) {
23+
if (type_of_task == ppc::core::TypeOfTask::kALL) {
24+
return "all";
25+
}
26+
if (type_of_task == ppc::core::TypeOfTask::kSTL) {
27+
return "stl";
28+
}
29+
if (type_of_task == ppc::core::TypeOfTask::kOMP) {
30+
return "omp";
31+
}
32+
if (type_of_task == ppc::core::TypeOfTask::kMPI) {
33+
return "mpi";
34+
}
35+
if (type_of_task == ppc::core::TypeOfTask::kTBB) {
36+
return "tbb";
37+
}
38+
if (type_of_task == ppc::core::TypeOfTask::kSEQ) {
39+
return "seq";
40+
}
41+
return "unknown";
42+
}
43+
2244
template <typename InType, typename OutType, typename TestType = void>
2345
using FuncTestParam = std::tuple<std::function<ppc::core::TaskPtr<InType, OutType>(InType)>, std::string, TestType>;
2446

@@ -32,8 +54,8 @@ template <typename InType, typename OutType>
3254
class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, OutType>> {
3355
public:
3456
static std::string CustomPerfTestName(const ::testing::TestParamInfo<PerfTestParam<InType, OutType>>& info) {
35-
return ppc::util::GetStringParamName(std::get<TestParamIndex::kTestParams>(info.param)) + "_" +
36-
std::get<TestParamIndex::kNameTest>(info.param);
57+
return ppc::util::GetStringParamName(std::get<GTestParamIndex::kTestParams>(info.param)) + "_" +
58+
std::get<GTestParamIndex::kNameTest>(info.param);
3759
}
3860

3961
protected:
@@ -42,9 +64,9 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
4264
virtual InType GetTestInputData() = 0;
4365

4466
void ExecuteTest(const PerfTestParam<InType, OutType>& perf_test_param) {
45-
auto task_getter = std::get<TestParamIndex::kTaskGetter>(perf_test_param);
46-
auto test_name = std::get<TestParamIndex::kNameTest>(perf_test_param);
47-
auto mode = std::get<TestParamIndex::kTestParams>(perf_test_param);
67+
auto task_getter = std::get<GTestParamIndex::kTaskGetter>(perf_test_param);
68+
auto test_name = std::get<GTestParamIndex::kNameTest>(perf_test_param);
69+
auto mode = std::get<GTestParamIndex::kTestParams>(perf_test_param);
4870

4971
task_ = task_getter(GetTestInputData());
5072
ppc::core::Perf perf(task_);
@@ -74,10 +96,14 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
7496
ppc::core::TaskPtr<InType, OutType> task_;
7597
};
7698

77-
#define ADD_PERF_MODES(TaskType, InputTypeParam) \
78-
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, ppc::util::GetNamespace<TaskType>(), \
79-
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
80-
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, ppc::util::GetNamespace<TaskType>(), \
99+
#define ADD_PERF_MODES(TaskType, InputTypeParam) \
100+
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
101+
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
102+
ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \
103+
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
104+
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
105+
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
106+
ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \
81107
ppc::core::PerfResults::TypeOfRunning::kTaskRun)
82108

83109
template <typename T, typename TestType>
@@ -100,13 +126,13 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
100126
template <typename Derived>
101127
static std::string PrintFuncTestName(const GTestFuncParam<InType, OutType, TestType>& info) {
102128
RequireStaticInterface<Derived>();
103-
TestType test_param = std::get<ppc::util::TestParamIndex::kTestParams>(info.param);
104-
return std::get<TestParamIndex::kNameTest>(info.param) + "_" + Derived::PrintTestParam(test_param);
129+
TestType test_param = std::get<ppc::util::GTestParamIndex::kTestParams>(info.param);
130+
return std::get<GTestParamIndex::kNameTest>(info.param) + "_" + Derived::PrintTestParam(test_param);
105131
}
106132

107133
protected:
108134
void ExecuteTest(FuncTestParam<InType, OutType, TestType> test_param) {
109-
task_ = std::get<TestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
135+
task_ = std::get<GTestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
110136
ASSERT_TRUE(task_->Validation());
111137
ASSERT_TRUE(task_->PreProcessing());
112138
ASSERT_TRUE(task_->Run());
@@ -129,16 +155,18 @@ auto ExpandToValues(const Tuple& t) {
129155
return ExpandToValuesImpl(t, std::make_index_sequence<kN>{});
130156
}
131157

132-
#define INIT_TASK_GENERATOR(InTypeParam, SizesParam) \
133-
template <typename Task, std::size_t... Is> \
134-
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
135-
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, ppc::util::GetNamespace<Task>(), \
136-
SizesParam[Is])...); \
137-
} \
138-
\
139-
template <typename Task> \
140-
auto TaskListGenerator() { \
141-
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
158+
#define INIT_TASK_GENERATOR(InTypeParam, SizesParam) \
159+
template <typename Task, std::size_t... Is> \
160+
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
161+
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \
162+
std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \
163+
ppc::util::GetStringTaskType(Task::GetTypeOfTask()), \
164+
SizesParam[Is])...); \
165+
} \
166+
\
167+
template <typename Task> \
168+
auto TaskListGenerator() { \
169+
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
142170
}
143171

144172
} // namespace ppc::util

tasks/example/all/include/ops_all.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
#include <utility>
44
#include <vector>
55

6-
#include "core/task/include/task.hpp"
6+
#include "example/common/include/common.hpp"
77

8-
namespace nesterov_a_test_task_all {
8+
namespace nesterov_a_test_task {
99

1010
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec);
1111
void MatMulTBB(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec);
1212

13-
using InType = std::vector<int>;
14-
using OutType = std::vector<int>;
15-
16-
class NesterovATestTaskALL : public ppc::core::Task<InType, OutType> {
13+
class NesterovATestTaskALL : public BaseTask {
1714
public:
15+
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kALL; }
1816
explicit NesterovATestTaskALL(const InType &in);
1917
bool ValidationImpl() override;
2018
bool PreProcessingImpl() override;
@@ -25,4 +23,4 @@ class NesterovATestTaskALL : public ppc::core::Task<InType, OutType> {
2523
int rc_size_{};
2624
};
2725

28-
} // namespace nesterov_a_test_task_all
26+
} // namespace nesterov_a_test_task

tasks/example/all/src/ops_all.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "core/util/include/util.hpp"
1212
#include "oneapi/tbb/parallel_for.h"
1313

14-
void nesterov_a_test_task_all::MatMul(const InType &in_vec, int rc_size, OutType &out_vec) {
14+
void nesterov_a_test_task::MatMul(const InType &in_vec, int rc_size, OutType &out_vec) {
1515
for (int i = 0; i < rc_size; ++i) {
1616
for (int j = 0; j < rc_size; ++j) {
1717
out_vec[(i * rc_size) + j] = 0;
@@ -22,26 +22,26 @@ void nesterov_a_test_task_all::MatMul(const InType &in_vec, int rc_size, OutType
2222
}
2323
}
2424

25-
void nesterov_a_test_task_all::MatMulTBB(const InType &in_vec, int rc_size, OutType &out_vec) {
25+
void nesterov_a_test_task::MatMulTBB(const InType &in_vec, int rc_size, OutType &out_vec) {
2626
tbb::parallel_for(0, ppc::util::GetPPCNumThreads(), [&](int i) { MatMul(in_vec, rc_size - i, out_vec); });
2727
MatMul(in_vec, rc_size, out_vec);
2828
}
2929

30-
nesterov_a_test_task_all::NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) { GetInput() = in; }
30+
nesterov_a_test_task::NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) { GetInput() = in; }
3131

32-
bool nesterov_a_test_task_all::NesterovATestTaskALL::ValidationImpl() {
32+
bool nesterov_a_test_task::NesterovATestTaskALL::ValidationImpl() {
3333
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3434
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3535
}
3636

37-
bool nesterov_a_test_task_all::NesterovATestTaskALL::PreProcessingImpl() {
37+
bool nesterov_a_test_task::NesterovATestTaskALL::PreProcessingImpl() {
3838
// Init value for input and output
3939
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
4040
GetOutput() = OutType(GetInput().size(), 0);
4141
return true;
4242
}
4343

44-
bool nesterov_a_test_task_all::NesterovATestTaskALL::RunImpl() {
44+
bool nesterov_a_test_task::NesterovATestTaskALL::RunImpl() {
4545
int rank = -1;
4646
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4747
if (rank == 0) {
@@ -65,4 +65,4 @@ bool nesterov_a_test_task_all::NesterovATestTaskALL::RunImpl() {
6565
return true;
6666
}
6767

68-
bool nesterov_a_test_task_all::NesterovATestTaskALL::PostProcessingImpl() { return true; }
68+
bool nesterov_a_test_task::NesterovATestTaskALL::PostProcessingImpl() { return true; }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <utility>
4+
#include <vector>
5+
6+
#include "core/task/include/task.hpp"
7+
#include "core/util/include/test_util.hpp"
8+
#include "core/util/include/util.hpp"
9+
10+
namespace nesterov_a_test_task {
11+
12+
using InType = std::vector<int>;
13+
using OutType = std::vector<int>;
14+
using TestType = std::tuple<int, std::string>;
15+
16+
using BaseTask = ppc::core::Task<InType, OutType>;
17+
using BasePerfTests = ppc::util::BaseRunPerfTests<InType, OutType>;
18+
using BaseFuncTests = ppc::util::BaseRunFuncTests<InType, OutType, TestType>;
19+
20+
} // namespace nesterov_a_test_task

tasks/example/mpi/include/ops_mpi.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
#include <vector>
55

66
#include "core/task/include/task.hpp"
7+
#include "example/common/include/common.hpp"
78

8-
namespace nesterov_a_test_task_mpi {
9+
namespace nesterov_a_test_task {
910

1011
void MultiplyRowMajor(const std::vector<int> &in, std::vector<int> &out, int rc_size);
1112
void MultiplyColumnMajor(const std::vector<int> &in, std::vector<int> &out, int rc_size);
1213

13-
using InType = std::vector<int>;
14-
using OutType = std::vector<int>;
15-
16-
class NesterovATestTaskMPI : public ppc::core::Task<InType, OutType> {
14+
class NesterovATestTaskMPI : public BaseTask {
1715
public:
16+
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kMPI; }
1817
explicit NesterovATestTaskMPI(const InType &in);
1918
bool ValidationImpl() override;
2019
bool PreProcessingImpl() override;
@@ -27,4 +26,4 @@ class NesterovATestTaskMPI : public ppc::core::Task<InType, OutType> {
2726
void MultiplyMatrixBasedOnRank();
2827
};
2928

30-
} // namespace nesterov_a_test_task_mpi
29+
} // namespace nesterov_a_test_task

tasks/example/mpi/src/ops_mpi.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <cstddef>
77
#include <vector>
88

9-
void nesterov_a_test_task_mpi::MultiplyRowMajor(const InType &in, OutType &out, int rc_size) {
9+
void nesterov_a_test_task::MultiplyRowMajor(const InType &in, OutType &out, int rc_size) {
1010
for (int i = 0; i < rc_size; ++i) {
1111
for (int j = 0; j < rc_size; ++j) {
1212
for (int k = 0; k < rc_size; ++k) {
@@ -16,7 +16,7 @@ void nesterov_a_test_task_mpi::MultiplyRowMajor(const InType &in, OutType &out,
1616
}
1717
}
1818

19-
void nesterov_a_test_task_mpi::MultiplyColumnMajor(const InType &in, OutType &out, int rc_size) {
19+
void nesterov_a_test_task::MultiplyColumnMajor(const InType &in, OutType &out, int rc_size) {
2020
for (int j = 0; j < rc_size; ++j) {
2121
for (int k = 0; k < rc_size; ++k) {
2222
for (int i = 0; i < rc_size; ++i) {
@@ -26,28 +26,28 @@ void nesterov_a_test_task_mpi::MultiplyColumnMajor(const InType &in, OutType &ou
2626
}
2727
}
2828

29-
nesterov_a_test_task_mpi::NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) { GetInput() = in; }
29+
nesterov_a_test_task::NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) { GetInput() = in; }
3030

31-
bool nesterov_a_test_task_mpi::NesterovATestTaskMPI::ValidationImpl() {
31+
bool nesterov_a_test_task::NesterovATestTaskMPI::ValidationImpl() {
3232
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));
3333
return sqrt_size * sqrt_size == static_cast<int>(GetInput().size());
3434
}
3535

36-
bool nesterov_a_test_task_mpi::NesterovATestTaskMPI::PreProcessingImpl() {
36+
bool nesterov_a_test_task::NesterovATestTaskMPI::PreProcessingImpl() {
3737
// Init value for input and output
3838
rc_size_ = static_cast<int>(std::sqrt(GetInput().size()));
3939
GetOutput() = OutType(GetInput().size(), 0);
4040
return true;
4141
}
4242

43-
bool nesterov_a_test_task_mpi::NesterovATestTaskMPI::RunImpl() {
43+
bool nesterov_a_test_task::NesterovATestTaskMPI::RunImpl() {
4444
MultiplyMatrixBasedOnRank();
4545
return true;
4646
}
4747

48-
bool nesterov_a_test_task_mpi::NesterovATestTaskMPI::PostProcessingImpl() { return true; }
48+
bool nesterov_a_test_task::NesterovATestTaskMPI::PostProcessingImpl() { return true; }
4949

50-
void nesterov_a_test_task_mpi::NesterovATestTaskMPI::MultiplyMatrixBasedOnRank() {
50+
void nesterov_a_test_task::NesterovATestTaskMPI::MultiplyMatrixBasedOnRank() {
5151
int rank = -1;
5252
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5353

tasks/example/omp/include/ops_omp.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#include <vector>
55

66
#include "core/task/include/task.hpp"
7+
#include "example/common/include/common.hpp"
78

8-
namespace nesterov_a_test_task_omp {
9+
namespace nesterov_a_test_task {
910

10-
using InType = std::vector<int>;
11-
using OutType = std::vector<int>;
12-
13-
class NesterovATestTaskOMP : public ppc::core::Task<InType, OutType> {
11+
class NesterovATestTaskOMP : public BaseTask {
1412
public:
13+
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kOMP; }
1514
explicit NesterovATestTaskOMP(const InType& in);
1615
bool ValidationImpl() override;
1716
bool PreProcessingImpl() override;
@@ -22,4 +21,4 @@ class NesterovATestTaskOMP : public ppc::core::Task<InType, OutType> {
2221
int rc_size_{};
2322
};
2423

25-
} // namespace nesterov_a_test_task_omp
24+
} // namespace nesterov_a_test_task

0 commit comments

Comments
 (0)