Skip to content

Commit cb553bf

Browse files
committed
refactor perf tests
1 parent d254cdb commit cb553bf

7 files changed

Lines changed: 279 additions & 404 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <gtest/gtest.h>
2+
#include <mpi.h>
3+
4+
#include <chrono>
5+
#include <cstddef>
6+
#include <cstdint>
7+
#include <memory>
8+
#include <vector>
9+
10+
#include "all/example/include/ops_all.hpp"
11+
#include "core/perf/include/perf.hpp"
12+
#include "core/task/include/task.hpp"
13+
14+
class NesterovAllRunTest : public ::testing::TestWithParam<ppc::core::PerfResults::TypeOfRunning> {
15+
protected:
16+
static constexpr int kCount = 400;
17+
std::vector<int> input_data;
18+
19+
void SetUp() override {
20+
input_data.assign(kCount * kCount, 0);
21+
for (int i = 0; i < kCount; ++i) {
22+
input_data[(i * kCount) + i] = 1;
23+
}
24+
}
25+
26+
void ExecuteTest(ppc::core::PerfResults::TypeOfRunning mode) {
27+
auto task = std::make_shared<nesterov_a_test_task_all::TestTaskALL>(input_data);
28+
29+
ppc::core::PerfAttr perf_attr;
30+
const auto t0 = std::chrono::high_resolution_clock::now();
31+
perf_attr.current_timer = [&] {
32+
auto now = std::chrono::high_resolution_clock::now();
33+
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now - t0).count();
34+
return static_cast<double>(ns) * 1e-9;
35+
};
36+
37+
ppc::core::PerfResults perf_results;
38+
ppc::core::Perf perf(task);
39+
40+
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
41+
perf.PipelineRun(perf_attr, perf_results);
42+
} else {
43+
perf.TaskRun(perf_attr, perf_results);
44+
}
45+
46+
int rank = -1;
47+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48+
if (rank == 0) {
49+
ppc::core::Perf::PrintPerfStatistic(perf_results);
50+
}
51+
52+
ASSERT_EQ(input_data, task->Get());
53+
}
54+
};
55+
56+
TEST_P(NesterovAllRunTest, RunModes) { ExecuteTest(GetParam()); }
57+
58+
INSTANTIATE_TEST_SUITE_P(RunModeTests, NesterovAllRunTest,
59+
::testing::Values(ppc::core::PerfResults::TypeOfRunning::kPipeline,
60+
ppc::core::PerfResults::TypeOfRunning::kTaskRun));

tasks/all/example/perf_tests/perf_all.cpp

Lines changed: 0 additions & 89 deletions
This file was deleted.

tasks/mpi/example/perf_tests/main.cpp

Lines changed: 47 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,53 @@
1111
#include "core/task/include/task.hpp"
1212
#include "mpi/example/include/ops_mpi.hpp"
1313

