| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #include "cpu.h" |
| 16 | #include "mat.h" |
| 17 | #include "arm_usability.h" |
| 18 | |
| 19 | namespace ncnn { |
| 20 | |
| 21 | #include "gemm_int8.h" |
| 22 | #include "gemm_int8_fp16s.h" |
| 23 | |
| 24 | #if NCNN_BF16 |
| 25 | #include "gemm_int8_bf16s.h" |
| 26 | #endif |
| 27 | |
| 28 | void pack_A_tile_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk) |
| 29 | { |
| 30 | pack_A_tile_int8(A, AT, i, max_ii, k, max_kk); |
| 31 | } |
| 32 | |
| 33 | void transpose_pack_A_tile_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk) |
| 34 | { |
| 35 | transpose_pack_A_tile_int8(A, AT, i, max_ii, k, max_kk); |
| 36 | } |
| 37 | |
| 38 | void pack_B_tile_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk) |
| 39 | { |
| 40 | pack_B_tile_int8(B, BT, j, max_jj, k, max_kk); |
| 41 | } |
| 42 | |
| 43 | void transpose_pack_B_tile_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk) |
| 44 | { |
| 45 | transpose_pack_B_tile_int8(B, BT, j, max_jj, k, max_kk); |
| 46 | } |
| 47 | |
| 48 | void pack_A_tile_fp32_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 49 | { |
| 50 | pack_A_tile_fp32_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 51 | } |
| 52 | |
| 53 | void transpose_pack_A_tile_fp32_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 54 | { |
| 55 | transpose_pack_A_tile_fp32_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 56 | } |
| 57 | |
| 58 | void pack_B_tile_fp32_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 59 | { |
| 60 | pack_B_tile_fp32_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 61 | } |
| 62 | |
| 63 | void transpose_pack_B_tile_fp32_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 64 | { |
| 65 | transpose_pack_B_tile_fp32_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 66 | } |
| 67 | |
| 68 | void unpack_output_tile_int32_to_fp32_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 69 | { |
| 70 | unpack_output_tile_int32_to_fp32(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 71 | } |
| 72 | |
| 73 | void transpose_unpack_output_tile_int32_to_fp32_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 74 | { |
| 75 | transpose_unpack_output_tile_int32_to_fp32(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 76 | } |
| 77 | |
| 78 | void gemm_transB_packed_tile_int8_asimddp(const Mat& AT_tile, const Mat& BT_tile, Mat& topT_tile, int i, int max_ii, int j, int max_jj, int k, int max_kk) |
| 79 | { |
| 80 | gemm_transB_packed_tile_int8(AT_tile, BT_tile, topT_tile, i, max_ii, j, max_jj, k, max_kk); |
| 81 | } |
| 82 | |
| 83 | void pack_A_tile_fp16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 84 | { |
| 85 | pack_A_tile_fp16_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 86 | } |
| 87 | |
| 88 | void transpose_pack_A_tile_fp16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 89 | { |
| 90 | transpose_pack_A_tile_fp16_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 91 | } |
| 92 | |
| 93 | void pack_B_tile_fp16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 94 | { |
| 95 | pack_B_tile_fp16_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 96 | } |
| 97 | |
| 98 | void transpose_pack_B_tile_fp16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 99 | { |
| 100 | transpose_pack_B_tile_fp16_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 101 | } |
| 102 | |
| 103 | void unpack_output_tile_int32_to_fp16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 104 | { |
| 105 | unpack_output_tile_int32_to_fp16(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 106 | } |
| 107 | |
| 108 | void transpose_unpack_output_tile_int32_to_fp16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 109 | { |
| 110 | transpose_unpack_output_tile_int32_to_fp16(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 111 | } |
| 112 | |
| 113 | #if NCNN_BF16 |
| 114 | void pack_A_tile_bf16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 115 | { |
| 116 | pack_A_tile_bf16_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 117 | } |
| 118 | |
| 119 | void transpose_pack_A_tile_bf16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 120 | { |
| 121 | transpose_pack_A_tile_bf16_to_int8(A, AT, i, max_ii, k, max_kk, scales); |
| 122 | } |
| 123 | |
| 124 | void pack_B_tile_bf16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 125 | { |
| 126 | pack_B_tile_bf16_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 127 | } |
| 128 | |
| 129 | void transpose_pack_B_tile_bf16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 130 | { |
| 131 | transpose_pack_B_tile_bf16_to_int8(B, BT, j, max_jj, k, max_kk, scale); |
| 132 | } |
| 133 | |
| 134 | void unpack_output_tile_int32_to_bf16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 135 | { |
| 136 | unpack_output_tile_int32_to_bf16(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 137 | } |
| 138 | |
| 139 | void transpose_unpack_output_tile_int32_to_bf16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta) |
| 140 | { |
| 141 | transpose_unpack_output_tile_int32_to_bf16(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 142 | } |
| 143 | #endif // NCNN_BF16 |
| 144 | |
| 145 | } // namespace ncnn |