GCC Code Coverage Report


Directory: ./
File: tasks/terekhov_d_gauss_vert/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 62 63 98.4%
Functions: 9 9 100.0%
Branches: 31 44 70.5%

Line Branch Exec Source
1 #include "terekhov_d_gauss_vert/tbb/include/ops_tbb.hpp"
2
3 #include <oneapi/tbb/blocked_range.h>
4 #include <oneapi/tbb/parallel_for.h>
5
6 #include <algorithm>
7 #include <cmath>
8 #include <cstddef>
9 #include <vector>
10
11 #include "terekhov_d_gauss_vert/common/include/common.hpp"
12
13 namespace terekhov_d_gauss_vert {
14
15 namespace {
16
17 5184 inline void ProcessPixel(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int row,
18 int col) {
19 5184 size_t idx = (static_cast<size_t>(row) * static_cast<size_t>(width)) + static_cast<size_t>(col);
20 float sum = 0.0F;
21
2/2
✓ Branch 0 taken 15552 times.
✓ Branch 1 taken 5184 times.
20736 for (int ky = -1; ky <= 1; ++ky) {
22
2/2
✓ Branch 0 taken 46656 times.
✓ Branch 1 taken 15552 times.
62208 for (int kx = -1; kx <= 1; ++kx) {
23 46656 int px = col + kx + 1;
24 46656 int py = row + ky + 1;
25 46656 int kernel_idx = ((ky + 1) * 3) + (kx + 1);
26 46656 size_t padded_idx = (static_cast<size_t>(py) * static_cast<size_t>(padded_width)) + static_cast<size_t>(px);
27 46656 sum += static_cast<float>(padded_image[padded_idx]) * kGaussKernel[static_cast<size_t>(kernel_idx)];
28 }
29 }
30 5184 output.data[idx] = static_cast<int>(std::lround(sum));
31 5184 }
32
33 48 inline void ProcessBand(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int height,
34 int band, int band_width, int num_bands) {
35 48 int start_x = band * band_width;
36
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 int end_x = (band == num_bands - 1) ? width : ((band + 1) * band_width);
37
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 48 times.
880 for (int row = 0; row < height; ++row) {
38
2/2
✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 832 times.
6016 for (int col = start_x; col < end_x; ++col) {
39 5184 ProcessPixel(output, padded_image, padded_width, width, row, col);
40 }
41 }
42 48 }
43
44 12 inline OutType SolveTBB(const std::vector<int> &padded_image, int width, int height) {
45 12 OutType output;
46 12 output.width = width;
47 12 output.height = height;
48
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 output.data.resize(static_cast<size_t>(width) * static_cast<size_t>(height));
49
50 12 const int padded_width = width + 2;
51
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 const int band_width = std::max(width / 4, 1);
52 const int num_bands = 4;
53
54 12 oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<int>(0, num_bands),
55
1/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
60 [&](const oneapi::tbb::blocked_range<int> &range) {
56
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 for (int band = range.begin(); band != range.end(); ++band) {
57 48 ProcessBand(output, padded_image, padded_width, width, height, band, band_width, num_bands);
58 }
59 48 });
60
61 12 return output;
62 }
63
64 } // namespace
65
66
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 TerekhovDGaussVertTBB::TerekhovDGaussVertTBB(const InType &in) {
67 SetTypeOfTask(GetStaticTypeOfTask());
68 GetInput() = in;
69 12 }
70
71 12 bool TerekhovDGaussVertTBB::ValidationImpl() {
72 const auto &input = GetInput();
73
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 if (input.width <= 0 || input.height <= 0) {
74 return false;
75 }
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (static_cast<int>(input.data.size()) != input.width * input.height) {
77 return false;
78 }
79 return true;
80 }
81
82 12 bool TerekhovDGaussVertTBB::PreProcessingImpl() {
83 const auto &input = GetInput();
84 12 width_ = input.width;
85 12 height_ = input.height;
86
87 12 int padded_width = width_ + 2;
88 12 int padded_height = height_ + 2;
89 12 padded_image_.resize(static_cast<size_t>(padded_width) * static_cast<size_t>(padded_height));
90
91
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 12 times.
244 for (int row = 0; row < padded_height; ++row) {
92
2/2
✓ Branch 0 taken 6064 times.
✓ Branch 1 taken 232 times.
6296 for (int col = 0; col < padded_width; ++col) {
93 6064 int src_x = col - 1;
94 6064 int src_y = row - 1;
95
96 6064 if (src_x < 0) {
97 src_x = -src_x - 1;
98 }
99
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 5832 times.
6064 if (src_x >= width_) {
100 232 src_x = (2 * width_) - src_x - 1;
101 }
102 6064 if (src_y < 0) {
103 src_y = -src_y - 1;
104 }
105
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 5832 times.
6064 if (src_y >= height_) {
106 232 src_y = (2 * height_) - src_y - 1;
107 }
108
109 6064 size_t padded_idx = (static_cast<size_t>(row) * static_cast<size_t>(padded_width)) + static_cast<size_t>(col);
110 6064 size_t src_idx = (static_cast<size_t>(src_y) * static_cast<size_t>(width_)) + static_cast<size_t>(src_x);
111 6064 padded_image_[padded_idx] = input.data[src_idx];
112 }
113 }
114 12 return true;
115 }
116
117
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 bool TerekhovDGaussVertTBB::RunImpl() {
118 const auto &input = GetInput();
119
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if (input.data.empty() || width_ <= 0 || height_ <= 0) {
120 return false;
121 }
122 12 GetOutput() = SolveTBB(padded_image_, width_, height_);
123 12 return true;
124 }
125
126 12 bool TerekhovDGaussVertTBB::PostProcessingImpl() {
127 12 return GetOutput().data.size() == (static_cast<size_t>(GetOutput().width) * static_cast<size_t>(GetOutput().height));
128 }
129
130 } // namespace terekhov_d_gauss_vert
131