This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
forked from mahbhlddnhakkh/ppc-2024-threads
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'learning-process:master' into master
- Loading branch information
Showing
396 changed files
with
44,356 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ venv* | |
sln/ | ||
.DS_Store | ||
.cache | ||
.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// Copyright 2024 Akopyan Zal | ||
#include <gtest/gtest.h> | ||
|
||
#include <vector> | ||
|
||
#include "omp/akopyan_z_bin_hull/include/ops_omp.hpp" | ||
|
||
namespace task = akopyan_z_bin_hull_omp; | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, small_test_tri) { | ||
int width = 3; | ||
int height = 4; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in = {0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0}; | ||
|
||
std::vector<int> hullTrue = {0, 1, 1, 0, 2, 1, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
|
||
// Create Task | ||
task::AkopyanZBinHull testTaskSequential(taskData); | ||
ASSERT_EQ(testTaskSequential.validation(), true); | ||
testTaskSequential.pre_processing(); | ||
testTaskSequential.run(); | ||
testTaskSequential.post_processing(); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) EXPECT_EQ(hullTrue[i], out[i]); | ||
} | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, small_test_cross) { | ||
int width = 3; | ||
int height = 4; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in = {0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}; | ||
|
||
std::vector<int> hullTrue = {0, 1, 1, 0, 2, 1, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
|
||
// Create Task | ||
task::AkopyanZBinHull testTaskSequential(taskData); | ||
ASSERT_EQ(testTaskSequential.validation(), true); | ||
testTaskSequential.pre_processing(); | ||
testTaskSequential.run(); | ||
testTaskSequential.post_processing(); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) EXPECT_EQ(hullTrue[i], out[i]); | ||
} | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, two_labels_test) { | ||
int width = 6; | ||
int height = 6; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in = {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, | ||
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0}; | ||
|
||
std::vector<int> hullTrue = {0, 2, 1, 1, 2, 2, 1, 3, task::SEPARATOR, 3, 4, 4, 2, 5, 4, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
|
||
// Create Task | ||
task::AkopyanZBinHull testTaskSequential(taskData); | ||
ASSERT_EQ(testTaskSequential.validation(), true); | ||
testTaskSequential.pre_processing(); | ||
testTaskSequential.run(); | ||
testTaskSequential.post_processing(); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) EXPECT_EQ(hullTrue[i], out[i]); | ||
} | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, two_labels_test2) { | ||
int width = 5; | ||
int height = 8; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in = {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0}; | ||
|
||
std::vector<int> hullTrue = {2, 2, 3, 1, 4, 2, task::SEPARATOR, 0, 6, 1, 6, 1, 7, 0, 7, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
|
||
// Create Task | ||
task::AkopyanZBinHull testTaskSequential(taskData); | ||
ASSERT_EQ(testTaskSequential.validation(), true); | ||
testTaskSequential.pre_processing(); | ||
testTaskSequential.run(); | ||
testTaskSequential.post_processing(); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) ASSERT_EQ(hullTrue[i], out[i]); | ||
} | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, generated_test) { | ||
int width = 10; | ||
int height = 10; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in(width * height, 0); | ||
int sqw = width / 2; | ||
int sqh = height / 2; | ||
for (int i = 0; i < sqh - 1; i++) { | ||
for (int j = 0; j < sqw - 1; j++) { | ||
in[i * width + j] = 1; | ||
in[i * width + (sqw + 1 + j)] = 1; | ||
} | ||
} | ||
for (int i = 0; i < width; i++) { | ||
in[sqh * width + i] = 1; | ||
in[(sqh + 2) * width + i] = 1; | ||
} | ||
for (int i = sqh + 3; i < height; i++) { | ||
in[i * width + sqw - 1] = 1; | ||
in[i * width + sqw] = 1; | ||
} | ||
|
||
std::vector<int> hullTrue = { | ||
0, 0, sqw - 2, 0, sqw - 2, sqh - 2, 0, sqh - 2, task::SEPARATOR, | ||
sqw + 1, 0, width - 1, 0, width - 1, sqh - 2, sqw + 1, sqh - 2, task::SEPARATOR, | ||
0, sqh, width - 1, sqh, task::SEPARATOR, 0, sqh + 2, width - 1, sqh + 2, | ||
sqw, height - 1, sqw - 1, height - 1, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
|
||
// Create Task | ||
task::AkopyanZBinHull testTaskSequential(taskData); | ||
ASSERT_EQ(testTaskSequential.validation(), true); | ||
testTaskSequential.pre_processing(); | ||
testTaskSequential.run(); | ||
testTaskSequential.post_processing(); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) ASSERT_EQ(hullTrue[i], out[i]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2024 Akopyan Zal | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "core/task/include/task.hpp" | ||
|
||
namespace akopyan_z_bin_hull_omp { | ||
struct pnt { | ||
int x{}; | ||
int y{}; | ||
pnt() = default; | ||
pnt(int x_, int y_) : x(x_), y(y_) {} | ||
}; | ||
|
||
const int SEPARATOR = -1; | ||
|
||
class AkopyanZBinHull : public ppc::core::Task { | ||
public: | ||
explicit AkopyanZBinHull(std::shared_ptr<ppc::core::TaskData> taskData_) : Task(std::move(taskData_)) {} | ||
bool pre_processing() override; | ||
bool validation() override; | ||
bool run() override; | ||
bool post_processing() override; | ||
|
||
private: | ||
std::vector<int> bin_image{}; | ||
std::vector<int> out_hull{}; | ||
int width{}; | ||
int height{}; | ||
|
||
std::vector<std::vector<pnt>> label_components(); | ||
static std::vector<pnt> graham(std::vector<pnt> points); | ||
}; | ||
} // namespace akopyan_z_bin_hull_omp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2024 Akopyan Zal | ||
#include <gtest/gtest.h> | ||
#include <omp.h> | ||
|
||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include "core/perf/include/perf.hpp" | ||
#include "omp/akopyan_z_bin_hull/include/ops_omp.hpp" | ||
|
||
namespace task = akopyan_z_bin_hull_omp; | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, test_pipeline_run) { | ||
int width = 2000; | ||
int height = 2000; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in(width * height, 0); | ||
int sqw = width / 2; | ||
int sqh = height / 2; | ||
for (int i = 0; i < sqh - 1; i++) { | ||
for (int j = 0; j < sqw - 1; j++) { | ||
in[i * width + j] = 1; | ||
in[i * width + (sqw + 1 + j)] = 1; | ||
} | ||
} | ||
for (int i = 0; i < width; i++) { | ||
in[sqh * width + i] = 1; | ||
in[(sqh + 2) * width + i] = 1; | ||
} | ||
for (int i = sqh + 3; i < height; i++) { | ||
in[i * width + sqw - 1] = 1; | ||
in[i * width + sqw] = 1; | ||
} | ||
|
||
std::vector<int> hullTrue = { | ||
0, 0, sqw - 2, 0, sqw - 2, sqh - 2, 0, sqh - 2, task::SEPARATOR, | ||
sqw + 1, 0, width - 1, 0, width - 1, sqh - 2, sqw + 1, sqh - 2, task::SEPARATOR, | ||
0, sqh, width - 1, sqh, task::SEPARATOR, 0, sqh + 2, width - 1, sqh + 2, | ||
sqw, height - 1, sqw - 1, height - 1, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
// Create Task | ||
auto testTaskSequential = std::make_shared<task::AkopyanZBinHull>(taskData); | ||
|
||
// Create Perf attributes | ||
auto perfAttr = std::make_shared<ppc::core::PerfAttr>(); | ||
perfAttr->num_running = 10; | ||
perfAttr->current_timer = [&] { return omp_get_wtime(); }; | ||
|
||
// Create and init perf results | ||
auto perfResults = std::make_shared<ppc::core::PerfResults>(); | ||
|
||
// Create Perf analyzer | ||
auto perfAnalyzer = std::make_shared<ppc::core::Perf>(testTaskSequential); | ||
perfAnalyzer->pipeline_run(perfAttr, perfResults); | ||
ppc::core::Perf::print_perf_statistic(perfResults); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) ASSERT_EQ(hullTrue[i], out[i]); | ||
} | ||
|
||
TEST(akopyan_z_bin_hull_omp_omp, test_task_run) { | ||
int width = 2000; | ||
int height = 2000; | ||
|
||
// Create data | ||
std::vector<int> out(width * height); | ||
std::vector<int> in(width * height, 0); | ||
int sqw = width / 2; | ||
int sqh = height / 2; | ||
for (int i = 0; i < sqh - 1; i++) { | ||
for (int j = 0; j < sqw - 1; j++) { | ||
in[i * width + j] = 1; | ||
in[i * width + (sqw + 1 + j)] = 1; | ||
} | ||
} | ||
for (int i = 0; i < width; i++) { | ||
in[sqh * width + i] = 1; | ||
in[(sqh + 2) * width + i] = 1; | ||
} | ||
for (int i = sqh + 3; i < height; i++) { | ||
in[i * width + sqw - 1] = 1; | ||
in[i * width + sqw] = 1; | ||
} | ||
|
||
std::vector<int> hullTrue = { | ||
0, 0, sqw - 2, 0, sqw - 2, sqh - 2, 0, sqh - 2, task::SEPARATOR, | ||
sqw + 1, 0, width - 1, 0, width - 1, sqh - 2, sqw + 1, sqh - 2, task::SEPARATOR, | ||
0, sqh, width - 1, sqh, task::SEPARATOR, 0, sqh + 2, width - 1, sqh + 2, | ||
sqw, height - 1, sqw - 1, height - 1, task::SEPARATOR}; | ||
|
||
// Create TaskData | ||
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>(); | ||
taskData->inputs.emplace_back(reinterpret_cast<uint8_t*>(in.data())); | ||
taskData->inputs_count.emplace_back(width); | ||
taskData->inputs_count.emplace_back(height); | ||
taskData->outputs.emplace_back(reinterpret_cast<uint8_t*>(out.data())); | ||
// Create Task | ||
auto testTaskSequential = std::make_shared<task::AkopyanZBinHull>(taskData); | ||
|
||
// Create Perf attributes | ||
auto perfAttr = std::make_shared<ppc::core::PerfAttr>(); | ||
perfAttr->num_running = 10; | ||
perfAttr->current_timer = [&] { return omp_get_wtime(); }; | ||
|
||
// Create and init perf results | ||
auto perfResults = std::make_shared<ppc::core::PerfResults>(); | ||
|
||
// Create Perf analyzer | ||
auto perfAnalyzer = std::make_shared<ppc::core::Perf>(testTaskSequential); | ||
perfAnalyzer->task_run(perfAttr, perfResults); | ||
ppc::core::Perf::print_perf_statistic(perfResults); | ||
|
||
for (size_t i = 0; i < hullTrue.size(); i++) ASSERT_EQ(hullTrue[i], out[i]); | ||
} |
Oops, something went wrong.