-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (75 loc) · 3.23 KB
/
main.cpp
File metadata and controls
93 lines (75 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <gtest/gtest.h>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>
#include "core/perf/include/perf.hpp"
#include "core/task/include/task.hpp"
#include "seq/example/include/ops_seq.hpp"
TEST(nesterov_a_test_task_seq, test_pipeline_run) {
constexpr int kCount = 500;
// Create data
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}
// Create task_data
auto task_data_seq = std::make_shared<ppc::core::TaskData>();
task_data_seq->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
task_data_seq->inputs_count.emplace_back(in.size());
task_data_seq->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
task_data_seq->outputs_count.emplace_back(out.size());
// Create Task
auto test_task_sequential = std::make_shared<nesterov_a_test_task_seq::TestTaskSequential>(task_data_seq);
// Create Perf attributes
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
perf_attr->num_running = 10;
const auto t0 = std::chrono::high_resolution_clock::now();
perf_attr->current_timer = [&] {
auto current_time_point = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
return static_cast<double>(duration) * 1e-9;
};
// Create and init perf results
auto perf_results = std::make_shared<ppc::core::PerfResults>();
// Create Perf analyzer
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_sequential);
perf_analyzer->PipelineRun(perf_attr, perf_results);
ppc::core::Perf::PrintPerfStatistic(perf_results);
ASSERT_EQ(in, out);
}
TEST(nesterov_a_test_task_seq, test_task_run) {
constexpr int kCount = 500;
// Create data
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}
// Create task_data
auto task_data_seq = std::make_shared<ppc::core::TaskData>();
task_data_seq->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
task_data_seq->inputs_count.emplace_back(in.size());
task_data_seq->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
task_data_seq->outputs_count.emplace_back(out.size());
// Create Task
auto test_task_sequential = std::make_shared<nesterov_a_test_task_seq::TestTaskSequential>(task_data_seq);
// Create Perf attributes
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
perf_attr->num_running = 10;
const auto t0 = std::chrono::high_resolution_clock::now();
perf_attr->current_timer = [&] {
auto current_time_point = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
return static_cast<double>(duration) * 1e-9;
};
// Create and init perf results
auto perf_results = std::make_shared<ppc::core::PerfResults>();
// Create Perf analyzer
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_sequential);
perf_analyzer->TaskRun(perf_attr, perf_results);
ppc::core::Perf::PrintPerfStatistic(perf_results);
ASSERT_EQ(in, out);
}