14-
TEST(nesterov_a_test_task_mpi, test_pipeline_run) {
15-
constexpr int kCount = 500;
16-
17-
// Create data
18-
std::vector<int> in(kCount * kCount, 0);
19-
20-
for (size_t i = 0; i < kCount; i++) {
21-
in[(i * kCount) + i] = 1;
22-
}
23-
24-
// Create Task
25-
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
26-
27-
// Create Perf attributes
28-
ppc::core::PerfAttr perf_attr;
29-
const auto t0 = std::chrono::high_resolution_clock::now();
30-
perf_attr.current_timer = [&] {
31-
auto current_time_point = std::chrono::high_resolution_clock::now();
32-
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
33-
return static_cast<double>(duration) * 1e-9;
34-
};
35-
36-
// Create and init perf results
37-
ppc::core::PerfResults perf_results;
38-
39-
ppc::core::Perf perf_analyzer(test_task_mpi);
40-
perf_analyzer.PipelineRun(perf_attr, perf_results);
41-
// Create Perf analyzer
42-
int rank = -1;
43-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
44-
if (rank == 0) {
45-
ppc::core::Perf::PrintPerfStatistic(perf_results);
46-
}
47-
48-
ASSERT_EQ(in, test_task_mpi->Get());
49-
}
50-
51-
TEST(nesterov_a_test_task_mpi, test_task_run) {
52-
constexpr int kCount = 500;
53-
54-
// Create data
55-
std::vector<int> in(kCount * kCount, 0);
56-
57-
for (size_t i = 0; i < kCount; i++) {
58-
in[(i * kCount) + i] = 1;
14+
class NesterovATaskMPITest : public ::testing::TestWithParam<ppc::core::PerfResults::TypeOfRunning> {
15+
protected:
16+
static void RunTest(ppc::core::PerfResults::TypeOfRunning mode) {
17+
constexpr int kCount = 500;
18+
19+
// Create data
20+
std::vector<int> in(kCount * kCount, 0);
21+
for (size_t i = 0; i < kCount; i++) {
22+
in[(i * kCount) + i] = 1;
23+
}
24+
25+
// Create Task
26+
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
27+
28+
// Create Perf attributes
29+
ppc::core::PerfAttr perf_attr;
30+
const auto t0 = std::chrono::high_resolution_clock::now();
31+
perf_attr.current_timer = [&] {
32+
auto current_time_point = std::chrono::high_resolution_clock::now();
33+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
34+
return static_cast<double>(duration) * 1e-9;
35+
};
36+
37+
// Create and init perf results
38+
ppc::core::PerfResults perf_results;
39+
40+
// Create Perf analyzer
41+
ppc::core::Perf perf_analyzer(test_task_mpi);
42+
43+
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
44+
perf_analyzer.PipelineRun(perf_attr, perf_results);
45+
} else {
46+
perf_analyzer.TaskRun(perf_attr, perf_results);
47+
}
48+
49+
int rank = -1;
50+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
51+
if (rank == 0) {
52+
ppc::core::Perf::PrintPerfStatistic(perf_results);
53+
}
54+
55+
ASSERT_EQ(in, test_task_mpi->Get());
5956
}
57+
};
6058

61-
// Create Task
62-
auto test_task_mpi = std::make_shared<nesterov_a_test_task_mpi::TestTaskMPI>(in);
63-
64-
// Create Perf attributes
65-
ppc::core::PerfAttr perf_attr;
66-
const auto t0 = std::chrono::high_resolution_clock::now();
67-
perf_attr.current_timer = [&] {
68-
auto current_time_point = std::chrono::high_resolution_clock::now();
69-
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
70-
return static_cast<double>(duration) * 1e-9;
71-
};
72-
73-
// Create and init perf results
74-
ppc::core::PerfResults perf_results;
75-
76-
// Create Perf analyzer
77-
ppc::core::Perf perf_analyzer(test_task_mpi);
78-
perf_analyzer.TaskRun(perf_attr, perf_results);
79-
// Create Perf analyzer
80-
int rank = -1;
81-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
82-
if (rank == 0) {
83-
ppc::core::Perf::PrintPerfStatistic(perf_results);
84-
}
59+
TEST_P(NesterovATaskMPITest, RunModes) { RunTest(GetParam()); }
8560

86-
ASSERT_EQ(in, test_task_mpi->Get());
87-
}
61+
INSTANTIATE_TEST_SUITE_P(NesterovATests, NesterovATaskMPITest,
62+
::testing::Values(ppc::core::PerfResults::TypeOfRunning::kPipeline,
63+
ppc::core::PerfResults::TypeOfRunning::kTaskRun));

tasks/omp/example/perf_tests/main.cpp

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,49 @@
1010
#include "core/task/include/task.hpp"
1111
#include "omp/example/include/ops_omp.hpp"
1212

