| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "chyokotov_a_dense_matrix_mul_foxs_algorithm/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "chyokotov_a_dense_matrix_mul_foxs_algorithm/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace chyokotov_a_dense_matrix_mul_foxs_algorithm { | ||
| 10 | |||
| 11 | ✗ | ChyokotovADenseMatMulFoxAlgorithmSEQ::ChyokotovADenseMatMulFoxAlgorithmSEQ(const InType &in) { | |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | GetOutput().clear(); | ||
| 15 | ✗ | } | |
| 16 | |||
| 17 | ✗ | bool ChyokotovADenseMatMulFoxAlgorithmSEQ::ValidationImpl() { | |
| 18 | ✗ | return (GetInput().first.size() == GetInput().second.size()); | |
| 19 | } | ||
| 20 | |||
| 21 | ✗ | bool ChyokotovADenseMatMulFoxAlgorithmSEQ::PreProcessingImpl() { | |
| 22 | GetOutput().clear(); | ||
| 23 | ✗ | GetOutput().resize(GetInput().first.size(), 0.0); | |
| 24 | ✗ | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | ✗ | int ChyokotovADenseMatMulFoxAlgorithmSEQ::CalculateBlockSize(int n) { | |
| 28 | ✗ | return static_cast<int>(std::sqrt(static_cast<double>(n))); | |
| 29 | } | ||
| 30 | |||
| 31 | ✗ | int ChyokotovADenseMatMulFoxAlgorithmSEQ::CountBlock(int n, int size) { | |
| 32 | ✗ | return (n + size - 1) / size; | |
| 33 | } | ||
| 34 | |||
| 35 | ✗ | void ChyokotovADenseMatMulFoxAlgorithmSEQ::Matmul(std::vector<double> &a, std::vector<double> &b, int n, int istart, | |
| 36 | int iend, int jstart, int jend, int kstart, int kend) { | ||
| 37 | ✗ | for (int i = istart; i < iend; i++) { | |
| 38 | ✗ | for (int j = jstart; j < jend; j++) { | |
| 39 | double sum = 0.0; | ||
| 40 | ✗ | for (int k = kstart; k < kend; k++) { | |
| 41 | ✗ | sum += a[(i * n) + k] * b[(k * n) + j]; | |
| 42 | } | ||
| 43 | ✗ | GetOutput()[(i * n) + j] += sum; | |
| 44 | } | ||
| 45 | } | ||
| 46 | ✗ | } | |
| 47 | |||
| 48 | ✗ | bool ChyokotovADenseMatMulFoxAlgorithmSEQ::RunImpl() { | |
| 49 | ✗ | std::vector<double> a = GetInput().first; | |
| 50 | ✗ | std::vector<double> b = GetInput().second; | |
| 51 | ✗ | int n = static_cast<int>(std::sqrt(static_cast<double>(a.size()))); | |
| 52 | ✗ | if (n == 0) { | |
| 53 | return true; | ||
| 54 | } | ||
| 55 | |||
| 56 | int block_size = CalculateBlockSize(n); | ||
| 57 | int count_block = CountBlock(n, block_size); | ||
| 58 | |||
| 59 | ✗ | for (int ic = 0; ic < count_block; ic++) { | |
| 60 | ✗ | for (int jc = 0; jc < count_block; jc++) { | |
| 61 | ✗ | for (int kc = 0; kc < count_block; kc++) { | |
| 62 | ✗ | int istart = ic * block_size; | |
| 63 | ✗ | int jstart = jc * block_size; | |
| 64 | ✗ | int kstart = kc * block_size; | |
| 65 | |||
| 66 | ✗ | int iend = std::min(istart + block_size, n); | |
| 67 | ✗ | int jend = std::min(jstart + block_size, n); | |
| 68 | ✗ | int kend = std::min(kstart + block_size, n); | |
| 69 | |||
| 70 | ✗ | Matmul(a, b, n, istart, iend, jstart, jend, kstart, kend); | |
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | return true; | ||
| 76 | } | ||
| 77 | |||
| 78 | ✗ | bool ChyokotovADenseMatMulFoxAlgorithmSEQ::PostProcessingImpl() { | |
| 79 | ✗ | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | } // namespace chyokotov_a_dense_matrix_mul_foxs_algorithm | ||
| 83 |