|
2 | 2 |
|
3 | 3 | #include <gtest/gtest.h> |
4 | 4 | #include <mpi.h> |
| 5 | +#include <omp.h> |
| 6 | +#include <tbb/tick_count.h> |
5 | 7 |
|
6 | 8 | #include "core/perf/include/perf.hpp" |
7 | 9 |
|
@@ -59,10 +61,33 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O |
59 | 61 | } |
60 | 62 |
|
61 | 63 | protected: |
62 | | - virtual void SetPerfAttributes(ppc::core::PerfAttr& perf_attrs) = 0; |
63 | 64 | virtual bool CheckTestOutputData(OutType& output_data) = 0; |
64 | 65 | virtual InType GetTestInputData() = 0; |
65 | 66 |
|
| 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 | + |
66 | 91 | void ExecuteTest(const PerfTestParam<InType, OutType>& perf_test_param) { |
67 | 92 | auto task_getter = std::get<GTestParamIndex::kTaskGetter>(perf_test_param); |
68 | 93 | auto test_name = std::get<GTestParamIndex::kNameTest>(perf_test_param); |
@@ -99,11 +124,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O |
99 | 124 | #define ADD_PERF_MODES(TaskType, InputTypeParam) \ |
100 | 125 | std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \ |
101 | 126 | std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \ |
102 | | - ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \ |
| 127 | + ppc::util::GetStringTaskType(TaskType::GetStaticTypeOfTask()), \ |
103 | 128 | ppc::core::PerfResults::TypeOfRunning::kPipeline), \ |
104 | 129 | std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \ |
105 | 130 | std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \ |
106 | | - ppc::util::GetStringTaskType(TaskType::GetTypeOfTask()), \ |
| 131 | + ppc::util::GetStringTaskType(TaskType::GetStaticTypeOfTask()), \ |
107 | 132 | ppc::core::PerfResults::TypeOfRunning::kTaskRun) |
108 | 133 |
|
109 | 134 | template <typename T, typename TestType> |
@@ -160,7 +185,7 @@ auto ExpandToValues(const Tuple& t) { |
160 | 185 | auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \ |
161 | 186 | return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \ |
162 | 187 | std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \ |
163 | | - ppc::util::GetStringTaskType(Task::GetTypeOfTask()), \ |
| 188 | + ppc::util::GetStringTaskType(Task::GetStaticTypeOfTask()), \ |
164 | 189 | SizesParam[Is])...); \ |
165 | 190 | } \ |
166 | 191 | \ |
|
0 commit comments