13-
TEST(nesterov_a_test_task_omp, test_pipeline_run) {
14-
constexpr int kCount = 300;
15-
16-
// Create data
17-
std::vector<int> in(kCount * kCount, 0);
18-
19-
for (size_t i = 0; i < kCount; i++) {
20-
in[(i * kCount) + i] = 1;
21-
}
22-
23-
// Create Task
24-
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
25-
26-
// Create Perf attributes
27-
ppc::core::PerfAttr perf_attr;
28-
const auto t0 = std::chrono::high_resolution_clock::now();
29-
perf_attr.current_timer = [&] {
30-
auto current_time_point = std::chrono::high_resolution_clock::now();
31-
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
32-
return static_cast<double>(duration) * 1e-9;
33-
};
34-
35-
// Create and init perf results
36-
ppc::core::PerfResults perf_results;
37-
38-
// Create Perf analyzer
39-
ppc::core::Perf perf_analyzer(test_task_omp);
40-
perf_analyzer.PipelineRun(perf_attr, perf_results);
41-
ppc::core::Perf::PrintPerfStatistic(perf_results);
42-
43-
ASSERT_EQ(in, test_task_omp->Get());
44-
}
45-
46-
TEST(nesterov_a_test_task_omp, test_task_run) {
47-
constexpr int kCount = 300;
48-
49-
// Create data
50-
std::vector<int> in(kCount * kCount, 0);
51-
52-
for (size_t i = 0; i < kCount; i++) {
53-
in[(i * kCount) + i] = 1;
13+
class NesterovTaskOMPTest : public ::testing::TestWithParam<ppc::core::PerfResults::TypeOfRunning> {
14+
protected:
15+
static void RunTest(ppc::core::PerfResults::TypeOfRunning mode) {
16+
constexpr int kCount = 300;
17+
18+
// Create data
19+
std::vector<int> in(kCount * kCount, 0);
20+
for (size_t i = 0; i < kCount; i++) {
21+
in[(i * kCount) + i] = 1;
22+
}
23+
24+
// Create Task
25+
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
26+
27+
// Create Perf attributes
28+
ppc::core::PerfAttr perf_attr;
29+
const auto t0 = std::chrono::high_resolution_clock::now();
30+
perf_attr.current_timer = [&] {
31+
auto current_time_point = std::chrono::high_resolution_clock::now();
32+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
33+
return static_cast<double>(duration) * 1e-9;
34+
};
35+
36+
// Create and init perf results
37+
ppc::core::PerfResults perf_results;
38+
39+
// Create Perf analyzer
40+
ppc::core::Perf perf_analyzer(test_task_omp);
41+
42+
if (mode == ppc::core::PerfResults::TypeOfRunning::kPipeline) {
43+
perf_analyzer.PipelineRun(perf_attr, perf_results);
44+
} else {
45+
perf_analyzer.TaskRun(perf_attr, perf_results);
46+
}
47+
48+
ppc::core::Perf::PrintPerfStatistic(perf_results);
49+
50+
ASSERT_EQ(in, test_task_omp->Get());
5451
}
52+
};
5553

56-
// Create Task
57-
auto test_task_omp = std::make_shared<nesterov_a_test_task_omp::TestTaskOpenMP>(in);
58-
59-
// Create Perf attributes
60-
ppc::core::PerfAttr perf_attr;
61-
const auto t0 = std::chrono::high_resolution_clock::now();
62-
perf_attr.current_timer = [&] {
63-
auto current_time_point = std::chrono::high_resolution_clock::now();
64-
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
65-
return static_cast<double>(duration) * 1e-9;
66-
};
67-
68-
// Create and init perf results
69-
ppc::core::PerfResults perf_results;
70-
71-
// Create Perf analyzer
72-
ppc::core::Perf perf_analyzer(test_task_omp);
73-
perf_analyzer.TaskRun(perf_attr, perf_results);
74-
ppc::core::Perf::PrintPerfStatistic(perf_results);
54+
TEST_P(NesterovTaskOMPTest, RunModes) { RunTest(GetParam()); }
7555

76-
ASSERT_EQ(in, test_task_omp->Get());
77-
}
56+
INSTANTIATE_TEST_SUITE_P(NesterovOMPTests, NesterovTaskOMPTest,
57+
::testing::Values(ppc::core::PerfResults::TypeOfRunning::kPipeline,
58+
ppc::core::PerfResults::TypeOfRunning::kTaskRun));

0 commit comments

Comments
 (0)