blob: 87310d996d63e395e95a1c98cc031aae405a1266 [file] [log] [blame]
Georgios Pinitascfa2bba2019-06-27 17:00:52 +01001/*
Michael Tyler74921ee2023-04-12 17:43:17 +01002 * Copyright (c) 2017-2018, 2022-2023 Arm Limited.
Georgios Pinitascfa2bba2019-06-27 17:00:52 +01003 *
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 */
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010024
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010025#ifndef NO_MULTI_THREADING
26#include <mutex>
27#endif
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +000028#include <cstdint>
29
30#include "arm_gemm.hpp"
31#include "kernel_weight_format.hpp"
32#include "utils.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010033
34namespace arm_gemm {
35
36#ifndef NO_MULTI_THREADING
37std::mutex report_mutex;
38#endif
39
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +000040WeightFormat get_weight_format(const KernelWeightFormat kwf, size_t element_size) {
41 if (kwf==KernelWeightFormat::NON_FIXED) {
42 return WeightFormat::UNSPECIFIED;
43 }
44
45 uint32_t kwf_i = static_cast<uint32_t>(kwf);
46 uint32_t wf_i = 0;
47
48 const auto block_bytes = (kwf_i >> 8) & 0xf;
49 const auto vector_count = (kwf_i >> 12) & 0xf;
50
51 uint32_t vector_bytes;
52
53 // For fast mode BF16 kernels set the appropriate bit and override element size to 2.
54 if (kwf_i & 0x10) {
55 element_size = 2;
56 wf_i |= 0x10;
57 }
58
Michael Tyler74921ee2023-04-12 17:43:17 +010059#ifdef ARM_COMPUTE_ENABLE_SVE
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +000060 // Get total bytes in vector output
61 if (kwf_i & 0x1) {
62 vector_bytes = vector_count * get_vector_length<uint8_t>();
63 } else {
Michael Tyler74921ee2023-04-12 17:43:17 +010064#else
65 if (1) {
66#endif
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +000067 vector_bytes = vector_count * 16;
68 }
69
70 auto input_blocking = block_bytes / element_size;
71 auto output_blocking = vector_bytes / block_bytes;
72
73 wf_i |= (input_blocking << 20);
74 wf_i |= (output_blocking << 8);
75
76 return static_cast<WeightFormat>(wf_i);
77}
78
79} // namespace arm_gemm