Skip to content

Commit 7d9558a

Browse files
committed
change perf api
1 parent d8a1474 commit 7d9558a

9 files changed

Lines changed: 102 additions & 98 deletions

File tree

modules/core/perf/func_tests/perf_tests.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ TEST(perf_tests, check_perf_pipeline) {
1717
auto test_task = std::make_shared<ppc::test::perf::TestTask<uint32_t>>(in);
1818

1919
// Create Perf attributes
20-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
20+
ppc::core::PerfAttr perf_attr;
2121

2222
// Create and init perf results
23-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
23+
ppc::core::PerfResults perf_results;
2424

2525
// Create Perf analyzer
2626
ppc::core::Perf perf_analyzer(test_task);
2727
perf_analyzer.PipelineRun(perf_attr, perf_results);
2828

2929
// Get perf statistic
3030
ppc::core::Perf::PrintPerfStatistic(perf_results);
31-
ASSERT_LE(perf_results->time_sec, ppc::core::PerfResults::kMaxTime);
31+
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
3232
EXPECT_EQ(test_task->Get(), in.size());
3333
}
3434

@@ -40,18 +40,18 @@ TEST(perf_tests, check_perf_pipeline_float) {
4040
auto test_task = std::make_shared<ppc::test::perf::TestTask<float>>(in);
4141

4242
// Create Perf attributes
43-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
43+
ppc::core::PerfAttr perf_attr;
4444

4545
// Create and init perf results
46-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
46+
ppc::core::PerfResults perf_results;
4747

4848
// Create Perf analyzer
4949
ppc::core::Perf perf_analyzer(test_task);
5050
perf_analyzer.PipelineRun(perf_attr, perf_results);
5151

5252
// Get perf statistic
5353
ppc::core::Perf::PrintPerfStatistic(perf_results);
54-
ASSERT_LE(perf_results->time_sec, ppc::core::PerfResults::kMaxTime);
54+
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
5555
EXPECT_EQ(test_task->Get(), in.size());
5656
}
5757

@@ -63,18 +63,18 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
6363
auto test_task = std::make_shared<ppc::test::perf::FakePerfTask<uint8_t>>(in);
6464

6565
// Create Perf attributes
66-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
67-
perf_attr->num_running = 1;
66+
ppc::core::PerfAttr perf_attr;
67+
perf_attr.num_running = 1;
6868

