Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_
11 changes: 1 addition & 10 deletions modules/core/task/include/task.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef MODULES_CORE_INCLUDE_TASK_HPP_
#define MODULES_CORE_INCLUDE_TASK_HPP_
#pragma once

#include <chrono>
#include <cstdint>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -70,11 +68,4 @@ class Task {
std::chrono::high_resolution_clock::time_point tmp_time_point_;
};

inline std::string GetAbsolutePath(const std::string &relative_path) {
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
return path.string();
}

} // namespace ppc::core

#endif // MODULES_CORE_INCLUDE_TASK_HPP_
35 changes: 35 additions & 0 deletions modules/core/util/util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#ifdef _WIN32
#include <cstdint>
#include <iostream>
#include <memory>
#include <vector>
#endif

#include <filesystem>
#include <string>

namespace ppc::util {

inline std::string GetAbsolutePath(const std::string &relative_path) {
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
return path.string();
}

inline int GetPPCNumThreads() {
#ifdef _WIN32
size_t len;
char omp_env[100];
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
if (err != 0 || len == 0) {
omp_env[0] = '\0';
}
#else
const char *omp_env = std::getenv("OMP_NUM_THREADS");
#endif
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
return num_threads;
}

} // namespace ppc::util
2 changes: 1 addition & 1 deletion scripts/generate_perf_results.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mkdir build/perf_stat_dir
source scripts/run_perf_collector.sh &> build/perf_stat_dir/perf_log.txt
source scripts/run_perf_collector.sh | tee build/perf_stat_dir/perf_log.txt
python3 scripts/create_perf_table.py --input build/perf_stat_dir/perf_log.txt --output build/perf_stat_dir
Binary file removed tasks/all/example/data/pic_mpi.jpg
Binary file not shown.
Binary file removed tasks/all/example/data/pic_omp.jpg
Binary file not shown.
Binary file removed tasks/all/example/data/pic_stl.jpg
Binary file not shown.
Binary file removed tasks/all/example/data/pic_tbb.jpg
Binary file not shown.
63 changes: 63 additions & 0 deletions tasks/all/example/func_tests/func_all.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <gtest/gtest.h>

#include <opencv2/opencv.hpp>
#include <vector>

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

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

// 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_all = std::make_shared<ppc::core::TaskData>();
task_data_all->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
task_data_all->inputs_count.emplace_back(in.size());
task_data_all->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
task_data_all->outputs_count.emplace_back(out.size());

// Create Task
nesterov_a_test_task_all::TestTaskALL test_task_all(task_data_all);
ASSERT_EQ(test_task_all.Validation(), true);
test_task_all.PreProcessing();
test_task_all.Run();
test_task_all.PostProcessing();
EXPECT_EQ(in, out);
}

TEST(nesterov_a_test_task_all, test_matmul_from_pic) {
cv::Mat img = cv::imread(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"));
EXPECT_EQ(img.rows, img.cols);
const int count = img.rows + img.cols;

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

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

// Create task_data
auto task_data_all = std::make_shared<ppc::core::TaskData>();
task_data_all->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
task_data_all->inputs_count.emplace_back(in.size());
task_data_all->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
task_data_all->outputs_count.emplace_back(out.size());

// Create Task
nesterov_a_test_task_all::TestTaskALL test_task_all(task_data_all);
ASSERT_EQ(test_task_all.Validation(), true);
test_task_all.PreProcessing();
test_task_all.Run();
test_task_all.PostProcessing();
EXPECT_EQ(in, out);
}
Loading
Loading