1 /* 2 * Copyright (c) 2017-2020 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 25 #ifndef ARM_COMPUTE_GCGEMM_H 26 #define ARM_COMPUTE_GCGEMM_H 27 28 #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.h" 29 #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.h" 30 #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.h" 31 #include "arm_compute/core/GLES_COMPUTE/kernels/GCGEMMTranspose1xWKernel.h" 32 #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" 33 #include "arm_compute/runtime/IFunction.h" 34 #include "arm_compute/runtime/MemoryGroup.h" 35 36 namespace arm_compute 37 { 38 class IGCTensor; 39 40 /** Basic function to execute GEMM on OpenGLES Compute. This function calls the following kernels: 41 * 42 * -# @ref GCGEMMInterleave4x4Kernel (if the output tensor is a matrix) 43 * -# @ref GCGEMMTranspose1xWKernel (if the output tensor is a matrix) 44 * -# @ref GCGEMMMatrixMultiplyKernel 45 * -# @ref GCGEMMMatrixAdditionKernel (if c != nullptr and beta != 0.0) 46 * 47 * @deprecated This function is deprecated and is intended to be removed in 21.05 release 48 * 49 */ 50 class GCGEMM : public IFunction 51 { 52 public: 53 /** Default constructor. */ 54 GCGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr); 55 /** Prevent instances of this class from being copied (As this class contains pointers) */ 56 GCGEMM(const GCGEMM &) = delete; 57 /** Default move constructor */ 58 GCGEMM(GCGEMM &&) = default; 59 /** Prevent instances of this class from being copied (As this class contains pointers) */ 60 GCGEMM &operator=(const GCGEMM &) = delete; 61 /** Default move assignment operator */ 62 GCGEMM &operator=(GCGEMM &&) = default; 63 /** Initialise the kernel's inputs and output 64 * 65 * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C]. 66 * 67 * @note All tensors must have the same data type. 68 * 69 * @note Whilst the first input tensor can be a vector, the second input tensor must be at least a matrix 70 * 71 * @param[in] a First input tensor (Matrix or Vector A). Data types supported: F32 72 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a. 73 * @param[in] c Third input tensor (Matrix C). It can be a nullptr if just the multiplication between @p a and @p b is needed. Data type supported: same as @p a. 74 * @param[out] output Output tensor. Data type supported: same as @p a 75 * @param[in] alpha Weight of the matrix product 76 * @param[in] beta Weight of matrix C 77 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and 78 * if the reshape of matrix B should happen only for the first run 79 */ 80 void configure(const IGCTensor *a, const IGCTensor *b, const IGCTensor *c, IGCTensor *output, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo()); 81 /** Static function to check if given info will lead to a valid configuration of @ref GCGEMM. 82 * 83 * @param[in] a First input tensor (Matrix or Vector A). Data types supported: F16/F32 84 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a. 85 * @param[in] c Third input tensor (Matrix C). It can be a nullptr if just the multiplication between @p a and @p b is needed. Data type supported: same as @p a. 86 * @param[out] output Output tensor. Data type supported: same as @p a 87 * @param[in] alpha Weight of the matrix product 88 * @param[in] beta Weight of matrix C 89 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and 90 * if the reshape of matrix B should happen only for the first run 91 * 92 * @return a status 93 */ 94 static Status validate(const ITensorInfo *a, const ITensorInfo *b, const IGCTensor *c, const ITensorInfo *output, const float alpha, const float beta, const GEMMInfo &gemm_info = GEMMInfo()); 95 96 // Inherited methods overridden: 97 void run() override; 98 void prepare() override; 99 100 private: 101 MemoryGroup _memory_group; 102 GCGEMMInterleave4x4Kernel _interleave_kernel; 103 GCGEMMTranspose1xWKernel _transpose_kernel; 104 GCGEMMMatrixMultiplyKernel _mm_kernel; 105 GCGEMMMatrixAdditionKernel _ma_kernel; 106 GCTensor _tmp_a; 107 GCTensor _tmp_b; 108 const IGCTensor *_original_b; 109 bool _is_interleaved_transposed; 110 bool _run_addition; 111 bool _reshape_b_only_on_first_run; 112 bool _is_prepared; 113 }; 114 } 115 116 #endif /* ARM_COMPUTE_GCGEMM_H */ 117