Skip to content

Commit ca057a4

Browse files
authored
Simplify examples (#236)
1 parent 8b7417b commit ca057a4

File tree

62 files changed

+915
-3666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+915
-3666
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 & 11 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 {
@@ -32,19 +30,16 @@ class Perf {
3230
void SetTask(const std::shared_ptr<Task>& task_ptr);
3331
// Check performance of full task's pipeline: PreProcessing() ->
3432
// Validation() -> Run() -> PostProcessing()
35-
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
36-
const std::shared_ptr<ppc::core::PerfResults>& perf_results);
33+
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
3734
// 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);
35+
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
3936
// Pint results for automation checkers
4037
static void PrintPerfStatistic(const std::shared_ptr<PerfResults>& perf_results);
4138

4239
private:
4340
std::shared_ptr<Task> task_;
4441
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);
42+
const std::shared_ptr<PerfResults>& perf_results);
4643
};
4744

4845
} // 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: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#ifndef MODULES_CORE_INCLUDE_TASK_HPP_
2-
#define MODULES_CORE_INCLUDE_TASK_HPP_
1+
#pragma once
32

43
#include <chrono>
54
#include <cstdint>
65
#include <filesystem>
7-
#include <iostream>
86
#include <memory>
97
#include <string>
108
#include <vector>
@@ -70,11 +68,4 @@ class Task {
7068
std::chrono::high_resolution_clock::time_point tmp_time_point_;
7169
};
7270

73-
inline std::string GetAbsolutePath(const std::string &relative_path) {
74-
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
75-
return path.string();
76-
}
77-
7871
} // namespace ppc::core
79-
80-
#endif // MODULES_CORE_INCLUDE_TASK_HPP_

modules/core/util/util.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#ifdef _WIN32
4+
#include <cstdint>
5+
#include <iostream>
6+
#include <memory>
7+
#include <vector>
8+
#endif
9+
10+
#include <filesystem>
11+
#include <string>
12+
13+
namespace ppc::util {
14+
15+
inline std::string GetAbsolutePath(const std::string &relative_path) {
16+
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
17+
return path.string();
18+
}
19+
20+
inline int GetPPCNumThreads() {
21+
#ifdef _WIN32
22+
size_t len;
23+
char omp_env[100];
24+
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
25+
if (err != 0 || len == 0) {
26+
omp_env[0] = '\0';
27+
}
28+
#else
29+
const char *omp_env = std::getenv("OMP_NUM_THREADS");
30+
#endif
31+
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
32+
return num_threads;
33+
}
34+
35+
} // namespace ppc::util

scripts/generate_perf_results.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mkdir build/perf_stat_dir
2-
source scripts/run_perf_collector.sh &> build/perf_stat_dir/perf_log.txt
2+
source scripts/run_perf_collector.sh | tee build/perf_stat_dir/perf_log.txt
33
python3 scripts/create_perf_table.py --input build/perf_stat_dir/perf_log.txt --output build/perf_stat_dir

tasks/all/example/data/pic_mpi.jpg

-14.4 KB
Binary file not shown.

tasks/all/example/data/pic_omp.jpg

-20.1 KB
Binary file not shown.

tasks/all/example/data/pic_stl.jpg

-50.4 KB
Binary file not shown.

tasks/all/example/data/pic_tbb.jpg

-13.9 KB
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <opencv2/opencv.hpp>
4+
#include <vector>
5+
6+
#include "all/example/include/ops_all.hpp"
7+
#include "core/util/util.hpp"
8+
9+
TEST(nesterov_a_test_task_all, test_matmul_50) {
10+
constexpr size_t kCount = 50;
11+
12+
// Create data
13+
std::vector<int> in(kCount * kCount, 0);
14+
std::vector<int> out(kCount * kCount, 0);
15+
16+
for (size_t i = 0; i < kCount; i++) {
17+
in[(i * kCount) + i] = 1;
18+
}
19+
20+
// Create task_data
21+
auto task_data_all = std::make_shared<ppc::core::TaskData>();
22+
task_data_all->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
23+
task_data_all->inputs_count.emplace_back(in.size());
24+
task_data_all->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
25+
task_data_all->outputs_count.emplace_back(out.size());
26+
27+
// Create Task
28+
nesterov_a_test_task_all::TestTaskALL test_task_all(task_data_all);
29+
ASSERT_EQ(test_task_all.Validation(), true);
30+
test_task_all.PreProcessing();
31+
test_task_all.Run();
32+
test_task_all.PostProcessing();
33+
EXPECT_EQ(in, out);
34+
}
35+
36+
TEST(nesterov_a_test_task_all, test_matmul_from_pic) {
37+
cv::Mat img = cv::imread(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"));
38+
EXPECT_EQ(img.rows, img.cols);
39+
const int count = img.rows + img.cols;
40+
41+
// Create data
42+
std::vector<int> in(count * count, 0);
43+
std::vector<int> out(count * count, 0);
44+
45+
for (int i = 0; i < count; i++) {
46+
in[(i * count) + i] = 1;
47+
}
48+
49+
// Create task_data
50+
auto task_data_all = std::make_shared<ppc::core::TaskData>();
51+
task_data_all->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
52+
task_data_all->inputs_count.emplace_back(in.size());
53+
task_data_all->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
54+
task_data_all->outputs_count.emplace_back(out.size());
55+
56+
// Create Task
57+
nesterov_a_test_task_all::TestTaskALL test_task_all(task_data_all);
58+
ASSERT_EQ(test_task_all.Validation(), true);
59+
test_task_all.PreProcessing();
60+
test_task_all.Run();
61+
test_task_all.PostProcessing();
62+
EXPECT_EQ(in, out);
63+
}

0 commit comments

Comments
 (0)