GCC Code Coverage Report


Directory: ./
File: tasks/remizov_k_dense_matrix_multiplication_cannon_algorithm/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 78 78 100.0%
Functions: 11 11 100.0%
Branches: 59 80 73.8%

Line Branch Exec Source
1 #include "remizov_k_dense_matrix_multiplication_cannon_algorithm/seq/include/ops_seq.hpp"
2
3 #include <cstddef>
4 #include <utility>
5 #include <vector>
6
7 #include "remizov_k_dense_matrix_multiplication_cannon_algorithm/common/include/common.hpp"
8
9 namespace remizov_k_dense_matrix_multiplication_cannon_algorithm {
10
11
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 RemizovKDenseMatrixMultiplicationCannonAlgorithm::RemizovKDenseMatrixMultiplicationCannonAlgorithm(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 GetInput() = in;
14 64 }
15
16 64 bool RemizovKDenseMatrixMultiplicationCannonAlgorithm::ValidationImpl() {
17 const auto &input_data = GetInput();
18
19 64 int block_dim = std::get<0>(input_data);
20 const auto &mat_a = std::get<1>(input_data);
21 const auto &mat_b = std::get<2>(input_data);
22
23
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (block_dim <= 0) {
24 return false;
25 }
26
2/4
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
64 if (mat_a.empty() || mat_b.empty()) {
27 return false;
28 }
29
30 size_t n = mat_a.size();
31
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if (n != mat_a[0].size()) {
32 return false;
33 }
34
2/4
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
64 if (n != mat_b.size() || n != mat_b[0].size()) {
35 return false;
36 }
37
38 64 return (n % static_cast<size_t>(block_dim) == 0);
39 }
40
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 bool RemizovKDenseMatrixMultiplicationCannonAlgorithm::PreProcessingImpl() {
42 GetOutput().clear();
43 64 return true;
44 }
45
46 456 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::MultiplyBlock(const std::vector<std::vector<double>> &a,
47 const std::vector<std::vector<double>> &b,
48 std::vector<std::vector<double>> &c,
49 int block_size) {
50
2/2
✓ Branch 0 taken 984 times.
✓ Branch 1 taken 456 times.
1440 for (int i = 0; i < block_size; ++i) {
51
2/2
✓ Branch 0 taken 2568 times.
✓ Branch 1 taken 984 times.
3552 for (int j = 0; j < block_size; ++j) {
52 double accumulator = 0.0;
53
2/2
✓ Branch 0 taken 7704 times.
✓ Branch 1 taken 2568 times.
10272 for (int k = 0; k < block_size; ++k) {
54 7704 accumulator += a[i][k] * b[k][j];
55 }
56 2568 c[i][j] += accumulator;
57 }
58 }
59 456 }
60
61 56 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::ShiftBlocksLeft(
62 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks, int block_count) {
63
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 56 times.
168 for (int i = 0; i < block_count; ++i) {
64 112 auto first_element = std::move(matrix_blocks[i][0]);
65
66
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 112 times.
224 for (int j = 1; j < block_count; ++j) {
67 112 matrix_blocks[i][j - 1] = std::move(matrix_blocks[i][j]);
68 }
69
70 112 matrix_blocks[i][block_count - 1] = std::move(first_element);
71 112 }
72 56 }
73
74 56 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::ShiftBlocksUp(
75 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks, int block_count) {
76
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 56 times.
168 for (int j = 0; j < block_count; ++j) {
77 112 auto first_element = std::move(matrix_blocks[0][j]);
78
79
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 112 times.
224 for (int i = 1; i < block_count; ++i) {
80 112 matrix_blocks[i - 1][j] = std::move(matrix_blocks[i][j]);
81 }
82
83 112 matrix_blocks[block_count - 1][j] = std::move(first_element);
84 112 }
85 56 }
86
87 64 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::RunCannonCycle(
88 std::vector<std::vector<std::vector<std::vector<double>>>> &a_blocks,
89 std::vector<std::vector<std::vector<std::vector<double>>>> &b_blocks,
90 std::vector<std::vector<std::vector<std::vector<double>>>> &c_blocks, int block_size, int block_count) {
91
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (int step = 0; step < block_count; ++step) {
92
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 120 times.
352 for (int i = 0; i < block_count; ++i) {
93
2/2
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 232 times.
688 for (int j = 0; j < block_count; ++j) {
94 456 RemizovKDenseMatrixMultiplicationCannonAlgorithm::MultiplyBlock(a_blocks[i][j], b_blocks[i][j], c_blocks[i][j],
95 block_size);
96 }
97 }
98
99
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 64 times.
120 if (step < block_count - 1) {
100 56 RemizovKDenseMatrixMultiplicationCannonAlgorithm::ShiftBlocksLeft(a_blocks, block_count);
101 56 RemizovKDenseMatrixMultiplicationCannonAlgorithm::ShiftBlocksUp(b_blocks, block_count);
102 }
103 }
104 64 }
105
106 64 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::InitializeBlocks(
107 const std::vector<std::vector<double>> &matrix_a, const std::vector<std::vector<double>> &matrix_b,
108 std::vector<std::vector<std::vector<std::vector<double>>>> &a_blocks,
109 std::vector<std::vector<std::vector<std::vector<double>>>> &b_blocks, int block_size, int block_count) {
110
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (int i = 0; i < block_count; ++i) {
111
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 120 times.
352 for (int j = 0; j < block_count; ++j) {
112 232 int shift_value = (i + j) % block_count;
113
114
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 232 times.
736 for (int bi = 0; bi < block_size; ++bi) {
115
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 504 times.
1824 for (int bj = 0; bj < block_size; ++bj) {
116 1320 a_blocks[i][j][bi][bj] = matrix_a[(i * block_size) + bi][(shift_value * block_size) + bj];
117 1320 b_blocks[i][j][bi][bj] = matrix_b[(shift_value * block_size) + bi][(j * block_size) + bj];
118 }
119 }
120 }
121 }
122 64 }
123
124 64 void RemizovKDenseMatrixMultiplicationCannonAlgorithm::AssembleOutput(
125 std::vector<std::vector<std::vector<std::vector<double>>>> &c_blocks, std::vector<std::vector<double>> &output,
126 int block_size, int block_count) {
127
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (int i = 0; i < block_count; ++i) {
128
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 120 times.
352 for (int j = 0; j < block_count; ++j) {
129
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 232 times.
736 for (int bi = 0; bi < block_size; ++bi) {
130
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 504 times.
1824 for (int bj = 0; bj < block_size; ++bj) {
131 1320 output[(i * block_size) + bi][(j * block_size) + bj] = c_blocks[i][j][bi][bj];
132 }
133 }
134 }
135 }
136 64 }
137
138 64 bool RemizovKDenseMatrixMultiplicationCannonAlgorithm::RunImpl() {
139 const auto &params = GetInput();
140
141 64 int block_dim = std::get<0>(params);
142 const auto &source_a = std::get<1>(params);
143 const auto &source_b = std::get<2>(params);
144
145 64 int matrix_size = static_cast<int>(source_a.size());
146 64 int blocks_per_dim = matrix_size / block_dim;
147
148 std::vector<std::vector<std::vector<std::vector<double>>>> blocks_a(
149 blocks_per_dim,
150 64 std::vector<std::vector<std::vector<double>>>(
151
3/6
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 64 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 64 times.
✗ Branch 9 not taken.
128 blocks_per_dim, std::vector<std::vector<double>>(block_dim, std::vector<double>(block_dim, 0.0))));
152
153 std::vector<std::vector<std::vector<std::vector<double>>>> blocks_b(
154 blocks_per_dim,
155 64 std::vector<std::vector<std::vector<double>>>(
156
4/8
✓ 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.
128 blocks_per_dim, std::vector<std::vector<double>>(block_dim, std::vector<double>(block_dim, 0.0))));
157
158 std::vector<std::vector<std::vector<std::vector<double>>>> blocks_c(
159 blocks_per_dim,
160 64 std::vector<std::vector<std::vector<double>>>(
161
4/8
✓ 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.
128 blocks_per_dim, std::vector<std::vector<double>>(block_dim, std::vector<double>(block_dim, 0.0))));
162
163 64 InitializeBlocks(source_a, source_b, blocks_a, blocks_b, block_dim, blocks_per_dim);
164 64 RunCannonCycle(blocks_a, blocks_b, blocks_c, block_dim, blocks_per_dim);
165
166
2/4
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
64 std::vector<std::vector<double>> result(matrix_size, std::vector<double>(matrix_size, 0.0));
167 64 AssembleOutput(blocks_c, result, block_dim, blocks_per_dim);
168
169 64 GetOutput() = std::move(result);
170 64 return true;
171 64 }
172
173 64 bool RemizovKDenseMatrixMultiplicationCannonAlgorithm::PostProcessingImpl() {
174 64 return true;
175 }
176
177 } // namespace remizov_k_dense_matrix_multiplication_cannon_algorithm
178