1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
17 #ifndef GEMM_UTILS_HPP
18 #define GEMM_UTILS_HPP
24 namespace gemm_utils {
26 template <typename T, bool isTransA, bool isTransB>
27 struct gemm_traits {};
29 template <bool isTransA, bool isTransB>
30 struct gemm_traits<double, isTransA, isTransB> {
31 static constexpr int m = 8;
32 static constexpr int n = 6;
33 static constexpr int BM = 4032;
34 static constexpr int BN = isTransA ? 96 : 192;
35 static constexpr int BK = isTransB ? 96 : 512;
38 template <bool isTransA, bool isTransB>
39 struct gemm_traits<float, isTransA, isTransB> {
40 static constexpr int m = 16;
41 static constexpr int n = 6;
42 static constexpr int BM = 4032;
43 static constexpr int BN = isTransA ? 96 : 48;
44 static constexpr int BK = isTransB ? 96 : 256;
48 using unroll_factor = gemm_traits<T, false, false>;
50 template <typename data_type>
51 void sum_two_matrices(
52 int m, int n, data_type *p_src, int ld_src, data_type *p_dst, int ld_dst);
54 void calc_nthr_nocopy_avx512_common(int m,
55 int n, int k, int nthrs, int *nthrs_m, int *nthrs_n, int *nthrs_k,
56 int *BM, int *BN, int *BK);
58 void calc_nthr_nocopy_avx(int m, int n, int k,
59 int nthrs, int *nthrs_m, int *nthrs_n, int *nthrs_k, int *BM, int *BN,
62 void partition_unit_diff(
63 int ithr, int nthr, int n, int *t_offset, int *t_block);
65 inline double saturate(double value, double min, double max);