| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "korolev_k_matrix_mult/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <functional> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "korolev_k_matrix_mult/common/include/common.hpp" | ||
| 8 | #include "korolev_k_matrix_mult/common/include/strassen_impl.hpp" | ||
| 9 | |||
| 10 | namespace korolev_k_matrix_mult { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | KorolevKMatrixMultSEQ::KorolevKMatrixMultSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput().clear(); | ||
| 16 | 24 | } | |
| 17 | |||
| 18 | 24 | bool KorolevKMatrixMultSEQ::ValidationImpl() { | |
| 19 | const auto &in = GetInput(); | ||
| 20 |
4/8✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
|
24 | return in.n > 0 && in.A.size() == in.n * in.n && in.B.size() == in.n * in.n && GetOutput().empty(); |
| 21 | } | ||
| 22 | |||
| 23 | 24 | bool KorolevKMatrixMultSEQ::PreProcessingImpl() { | |
| 24 | 24 | GetOutput().resize(GetInput().n * GetInput().n); | |
| 25 | 24 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 24 | bool KorolevKMatrixMultSEQ::RunImpl() { | |
| 29 | const auto &in = GetInput(); | ||
| 30 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | size_t n = in.n; |
| 31 | size_t np2 = strassen_impl::NextPowerOf2(n); | ||
| 32 | |||
| 33 | ✗ | auto sequential_run = [](std::vector<std::function<void()>> &tasks) { | |
| 34 | ✗ | for (auto &t : tasks) { | |
| 35 | t(); | ||
| 36 | } | ||
| 37 | ✗ | }; | |
| 38 | |||
| 39 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (np2 == n) { |
| 40 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
48 | strassen_impl::StrassenMultiply(in.A, in.B, GetOutput(), n, sequential_run); |
| 41 | } else { | ||
| 42 | ✗ | std::vector<double> a_pad(np2 * np2, 0); | |
| 43 | ✗ | std::vector<double> b_pad(np2 * np2, 0); | |
| 44 | ✗ | std::vector<double> c_pad(np2 * np2, 0); | |
| 45 | ✗ | for (size_t i = 0; i < n; ++i) { | |
| 46 | ✗ | for (size_t j = 0; j < n; ++j) { | |
| 47 | ✗ | a_pad[(i * np2) + j] = in.A[(i * n) + j]; | |
| 48 | ✗ | b_pad[(i * np2) + j] = in.B[(i * n) + j]; | |
| 49 | } | ||
| 50 | } | ||
| 51 | ✗ | strassen_impl::StrassenMultiply(a_pad, b_pad, c_pad, np2, sequential_run); | |
| 52 | ✗ | for (size_t i = 0; i < n; ++i) { | |
| 53 | ✗ | for (size_t j = 0; j < n; ++j) { | |
| 54 | ✗ | GetOutput()[(i * n) + j] = c_pad[(i * np2) + j]; | |
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | 24 | return true; | |
| 59 | } | ||
| 60 | |||
| 61 | 24 | bool KorolevKMatrixMultSEQ::PostProcessingImpl() { | |
| 62 | 24 | return !GetOutput().empty(); | |
| 63 | } | ||
| 64 | |||
| 65 | } // namespace korolev_k_matrix_mult | ||
| 66 |