Compute Library
 21.02
CLMagnitudePhaseKernel Class Reference

Template interface for the kernel to compute magnitude and phase. More...

#include <CLMagnitudePhaseKernel.h>

Collaboration diagram for CLMagnitudePhaseKernel:
[legend]

Public Member Functions

 CLMagnitudePhaseKernel ()
 Default constructor. More...
 
 CLMagnitudePhaseKernel (const CLMagnitudePhaseKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLMagnitudePhaseKerneloperator= (const CLMagnitudePhaseKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLMagnitudePhaseKernel (CLMagnitudePhaseKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLMagnitudePhaseKerneloperator= (CLMagnitudePhaseKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, MagnitudeType mag_type=MagnitudeType::L2NORM, PhaseType phase_type=PhaseType::SIGNED)
 Initialise the kernel's input, output. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, MagnitudeType mag_type=MagnitudeType::L2NORM, PhaseType phase_type=PhaseType::SIGNED)
 Initialise the kernel's input, output. More...
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Template interface for the kernel to compute magnitude and phase.

Definition at line 37 of file CLMagnitudePhaseKernel.h.

Constructor & Destructor Documentation

◆ CLMagnitudePhaseKernel() [1/3]

Default constructor.

Definition at line 41 of file CLMagnitudePhaseKernel.cpp.

42  : _gx(nullptr), _gy(nullptr), _magnitude(nullptr), _phase(nullptr), _run_mag(false), _run_phase(false)
43 {
44 }

◆ CLMagnitudePhaseKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLMagnitudePhaseKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor gx,
const ICLTensor gy,
ICLTensor magnitude,
ICLTensor phase,
MagnitudeType  mag_type = MagnitudeType::L2NORM,
PhaseType  phase_type = PhaseType::SIGNED 
)

Initialise the kernel's input, output.

Note
At least one of output1 or output2 must be set.
Parameters
[in]gxThe input gradient X tensor. Data types supported: S16/S32.
[in]gyThe input gradient Y tensor. Data types supported: S16/S32.
[out]magnitude(Optional) The output tensor - Magnitude. Data types supported: S16/S32.
[out]phase(Optional) The output tensor - Phase. Data types supported: U8.
[in]mag_type(Optional) Magnitude calculation type. Default: L2NORM.
[in]phase_type(Optional) Phase calculation type. Default: SIGNED.

Definition at line 46 of file CLMagnitudePhaseKernel.cpp.

References CLKernelLibrary::get().

48 {
49  configure(CLKernelLibrary::get().get_compile_context(), gx, gy, magnitude, phase, mag_type, phase_type);
50 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, MagnitudeType mag_type=MagnitudeType::L2NORM, PhaseType phase_type=PhaseType::SIGNED)
Initialise the kernel&#39;s input, output.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor gx,
const ICLTensor gy,
ICLTensor magnitude,
ICLTensor phase,
MagnitudeType  mag_type = MagnitudeType::L2NORM,
PhaseType  phase_type = PhaseType::SIGNED 
)

Initialise the kernel's input, output.

Note
At least one of output1 or output2 must be set.
Parameters
[in]compile_contextThe compile context to be used.
[in]gxThe input gradient X tensor. Data types supported: S16/S32.
[in]gyThe input gradient Y tensor. Data types supported: S16/S32.
[out]magnitude(Optional) The output tensor - Magnitude. Data types supported: S16/S32.
[out]phase(Optional) The output tensor - Phase. Data types supported: U8.
[in]mag_type(Optional) Magnitude calculation type. Default: L2NORM.
[in]phase_type(Optional) Phase calculation type. Default: SIGNED.

Definition at line 52 of file CLMagnitudePhaseKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::intersect_valid_regions(), kernel_name, arm_compute::L1NORM, arm_compute::L2NORM, arm_compute::lower_string(), arm_compute::test::validation::reference::magnitude(), num_elems_processed_per_iteration, arm_compute::test::validation::reference::phase(), arm_compute::S16, arm_compute::S32, arm_compute::SIGNED, arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), arm_compute::U8, arm_compute::UNSIGNED, arm_compute::update_window_and_padding(), arm_compute::test::validation::valid_region, and ITensorInfo::valid_region().

