Compute Library
 21.02
GCNormalizationLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 
26 
27 #include "arm_compute/core/Error.h"
30 #include "arm_compute/core/Types.h"
33 
34 using namespace arm_compute;
35 
36 GCNormalizationLayer::GCNormalizationLayer(std::shared_ptr<IMemoryManager> memory_manager)
37  : _memory_group(std::move(memory_manager)), _squared_input(), _norm_kernel(), _multiply_kernel(), _border_handler()
38 {
39 }
40 
42 {
43  ARM_COMPUTE_ERROR_ON(input == nullptr);
44 
45  _squared_input.allocator()->init(TensorInfo(input->info()->tensor_shape(), 1, input->info()->data_type()));
46  _memory_group.manage(&_squared_input);
47 
48  _norm_kernel.configure(input, &_squared_input, output, norm_info);
49  _multiply_kernel.configure(input, input, &_squared_input, 1.0f);
50  // Fill the border by 3 elements since we need vload4 in the IN_MAP normalization kernel
51  _border_handler.configure(&_squared_input, _norm_kernel.border_size(), BorderMode::CONSTANT, PixelValue());
52 
53  // Allocate intermediate buffers
54  _squared_input.allocator()->allocate();
55 }
56 
58 {
59  MemoryGroupResourceScope scope_mg(_memory_group);
60 
61  GCScheduler::get().dispatch(_multiply_kernel, false);
63  GCScheduler::get().dispatch(_border_handler, false);
65  GCScheduler::get().dispatch(_norm_kernel, true);
66 }
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
void dispatch(IGCKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: GCScheduler.cpp:77
virtual DataType data_type() const =0
Data type used for each element of the tensor.
Normalization Layer Information class.
Definition: Types.h:1647
void memory_barrier()
Defines a barrier ordering memory transactions.
Definition: GCScheduler.cpp:86
#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
GCNormalizationLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
void configure(const IGCTensor *input1, const IGCTensor *input2, IGCTensor *output, float scale)
Initialise the kernel&#39;s input, output and border mode.
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
Copyright (c) 2017-2021 Arm Limited.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
static GCScheduler & get()
Access the scheduler singleton.
Definition: GCScheduler.cpp:70
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(const IGCTensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the kernel&#39;s input, output and border mode.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void configure(const IGCTensor *input, const IGCTensor *squared_input, IGCTensor *output, NormalizationLayerInfo norm_info)
Set the input and output tensors.
virtual void allocate()=0
Interface to be implemented by the child class to allocate the tensor.
void run() override
Run the kernels contained in the function.
BorderSize border_size() const override
The size of the border for that kernel.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
Interface to enqueue GLES kernels and get/set the GLES CommandQueue.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
ITensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: GCTensor.cpp:34
void configure(const IGCTensor *input, IGCTensor *output, const NormalizationLayerInfo &norm_info)
Set the input and output tensors.