forked from learning-process/parallel_programming_course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (68 loc) · 2.79 KB
/
main.cpp
File metadata and controls
86 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <gtest/gtest.h>
#include <stb/stb_image.h>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <numeric>
#include <stdexcept>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "example_processes_2/common/include/common.hpp"
#include "example_processes_2/mpi/include/ops_mpi.hpp"
#include "example_processes_2/seq/include/ops_seq.hpp"
#include "util/include/func_test_util.hpp"
#include "util/include/util.hpp"
namespace nesterov_a_test_task_processes_2 {
class NesterovARunFuncTestsProcesses2 : public ppc::util::BaseRunFuncTests<InType, OutType, TestType> {
public:
static std::string PrintTestParam(const TestType &test_param) {
return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param);
}
protected:
void SetUp() override {
int width = -1;
int height = -1;
int channels = -1;
std::vector<uint8_t> img;
// Read image in RGB to ensure consistent channel count
{
std::string abs_path = ppc::util::GetAbsoluteTaskPath(PPC_ID_example_processes_2, "pic.ppm");
auto *data = stbi_load(abs_path.c_str(), &width, &height, &channels, STBI_rgb);
if (data == nullptr) {
throw std::runtime_error("Failed to load image: " + std::string(stbi_failure_reason()));
}
channels = STBI_rgb;
img = std::vector<uint8_t>(data, data + (static_cast<ptrdiff_t>(width * height * channels)));
stbi_image_free(data);
if (std::cmp_not_equal(width, height)) {
throw std::runtime_error("width != height: ");
}
}
TestType params = std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kTestParams)>(GetParam());
input_data_ = width - height + std::min(std::accumulate(img.begin(), img.end(), 0), channels);
}
bool CheckTestOutputData(OutType &output_data) final {
return (input_data_ == output_data);
}
InType GetTestInputData() final {
return input_data_;
}
private:
InType input_data_ = 0;
};
namespace {
TEST_P(NesterovARunFuncTestsProcesses2, MatmulFromPic) {
ExecuteTest(GetParam());
}
const std::array<TestType, 3> kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")};
const auto kTestTasksList =
std::tuple_cat(ppc::util::AddFuncTask<NesterovATestTaskMPI, InType>(kTestParam, PPC_SETTINGS_example_processes_2),
ppc::util::AddFuncTask<NesterovATestTaskSEQ, InType>(kTestParam, PPC_SETTINGS_example_processes_2));
const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
const auto kPerfTestName = NesterovARunFuncTestsProcesses2::PrintFuncTestName<NesterovARunFuncTestsProcesses2>;
INSTANTIATE_TEST_SUITE_P(PicMatrixTests, NesterovARunFuncTestsProcesses2, kGtestValues, kPerfTestName);
} // namespace
} // namespace nesterov_a_test_task_processes_2