Skip to content

Commit c339784

Browse files
authored
Merge branch 'master' into dep/update_pre_commit_01KYTWK0K6RPHW2R73BPD9ATDA
2 parents 30a1b4d + 22634c3 commit c339784

27 files changed

Lines changed: 325 additions & 374 deletions

File tree

modules/task/include/task.hpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ template <typename InType, typename OutType>
203203
/// @tparam OutType Output data type.
204204
class Task {
205205
public:
206+
using InputType = InType;
207+
using OutputType = OutType;
208+
206209
Task() = default;
210+
explicit Task(InType input, TypeOfTask type_of_task) : input_(std::move(input)), type_of_task_(type_of_task) {}
207211
Task(const Task &) = delete;
208212
Task(Task &&) = delete;
209213
Task &operator=(const Task &) = delete;
@@ -263,16 +267,14 @@ class Task {
263267
return PostProcessingImpl();
264268
}
265269

266-
/// @brief Returns the current testing mode.
267-
/// @return Reference to the current StateOfTesting.
268-
StateOfTesting &GetStateOfTesting() {
269-
return state_of_testing_;
270+
/// @brief Sets the current testing mode.
271+
void SetStateOfTesting(StateOfTesting state_of_testing) {
272+
state_of_testing_ = state_of_testing;
270273
}
271274

272-
/// @brief Sets the dynamic task type.
273-
/// @param type_of_task Task type to set.
274-
void SetTypeOfTask(TypeOfTask type_of_task) {
275-
type_of_task_ = type_of_task;
275+
/// @brief Returns the current testing mode.
276+
[[nodiscard]] StateOfTesting GetStateOfTesting() const {
277+
return state_of_testing_;
276278
}
277279

278280
/// @brief Returns the dynamic task type.
@@ -281,12 +283,6 @@ class Task {
281283
return type_of_task_;
282284
}
283285

284-
/// @brief Returns the current task status.
285-
/// @return Task status (enabled or disabled).
286-
[[nodiscard]] StatusOfTask GetStatusOfTask() const {
287-
return status_of_task_;
288-
}
289-
290286
/// @brief Returns the static task type.
291287
/// @return Static task type (default: kUnknown).
292288
static constexpr TypeOfTask GetStaticTypeOfTask() {
@@ -295,13 +291,13 @@ class Task {
295291

296292
/// @brief Returns a reference to the input data.
297293
/// @return Reference to the task's input data.
298-
InType &GetInput() {
294+
[[nodiscard]] const InType &GetInput() const {
299295
return input_;
300296
}
301297

302298
/// @brief Returns a reference to the output data.
303299
/// @return Reference to the task's output data.
304-
OutType &GetOutput() {
300+
[[nodiscard]] const OutType &GetOutput() const {
305301
return output_;
306302
}
307303

@@ -317,6 +313,16 @@ class Task {
317313
}
318314

319315
protected:
316+
/// @brief Returns mutable access to the input for task implementations.
317+
InType &GetMutableInput() {
318+
return input_;
319+
}
320+
321+
/// @brief Returns mutable access to the output for task implementations.
322+
OutType &GetMutableOutput() {
323+
return output_;
324+
}
325+
320326
/// @brief Measures execution time between preprocessing and postprocessing steps.
321327
/// @throws std::runtime_error If execution exceeds the allowed time limit.
322328
virtual void InternalTimeTest() final {
@@ -364,7 +370,6 @@ class Task {
364370
OutType output_{};
365371
StateOfTesting state_of_testing_ = StateOfTesting::kFunc;
366372
TypeOfTask type_of_task_ = TypeOfTask::kUnknown;
367-
StatusOfTask status_of_task_ = StatusOfTask::kEnabled;
368373
std::chrono::high_resolution_clock::time_point tmp_time_point_;
369374
enum class PipelineStage : uint8_t {
370375
kNone,
@@ -388,8 +393,8 @@ using TaskPtr = std::unique_ptr<Task<InType, OutType>>;
388393
/// @param in Input to pass to the task constructor.
389394
/// @return Unique pointer to the newly created task.
390395
template <typename TaskType, typename InType>
391-
std::unique_ptr<TaskType> TaskGetter(const InType &in) {
392-
return std::make_unique<TaskType>(in);
396+
std::unique_ptr<TaskType> TaskGetter(InType &&in) {
397+
return std::make_unique<TaskType>(std::forward<InType>(in));
393398
}
394399

395400
} // namespace ppc::task

modules/task/tests/task_tests.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,21 @@ namespace ppc::test {
4646
template <typename InType, typename OutType>
4747
class TestTask : public ppc::task::Task<InType, OutType> {
4848
public:
49-
explicit TestTask(const InType &in) {
50-
this->GetInput() = in;
51-
}
49+
explicit TestTask(InType in) : ppc::task::Task<InType, OutType>(std::move(in), TypeOfTask::kUnknown) {}
5250

5351
protected:
5452
bool ValidationImpl() override {
5553
return !this->GetInput().empty();
5654
}
5755

5856
bool PreProcessingImpl() override {
59-
this->GetOutput() = 0;
57+
this->GetMutableOutput() = 0;
6058
return true;
6159
}
6260

6361
bool RunImpl() override {
6462
for (const auto &value : this->GetInput()) {
65-
this->GetOutput() += value;
63+
this->GetMutableOutput() += value;
6664
}
6765
return true;
6866
}
@@ -287,9 +285,8 @@ TEST(TaskTest, TaskDestructorThrowsIfStageIncomplete) {
287285
std::vector<int32_t> in(20, 1);
288286
struct LocalTask : Task<std::vector<int32_t>, int32_t> {
289287
public:
290-
explicit LocalTask(const std::vector<int32_t> &in) {
291-
this->GetInput() = in;
292-
}
288+
explicit LocalTask(std::vector<int32_t> in)
289+
: Task<std::vector<int32_t>, int32_t>(std::move(in), TypeOfTask::kUnknown) {}
293290

294291
protected:
295292
bool ValidationImpl() override {
@@ -316,9 +313,8 @@ TEST(TaskTest, TaskDestructorThrowsIfEmpty) {
316313
std::vector<int32_t> in(20, 1);
317314
struct LocalTask : Task<std::vector<int32_t>, int32_t> {
318315
public:
319-
explicit LocalTask(const std::vector<int32_t> &in) {
320-
this->GetInput() = in;
321-
}
316+
explicit LocalTask(std::vector<int32_t> in)
317+
: Task<std::vector<int32_t>, int32_t>(std::move(in), TypeOfTask::kUnknown) {}
322318

323319
protected:
324320
bool ValidationImpl() override {
@@ -345,9 +341,8 @@ TEST(TaskTest, InternalTimeTestThrowsIfTimeoutExceeded) {
345341
#endif
346342
struct SlowTask : Task<std::vector<int32_t>, int32_t> {
347343
public:
348-
explicit SlowTask(const std::vector<int32_t> &in) {
349-
this->GetInput() = in;
350-
}
344+
explicit SlowTask(std::vector<int32_t> in)
345+
: Task<std::vector<int32_t>, int32_t>(std::move(in), TypeOfTask::kUnknown) {}
351346

352347
protected:
353348
bool ValidationImpl() override {
@@ -367,7 +362,7 @@ TEST(TaskTest, InternalTimeTestThrowsIfTimeoutExceeded) {
367362

368363
std::vector<int32_t> in(20, 1);
369364
SlowTask task(in);
370-
task.GetStateOfTesting() = StateOfTesting::kFunc;
365+
task.SetStateOfTesting(StateOfTesting::kFunc);
371366
task.Validation();
372367
EXPECT_NO_THROW(task.PreProcessing());
373368
task.Run();
@@ -394,8 +389,7 @@ class DummyTask : public Task<int, int> {
394389
};
395390

396391
TEST(TaskTest, GetDynamicTypeReturnsCorrectEnum) {
397-
DummyTask task;
398-
task.SetTypeOfTask(TypeOfTask::kOMP);
392+
DummyTask task(0, TypeOfTask::kOMP);
399393
task.Validation();
400394
task.PreProcessing();
401395
task.Run();

modules/util/include/func_test_util.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919
namespace ppc::util {
2020

2121
template <typename InType, typename OutType, typename TestType = void>
22-
using FuncTestParam = std::tuple<std::function<ppc::task::TaskPtr<InType, OutType>(InType)>, std::string, TestType,
23-
ppc::task::TaskDescriptor>;
22+
struct FuncTestCase {
23+
std::function<ppc::task::TaskPtr<InType, OutType>(InType)> task_getter;
24+
TestType test_param;
25+
ppc::task::TaskDescriptor descriptor;
26+
};
27+
28+
template <typename InType, typename OutType, typename TestType = void>
29+
using FuncTestParam = FuncTestCase<InType, OutType, TestType>;
2430

2531
template <typename InType, typename OutType, typename TestType = void>
2632
using GTestFuncParam = ::testing::TestParamInfo<FuncTestParam<InType, OutType, TestType>>;
@@ -49,12 +55,11 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
4955
template <typename Derived>
5056
static std::string PrintFuncTestName(const GTestFuncParam<InType, OutType, TestType> &info) {
5157
RequireStaticInterface<Derived>();
52-
TestType test_param = std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kTestParams)>(info.param);
53-
return GetTaskDescriptor(info.param).display_name + "_" + Derived::PrintTestParam(test_param);
58+
return info.param.descriptor.display_name + "_" + Derived::PrintTestParam(info.param.test_param);
5459
}
5560

5661
protected:
57-
virtual bool CheckTestOutputData(OutType &output_data) = 0;
62+
virtual bool CheckTestOutputData(const OutType &output_data) = 0;
5863
/// @brief Provides input data for the task.
5964
/// @return Initialized input data.
6065
virtual InType GetTestInputData() = 0;
@@ -70,7 +75,7 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
7075
}
7176

7277
void ExecuteTest(const FuncTestParam<InType, OutType, TestType> &test_param) {
73-
const auto &descriptor = GetTaskDescriptor(test_param);
78+
const auto &descriptor = test_param.descriptor;
7479

7580
ValidateTaskDescriptor(descriptor);
7681

@@ -101,13 +106,13 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
101106
}
102107

103108
bool ShouldSkipTestCase(const FuncTestParam<InType, OutType, TestType> &test_param) {
104-
const auto &descriptor = GetTaskDescriptor(test_param);
109+
const auto &descriptor = test_param.descriptor;
105110
return IsTestDisabled(descriptor) || ShouldSkipNonMpiTask(descriptor);
106111
}
107112

108113
/// @brief Initializes task instance and runs it through the full pipeline.
109114
void InitializeAndRunTask(const FuncTestParam<InType, OutType, TestType> &test_param) {
110-
task_ = std::get<static_cast<std::size_t>(GTestParamIndex::kTaskGetter)>(test_param)(GetTestInputData());
115+
task_ = test_param.task_getter(GetTestInputData());
111116
ExecuteTaskPipeline();
112117
}
113118

@@ -161,7 +166,7 @@ void RunTestCasesWithTag(const TestTasksList &test_tasks_list, std::string_view
161166
bool has_matching_task = false;
162167
std::apply([&](const auto &...test_params) {
163168
auto run_if_tagged = [&](const auto &test_param) {
164-
const auto &descriptor = GetTaskDescriptor(test_param);
169+
const auto &descriptor = test_param.descriptor;
165170
if (descriptor.type == task_type) {
166171
has_matching_task = true;
167172
std::invoke(run_test_case, test_param);
@@ -186,10 +191,10 @@ auto ExpandToValues(const Tuple &t) {
186191
template <typename Task, typename InType, typename SizesContainer, std::size_t... Is>
187192
auto GenTaskTuplesImpl(const SizesContainer &sizes, const std::string &settings_path,
188193
std::string_view settings_task_path, std::index_sequence<Is...> /*unused*/) {
189-
const auto descriptor =
190-
MakeTaskDescriptor(GetNamespace<Task>(), Task::GetStaticTypeOfTask(), settings_path, settings_task_path);
191-
return std::make_tuple(std::make_tuple(ppc::task::TaskGetter<Task, InType>, descriptor.display_name,
192-
std::get<Is>(sizes), descriptor)...);
194+
const auto descriptor = MakeTaskDescriptor(ResolveTaskIdentifier<Task>(settings_path), Task::GetStaticTypeOfTask(),
195+
settings_path, settings_task_path);
196+
return std::make_tuple(FuncTestCase<InType, typename Task::OutputType, std::decay_t<decltype(std::get<Is>(sizes))>>{
197+
ppc::task::TaskGetter<Task, InType>, std::get<Is>(sizes), descriptor}...);
193198
}
194199

195200
template <typename Task, typename InType, typename SizesContainer>

modules/util/include/perf_test_util.hpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ template <typename InType, typename OutType>
114114
double RunTaskForBenchmark(const ppc::task::TaskPtr<InType, OutType> &task) {
115115
const auto task_type = task->GetDynamicTypeOfTask();
116116
const auto timer = MakeTechnologyTimer(task_type);
117-
task->GetStateOfTesting() = ppc::task::StateOfTesting::kPerf;
117+
task->SetStateOfTesting(ppc::task::StateOfTesting::kPerf);
118118

119119
task->Validation();
120120
task->PreProcessing();
@@ -137,7 +137,8 @@ void RunBenchmarkBody(const TaskGetter &task_getter, const InType &input_data, c
137137
auto task = task_getter(input_data);
138138
const double elapsed = RunTaskForBenchmark(task);
139139
state.SetIterationTime(elapsed);
140-
benchmark::DoNotOptimize(task->GetOutput());
140+
auto output = task->GetOutput();
141+
benchmark::DoNotOptimize(output);
141142
}
142143
} catch (const std::exception &e) {
143144
PerformanceFailureFlag::Set();
@@ -169,8 +170,13 @@ class BenchmarkTaskBody final {
169170
} // namespace detail
170171

171172
template <typename InType, typename OutType>
172-
using PerfTestParam = std::tuple<std::function<ppc::task::TaskPtr<InType, OutType>(InType)>, std::string,
173-
ppc::task::TaskCategory, ppc::task::TaskDescriptor>;
173+
struct PerfTestCase {
174+
std::function<ppc::task::TaskPtr<InType, OutType>(InType)> task_getter;
175+
ppc::task::TaskDescriptor descriptor;
176+
};
177+
178+
template <typename InType, typename OutType>
179+
using PerfTestParam = PerfTestCase<InType, OutType>;
174180

175181
template <typename InType, typename OutType>
176182
/// @brief Base class for performance testing of parallel tasks.
@@ -180,11 +186,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
180186
public:
181187
/// @brief Generates a readable name for the performance test case.
182188
static std::string CustomPerfTestName(const ::testing::TestParamInfo<PerfTestParam<InType, OutType>> &info) {
183-
return GetTaskDescriptor(info.param).display_name;
189+
return info.param.descriptor.display_name;
184190
}
185191

186192
protected:
187-
virtual bool CheckTestOutputData(OutType &output_data) = 0;
193+
virtual bool CheckTestOutputData(const OutType &output_data) = 0;
188194
/// @brief Supplies input data for performance testing.
189195
virtual InType GetTestInputData() = 0;
190196

@@ -193,8 +199,8 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
193199
}
194200

195201
void ExecuteTest(const PerfTestParam<InType, OutType> &perf_test_param) {
196-
auto task_getter = std::get<static_cast<std::size_t>(GTestParamIndex::kTaskGetter)>(perf_test_param);
197-
const auto &descriptor = GetTaskDescriptor(perf_test_param);
202+
auto task_getter = perf_test_param.task_getter;
203+
const auto &descriptor = perf_test_param.descriptor;
198204

199205
ASSERT_NE(descriptor.type, ppc::task::TypeOfTask::kUnknown);
200206
if (descriptor.status == ppc::task::StatusOfTask::kDisabled) {
@@ -209,12 +215,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
209215

210216
const auto input_data = GetTestInputData();
211217
task_ = task_getter(input_data);
212-
task_->GetStateOfTesting() = ppc::task::StateOfTesting::kPerf;
218+
task_->SetStateOfTesting(ppc::task::StateOfTesting::kPerf);
213219
SynchronizeMpiRanks();
214220
detail::RunTaskForValidation(task_);
215221

216-
OutType output_data = task_->GetOutput();
217-
ASSERT_TRUE(CheckTestOutputData(output_data));
222+
ASSERT_TRUE(CheckTestOutputData(task_->GetOutput()));
218223

219224
PerfAttr perf_attr;
220225
SetPerfAttributes(perf_attr);
@@ -236,11 +241,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
236241

237242
template <typename TaskType, typename InputType>
238243
auto MakePerfTaskTuples(const std::string &settings_path, std::string_view settings_task_path = {}) {
239-
const auto descriptor =
240-
MakeTaskDescriptor(GetNamespace<TaskType>(), TaskType::GetStaticTypeOfTask(), settings_path, settings_task_path);
244+
const auto descriptor = MakeTaskDescriptor(ResolveTaskIdentifier<TaskType>(settings_path),
245+
TaskType::GetStaticTypeOfTask(), settings_path, settings_task_path);
241246

242-
return std::make_tuple(std::make_tuple(ppc::task::TaskGetter<TaskType, InputType>, descriptor.display_name,
243-
descriptor.category, descriptor));
247+
return std::make_tuple(
248+
PerfTestCase<InputType, typename TaskType::OutputType>{ppc::task::TaskGetter<TaskType, InputType>, descriptor});
244249
}
245250

246251
template <typename Tuple, std::size_t... I>

modules/util/include/task_descriptor_util.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
#pragma once
22

3-
#include <cstddef>
3+
#include <concepts>
4+
#include <filesystem>
45
#include <string>
56
#include <string_view>
67

78
#include "task/include/task.hpp"
8-
#include "util/include/util.hpp"
99

1010
namespace ppc::util {
1111

12+
template <typename Task>
13+
std::string ResolveTaskIdentifier(const std::string &settings_path) {
14+
if constexpr (requires {
15+
{ Task::GetTaskIdentifier() } -> std::convertible_to<std::string_view>;
16+
}) {
17+
return std::string(Task::GetTaskIdentifier());
18+
} else {
19+
const std::filesystem::path path(settings_path);
20+
return path.has_parent_path() ? path.parent_path().filename().string() : path.stem().string();
21+
}
22+
}
23+
1224
inline ppc::task::TaskDescriptor MakeTaskDescriptor(std::string_view task_namespace, ppc::task::TypeOfTask task_type,
1325
const std::string &settings_path,
1426
std::string_view settings_task_path = {}) {
@@ -23,11 +35,6 @@ inline ppc::task::TaskDescriptor MakeTaskDescriptor(std::string_view task_namesp
2335
.display_name = std::string(task_namespace) + "_" + task_name};
2436
}
2537

26-
template <typename TestParam>
27-
const ppc::task::TaskDescriptor &GetTaskDescriptor(const TestParam &test_param) {
28-
return std::get<static_cast<std::size_t>(GTestParamIndex::kTaskDescriptor)>(test_param);
29-
}
30-
3138
inline bool IsMpiTaskType(ppc::task::TypeOfTask type) {
3239
return type == ppc::task::TypeOfTask::kMPI || type == ppc::task::TypeOfTask::kALL;
3340
}

0 commit comments

Comments
 (0)