1 // Copyright 2015 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // kernel_default.h: Chooses default GEMM and GEMV kernels for the
16 // host platform.
17 
18 #ifndef GEMMLOWP_INTERNAL_KERNEL_DEFAULT_H_
19 #define GEMMLOWP_INTERNAL_KERNEL_DEFAULT_H_
20 
21 #include "../public/bit_depth.h"
22 #include "common.h"
23 
24 namespace gemmlowp {
25 
26 enum class KernelFamily { Gemm, Gemv };
27 
28 template <KernelFamily Family, int ProductBits>
29 struct DefaultKernelImpl : DefaultKernelImpl<Family, ProductBits + 1> {
30   static_assert(ProductBits <= 16, "Bit depth too large");
31 };
32 
33 template <KernelFamily Family, typename BitDepthParams>
34 struct DefaultKernel
35     : DefaultKernelImpl<Family, BitDepthParams::LhsBitDepth::kBits +
36                                     BitDepthParams::RhsBitDepth::kBits> {};
37 
38 }  // end namespace gemmlowp
39 
40 #define GEMMLOWP_SET_DEFAULT_KERNEL(op, max_product_bits, kernel)           \
41   namespace gemmlowp {                                                      \
42   template <>                                                               \
43   struct DefaultKernelImpl<KernelFamily::op, max_product_bits> : kernel {}; \
44   }
45 
46 #if defined GEMMLOWP_NEON_32
47 #include "kernel_neon.h"
48 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 16, NEON_32_Kernel12x4Depth2)
49 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 12,
50                             NEON_32_Kernel12x4Depth2Assuming12BitProducts)
51 GEMMLOWP_SET_DEFAULT_KERNEL(Gemv, 16, NEONKernel4Nx1Depth2<3>)
52 #elif defined GEMMLOWP_NEON_64
53 #include "kernel_neon.h"
54 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 16, NEON_64_Kernel12x8Depth2)
55 GEMMLOWP_SET_DEFAULT_KERNEL(Gemv, 16, NEONKernel4Nx1Depth2<3>)
56 #elif defined GEMMLOWP_SSE4_32
57 #include "kernel_SSE.h"
58 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 16, SSE4_32_Kernel4x4Depth2)
59 GEMMLOWP_SET_DEFAULT_KERNEL(Gemv, 16, SSE4_32_Kernel4x4Depth2)
60 #elif defined GEMMLOWP_SSE4_64
61 #include "kernel_SSE.h"
62 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 16, SSE4_64_Kernel12x4Depth2)
63 GEMMLOWP_SET_DEFAULT_KERNEL(Gemv, 16, SSE4_64_Kernel12x4Depth2)
64 #else
65 #include "kernel_reference.h"
66 namespace gemmlowp {
67 typedef ReferenceKernel<KernelFormat<KernelSideFormat<CellFormat<4, 4>, 2>,
68                                      KernelSideFormat<CellFormat<4, 4>, 2> > >
69     DefaultReferenceKernel;
70 }
71 GEMMLOWP_SET_DEFAULT_KERNEL(Gemm, 16, DefaultReferenceKernel)
72 GEMMLOWP_SET_DEFAULT_KERNEL(Gemv, 16, DefaultReferenceKernel)
73 #endif
74 
75 #endif  // GEMMLOWP_INTERNAL_KERNEL_DEFAULT_H_
76