1 /* 2 * Copyright (c) 2017-2018,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 "../performance_parameters.hpp" 29 #include "../std_transforms_fixed.hpp" 30 31 namespace arm_gemm { 32 33 // Load the actual kernel 34 void a64_gemm_u8_8x12(const uint8_t *, const uint8_t *, uint32_t *, int, int, int); 35 void a64_gemm_u8_8x12_a55r1(const uint8_t *, const uint8_t *, uint32_t *, int, int, int); 36 void a64_gemm_u8_8x12_x1(const uint8_t *, const uint8_t *, uint32_t *, int, int, int); 37 38 class cls_a64_gemm_u8_8x12 { 39 public: 40 typedef uint8_t operand_type; 41 typedef uint32_t result_type; 42 43 typedef void (*kern_type)(const uint8_t *, const uint8_t *, uint32_t *, int, int, int); 44 45 /* Describes the data layout for A input */ 46 static const int A_interleave = 8; 47 static const int A_block = 4; 48 static const bool A_transpose = false; 49 50 /* Same for B input */ 51 static const int B_interleave = 12; 52 static const int B_block = 4; 53 static const bool B_transpose = true; 54 55 /* Kernel blocking parameters */ out_width()56 static unsigned int out_width() { 57 return 12; 58 } 59 out_height()60 static unsigned int out_height() { 61 return 8; 62 } 63 k_unroll()64 static unsigned int k_unroll() { 65 return 4; 66 } 67 68 // Use the standard fixed sized transforms. 69 StdTransformsFixed<operand_type, result_type, 8, 12, 4> transforms = {}; 70 StdTransformsFixed<operand_type, result_type, 8, 12, 4, true> transforms_quantized = {}; 71 72 template<typename T> get_performance_parameters(const CPUInfo * ci)73 static PerformanceParameters get_performance_parameters(const CPUInfo *ci) { 74 if (std::is_same<T, uint8_t>::value) { 75 switch (ci->get_cpu_model()) { 76 case CPUModel::A510: 77 return { 19.73, 3.38, 0.27 }; 78 79 case CPUModel::A55r1: 80 return { 15.361, 0.9341, 0.1636 }; 81 82 case CPUModel::V1: 83 return { 51.14, 7.38, 0.65 }; 84 85 default: 86 return { 29.0698, 3.9793, 0.4003 }; 87 } 88 } 89 90 if (std::is_same<T, uint32_t>::value) { 91 switch (ci->get_cpu_model()) { 92 case CPUModel::A510: 93 return { 19.73, 3.38, 3.70 }; 94 95 case CPUModel::A55r1: 96 return { 14.286, 1.171, 1.209 }; 97 98 case CPUModel::V1: 99 return { 61.58, 4.78, 10.83 }; 100 101 default: 102 return { 31.82, 3.51, 8.03 }; 103 } 104 } 105 106 return { 0.0 }; 107 } 108 109 kern_type kernel = a64_gemm_u8_8x12; 110 cls_a64_gemm_u8_8x12(const CPUInfo * ci)111 cls_a64_gemm_u8_8x12(const CPUInfo *ci) { 112 auto mod = ci->get_cpu_model(); 113 114 if (mod == CPUModel::A55r1) { 115 kernel = a64_gemm_u8_8x12_a55r1; 116 } else if (mod == CPUModel::X1) { 117 kernel = a64_gemm_u8_8x12_x1; 118 } 119 } 120 }; 121 122 } // namespace arm_gemm 123 124 #endif // __aarch64__ 125