6969
const auto t0 = std::chrono::high_resolution_clock::now();
70-
perf_attr->current_timer = [&] {
70+
perf_attr.current_timer = [&] {
7171
auto current_time_point = std::chrono::high_resolution_clock::now();
7272
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
7373
return static_cast<double>(duration) * 1e-9;
7474
};
7575

7676
// Create and init perf results
77-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
77+
ppc::core::PerfResults perf_results;
7878

7979
// Create Perf analyzer
8080
ppc::core::Perf perf_analyzer(test_task);
@@ -92,19 +92,19 @@ TEST(perf_tests, check_perf_task) {
9292
auto test_task = std::make_shared<ppc::test::perf::TestTask<uint32_t>>(in);
9393

9494
// Create Perf attributes
95-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
95+
ppc::core::PerfAttr perf_attr;
9696

9797
// Create and init perf results
98-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
98+
ppc::core::PerfResults perf_results;
9999

100100
// Create Perf analyzer
101101
ppc::core::Perf perf_analyzer(test_task);
102102
perf_analyzer.TaskRun(perf_attr, perf_results);
103103

104104
// Get perf statistic
105-
perf_results->type_of_running = ppc::core::PerfResults::kNone;
105+
perf_results.type_of_running = ppc::core::PerfResults::kNone;
106106
ppc::core::Perf::PrintPerfStatistic(perf_results);
107-
ASSERT_LE(perf_results->time_sec, ppc::core::PerfResults::kMaxTime);
107+
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
108108
EXPECT_EQ(test_task->Get(), in.size());
109109
}
110110

@@ -116,18 +116,18 @@ TEST(perf_tests, check_perf_task_float) {
116116
auto test_task = std::make_shared<ppc::test::perf::TestTask<float>>(in);
117117

118118
// Create Perf attributes
119-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
119+
ppc::core::PerfAttr perf_attr;
120120

121121
// Create and init perf results
122-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
122+
ppc::core::PerfResults perf_results;
123123

124124
// Create Perf analyzer
125125
ppc::core::Perf perf_analyzer(test_task);
126126
perf_analyzer.TaskRun(perf_attr, perf_results);
127127

128128
// Get perf statistic
129-
perf_results->type_of_running = ppc::core::PerfResults::kPipeline;
129+
perf_results.type_of_running = ppc::core::PerfResults::kPipeline;
130130
ppc::core::Perf::PrintPerfStatistic(perf_results);
131-
ASSERT_LE(perf_results->time_sec, ppc::core::PerfResults::kMaxTime);
131+
ASSERT_LE(perf_results.time_sec, ppc::core::PerfResults::kMaxTime);
132132
EXPECT_EQ(test_task->Get(), in.size());
133133
}

modules/core/perf/include/perf.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ class Perf {
2525
public:
2626
// Init performance analysis with initialized task and initialized data
2727
explicit Perf(const std::shared_ptr<Task>& task_ptr);
28-
// Set task with initialized task and initialized data for performance
28+
// Set task with an initialized task and initialized data for performance
2929
// analysis c
3030
void SetTask(const std::shared_ptr<Task>& task_ptr);
3131
// Check performance of full task's pipeline: PreProcessing() ->
3232
// Validation() -> Run() -> PostProcessing()
33-
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
33+
void PipelineRun(const PerfAttr& perf_attr, PerfResults& perf_results) const;
3434
// Check performance of task's Run() function
35-
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
35+
void TaskRun(const PerfAttr& perf_attr, PerfResults& perf_results) const;
3636
// Pint results for automation checkers
37-
static void PrintPerfStatistic(const std::shared_ptr<PerfResults>& perf_results);
37+
static void PrintPerfStatistic(const PerfResults& perf_results);
3838

3939
private:
4040
std::shared_ptr<Task> task_;
41-
static void CommonRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::function<void()>& pipeline,
42-
const std::shared_ptr<PerfResults>& perf_results);
41+
static void CommonRun(const PerfAttr& perf_attr, const std::function<void()>& pipeline, PerfResults& perf_results);
4342
};
4443

4544
} // namespace ppc::core

modules/core/perf/src/perf.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ void ppc::core::Perf::SetTask(const std::shared_ptr<Task>& task_ptr) {
2020
this->task_ = task_ptr;
2121
}
2222

