Skip to content

Commit d0fe9b0

Browse files
committed
fix tasks
1 parent 728f00f commit d0fe9b0

File tree

31 files changed

+172
-189
lines changed

31 files changed

+172
-189
lines changed

modules/core/perf/func_tests/test_task.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#ifndef MODULES_CORE_TESTS_TEST_TASK_HPP_
2-
#define MODULES_CORE_TESTS_TEST_TASK_HPP_
3-
4-
#include <gtest/gtest.h>
1+
#pragma once
52

63
#include <memory>
74
#include <thread>
@@ -16,7 +13,7 @@ namespace ppc::test::perf {
1613
template <class T>
1714
class TestTask : public ppc::core::Task {
1815
public:
19-
explicit TestTask(ppc::core::TaskDataPtr task_data) : Task(task_data) {}
16+
explicit TestTask(const ppc::core::TaskDataPtr &task_data) : Task(task_data) {}
2017

2118
bool PreProcessingImpl() override {
2219
input_ = reinterpret_cast<T *>(task_data->inputs[0]);
@@ -53,5 +50,3 @@ class FakePerfTask : public TestTask<T> {
5350
};
5451

5552
} // namespace ppc::test::perf
56-
57-
#endif // MODULES_CORE_TESTS_TEST_TASK_HPP_

modules/core/perf/include/perf.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#ifndef MODULES_CORE_INCLUDE_PERF_HPP_
2-
#define MODULES_CORE_INCLUDE_PERF_HPP_
1+
#pragma once
32

43
#include <cstdint>
54
#include <functional>
65
#include <memory>
7-
#include <vector>
86

97
#include "core/task/include/task.hpp"
108

@@ -13,14 +11,14 @@ namespace ppc::core {
1311
struct PerfAttr {
1412
// count of task's running
1513
uint64_t num_running;
16-
std::function<double(void)> current_timer = [&] { return 0.0; };
14+
std::function<double()> current_timer = [&] { return 0.0; };
1715
};
1816

1917
struct PerfResults {
2018
// measurement of task's time (in seconds)
2119
double time_sec = 0.0;
2220
enum TypeOfRunning : uint8_t { kPipeline, kTaskRun, kNone } type_of_running = kNone;
23-
constexpr const static double kMaxTime = 10.0;
21+
constexpr static double kMaxTime = 10.0;
2422
};
2523

2624
class Perf {
@@ -33,18 +31,16 @@ class Perf {
3331
// Check performance of full task's pipeline: PreProcessing() ->
3432
// Validation() -> Run() -> PostProcessing()
3533
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
36-
const std::shared_ptr<ppc::core::PerfResults>& perf_results);
34+
const std::shared_ptr<PerfResults>& perf_results) const;
3735
// Check performance of task's Run() function
38-
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<ppc::core::PerfResults>& perf_results);
36+
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
3937
// Pint results for automation checkers
4038
static void PrintPerfStatistic(const std::shared_ptr<PerfResults>& perf_results);
4139

4240
private:
4341
std::shared_ptr<Task> task_;
4442
static void CommonRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::function<void()>& pipeline,
45-
const std::shared_ptr<ppc::core::PerfResults>& perf_results);
43+
const std::shared_ptr<PerfResults>& perf_results);
4644
};
4745

4846
} // namespace ppc::core
49-
50-
#endif // MODULES_CORE_INCLUDE_PERF_HPP_

modules/core/perf/src/perf.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <iomanip>
66
#include <iostream>
77
#include <sstream>
8-
#include <utility>
98

109
ppc::core::Perf::Perf(const std::shared_ptr<Task>& task_ptr) { SetTask(task_ptr); }
1110

@@ -15,7 +14,7 @@ void ppc::core::Perf::SetTask(const std::shared_ptr<Task>& task_ptr) {
1514
}
1615

