1 /* 2 * Copyright (c) 2018-2021 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/IFunction.h" 28 29 #include "arm_compute/core/Types.h" 30 31 #include <memory> 32 #include <vector> 33 34 namespace arm_compute 35 { 36 // Forward declarations 37 class CLCompileContext; 38 class ICLTensor; 39 class ICLKernel; 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 opencl::kernels::ClWidthConcatenateKernel (if underlying concatenation axis is 0). 46 * -# @ref opencl::kernels::ClHeightConcatenateKernel (if underlying concatenation axis is 1). 47 * -# @ref opencl::kernels::ClDepthConcatenateKernel (if underlying concatenation axis is 2). 48 * -# @ref opencl::kernels::ClBatchConcatenateKernel (if underlying concatenation axis is 3). 49 */ 50 class CLConcatenateLayer : public IFunction 51 { 52 public: 53 /** Default constructor */ 54 CLConcatenateLayer(); 55 /** Destructor */ 56 ~CLConcatenateLayer(); 57 /** Prevent instances of this class from being copied (As this class contains pointers) */ 58 CLConcatenateLayer(const CLConcatenateLayer &) = delete; 59 /** Default move constructor */ 60 CLConcatenateLayer(CLConcatenateLayer &&); 61 /** Prevent instances of this class from being copied (As this class contains pointers) */ 62 CLConcatenateLayer &operator=(const CLConcatenateLayer &) = delete; 63 /** Default move assignment operator */ 64 CLConcatenateLayer &operator=(CLConcatenateLayer &&); 65 /** Initialise the kernel's inputs vector and output. 66 * 67 * Valid data layouts: 68 * - All 69 * 70 * Valid data type configurations: 71 * |src |dst | 72 * |:--------------|:--------------| 73 * |QASYMM8 |QASYMM8 | 74 * |QASYMM8_SIGNED |QASYMM8_SIGNED | 75 * |F16 |F16 | 76 * |F32 |F32 | 77 * 78 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 79 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel, 80 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel. 81 * 82 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. 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(std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); 87 /** Initialise the kernel's inputs vector and output. 88 * 89 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 90 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel, 91 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel. 92 * 93 * @param[in] compile_context The compile context to be used. 94 * @param[in,out] inputs_vector The vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. 95 * @param[out] output Output tensor. Data types supported: Same as @p input. 96 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 97 */ 98 void configure(const CLCompileContext &compile_context, std::vector<const ICLTensor *> &inputs_vector, ICLTensor *output, size_t axis); 99 /** Static function to check if given info will lead to a valid configuration of @ref CLConcatenateLayer 100 * 101 * @note Input and output tensor dimensions preconditions defer depending on the concatenation axis. 102 * @note Preconditions can be found respectively at @ref opencl::kernels::ClWidthConcatenateKernel, 103 * @ref opencl::kernels::ClHeightConcatenateKernel and @ref opencl::kernels::ClDepthConcatenateKernel. 104 * 105 * @param[in] inputs_vector The vectors containing all the tensors info to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. 106 * @param[in] output Output tensor info. Data types supported: Same as @p input. 107 * @param[in] axis Concatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3. 108 * 109 * @return a status 110 */ 111 static Status validate(const std::vector<const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis); 112 113 // Inherited methods overridden: 114 void run() override; 115 116 private: 117 struct Impl; 118 std::unique_ptr<Impl> _impl; 119 }; 120 } // namespace arm_compute 121 #endif /* ARM_COMPUTE_CLCONCATENATELAYER_H */ 122