GCC Code Coverage Report


Directory: ./
File: tasks/makoveeva_matmul_double/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 52 53 98.1%
Functions: 7 7 100.0%
Branches: 23 38 60.5%

Line Branch Exec Source
1 #include "makoveeva_matmul_double/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "makoveeva_matmul_double/common/include/common.hpp"
9
10 namespace makoveeva_matmul_double_seq {
11 namespace {
12
13 // Вспомогательная функция для выбора размера блока
14 64 int ChooseBlockSize(int n) {
15 64 int block_size = static_cast<int>(std::sqrt(static_cast<double>(n)));
16 64 block_size = std::max(1, block_size);
17
18
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64 while ((n % block_size != 0) && (block_size > 1)) {
19 --block_size;
20 }
21
22 64 return block_size;
23 }
24
25 // Вспомогательная функция для умножения блоков
26 1808 void MultiplyBlocks(const std::vector<double> &a, const std::vector<double> &b, std::vector<double> &c, int n,
27 int row_start, int row_end, int col_start, int col_end, int k_start, int k_end) {
28 1808 const auto n_size = static_cast<size_t>(n);
29
30
2/2
✓ Branch 0 taken 4056 times.
✓ Branch 1 taken 1808 times.
5864 for (int row = row_start; row < row_end; ++row) {
31 4056 const auto row_idx = static_cast<size_t>(row);
32 4056 const auto row_offset = row_idx * n_size;
33
34
2/2
✓ Branch 0 taken 10008 times.
✓ Branch 1 taken 4056 times.
14064 for (int col = col_start; col < col_end; ++col) {
35 10008 const auto col_idx = static_cast<size_t>(col);
36 double sum = 0.0;
37
38
2/2
✓ Branch 0 taken 26280 times.
✓ Branch 1 taken 10008 times.
36288 for (int k = k_start; k < k_end; ++k) {
39 26280 const auto k_idx = static_cast<size_t>(k);
40 26280 const auto a_idx = row_offset + k_idx;
41 26280 const auto b_idx = (k_idx * n_size) + col_idx;
42 26280 sum += a[a_idx] * b[b_idx];
43 }
44
45 10008 const auto c_idx = row_offset + col_idx;
46 10008 c[c_idx] += sum;
47 }
48 }
49 1808 }
50
51 } // namespace
52
53
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 MatmulDoubleSeqTask::MatmulDoubleSeqTask(const InType &in)
54
4/10
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 64 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 64 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
64 : n_(std::get<0>(in)), A_(std::get<1>(in)), B_(std::get<2>(in)), C_(n_ * n_, 0.0) {
55 SetTypeOfTask(GetStaticTypeOfTask());
56
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 GetOutput() = C_;
57 64 }
58
59 64 bool MatmulDoubleSeqTask::ValidationImpl() {
60 64 const auto expected_size = n_ * n_;
61
3/6
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
64 const auto is_valid = (n_ > 0) && (A_.size() == expected_size) && (B_.size() == expected_size);
62 64 return is_valid;
63 }
64
65 64 bool MatmulDoubleSeqTask::PreProcessingImpl() {
66 64 return true;
67 }
68
69 64 bool MatmulDoubleSeqTask::RunImpl() {
70
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (n_ <= 0) {
71 return false;
72 }
73
74 64 const auto n_int = static_cast<int>(n_);
75 64 auto block_size = ChooseBlockSize(n_int);
76
77 if (block_size == 1 && n_int > 1 && (n_int % block_size != 0)) {
78 block_size = n_int;
79 }
80
81 64 const auto total_size = n_ * n_;
82 64 C_.assign(total_size, 0.0);
83
84 64 const auto grid_size = n_int / block_size;
85
86
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 64 times.
240 for (int stage = 0; stage < grid_size; ++stage) {
87
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 176 times.
720 for (int i_block = 0; i_block < grid_size; ++i_block) {
88
2/2
✓ Branch 0 taken 1808 times.
✓ Branch 1 taken 544 times.
2352 for (int j_block = 0; j_block < grid_size; ++j_block) {
89 1808 const auto root_block = (i_block + stage) % grid_size;
90
91 1808 const auto row_start = i_block * block_size;
92 1808 const auto row_end = row_start + block_size;
93 1808 const auto col_start = j_block * block_size;
94 1808 const auto col_end = col_start + block_size;
95 1808 const auto k_start = root_block * block_size;
96 1808 const auto k_end = k_start + block_size;
97
98 1808 MultiplyBlocks(A_, B_, C_, n_int, row_start, row_end, col_start, col_end, k_start, k_end);
99 }
100 }
101 }
102
103 64 GetOutput() = C_;
104 64 return true;
105 }
106
107 64 bool MatmulDoubleSeqTask::PostProcessingImpl() {
108 64 return true;
109 }
110
111 } // namespace makoveeva_matmul_double_seq
112