xref: /aosp_15_r20/external/ComputeLibrary/src/core/NEON/kernels/arm_gemm/kernels/a64_gemm_s8_8x12.hpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 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 #ifdef __aarch64__
27 
28 #include "arm_gemm.hpp"
29 
30 #include "../performance_parameters.hpp"
31 #include "../std_transforms_fixed.hpp"
32 
33 namespace arm_gemm {
34 
35 // Load the actual kernel
36 void a64_gemm_s8_8x12(const int8_t *, const int8_t *, int32_t *, int, int, int);
37 void a64_gemm_s8_8x12_a55r1(const int8_t *, const int8_t *, int32_t *, int, int, int);
38 void a64_gemm_s8_8x12_x1(const int8_t *, const int8_t *, int32_t *, int, int, int);
39 
40 class cls_a64_gemm_s8_8x12 {
41 public:
42     typedef int8_t operand_type;
43     typedef int32_t result_type;
44 
45     typedef void (*kern_type)(const int8_t *, const int8_t *, int32_t *, int, int, int);
46 
47     /* Kernel blocking parameters */
out_width()48     static unsigned int out_width() {
49         return 12;
50     }
51 
out_height()52     static unsigned int out_height() {
53         return 8;
54     }
55 
k_unroll()56     static unsigned int k_unroll() {
57         return 4;
58     }
59 
60     // Use the standard fixed size transforms.
61     StdTransformsFixed<operand_type, result_type, 8, 12, 4> transforms = {};
62     StdTransformsFixed<operand_type, result_type, 8, 12, 4, true> transforms_quantized = {};
63 
64     template<typename T>
get_performance_parameters(const CPUInfo * ci)65     static PerformanceParameters get_performance_parameters(const CPUInfo *ci) {
66         if (std::is_same<T, int8_t>::value) {
67             switch (ci->get_cpu_model()) {
68                 case CPUModel::A510:
69                     return { 19.73, 3.38, 0.27 };
70 
71                 case CPUModel::A55r1:
72                     return { 15.361, 0.9341, 0.1636 };
73 
74                 case CPUModel::V1:
75                     return { 51.14, 7.38, 0.65 };
76 
77                 default:
78                     return { 29.0698, 3.9793, 0.4003 };
79             }
80         }
81 
82         if (std::is_same<T, int32_t>::value) {
83             switch (ci->get_cpu_model()) {
84                 case CPUModel::A510:
85                     return { 19.73, 3.38, 3.70 };
86 
87                 case CPUModel::A55r1:
88                     return { 14.286, 1.171, 1.209 };
89 
90                 case CPUModel::V1:
91                     return { 61.58, 4.78, 10.83 };
92 
93                 default:
94                     return { 31.82, 3.51, 8.03 };
95             }
96         }
97     }
98 
99     kern_type kernel = a64_gemm_s8_8x12;
100 
cls_a64_gemm_s8_8x12(const CPUInfo * ci)101     cls_a64_gemm_s8_8x12(const CPUInfo *ci) {
102         auto mod = ci->get_cpu_model();
103 
104         if (mod == CPUModel::A55r1) {
105             kernel = a64_gemm_s8_8x12_a55r1;
106         } else if (mod == CPUModel::X1) {
107             kernel = a64_gemm_s8_8x12_x1;
108         }
109     }
110 };
111 
112 } // namespace arm_gemm
113 
114 #endif // __aarch64__
115