blob: a02fbe8f28b6a7e5c00bffd3efd9b42c968c9ee0 [file] [log] [blame]
Georgios Pinitas7cd26d42019-01-09 18:35:17 +00001/*
Michael Tyler74921ee2023-04-12 17:43:17 +01002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Georgios Pinitas7cd26d42019-01-09 18:35:17 +00003 *
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 *
Michael Tyler74921ee2023-04-12 17:43:17 +010013 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000015 *
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
Michael Tyler74921ee2023-04-12 17:43:17 +010020 * 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.
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000023 */
24#pragma once
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010025#ifdef __aarch64__
Michael Tyler74921ee2023-04-12 17:43:17 +010026
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000027#include "../std_transforms_fixed.hpp"
Georgios Pinitas33e03072021-01-14 13:43:40 +000028#include "../performance_parameters.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000029
30#define ARGLIST \
Georgios Pinitas33e03072021-01-14 13:43:40 +000031 unsigned int, const unsigned int *, \
32 IndirectInputArg<int8_t>, \
33 size_t, size_t, \
34 const int8_t *, \
35 IndirectOutputArg<int32_t>, \
36 const int32_t *, Activation, bool
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000037
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000038namespace arm_gemm
39{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000040// Actual kernel implementations
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000041void a64_hybrid_s8s32_dot_6x16( ARGLIST );
Georgios Pinitase28cf392021-01-31 05:18:43 +000042void a64_hybrid_s8s32_dot_6x16_a55( ARGLIST );
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000043
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000044class cls_a64_hybrid_s8s32_dot_6x16
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000045{
46public:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010047 typedef int8_t lhs_operand_type;
48 typedef int8_t rhs_operand_type;
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000049 typedef int32_t result_type;
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000050
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000051 typedef void (*kern_type)( ARGLIST );
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000052
53 /* Kernel blocking parameters */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010054 static constexpr unsigned int out_height()
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000055 {
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010056 return 6;
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000057 }
58
Georgios Pinitas1d480652019-01-23 11:24:50 +000059 static unsigned int out_width()
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000060 {
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000061 return 16;
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000062 }
63
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010064 static constexpr unsigned int k_unroll()
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000065 {
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000066 return 4;
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000067 }
68
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010069 static constexpr bool supports_accumulate()
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010070 {
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010071 return true;
72 }
73
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010074 StdTransformsFixed<rhs_operand_type, result_type, 6, 16, 4> transforms = {};
75 template<typename T>
76 static inline PerformanceParameters get_performance_parameters(const CPUInfo *ci)
Georgios Pinitase28cf392021-01-31 05:18:43 +000077 {
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010078 if (std::is_same<T, int32_t>::value) {
79 switch (ci->get_cpu_model()) {
80 default:
81 return { 31.65 };
82 case CPUModel::A510:
83 return { 15.87 };
84 case CPUModel::V1:
85 return { 54.50 };
Michael Tyler74921ee2023-04-12 17:43:17 +010086 case CPUModel::A55r1:
87 return { 9.217 };
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010088 }
Georgios Pinitas33e03072021-01-14 13:43:40 +000089 }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010090
91 if (std::is_same<T, int8_t>::value) {
92 switch (ci->get_cpu_model()) {
93 case CPUModel::A55r1:
94 return { 9.5238, 2.0799, 0.2279 };
95 default:
96 return { 29.6736, 11.4025, 0.5591 };
97 case CPUModel::A510:
98 return { 16.66, 3.92, 0.48 };
99 case CPUModel::V1:
Michael Tyler74921ee2023-04-12 17:43:17 +0100100 return { 42.62, 16.32, 0.83 };
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100101 }
102 }
103
104 return { 1.0 };
Georgios Pinitas33e03072021-01-14 13:43:40 +0000105 }
106
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000107 // Default to the generic kernel
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000108 kern_type kernel=a64_hybrid_s8s32_dot_6x16;
Georgios Pinitase28cf392021-01-31 05:18:43 +0000109 cls_a64_hybrid_s8s32_dot_6x16(const CPUInfo *ci)
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100110 {
Georgios Pinitase28cf392021-01-31 05:18:43 +0000111 switch(ci->get_cpu_model()) {
112 default:
113 break;
114 case CPUModel::A55r1:
115 kernel=a64_hybrid_s8s32_dot_6x16_a55;
116 break;
117 }
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100118 }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000119};
120
121} // namespace arm_gemm
122
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000123#undef ARGLIST
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100124#endif // __aarch64__