Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 24 | |
| 25 | // This can only be built if the target/compiler supports FP16 arguments. |
| 26 | #ifdef __ARM_FP16_ARGS |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 27 | |
| 28 | #include "arm_gemm.hpp" |
| 29 | |
| 30 | #include "gemm_common.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame^] | 31 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 32 | #include "gemm_interleaved.hpp" |
| 33 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 34 | #include "kernels/a64_hgemm_24x8.hpp" |
| 35 | #include "kernels/a64_sgemm_12x8.hpp" |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 36 | #include "kernels/a32_sgemm_8x6.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 37 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 38 | namespace arm_gemm { |
| 39 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 40 | #ifdef __aarch64__ |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 41 | |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 42 | #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(FP16_KERNELS) |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame^] | 43 | class GemmImpl_gemm_fp16_interleaved_fp16 : public GemmImplementation<__fp16, __fp16> { |
| 44 | public: |
| 45 | #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 46 | bool is_supported(const GemmArgs<__fp16> &args) override { |
| 47 | return args._ci->has_fp16(); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 48 | } |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 49 | #endif |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 50 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame^] | 51 | UniqueGemmCommon<__fp16, __fp16> instantiate(const GemmArgs<__fp16> &args) override { |
| 52 | return UniqueGemmCommon<__fp16, __fp16>(new GemmInterleaved<hgemm_24x8, __fp16, __fp16>(args)); |
| 53 | } |
| 54 | |
| 55 | GemmImpl_gemm_fp16_interleaved_fp16() : GemmImplementation<__fp16, __fp16>(GemmMethod::GEMM_INTERLEAVED_FP16) { } |
| 56 | }; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 57 | #endif |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame^] | 58 | |
| 59 | #endif // __aarch64__ |
| 60 | |
| 61 | class GemmImpl_gemm_fp16_interleaved : public GemmImplementation<__fp16, __fp16> { |
| 62 | public: |
| 63 | UniqueGemmCommon<__fp16, __fp16> instantiate(const GemmArgs<__fp16> &args) override { |
| 64 | #ifdef __aarch64__ |
| 65 | return UniqueGemmCommon<__fp16, __fp16>(new GemmInterleaved<sgemm_12x8, __fp16, __fp16>(args)); |
| 66 | #elif defined(__arm__) |
| 67 | return UniqueGemmCommon<__fp16, __fp16>(new GemmInterleaved<sgemm_8x6, __fp16, __fp16>(args)); |
| 68 | #else |
| 69 | # error Unknown Architecture |
| 70 | #endif |
| 71 | } |
| 72 | |
| 73 | GemmImpl_gemm_fp16_interleaved() : GemmImplementation<__fp16, __fp16>(GemmMethod::GEMM_INTERLEAVED) { } |
| 74 | }; |
| 75 | |
| 76 | static std::vector<GemmImplementation<__fp16, __fp16> *> gemm_fp16_methods = { |
| 77 | #if defined(__aarch64__) && (defined(__ARM_FEATURE_VECTOR_ARITHMETIC) || defined(FP16_KERNELS)) |
| 78 | new GemmImpl_gemm_fp16_interleaved_fp16(), |
| 79 | #endif |
| 80 | new GemmImpl_gemm_fp16_interleaved() |
| 81 | }; |
| 82 | |
| 83 | template<> |
| 84 | std::vector<GemmImplementation<__fp16, __fp16> *> &gemm_implementation_list<__fp16, __fp16>() { |
| 85 | return gemm_fp16_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 86 | } |
| 87 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame^] | 88 | /* Explicitly instantiate the external functions for these types. */ |
| 89 | template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16>(GemmArgs<__fp16> &args, GemmConfig *cfg); |
| 90 | template GemmMethod get_gemm_method<__fp16, __fp16>(GemmArgs<__fp16> &args); |
| 91 | template bool method_is_compatible<__fp16, __fp16>(GemmMethod method, GemmArgs<__fp16> &args); |
| 92 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 93 | } // namespace arm_gemm |
| 94 | |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 95 | #endif // __ARM_FP16_ARGS |