blob: d172a773b611ddf03b8b5eebf09bfcf3f0cf9ba7 [file] [log] [blame]
Pablo Tello299025a2017-09-29 11:30:12 +01001/*
2 * Copyright (c) 2017 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#include "GEMM.h"
25
26#include "arm_compute/core/Types.h"
27#include "tests/validation/FixedPoint.h"
28
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
37template <typename T>
38SimpleTensor<T> gemmlowp(const SimpleTensor<T> &a, const SimpleTensor<T> &b, SimpleTensor<T> &c,
39 int32_t a_offset, int32_t b_offset, int32_t c_offset, int32_t c_mult_int, int32_t out_shift)
40{
41 const int K = a.shape().x();
42 const int b_width = b.shape().x();
43 const int rows = c.shape().y(); //M
44 const int cols = c.shape().x(); //N
45 std::vector<int32_t> acc;
46 acc.resize(cols);
47 for(int i = 0; i < rows; ++i)
48 {
49 for(int j = 0; j < cols; ++j)
50 {
51 acc[j] = 0;
52 }
53 for(int k = 0; k < K; ++k)
54 {
55 const int32_t tmp_a = a_offset + static_cast<int32_t>(a[k + i * K]);
56 for(int j = 0; j < b_width; ++j)
57 {
58 const int32_t tmp_b = b_offset + static_cast<int32_t>(b[j + k * b_width]);
59 const int32_t mult_as_int = tmp_a * tmp_b;
60 acc[j] += mult_as_int;
61 }
62 }
63 for(int j = 0; j < cols; ++j)
64 {
65 const int32_t result = ((c_offset + acc[j]) * c_mult_int) >> out_shift;
66 c[j + i * cols] = static_cast<uint8_t>(std::min(255, std::max(0, result)));
67 }
68 }
69
70 return c;
71}
72
73template SimpleTensor<uint8_t> gemmlowp(const SimpleTensor<uint8_t> &a, const SimpleTensor<uint8_t> &b, SimpleTensor<uint8_t> &c,
74 int32_t a_offset, int32_t b_offset, int32_t c_offset, int32_t c_mult_int, int32_t out_shift);
75} // namespace reference
76} // namespace validation
77} // namespace test
78} // namespace arm_compute