blob: 6e47adbaa47b72c10d6f010cb5b5c63f69ff69cb [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
2 * Copyright (c) 2017-2018 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#include "arm_gemm.hpp"
25#include "gemm_common.hpp"
David Manselle39334c2018-07-06 17:53:35 +010026#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000027#include "gemm_interleaved.hpp"
28#include "gemm_native.hpp"
David Mansellce8f6052018-05-17 18:51:26 +010029#include "gemv_batched.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000030#include "gemv_native_transposed.hpp"
31#include "gemv_pretransposed.hpp"
32
Pablo Telloeb82fd22018-02-23 13:43:50 +000033#include "kernels/a64_sgemm_12x8.hpp"
Anthony Barbier5f707732018-07-03 16:22:02 +010034#include "kernels/a32_sgemm_8x6.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000035#include "kernels/a64_sgemv_trans.hpp"
Anthony Barbier5f707732018-07-03 16:22:02 +010036#include "kernels/a64_sgemv_pretransposed.hpp"
37#include "kernels/a64_sgemm_native_16x4.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000038
Anthony Barbier5f707732018-07-03 16:22:02 +010039namespace arm_gemm {
40
Pablo Telloeb82fd22018-02-23 13:43:50 +000041#ifdef __aarch64__
David Manselle39334c2018-07-06 17:53:35 +010042// SGEMM implementations for AArch64
43
44// Pretransposed GEMV
45class GemmImpl_sgemm_gemv_pretransposed : public GemmImplementation<float, float> {
46public:
47 bool is_supported(const GemmArgs<float> &args) override {
48 return (args._Msize==1 && args._alpha==1.0f && args._pretransposed_hint && args._nbatches==1);
Pablo Telloeb82fd22018-02-23 13:43:50 +000049 }
50
David Manselle39334c2018-07-06 17:53:35 +010051 UniqueGemmCommon<float, float> instantiate(const GemmArgs<float> &args) override {
52 return UniqueGemmCommon<float, float> (new GemvPretransposed<sgemv_pretransposed, float, float>(args._ci, args._Nsize, args._Ksize, args._nmulti, args._trB, args._beta));
Pablo Telloeb82fd22018-02-23 13:43:50 +000053 }
54
David Manselle39334c2018-07-06 17:53:35 +010055 GemmImpl_sgemm_gemv_pretransposed() : GemmImplementation<float, float>(GemmMethod::GEMV_PRETRANSPOSED) { }
56};
57
58// Native GEMV
59class GemmImpl_sgemm_gemv_native_transposed : public GemmImplementation<float, float> {
60public:
61 bool is_supported(const GemmArgs<float> &args) override {
62 return (args._Msize==1 && args._alpha==1.0f && !args._trA && !args._trB && args._nbatches==1);
Pablo Telloeb82fd22018-02-23 13:43:50 +000063 }
64
David Manselle39334c2018-07-06 17:53:35 +010065 UniqueGemmCommon<float, float> instantiate(const GemmArgs<float> &args) override {
66 return UniqueGemmCommon<float, float> (new GemvNativeTransposed<sgemv_trans, float, float>(args._ci, args._Nsize, args._Ksize, args._nmulti, args._beta));
67 }
68
69 GemmImpl_sgemm_gemv_native_transposed() : GemmImplementation<float, float>(GemmMethod::GEMV_NATIVE_TRANSPOSED) { }
70};
71
72// Native GEMM
73class GemmImpl_sgemm_gemm_native : public GemmImplementation<float, float> {
74public:
75 bool is_supported(const GemmArgs<float> &args) override {
76 return (args._Ksize>4 && (args._Nsize % 16)==0 && args._alpha==1.0f && !args._trA && !args._trB);
77 }
78
79 bool is_recommended(const GemmArgs<float> &args) override {
80 return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8));
81 }
82
83 UniqueGemmCommon<float, float> instantiate(const GemmArgs<float> &args) override {
84 return UniqueGemmCommon<float, float> (new GemmNative<sgemm_native_16x4, float, float>(args._ci, args._Msize, args._Nsize, args._Ksize, args._nbatches, args._nmulti, args._beta));
85 }
86
87 GemmImpl_sgemm_gemm_native() : GemmImplementation<float, float>(GemmMethod::GEMM_NATIVE) { }
88};
89#endif // __aarch64__
90
91// Interleaved GEMM
92class GemmImpl_sgemm_gemm_interleaved : public GemmImplementation<float, float> {
93public:
94 UniqueGemmCommon<float, float> instantiate(const GemmArgs<float> &args) override {
95#ifdef __aarch64__
96 return UniqueGemmCommon<float, float> (new GemmInterleaved<sgemm_12x8, float, float>(args));
97#elif defined(__arm__)
98 return UniqueGemmCommon<float, float> (new GemmInterleaved<sgemm_8x6, float, float>(args));
Pablo Telloeb82fd22018-02-23 13:43:50 +000099#else
David Manselle39334c2018-07-06 17:53:35 +0100100# error Unknown Architecture.
Pablo Telloeb82fd22018-02-23 13:43:50 +0000101#endif
David Manselle39334c2018-07-06 17:53:35 +0100102 }
103
104 GemmImpl_sgemm_gemm_interleaved() : GemmImplementation<float, float>(GemmMethod::GEMM_INTERLEAVED) { }
105};
106
107/* List of implementations (order matters) */
108static std::vector<GemmImplementation<float, float> *> SGemmMethods = {
109 new GemmImpl_gemv_batched<float, float>(),
110#ifdef __aarch64__
111 new GemmImpl_sgemm_gemv_pretransposed(),
112 new GemmImpl_sgemm_gemv_native_transposed(),
113 new GemmImpl_sgemm_gemm_native(),
114#endif
115 new GemmImpl_sgemm_gemm_interleaved()
116};
117
118/* Templated function to return this list. */
119template<>
120std::vector<GemmImplementation<float, float> *> &gemm_implementation_list<float, float>() {
121 return SGemmMethods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000122}
123
David Manselle39334c2018-07-06 17:53:35 +0100124/* Explicitly instantiate the external functions for these types. */
125template UniqueGemmCommon<float, float> gemm<float, float>(GemmArgs<float> &args, GemmConfig *cfg);
126template GemmMethod get_gemm_method<float, float>(GemmArgs<float> &args);
127template bool method_is_compatible<float, float>(GemmMethod method, GemmArgs<float> &args);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000128
129} // namespace arm_gemm