blob: 88cfed002a9b03eacc9bacf8ded85b3f0b42c4bb [file] [log] [blame]
Anthony Barbier71d9b572018-07-06 17:05:59 +01001/*
Georgios Pinitas2ee98012021-02-15 20:42:39 +00002 * Copyright (c) 2018-2021 Arm Limited.
Anthony Barbier71d9b572018-07-06 17:05:59 +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 */
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010024#ifndef ARM_COMPUTE_CPU_INTERNAL_CPU_GEMM_ASSEMBLY_DISPATCH_H
25#define ARM_COMPUTE_CPU_INTERNAL_CPU_GEMM_ASSEMBLY_DISPATCH_H
Anthony Barbier71d9b572018-07-06 17:05:59 +010026
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010027#include "src/core/common/Macros.h"
28#include "src/runtime/cpu/ICpuOperator.h"
Anthony Barbier71d9b572018-07-06 17:05:59 +010029
Anthony Barbier71d9b572018-07-06 17:05:59 +010030namespace arm_compute
31{
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +010032namespace cpu
33{
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000034/* Convolution method supported by the assembly gemm interface */
35enum class AsmConvMethod
36{
37 Im2Col,
38 Indirect,
39 Conv
40};
41
42struct AsmGemmInfo
43{
44 AsmConvMethod method{ AsmConvMethod::Im2Col };
45 PadStrideInfo ps_info{};
46 ActivationLayerInfo activation_info{};
47 GEMMLowpOutputStageInfo output_stage{};
48 bool negated_offsets{ true };
49 bool reinterpret_input_as_3d{ false };
50 bool depth_output_gemm3d{ false };
51 int64_t padding_top{ 0 };
52 int64_t padding_left{ 0 };
53 float padding_value{ 0.f };
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010054 bool fast_mode{ false };
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000055};
56
Anthony Barbier71d9b572018-07-06 17:05:59 +010057/** Assembly kernel glue */
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010058class CpuGemmAssemblyDispatch : public ICpuOperator
Anthony Barbier71d9b572018-07-06 17:05:59 +010059{
60public:
Michalis Spyrou1a569a32019-09-10 17:20:34 +010061 /** Constructor */
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +010062 CpuGemmAssemblyDispatch();
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +010063 /** Defautl destructor */
64 ~CpuGemmAssemblyDispatch() = default;
Anthony Barbiereaefd002018-07-20 17:49:35 +010065
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010066 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuGemmAssemblyDispatch);
67
Anthony Barbiereaefd002018-07-20 17:49:35 +010068 class IFallback
69 {
70 public:
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +010071 virtual void run(ITensorPack &tensors) = 0;
72 virtual void prepare(ITensorPack &tensors) = 0;
73 virtual experimental::MemoryRequirements workspace() const = 0;
74 virtual bool is_configured() const = 0;
75 virtual ~IFallback() = default;
Anthony Barbiereaefd002018-07-20 17:49:35 +010076 };
Anthony Barbier71d9b572018-07-06 17:05:59 +010077
Anthony Barbier71d9b572018-07-06 17:05:59 +010078public:
Michele Di Giorgio57f30a92020-09-08 14:03:51 +010079 /** If supported create a Compute Library function else fallback to the arm_gemm function.
Anthony Barbierc8e84b52018-07-17 16:48:42 +010080 *
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000081 * @param[in] a Input tensor (Matrix A)
82 * @param[in] b Input tensor (Matrix B)
83 * @param[in] c Input tensor (Matrix C) used to pass the bias for quantized calculations
84 * @param[out] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
85 * @param[in] info GEMM meta-data
Anthony Barbierc8e84b52018-07-17 16:48:42 +010086 */
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +010087 void configure(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, ITensorInfo *d, const AsmGemmInfo &info);
Anthony Barbiereaefd002018-07-20 17:49:35 +010088
89 /** Indicates whether or not this function can be used to process the given parameters.
90 *
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000091 * @param[in] a Input tensor info (Matrix A)
92 * @param[in] b Input tensor info (Matrix B)
93 * @param[in] c Input tensor info (Matrix C) used to pass the bias for quantized calculations
94 * @param[in] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
95 * @param[in] info GEMM meta-data
Anthony Barbiereaefd002018-07-20 17:49:35 +010096 *
97 * @return a status.
98 */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000099 static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const AsmGemmInfo &info);
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100100 /** Checks if activation is supported by the gemm assembly dispatcher
101 *
102 * @param[in] activation Activation to check
103 *
104 * @return True if activation is supported else false
105 */
106 static bool is_activation_supported(const ActivationLayerInfo &activation);
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100107 /** Was the function successfully configured ?
108 *
109 * @return True if the function is configured and ready to run
110 */
Anthony Barbier71d9b572018-07-06 17:05:59 +0100111 bool is_configured() const;
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000112
Anthony Barbier71d9b572018-07-06 17:05:59 +0100113 // Inherited methods overridden:
Michele Di Giorgio8ae3cda2021-06-07 15:30:26 +0100114 void prepare(ITensorPack &tensors) override;
115 void run(ITensorPack &tensors) override;
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +0100116 experimental::MemoryRequirements workspace() const override;
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000117
118private:
Michele Di Giorgiod7316eb2021-06-16 11:14:41 +0100119 std::unique_ptr<IFallback> _arm_gemm; /**< Interface for the arm_gemm fallback */
Anthony Barbier71d9b572018-07-06 17:05:59 +0100120};
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100121} // namespace cpu
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100122} // namespace arm_compute
Sang-Hoon Parkd89e2fa2021-05-17 17:04:50 +0100123#endif /* ARM_COMPUTE_CPU_INTERNAL_CPU_GEMM_ASSEMBLY_DISPATCH_H */