54 {
57  ARM_COMPUTE_ERROR_ON((magnitude == nullptr) && (phase == nullptr));
59 
60  _run_mag = (magnitude != nullptr);
61  _run_phase = (phase != nullptr);
62  if(_run_mag)
63  {
66  }
67  if(_run_phase)
68  {
70  }
71 
72  if(!_run_mag && !_run_phase)
73  {
74  ARM_COMPUTE_ERROR("At least one output must be NOT NULL");
75  }
76 
77  _gx = gx;
78  _gy = gy;
79  _magnitude = magnitude;
80  _phase = phase;
81 
82  // Construct kernel name
83  std::set<std::string> build_opts = {};
84 
85  // Add magnitude type
86  if(_run_mag)
87  {
88  switch(mag_type)
89  {
91  build_opts.insert("-DMAGNITUDE=1");
92  break;
94  build_opts.insert("-DMAGNITUDE=2");
95  break;
96  default:
97  ARM_COMPUTE_ERROR("Unsupported magnitude calculation type.");
98  build_opts.insert("-DMAGNITUDE=0");
99  break;
100  }
101  }
102 
103  // Add phase type
104  if(_run_phase)
105  {
106  switch(phase_type)
107  {
108  case PhaseType::UNSIGNED:
109  build_opts.insert("-DPHASE=1");
110  break;
111  case PhaseType::SIGNED:
112  build_opts.insert("-DPHASE=2");
113  break;
114  default:
115  ARM_COMPUTE_ERROR("Unsupported phase calculation type.");
116  build_opts.insert("-DPHASE=0");
117  break;
118  }
119  }
120 
121  // Add data_type
122  build_opts.insert("-DDATA_TYPE=" + get_cl_type_from_data_type(gx->info()->data_type()));
123 
124  // Create kernel
125  const std::string kernel_name = std::string("magnitude_phase");
126  _kernel = create_kernel(compile_context, kernel_name, build_opts);
127 
128  // Configure kernel window
129  constexpr unsigned int num_elems_processed_per_iteration = 16;
130 
131  Window win = calculate_max_window(*gx->info(), Steps(num_elems_processed_per_iteration));
132 
135  AccessWindowHorizontal output_magnitude_access(magnitude == nullptr ? nullptr : magnitude->info(), 0, num_elems_processed_per_iteration);
136  AccessWindowHorizontal output_phase_access(phase == nullptr ? nullptr : phase->info(), 0, num_elems_processed_per_iteration);
137 
139  gx_access, gy_access,
140  output_magnitude_access, output_phase_access);
141 
143  gy->info()->valid_region());
144  output_magnitude_access.set_valid_region(win, valid_region);
145  output_phase_access.set_valid_region(win, valid_region);
146 
147  ICLKernel::configure_internal(win);
148 
149  // Set config_id for enabling LWS tuning
150  _config_id = kernel_name;
151  _config_id += "_";
152  _config_id += lower_string(string_from_data_type(gx->info()->data_type()));
153  _config_id += "_";
154  _config_id += support::cpp11::to_string(gx->info()->dimension(0));
155  _config_id += "_";
156  _config_id += support::cpp11::to_string(gx->info()->dimension(1));
157 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
L1 normalization type.
Angle range: [0, 180].
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Angle range: [0, 360].
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:350
const ValidRegion valid_region
Definition: Scale.cpp:221
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
1 channel, 1 S32 per channel
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:403
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Implementation of a row access pattern.
std::string kernel_name
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
ValidRegion intersect_valid_regions(const Ts &... regions)
Intersect multiple valid regions.
Definition: WindowHelpers.h:74
1 channel, 1 S16 per channel
L2 normalization type.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
Container for valid region of a window.
Definition: Types.h:188
Describe a multidimensional execution window.
Definition: Window.h:39
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35

◆ operator=() [1/2]

CLMagnitudePhaseKernel& operator= ( const CLMagnitudePhaseKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

CLMagnitudePhaseKernel& operator= ( CLMagnitudePhaseKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Reimplemented from ICLKernel.

Definition at line 159 of file CLMagnitudePhaseKernel.cpp.

References ICLKernel::add_2D_tensor_argument(), ICLKernel::add_2D_tensor_argument_if(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().

160 {
163 
165  do
166  {
167  unsigned int idx = 0;
168  add_2D_tensor_argument(idx, _gx, slice);
169  add_2D_tensor_argument(idx, _gy, slice);
170  add_2D_tensor_argument_if((_run_mag), idx, _magnitude, slice);
171  add_2D_tensor_argument_if((_run_phase), idx, _phase, slice);
172 
173  enqueue(queue, *this, slice, lws_hint());
174  }
175  while(window.slide_window_slice_2D(slice));
176 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void add_2D_tensor_argument_if(bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx ...
Definition: ICLKernel.h:159
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
Definition: IGCKernel.cpp:41
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:323
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:148
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

The documentation for this class was generated from the following files: