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
75 lines (60 loc) · 2.19 KB
/
main.cpp
File metadata and controls
75 lines (60 loc) · 2.19 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
#include <gtest/gtest.h>
#include <cstddef>
#include <cstdint>
#include <stb_library.hpp>
#include <string>
#include <vector>
#include "all/example/include/ops_all.hpp"
#include "core/util/include/util.hpp"
class NesterovATestTaskAll : public ::testing::TestWithParam<int> {
protected:
void SetUp() override {
width = height = channels = -1;
std::string abs_path = ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg");
data = stbi_load(abs_path.c_str(), &width, &height, &channels, 0);
ASSERT_TRUE(data != nullptr) << "Failed to load image: " << stbi_failure_reason();
img = std::vector<uint8_t>(data, data + (static_cast<size_t>(width) * height * channels));
stbi_image_free(data);
ASSERT_EQ(width, height);
}
int width = -1, height = -1, channels = -1;
unsigned char* data = nullptr;
std::vector<uint8_t> img;
};
TEST_P(NesterovATestTaskAll, MatmulFromPic) {
int divider = GetParam();
const size_t k_count = (width + height) / divider;
std::vector<int> in(k_count * k_count, 0);
for (size_t i = 0; i < k_count; i++) {
in[(i * k_count) + i] = 1;
}
nesterov_a_test_task_all::TestTaskALL test_task_all(in);
ASSERT_TRUE(test_task_all.Validation());
test_task_all.PreProcessing();
test_task_all.Run();
test_task_all.PostProcessing();
EXPECT_EQ(in, test_task_all.Get());
}
TEST_P(NesterovATestTaskAll, MatMulUtilFromPic) {
int divider = GetParam();
const size_t k_count = (width + height) / divider;
std::vector<int> in(k_count * k_count, 0);
for (size_t i = 0; i < k_count; i++) {
in[(i * k_count) + i] = 1;
}
std::vector<int> out(k_count * k_count, 0);
nesterov_a_test_task_all::MatMul(in, static_cast<int>(k_count), out);
EXPECT_EQ(in, out);
}
TEST_P(NesterovATestTaskAll, MatMulTBBUtilFromPic) {
int divider = GetParam();
const size_t k_count = (width + height) / divider;
std::vector<int> in(k_count * k_count, 0);
for (size_t i = 0; i < k_count; i++) {
in[(i * k_count) + i] = 1;
}
std::vector<int> out(k_count * k_count, 0);
nesterov_a_test_task_all::MatMulTBB(in, static_cast<int>(k_count), out);
EXPECT_EQ(in, out);
}
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovATestTaskAll, ::testing::Values(5, 10));