Compute Library
 21.02
GCConcatenateLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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  */
25 
26 #include "arm_compute/core/Error.h"
29 #include "arm_compute/core/Types.h"
33 
34 namespace arm_compute
35 {
37  : _concat_kernels(),
38  _num_inputs(0),
39  _axis(Window::DimZ)
40 {
41 }
42 
43 void GCConcatenateLayer::configure(std::vector<IGCTensor *> inputs_vector, IGCTensor *output, size_t axis)
44 {
45  ARM_COMPUTE_ERROR_ON(inputs_vector.size() < 2);
46 
47  _num_inputs = inputs_vector.size();
48  _axis = axis;
49 
51 
52  // Output auto inizialitation if not yet initialized
53  auto_init_if_empty(*output->info(), output_shape, 1, inputs_vector[0]->info()->data_type());
54 
55  unsigned int offset = 0;
56  switch(axis)
57  {
58  case Window::DimZ:
59  {
60  for(unsigned int i = 0; i < _num_inputs; ++i)
61  {
62  auto kernel = std::make_unique<GCDepthConcatenateLayerKernel>();
63  kernel->configure(inputs_vector.at(i), offset, output);
64  offset += inputs_vector.at(i)->info()->dimension(axis);
65  _concat_kernels.emplace_back(std::move(kernel));
66  }
67  break;
68  }
69  default:
70  ARM_COMPUTE_ERROR("Axis not supported");
71  }
72 }
73 
75 {
76  for(auto &kernel : _concat_kernels)
77  {
78  GCScheduler::get().dispatch(*kernel, true);
79  }
80 }
81 } // namespace arm_compute
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:846
Shape of a tensor.
Definition: TensorShape.h:39
void dispatch(IGCKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: GCScheduler.cpp:77
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
GCConcatenateLayer()
Default constructor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Interface for GLES Compute tensor.
Definition: IGCTensor.h:35
Copyright (c) 2017-2021 Arm Limited.
static GCScheduler & get()
Access the scheduler singleton.
Definition: GCScheduler.cpp:70
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void configure(std::vector< IGCTensor *> inputs_vector, IGCTensor *output, size_t axis)
Initialise the kernel&#39;s inputs vector and output.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Interface to enqueue GLES kernels and get/set the GLES CommandQueue.
void run() override
Run the kernels contained in the function.
TensorShape calculate_concatenate_shape(const std::vector< T *> &input, size_t axis)
Calculate the concatenate output shape of the concatenate operation along a single axis...
Describe a multidimensional execution window.
Definition: Window.h:39