Skip to content

Commit d8f9a49

Browse files
committed
Refactor task type handling and improve performance tracking.
Replaced `GetTypeOfTask` with `GetStaticTypeOfTask` for clarity and added `SetTypeOfTask` and `GetDynamicTypeOfTask` to support dynamic task type management. Enhanced performance tracking with task-specific timing implementations (TBB, MPI, OMP, etc.).
1 parent e240d51 commit d8f9a49

16 files changed

Lines changed: 70 additions & 29 deletions

File tree

modules/core/perf/include/perf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ppc::core {
1111
struct PerfAttr {
1212
// count of task's running
1313
uint64_t num_running = 10;
14-
std::function<double()> current_timer = [&] { return 0.0; };
14+
std::function<double()> current_timer = [&] { return -1.0; };
1515
};
1616

1717
struct PerfResults {

modules/core/task/include/task.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ class Task {
6868
// get state of testing
6969
StateOfTesting &GetStateOfTesting() { return state_of_testing_; }
7070

71-
// get a type of task
72-
static constexpr TypeOfTask GetTypeOfTask() { return TypeOfTask::kUnknown; }
71+
// set a type of task
72+
void SetTypeOfTask(TypeOfTask type_of_task) { type_of_task_ = type_of_task; }
73+
74+
// get a dynamic type of task
75+
TypeOfTask GetDynamicTypeOfTask() { return type_of_task_; }
76+
77+
// get a static type of task
78+
static constexpr TypeOfTask GetStaticTypeOfTask() { return TypeOfTask::kUnknown; }
7379

7480
InType &GetInput() { return input_; }
7581

@@ -130,6 +136,7 @@ class Task {
130136
InType input_;
131137
OutType output_;
132138
StateOfTesting state_of_testing_ = kFunc;
139+
TypeOfTask type_of_task_ = kUnknown;
133140
std::vector<std::string> functions_order_;
134141
std::vector<std::string> right_functions_order_ = {"Validation", "PreProcessing", "Run", "PostProcessing"};
135142
static constexpr double kMaxTestTime = 1.0;

modules/core/util/include/test_util.hpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <gtest/gtest.h>
44
#include <mpi.h>
5+
#include <omp.h>
6+
#include <tbb/tick_count.h>
57

68
#include "core/perf/include/perf.hpp"
79

@@ -59,10 +61,33 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
5961
}
6062

6163
protected:
62-
virtual void SetPerfAttributes(ppc::core::PerfAttr& perf_attrs) = 0;
6364
virtual bool CheckTestOutputData(OutType& output_data) = 0;
6465
virtual InType GetTestInputData() = 0;
6566

67+
virtual void SetPerfAttributes(ppc::core::PerfAttr& perf_attrs) {
68+
if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kTBB) {
69+
const tbb::tick_count t0 = tbb::tick_count::now();
70+
perf_attrs.current_timer = [t0] { return (tbb::tick_count::now() - t0).seconds(); };
71+
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kMPI ||
72+
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kALL) {
73+
const double t0 = MPI_Wtime();
74+
perf_attrs.current_timer = [t0] { return MPI_Wtime() - t0; };
75+
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kOMP) {
76+
const double t0 = omp_get_wtime();
77+
perf_attrs.current_timer = [t0] { return omp_get_wtime() - t0; };
78+
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kSEQ ||
79+
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kSTL) {
80+
const auto t0 = std::chrono::high_resolution_clock::now();
81+
perf_attrs.current_timer = [&] {
82+
auto now = std::chrono::high_resolution_clock::now();
83+
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now - t0).count();
84+
return static_cast<double>(ns) * 1e-9;
85+
};
86+
} else {
87+
throw std::runtime_error("The task type is not supported for performance testing.");
88+
}
89+
}
90+
6691
void ExecuteTest(const PerfTestParam<InType, OutType>& perf_test_param) {
6792
auto task_getter = std::get<GTestParamIndex::kTaskGetter>(perf_test_param);
6893
auto test_name = std::get<GTestParamIndex::kNameTest>(perf_test_param);
@@ -99,11 +124,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
99124
#define ADD_PERF_MODES(TaskType, InputTypeParam) \
100125
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
101126
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
102-
ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \
127+
ppc::util::GetStringTaskType(TaskType::GetStaticTypeOfTask()), \
103128
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
104129
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
105130
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
106-
ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \
131+
ppc::util::GetStringTaskType(TaskType::GetStaticTypeOfTask()), \
107132
ppc::core::PerfResults::TypeOfRunning::kTaskRun)
108133

109134
template <typename T, typename TestType>
@@ -160,7 +185,7 @@ auto ExpandToValues(const Tuple& t) {
160185
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
161186
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \
162187
std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \
163-
ppc::util::GetStringTaskType(Task::GetTypeOfTask()), \
188+
ppc::util::GetStringTaskType(Task::GetStaticTypeOfTask()), \
164189
SizesParam[Is])...); \
165190
} \
166191
\

