1 /* 2 * Copyright (c) 2018-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 #ifndef ARM_COMPUTE_CLCONCATENATELAYER_H 25 #define ARM_COMPUTE_CLCONCATENATELAYER_H 26 27 #include "arm_compute/runtime/CL/ICLOperator.h" 28 #include "arm_compute/runtime/IFunction.h" 29 30 #include "arm_compute/core/Types.h" 31 32 #include <memory> 33 #include <vector> 34 35 namespace arm_compute 36 { 37 // Forward declarations 38 class CLCompileContext; 39 class ICLTensor; 40 class ICLKernel; 41 class ITensorInfo; 42 class Status; 43 44 /** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels: 45 * 46 * -# @ref CLWidthConcatenateLayerKernel (if underlying concatenation axis is 0). 47 * -# @ref CLHeightConcatenateLayerKernel (if underlying concatenation axis is 1). 48 * -# @ref CLDepthConcatenateLayerKernel (if underlying concatenation axis is 2). 49 * -# @ref CLBatchConcatenateLayerKernel (if underlying concatenation axis is 3). 50 */ 51 class CLConcatenateLayer : public IFunction 52 { 53 public: 54 /** Default constructor */ 55 CLConcatenateLayer(); 56 /** Destructor */ 57 ~CLConcatenateLayer(); 58 /** Prevent instances of this class from being copied (As this class contains pointers) */ 59 CLConcatenateLayer(const CLConcatenateLayer &) = delete; 60 /** Default move constructor */ 61 CLConcatenateLayer(CLConcatenateLayer &&); 62 /** Prevent instances of this class from being copied (As this class contains pointers) */ 63 CLConcatenateLayer &operator=(const CLConcatenateLayer &) = delete; 64 /** Default move assignment operator */ 65 CLConcatenateLayer &operator=(CLConcatenateLayer &&); 66 /** Initialise the kernel's inputs vector and output. 67 * 68 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 69 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. 70 * 71 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All 72 * @param[out] output Output tensor. Data types supported: Same as @p input. 73 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 74 */ 75 void configure(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); 76 /** Initialise the kernel's inputs vector and output. 77 * 78 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 79 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. 80 * 81 * @param[in] compile_context The compile context to be used. 82 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All 83 * @param[out] output Output tensor. Data types supported: Same as @p input. 84 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 85 */ 86 void configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); 87 /** Static function to check if given info will lead to a valid configuration of @ref CLConcatenateLayer 88 * 89 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 90 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. 91 * 92 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: All. 93 * @param[in] output Output tensor info. Data types supported: Same as @p input. 94 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 95 * 96 * @return a status 97 */ 98 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis); 99 100 // Inherited methods overridden: 101 void run() override; 102 103 private: 104 struct Impl; 105 std::unique_ptr<Impl> _impl; 106 }; 107 108 namespace experimental 109 { 110 /** Basic function to execute concatenate tensors along a given axis. This function calls the following kernels: 111 * 112 * -# @ref CLWidthConcatenateLayerKernel (if underlying concatenation axis is 0). 113 * -# @ref CLHeightConcatenateLayerKernel (if underlying concatenation axis is 1). 114 * -# @ref CLDepthConcatenateLayerKernel (if underlying concatenation axis is 2). 115 * -# @ref CLBatchConcatenateLayerKernel (if underlying concatenation axis is 3). 116 */ 117 class CLConcatenation : public ICLOperator 118 { 119 public: 120 /** Default constructor */ 121 CLConcatenation(); 122 /** Initialise the kernel's inputs vector and output. 123 * 124 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 125 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. 126 * 127 * 128 * @param[in] compile_context The compile context to be used. 129 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: All 130 * @param[out] output Output tensor. Data types supported: Same as @p input. 131 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 132 */ 133 void configure(const CLCompileContext &compile_context, const std::vector<ITensorInfo *> &inputs_vector, ITensorInfo *output, size_t axis); 134 /** Static function to check if given info will lead to a valid configuration of @ref NEConcatenateLayer 135 * 136 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 137 * @note Preconditions can be found respectively at @ref CLWidthConcatenateLayerKernel, @ref CLHeightConcatenateLayerKernel and @ref CLDepthConcatenateLayerKernel. 138 * 139 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: All 140 * @param[in] output Output tensor info. Data types supported: Same as @p input. 141 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 142 * 143 * @return a status 144 */ 145 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis); 146 147 // Inherited methods overridden: 148 void run(ITensorPack &tensors) override; 149 150 private: 151 std::vector<std::unique_ptr<ICLKernel>> _concat_kernels; 152 unsigned int _num_inputs; 153 unsigned int _axis; 154 }; 155 } // namespace experimental 156 } // namespace arm_compute 157 #endif /* ARM_COMPUTE_CLCONCATENATELAYER_H */ 158