1716
void ppc::core::Perf::PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
18-
const std::shared_ptr<ppc::core::PerfResults>& perf_results) {
17+
const std::shared_ptr<ppc::core::PerfResults>& perf_results) const {
1918
perf_results->type_of_running = PerfResults::TypeOfRunning::kPipeline;
2019

2120
CommonRun(
@@ -30,7 +29,7 @@ void ppc::core::Perf::PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
3029
}
3130

3231
void ppc::core::Perf::TaskRun(const std::shared_ptr<PerfAttr>& perf_attr,
33-
const std::shared_ptr<ppc::core::PerfResults>& perf_results) {
32+
const std::shared_ptr<ppc::core::PerfResults>& perf_results) const {
3433
perf_results->type_of_running = PerfResults::TypeOfRunning::kTaskRun;
3534

3635
task_->Validation();

modules/core/task/func_tests/test_task.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#ifndef MODULES_CORE_TESTS_TEST_TASK_HPP_
2-
#define MODULES_CORE_TESTS_TEST_TASK_HPP_
1+
#pragma once
32

4-
#include <gtest/gtest.h>
5-
6-
#include <memory>
73
#include <vector>
84

95
#include "core/task/include/task.hpp"
@@ -13,7 +9,7 @@ namespace ppc::test::task {
139
template <class T>
1410
class TestTask : public ppc::core::Task {
1511
public:
16-
explicit TestTask(ppc::core::TaskDataPtr task_data) : Task(task_data) {}
12+
explicit TestTask(const ppc::core::TaskDataPtr &task_data) : Task(task_data) {}
1713
bool PreProcessingImpl() override {
1814
input_ = reinterpret_cast<T *>(task_data->inputs[0]);
1915
output_ = reinterpret_cast<T *>(task_data->outputs[0]);
@@ -38,5 +34,3 @@ class TestTask : public ppc::core::Task {
3834
};
3935

4036
} // namespace ppc::test::task
41-
42-
#endif // MODULES_CORE_TESTS_TEST_TASK_HPP_

modules/core/task/include/task.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <chrono>
44
#include <cstdint>
55
#include <filesystem>
6-
#include <iostream>
76
#include <memory>
87
#include <string>
98
#include <vector>

modules/core/util/util.hpp

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

3-
#include <chrono>
3+
#ifdef _WIN32
44
#include <cstdint>
5-
#include <filesystem>
65
#include <iostream>
76
#include <memory>
8-
#include <string>
97
#include <vector>
8+
#endif
9+
10+
#include <filesystem>
11+
#include <string>
1012

1113
namespace ppc::util {
1214

tasks/all/example/func_tests/func_all.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
#include "core/util/util.hpp"
88

99
TEST(nesterov_a_test_task_all, test_matmul_50) {
10-
const size_t count = 50;
10+
constexpr size_t kCount = 50;
1111

1212
// Create data
13-
std::vector<int> in(count * count, 0);
14-
std::vector<int> out(count * count, 0);
13+
std::vector<int> in(kCount * kCount, 0);
14+
std::vector<int> out(kCount * kCount, 0);
1515

16-
for (size_t i = 0; i < count; i++) {
17-
in[(i * count) + i] = 1;
16+
for (size_t i = 0; i < kCount; i++) {
17+
in[(i * kCount) + i] = 1;
1818
}
1919

2020
// Create task_data

tasks/all/example/include/ops_all.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#pragma once
22

3-
#include <tbb/tbb.h>
3+
#include <oneapi/tbb.h>
44

55
#include <boost/mpi/collectives.hpp>
66
#include <boost/mpi/communicator.hpp>
7-
#include <string>
87
#include <vector>
98

109
#include "core/task/include/task.hpp"

tasks/all/example/perf_tests/perf_all.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#include <gtest/gtest.h>
22

3-
#include <boost/mpi/timer.hpp>
43
#include <vector>
54

65
#include "all/example/include/ops_all.hpp"
76
#include "core/perf/include/perf.hpp"
87

98
TEST(nesterov_a_test_task_all, test_pipeline_run) {
10-
const int count = 900;
9+
constexpr int kCount = 900;
1110

1211
// Create data
13-
std::vector<int> in(count * count, 0);
14-
std::vector<int> out(count * count, 0);
12+
std::vector<int> in(kCount * kCount, 0);
13+
std::vector<int> out(kCount * kCount, 0);
1514

16-
for (size_t i = 0; i < count; i++) {
17-
in[(i * count) + i] = 1;
15+
for (size_t i = 0; i < kCount; i++) {
16+
in[(i * kCount) + i] = 1;
1817
}
1918

2019
// Create task_data
@@ -52,14 +51,14 @@ TEST(nesterov_a_test_task_all, test_pipeline_run) {
5251
}
5352

5453
TEST(nesterov_a_test_task_all, test_task_run) {
55-
const int count = 900;
54+
constexpr int kCount = 900;
5655

5756
// Create data
58-
std::vector<int> in(count * count, 0);
59-
std::vector<int> out(count * count, 0);
57+
std::vector<int> in(kCount * kCount, 0);
58+
std::vector<int> out(kCount * kCount, 0);
6059

61-
for (size_t i = 0; i < count; i++) {
62-
in[(i * count) + i] = 1;
60+
for (size_t i = 0; i < kCount; i++) {
61+
in[(i * kCount) + i] = 1;
6362
}
6463

6564
// Create task_data

tasks/all/example/src/ops_all.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,13 @@ namespace {
99
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
1010
for (int i = 0; i < rc_size; ++i) {
1111
for (int j = 0; j < rc_size; ++j) {
12+
out_vec[(i * rc_size) + j] = 0;
1213
for (int k = 0; k < rc_size; ++k) {
1314
out_vec[(i * rc_size) + j] += in_vec[(i * rc_size) + k] * in_vec[(k * rc_size) + j];
1415
}
1516
}
1617
}
1718
}
18-
void MatMulElse(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
19-
for (int k = 0; k < rc_size; ++k) {
20-
for (int j = 0; j < rc_size; ++j) {
21-
for (int i = 0; i < rc_size; ++i) {
22-
out_vec[(i * rc_size) + j] += in_vec[(i * rc_size) + k] * in_vec[(k * rc_size) + j];
23-
}
24-
}
25-
}
26-
}
2719
} // namespace
2820

2921
bool nesterov_a_test_task_all::TestTaskALL::PreProcessingImpl() {
@@ -46,8 +38,11 @@ bool nesterov_a_test_task_all::TestTaskALL::ValidationImpl() {
4638

4739
bool nesterov_a_test_task_all::TestTaskALL::RunImpl() {
4840
if (world_.rank() == 0) {
49-
#pragma omp parallel
50-
{ MatMul(input_, rc_size_, output_); }
41+
#pragma omp parallel default(none)
42+
{
43+
#pragma omp critical
44+
{ MatMul(input_, rc_size_, output_); }
45+
}
5146
} else if (world_.rank() == 1) {
5247
const int num_threads = ppc::util::GetPPCNumThreads();
5348
std::vector<std::thread> threads(num_threads);
@@ -56,10 +51,16 @@ bool nesterov_a_test_task_all::TestTaskALL::RunImpl() {
5651
threads[i].join();
5752
}
5853
} else if (world_.rank() == 2) {
59-
oneapi::tbb::task_arena arena;
60-
arena.execute([&] { MatMul(input_, rc_size_, output_); });
54+
oneapi::tbb::task_arena arena(1);
55+
arena.execute([&] {
56+
tbb::task_group tg;
57+
for (int i = 0; i < ppc::util::GetPPCNumThreads(); ++i) {
58+
tg.run([&] { MatMul(input_, rc_size_, output_); });
59+
}
60+
tg.wait();
61+
});
6162
} else {
62-
MatMulElse(input_, rc_size_, output_);
63+
MatMul(input_, rc_size_, output_);
6364
}
6465
world_.barrier();
6566
return true;

0 commit comments

Comments
 (0)