Compute Library
 20.08
NEHOGGradient.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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 
29 #include "support/MemorySupport.h"
30 
31 using namespace arm_compute;
32 
33 NEHOGGradient::NEHOGGradient(std::shared_ptr<IMemoryManager> memory_manager) // NOLINT
34  : _memory_group(std::move(memory_manager)),
35  _derivative(),
36  _mag_phase(nullptr),
37  _gx(),
38  _gy()
39 {
40 }
41 
42 void NEHOGGradient::configure(ITensor *input, ITensor *output_magnitude, ITensor *output_phase, PhaseType phase_type, BorderMode border_mode, uint8_t constant_border_value)
43 {
47 
48  const TensorShape &shape_img = input->info()->tensor_shape();
49 
50  // Allocate image memory
51  TensorInfo info(shape_img, Format::S16);
52  _gx.allocator()->init(info);
53  _gy.allocator()->init(info);
54 
55  // Manage intermediate buffers
56  _memory_group.manage(&_gx);
57  _memory_group.manage(&_gy);
58 
59  // Initialise derivate kernel
60  _derivative.configure(input, &_gx, &_gy, border_mode, constant_border_value);
61 
62  // Initialise magnitude/phase kernel
63  if(PhaseType::UNSIGNED == phase_type)
64  {
65  auto k = arm_compute::support::cpp14::make_unique<NEMagnitudePhaseKernel<MagnitudeType::L2NORM, PhaseType::UNSIGNED>>();
66  k->configure(&_gx, &_gy, output_magnitude, output_phase);
67  _mag_phase = std::move(k);
68  }
69  else
70  {
71  auto k = arm_compute::support::cpp14::make_unique<NEMagnitudePhaseKernel<MagnitudeType::L2NORM, PhaseType::SIGNED>>();
72  k->configure(&_gx, &_gy, output_magnitude, output_phase);
73  _mag_phase = std::move(k);
74  }
75 
76  // Allocate intermediate tensors
77  _gx.allocator()->allocate();
78  _gy.allocator()->allocate();
79 }
80 
82 {
83  MemoryGroupResourceScope scope_mg(_memory_group);
84 
85  // Run derivative
86  _derivative.run();
87 
88  // Run magnitude/phase kernel
89  NEScheduler::get().schedule(_mag_phase.get(), Window::DimY);
90 }
BorderMode
Methods available to handle borders.
Definition: Types.h:264
Shape of a tensor.
Definition: TensorShape.h:39
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
Angle range: [0, 180].
PhaseType
Phase calculation type.
Definition: Types.h:409
void configure(ITensor *input, ITensor *output_x, ITensor *output_y, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function's source, destinations and border mode.
1 channel, 1 U8 per channel
NEHOGGradient(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
Interface for NEON tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2020 Arm Limited.
void run() override
Run the kernels contained in the function.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: Tensor.cpp:48
void configure(ITensor *input, ITensor *output_magnitude, ITensor *output_phase, PhaseType phase_type, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function's source, destinations, phase type and border mode.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
void run() override
Run the kernels contained in the function.
Store the tensor's metadata.
Definition: TensorInfo.h:45
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:95