Skip to content

Commit

Permalink
fix tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
allnes committed Jan 19, 2025
1 parent 728f00f commit 442ac45
Show file tree
Hide file tree
Showing 31 changed files with 172 additions and 190 deletions.
9 changes: 2 additions & 7 deletions modules/core/perf/func_tests/test_task.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#ifndef MODULES_CORE_TESTS_TEST_TASK_HPP_
#define MODULES_CORE_TESTS_TEST_TASK_HPP_

#include <gtest/gtest.h>
#pragma once

#include <memory>
#include <thread>
Expand All @@ -16,7 +13,7 @@ namespace ppc::test::perf {
template <class T>
class TestTask : public ppc::core::Task {
public:
explicit TestTask(ppc::core::TaskDataPtr task_data) : Task(task_data) {}
explicit TestTask(const ppc::core::TaskDataPtr &task_data) : Task(task_data) {}

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

} // namespace ppc::test::perf

#endif // MODULES_CORE_TESTS_TEST_TASK_HPP_
17 changes: 6 additions & 11 deletions modules/core/perf/include/perf.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef MODULES_CORE_INCLUDE_PERF_HPP_
#define MODULES_CORE_INCLUDE_PERF_HPP_
#pragma once

#include <cstdint>
#include <functional>
#include <memory>
#include <vector>

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

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

struct PerfResults {
// measurement of task's time (in seconds)
double time_sec = 0.0;
enum TypeOfRunning : uint8_t { kPipeline, kTaskRun, kNone } type_of_running = kNone;
constexpr const static double kMaxTime = 10.0;
constexpr static double kMaxTime = 10.0;
};

class Perf {
Expand All @@ -32,19 +30,16 @@ class Perf {
void SetTask(const std::shared_ptr<Task>& task_ptr);
// Check performance of full task's pipeline: PreProcessing() ->
// Validation() -> Run() -> PostProcessing()
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr,
const std::shared_ptr<ppc::core::PerfResults>& perf_results);
void PipelineRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
// Check performance of task's Run() function
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<ppc::core::PerfResults>& perf_results);
void TaskRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::shared_ptr<PerfResults>& perf_results) const;
// Pint results for automation checkers
static void PrintPerfStatistic(const std::shared_ptr<PerfResults>& perf_results);

private:
std::shared_ptr<Task> task_;
static void CommonRun(const std::shared_ptr<PerfAttr>& perf_attr, const std::function<void()>& pipeline,
const std::shared_ptr<ppc::core::PerfResults>& perf_results);
const std::shared_ptr<PerfResults>& perf_results);
};

} // namespace ppc::core

#endif // MODULES_CORE_INCLUDE_PERF_HPP_
5 changes: 2 additions & 3 deletions modules/core/perf/src/perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <iomanip>
#include <iostream>
#include <sstream>
#include <utility>

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

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

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

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

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

task_->Validation();
Expand Down
10 changes: 2 additions & 8 deletions modules/core/task/func_tests/test_task.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#ifndef MODULES_CORE_TESTS_TEST_TASK_HPP_
#define MODULES_CORE_TESTS_TEST_TASK_HPP_
#pragma once

#include <gtest/gtest.h>

#include <memory>
#include <vector>

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

} // namespace ppc::test::task

#endif // MODULES_CORE_TESTS_TEST_TASK_HPP_
1 change: 0 additions & 1 deletion modules/core/task/include/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <chrono>
#include <cstdint>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
Expand Down
8 changes: 5 additions & 3 deletions modules/core/util/util.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <chrono>
#ifdef _WIN32
#include <cstdint>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#endif

#include <filesystem>
#include <string>

