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