tasks/example/all/include/ops_all.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void MatMulTBB(const std::vector<int> &in_vec, int rc_size, std::vector<int> &ou
1212

1313
class NesterovATestTaskALL : public BaseTask {
1414
public:
15-
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kALL; }
15+
static constexpr ppc::core::TypeOfTask GetStaticTypeOfTask() { return ppc::core::TypeOfTask::kALL; }
1616
explicit NesterovATestTaskALL(const InType &in);
1717
bool ValidationImpl() override;
1818
bool PreProcessingImpl() override;

tasks/example/all/src/ops_all.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ void nesterov_a_test_task::MatMulTBB(const InType &in_vec, int rc_size, OutType
2727
MatMul(in_vec, rc_size, out_vec);
2828
}
2929

30-
nesterov_a_test_task::NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) { GetInput() = in; }
30+
nesterov_a_test_task::NesterovATestTaskALL::NesterovATestTaskALL(const InType &in) {
31+
SetTypeOfTask(GetStaticTypeOfTask());
32+
GetInput() = in;
33+
}
3134

3235
bool nesterov_a_test_task::NesterovATestTaskALL::ValidationImpl() {
3336
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));

tasks/example/mpi/include/ops_mpi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void MultiplyColumnMajor(const std::vector<int> &in, std::vector<int> &out, int
1313

1414
class NesterovATestTaskMPI : public BaseTask {
1515
public:
16-
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kMPI; }
16+
static constexpr ppc::core::TypeOfTask GetStaticTypeOfTask() { return ppc::core::TypeOfTask::kMPI; }
1717
explicit NesterovATestTaskMPI(const InType &in);
1818
bool ValidationImpl() override;
1919
bool PreProcessingImpl() override;

tasks/example/mpi/src/ops_mpi.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ void nesterov_a_test_task::MultiplyColumnMajor(const InType &in, OutType &out, i
2626
}
2727
}
2828

29-
nesterov_a_test_task::NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) { GetInput() = in; }
29+
nesterov_a_test_task::NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) {
30+
SetTypeOfTask(GetStaticTypeOfTask());
31+
GetInput() = in;
32+
}
3033

3134
bool nesterov_a_test_task::NesterovATestTaskMPI::ValidationImpl() {
3235
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));

tasks/example/omp/include/ops_omp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace nesterov_a_test_task {
1010

1111
class NesterovATestTaskOMP : public BaseTask {
1212
public:
13-
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kOMP; }
13+
static constexpr ppc::core::TypeOfTask GetStaticTypeOfTask() { return ppc::core::TypeOfTask::kOMP; }
1414
explicit NesterovATestTaskOMP(const InType& in);
1515
bool ValidationImpl() override;
1616
bool PreProcessingImpl() override;

tasks/example/omp/src/ops_omp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#include <cstddef>
55
#include <vector>
66

7-
nesterov_a_test_task::NesterovATestTaskOMP::NesterovATestTaskOMP(const InType& in) { GetInput() = in; }
7+
nesterov_a_test_task::NesterovATestTaskOMP::NesterovATestTaskOMP(const InType& in) {
8+
SetTypeOfTask(GetStaticTypeOfTask());
9+
GetInput() = in;
10+
}
811

912
bool nesterov_a_test_task::NesterovATestTaskOMP::ValidationImpl() {
1013
auto sqrt_size = static_cast<int>(std::sqrt(GetInput().size()));

tasks/example/seq/include/ops_seq.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace nesterov_a_test_task {
1010

1111
class NesterovATestTaskSEQ : public BaseTask {
1212
public:
13-
static constexpr ppc::core::TypeOfTask GetTypeOfTask() { return ppc::core::TypeOfTask::kSEQ; }
13+
static constexpr ppc::core::TypeOfTask GetStaticTypeOfTask() { return ppc::core::TypeOfTask::kSEQ; }
1414
explicit NesterovATestTaskSEQ(const InType& in);
1515
bool ValidationImpl() override;
1616
bool PreProcessingImpl() override;

0 commit comments

Comments
 (0)