23-
void ppc::core::Perf::PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
24-
const std::shared_ptr<ppc::core::PerfResults>& perf_results) const {
25-
perf_results->type_of_running = PerfResults::TypeOfRunning::kPipeline;
23+
void ppc::core::Perf::PipelineRun(const PerfAttr& perf_attr, ppc::core::PerfResults& perf_results) const {
24+
perf_results.type_of_running = PerfResults::TypeOfRunning::kPipeline;
2625

2726
CommonRun(
2827
perf_attr,
@@ -35,9 +34,8 @@ void ppc::core::Perf::PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
3534
perf_results);
3635
}
3736

38-
void ppc::core::Perf::TaskRun(const std::shared_ptr<PerfAttr>& perf_attr,
39-
const std::shared_ptr<ppc::core::PerfResults>& perf_results) const {
40-
perf_results->type_of_running = PerfResults::TypeOfRunning::kTaskRun;
37+
void ppc::core::Perf::TaskRun(const PerfAttr& perf_attr, ppc::core::PerfResults& perf_results) const {
38+
perf_results.type_of_running = PerfResults::TypeOfRunning::kTaskRun;
4139

4240
task_->Validation();
4341
task_->PreProcessing();
@@ -50,27 +48,27 @@ void ppc::core::Perf::TaskRun(const std::shared_ptr<PerfAttr>& perf_attr,
5048
task_->PostProcessing();
5149
}
5250

53-
void ppc::core::Perf::CommonRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::function<void()>& pipeline,
54-
const std::shared_ptr<ppc::core::PerfResults>& perf_results) {
55-
auto begin = perf_attr->current_timer();
56-
for (uint64_t i = 0; i < perf_attr->num_running; i++) {
51+
void ppc::core::Perf::CommonRun(const PerfAttr& perf_attr, const std::function<void()>& pipeline,
52+
ppc::core::PerfResults& perf_results) {
53+
auto begin = perf_attr.current_timer();
54+
for (uint64_t i = 0; i < perf_attr.num_running; i++) {
5755
pipeline();
5856
}
59-
auto end = perf_attr->current_timer();
60-
perf_results->time_sec = end - begin;
57+
auto end = perf_attr.current_timer();
58+
perf_results.time_sec = end - begin;
6159
}
6260

63-
void ppc::core::Perf::PrintPerfStatistic(const std::shared_ptr<PerfResults>& perf_results) {
61+
void ppc::core::Perf::PrintPerfStatistic(const PerfResults& perf_results) {
6462
std::string relative_path(::testing::UnitTest::GetInstance()->current_test_info()->file());
6563
std::string ppc_regex_template("parallel_programming_course");
6664
std::string perf_regex_template("perf_tests");
6765
std::string type_test_name;
6866

69-
auto time_secs = perf_results->time_sec;
67+
auto time_secs = perf_results.time_sec;
7068

71-
if (perf_results->type_of_running == PerfResults::TypeOfRunning::kTaskRun) {
69+
if (perf_results.type_of_running == PerfResults::TypeOfRunning::kTaskRun) {
7270
type_test_name = "task_run";
73-
} else if (perf_results->type_of_running == PerfResults::TypeOfRunning::kPipeline) {
71+
} else if (perf_results.type_of_running == PerfResults::TypeOfRunning::kPipeline) {
7472
type_test_name = "pipeline";
7573
} else {
7674
type_test_name = "none";

tasks/all/example/perf_tests/perf_all.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ TEST(nesterov_a_test_task_all, test_pipeline_run) {
2525
auto test_task_all = std::make_shared<nesterov_a_test_task_all::TestTaskALL>(in);
2626

2727
// Create Perf attributes
28-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
28+
ppc::core::PerfAttr perf_attr;
2929
const auto t0 = std::chrono::high_resolution_clock::now();
30-
perf_attr->current_timer = [&] {
30+
perf_attr.current_timer = [&] {
3131
auto current_time_point = std::chrono::high_resolution_clock::now();
3232
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
3333
return static_cast<double>(duration) * 1e-9;
3434
};
3535

3636
// Create and init perf results
37-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
37+
ppc::core::PerfResults perf_results;
3838

39-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_all);
40-
perf_analyzer->PipelineRun(perf_attr, perf_results);
39+
// Create Perf analyzer
40+
ppc::core::Perf perf_analyzer(test_task_all);
41+
perf_analyzer.PipelineRun(perf_attr, perf_results);
4142
// Create Perf analyzer
4243
int rank = -1;
4344
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -62,20 +63,21 @@ TEST(nesterov_a_test_task_all, test_task_run) {
6263
auto test_task_all = std::make_shared<nesterov_a_test_task_all::TestTaskALL>(in);
6364

6465
// Create Perf attributes
65-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
66+
ppc::core::PerfAttr perf_attr;
6667
const auto t0 = std::chrono::high_resolution_clock::now();
67-
perf_attr->current_timer = [&] {
68+
perf_attr.current_timer = [&] {
6869
auto current_time_point = std::chrono::high_resolution_clock::now();
6970
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
7071
return static_cast<double>(duration) * 1e-9;
7172
};
7273

7374
// Create and init perf results
74-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
75+
ppc::core::PerfResults perf_results;
7576

7677
// Create Perf analyzer
77-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_all);
78-
perf_analyzer->TaskRun(perf_attr, perf_results);
78+
ppc::core::Perf perf_analyzer(test_task_all);
79+
perf_analyzer.TaskRun(perf_attr, perf_results);
80+
7981
// Create Perf analyzer
8082
int rank = -1;
8183
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

tasks/mpi/example/perf_tests/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ TEST(nesterov_a_test_task_mpi, test_pipeline_run) {
2525
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
2626

2727
// Create Perf attributes
28-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
28+
ppc::core::PerfAttr perf_attr;
2929
const auto t0 = std::chrono::high_resolution_clock::now();
30-
perf_attr->current_timer = [&] {
30+
perf_attr.current_timer = [&] {
3131
auto current_time_point = std::chrono::high_resolution_clock::now();
3232
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
3333
return static_cast<double>(duration) * 1e-9;
3434
};
3535

3636
// Create and init perf results
37-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
37+
ppc::core::PerfResults perf_results;
3838

39-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_mpi);
40-
perf_analyzer->PipelineRun(perf_attr, perf_results);
39+
ppc::core::Perf perf_analyzer(test_task_mpi);
40+
perf_analyzer.PipelineRun(perf_attr, perf_results);
4141
// Create Perf analyzer
4242
int rank = -1;
4343
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -62,20 +62,20 @@ TEST(nesterov_a_test_task_mpi, test_task_run) {
6262
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
6363

6464
// Create Perf attributes
65-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
65+
ppc::core::PerfAttr perf_attr;
6666
const auto t0 = std::chrono::high_resolution_clock::now();
67-
perf_attr->current_timer = [&] {
67+
perf_attr.current_timer = [&] {
6868
auto current_time_point = std::chrono::high_resolution_clock::now();
6969
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
7070
return static_cast<double>(duration) * 1e-9;
7171
};
7272

7373
// Create and init perf results
74-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
74+
ppc::core::PerfResults perf_results;
7575

7676
// Create Perf analyzer
77-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_mpi);
78-
perf_analyzer->TaskRun(perf_attr, perf_results);
77+
ppc::core::Perf perf_analyzer(test_task_mpi);
78+
perf_analyzer.TaskRun(perf_attr, perf_results);
7979
// Create Perf analyzer
8080
int rank = -1;
8181
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

tasks/omp/example/perf_tests/main.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ TEST(nesterov_a_test_task_omp, test_pipeline_run) {
2424
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
2525

2626
// Create Perf attributes
27-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
27+
ppc::core::PerfAttr perf_attr;
2828
const auto t0 = std::chrono::high_resolution_clock::now();
29-
perf_attr->current_timer = [&] {
29+
perf_attr.current_timer = [&] {
3030
auto current_time_point = std::chrono::high_resolution_clock::now();
3131
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
3232
return static_cast<double>(duration) * 1e-9;
3333
};
3434

3535
// Create and init perf results
36-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
36+
ppc::core::PerfResults perf_results;
3737

3838
// Create Perf analyzer
39-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_omp);
40-
perf_analyzer->PipelineRun(perf_attr, perf_results);
39+
ppc::core::Perf perf_analyzer(test_task_omp);
40+
perf_analyzer.PipelineRun(perf_attr, perf_results);
4141
ppc::core::Perf::PrintPerfStatistic(perf_results);
42+
4243
ASSERT_EQ(in, test_task_omp->Get());
4344
}
4445

@@ -56,20 +57,21 @@ TEST(nesterov_a_test_task_omp, test_task_run) {
5657
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
5758

5859
// Create Perf attributes
59-
auto perf_attr = std::make_shared<ppc::core::PerfAttr>();
60+
ppc::core::PerfAttr perf_attr;
6061
const auto t0 = std::chrono::high_resolution_clock::now();
61-
perf_attr->current_timer = [&] {
62+
perf_attr.current_timer = [&] {
6263
auto current_time_point = std::chrono::high_resolution_clock::now();
6364
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
6465
return static_cast<double>(duration) * 1e-9;
6566
};
6667

6768
// Create and init perf results
68-
auto perf_results = std::make_shared<ppc::core::PerfResults>();
69+
ppc::core::PerfResults perf_results;
6970

7071
// Create Perf analyzer
71-
auto perf_analyzer = std::make_shared<ppc::core::Perf>(test_task_omp);
72-
perf_analyzer->TaskRun(perf_attr, perf_results);
72+
ppc::core::Perf perf_analyzer(test_task_omp);
73+
perf_analyzer.TaskRun(perf_attr, perf_results);
7374
ppc::core::Perf::PrintPerfStatistic(perf_results);
75+
7476
ASSERT_EQ(in, test_task_omp->Get());
7577
}

0 commit comments

Comments
 (0)