namespace ppc::util {

Expand Down
10 changes: 5 additions & 5 deletions tasks/all/example/func_tests/func_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "core/util/util.hpp"

TEST(nesterov_a_test_task_all, test_matmul_50) {
const size_t count = 50;
constexpr size_t kCount = 50;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down
3 changes: 1 addition & 2 deletions tasks/all/example/include/ops_all.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include <tbb/tbb.h>
#include <oneapi/tbb.h>

#include <boost/mpi/collectives.hpp>
#include <boost/mpi/communicator.hpp>
#include <string>
#include <vector>

#include "core/task/include/task.hpp"
Expand Down
21 changes: 10 additions & 11 deletions tasks/all/example/perf_tests/perf_all.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <gtest/gtest.h>

#include <boost/mpi/timer.hpp>
#include <vector>

#include "all/example/include/ops_all.hpp"
#include "core/perf/include/perf.hpp"

TEST(nesterov_a_test_task_all, test_pipeline_run) {
const int count = 900;
constexpr int kCount = 900;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down Expand Up @@ -52,14 +51,14 @@ TEST(nesterov_a_test_task_all, test_pipeline_run) {
}

TEST(nesterov_a_test_task_all, test_task_run) {
const int count = 900;
constexpr int kCount = 900;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down
29 changes: 15 additions & 14 deletions tasks/all/example/src/ops_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ namespace {
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
for (int i = 0; i < rc_size; ++i) {
for (int j = 0; j < rc_size; ++j) {
out_vec[(i * rc_size) + j] = 0;
for (int k = 0; k < rc_size; ++k) {
out_vec[(i * rc_size) + j] += in_vec[(i * rc_size) + k] * in_vec[(k * rc_size) + j];
}
}
}
}
void MatMulElse(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {
for (int k = 0; k < rc_size; ++k) {
for (int j = 0; j < rc_size; ++j) {
for (int i = 0; i < rc_size; ++i) {
out_vec[(i * rc_size) + j] += in_vec[(i * rc_size) + k] * in_vec[(k * rc_size) + j];
}
}
}
}
} // namespace

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

bool nesterov_a_test_task_all::TestTaskALL::RunImpl() {
if (world_.rank() == 0) {
#pragma omp parallel
{ MatMul(input_, rc_size_, output_); }
#pragma omp parallel default(none)
{
#pragma omp critical
{ MatMul(input_, rc_size_, output_); }
}
} else if (world_.rank() == 1) {
const int num_threads = ppc::util::GetPPCNumThreads();
std::vector<std::thread> threads(num_threads);

Check warning on line 48 in tasks/all/example/src/ops_all.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/all/example/src/ops_all.cpp#L47-L48

Added lines #L47 - L48 were not covered by tests
Expand All @@ -56,10 +51,16 @@ bool nesterov_a_test_task_all::TestTaskALL::RunImpl() {
threads[i].join();
}
} else if (world_.rank() == 2) {
oneapi::tbb::task_arena arena;
arena.execute([&] { MatMul(input_, rc_size_, output_); });
oneapi::tbb::task_arena arena(1);
arena.execute([&] {
tbb::task_group tg;
for (int i = 0; i < ppc::util::GetPPCNumThreads(); ++i) {
tg.run([&] { MatMul(input_, rc_size_, output_); });
}
tg.wait();
});

Check warning on line 61 in tasks/all/example/src/ops_all.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/all/example/src/ops_all.cpp#L61

Added line #L61 was not covered by tests
} else {
MatMulElse(input_, rc_size_, output_);
MatMul(input_, rc_size_, output_);

Check warning on line 63 in tasks/all/example/src/ops_all.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/all/example/src/ops_all.cpp#L63

Added line #L63 was not covered by tests
}
world_.barrier();
return true;
Expand Down
10 changes: 5 additions & 5 deletions tasks/mpi/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "mpi/example/include/ops_mpi.hpp"

TEST(nesterov_a_test_task_mpi, test_matmul_50) {
const size_t count = 50;
constexpr size_t kCount = 50;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down
2 changes: 0 additions & 2 deletions tasks/mpi/example/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <boost/mpi/collectives.hpp>
#include <boost/mpi/communicator.hpp>
#include <memory>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

Expand Down
21 changes: 10 additions & 11 deletions tasks/mpi/example/perf_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <gtest/gtest.h>

#include <boost/mpi/timer.hpp>
#include <vector>

#include "core/perf/include/perf.hpp"
#include "mpi/example/include/ops_mpi.hpp"

TEST(nesterov_a_test_task_mpi, test_pipeline_run) {
const int count = 500;
constexpr int kCount = 500;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down Expand Up @@ -52,14 +51,14 @@ TEST(nesterov_a_test_task_mpi, test_pipeline_run) {
}

TEST(nesterov_a_test_task_mpi, test_task_run) {
const int count = 500;
constexpr int kCount = 500;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down
10 changes: 5 additions & 5 deletions tasks/omp/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "omp/example/include/ops_omp.hpp"

TEST(nesterov_a_test_task_omp, test_matmul_50) {
const size_t count = 50;
constexpr size_t kCount = 50;

// Create data
std::vector<int> in(count * count, 0);
std::vector<int> out(count * count, 0);
std::vector<int> in(kCount * kCount, 0);
std::vector<int> out(kCount * kCount, 0);

for (size_t i = 0; i < count; i++) {
in[(i * count) + i] = 1;
for (size_t i = 0; i < kCount; i++) {
in[(i * kCount) + i] = 1;
}

// Create task_data
Expand Down
1 change: 0 additions & 1 deletion tasks/omp/example/include/ops_omp.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <string>
#include <vector>

#include "core/task/include/task.hpp"
Expand Down
Loading

0 comments on commit 442ac45

Please sign in to comment.