blob: c0b886266d530d69f879c92f28ce5f2026b79b24 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#pragma once
25
26#include <stdio.h>
27
28#include "arm_gemm.hpp"
29
30#include "mergeresults.hpp"
31#include "profiler.hpp"
32#include "transform.hpp"
33
34namespace arm_gemm
35{
36// Implementation of the GemmCommon abstract class.
37//
38// This is implementation is for a "native" (no-transform) GEMV with a
39// transposed matrix.
40//
41// As a native operation the source data is used in-place, so the internal
42// and external operand/result types must match.
43template <typename strategy, typename To, typename Tr>
44class GemvNativeTransposed : public GemmCommon<To, Tr>
45{
46 typedef typename strategy::operand_type Toi;
47 typedef typename strategy::result_type Tri;
48
49 const unsigned int _Nsize;
50 const unsigned int _Ksize;
51
52 const Tr _alpha;
53
54 const CPUInfo *const _ci;
55
56 unsigned int m_block = 0;
57 unsigned int n_block = 0;
58
59public:
60 GemvNativeTransposed(GemvNativeTransposed &) = delete;
61 GemvNativeTransposed &operator=(GemvNativeTransposed &) = delete;
62
63 GemvNativeTransposed(const CPUInfo *ci, const unsigned int N, const unsigned int K, const Tr alpha)
64 : _Nsize(N), _Ksize(K), _alpha(alpha), _ci(ci)
65 {
66 /* For now don't do any blocking. TODO: figure out if we should. */
67 m_block = K;
68 n_block = N;
69 }
70
71 // Window is number of out_width blocks.
72 unsigned int get_window_size() const override
73 {
74 return iceildiv(_Nsize, strategy::out_width);
75 }
76
77 // Actually execute the GEMV.
78 void execute(unsigned int start, unsigned int end, int) override
79 {
80 profiler prof;
81 strategy strat(_ci);
82
83 unsigned int N_start = start * strategy::out_width;
84 unsigned int N_end = std::min(end * strategy::out_width, _Nsize);
85
86 static_assert(std::is_same<To, Toi>::value, "gemv_transposed: Operand types must be the same.");
87 static_assert(std::is_same<Tr, Tri>::value, "gemv_transposed: Result types must be the same.");
88
89 for(unsigned int m0 = 0; m0 < _Ksize; m0 += m_block)
90 {
91 unsigned int mmax = std::min(m0 + m_block, _Ksize);
92
93 for(unsigned int n0 = N_start; n0 < N_end; n0 += n_block)
94 {
95 unsigned int nmax = std::min(n0 + n_block, N_end);
96
97 prof(PROFILE_KERNEL, ((mmax - m0) * (nmax - n0)), [&](void)
98 {
99 strat.kernel(this->_Bptr + (m0 * this->_ldb) + n0, this->_Aptr + m0, this->_Cptr + n0,
100 _alpha, this->_ldb, (mmax - m0), (nmax - n0));
101 });
102 }
103 }
104 }
105};
106
107} // namespace arm_gemm