Compute Library
 19.08
NEUpsampleLayerKernel Class Reference

Interface for the Upsample layer kernel. More...

#include <NEUpsampleLayerKernel.h>

Collaboration diagram for NEUpsampleLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEUpsampleLayerKernel ()
 Default constructor. More...
 
 NEUpsampleLayerKernel (const NEUpsampleLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEUpsampleLayerKerneloperator= (const NEUpsampleLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEUpsampleLayerKernel (NEUpsampleLayerKernel &&)=default
 Default Move Constructor. More...
 
NEUpsampleLayerKerneloperator= (NEUpsampleLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~NEUpsampleLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const Size2D &info, const InterpolationPolicy policy)
 Set the input output tensors. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const Size2D &info, const InterpolationPolicy policy)
 Static function to check if given info will lead to a valid configuration of NEUpsampleLayerKernel. More...
 

Detailed Description

Interface for the Upsample layer kernel.

Definition at line 34 of file NEUpsampleLayerKernel.h.

Constructor & Destructor Documentation

◆ NEUpsampleLayerKernel() [1/3]

Default constructor.

Definition at line 85 of file NEUpsampleLayerKernel.cpp.

86  : _func(nullptr), _input(nullptr), _output(nullptr), _info(), _num_elems_processed_per_iteration_x()
87 {
88 }

◆ NEUpsampleLayerKernel() [2/3]

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

◆ NEUpsampleLayerKernel() [3/3]

Default Move Constructor.

◆ ~NEUpsampleLayerKernel()

~NEUpsampleLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const Size2D info,
const InterpolationPolicy  policy 
)

Set the input output tensors.

Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F16/F32.
[out]outputDestination tensor. Data types supported: same as input.
[in]infoContains stride information described in Size2D.
[in]policyDefines the policy to fill the intermediate pixels.

Definition at line 295 of file NEUpsampleLayerKernel.cpp.

296 {
297  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
299 
300  _input = input;
301  _output = output;
302  _info = info;
303 
304  const DataLayout data_layout = input->info()->data_layout();
305 
307  auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
308  output->info()->set_data_layout(data_layout);
309 
310  // Perform validation step
311  ARM_COMPUTE_ERROR_THROW_ON(NEUpsampleLayerKernel::validate(input->info(), output->info(), info, policy));
312 
313  _num_elems_processed_per_iteration_x = 16 / output->info()->element_size();
314 
315  switch(data_layout)
316  {
317  case DataLayout::NCHW:
318  {
319  switch(input->info()->data_type())
320  {
321  case DataType::QASYMM8:
322  _func = &NEUpsampleLayerKernel::upsample_qasymm8_nchw;
323  break;
324  case DataType::F32:
325  _func = &NEUpsampleLayerKernel::upsample_f32_nchw;
326  break;
327 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
328  case DataType::F16:
329  _func = &NEUpsampleLayerKernel::upsample_f16_nchw;
330  break;
331 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
332  default:
333  ARM_COMPUTE_ERROR("Not implemented");
334  }
335  break;
336  }
337  case DataLayout::NHWC:
338  {
339  switch(input->info()->data_type())
340  {
341  case DataType::QASYMM8:
342  _func = &NEUpsampleLayerKernel::upsample_qasymm8_nhwc;
343  break;
344  case DataType::F32:
345  _func = &NEUpsampleLayerKernel::upsample_f32_nhwc;
346  break;
347 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
348  case DataType::F16:
349  _func = &NEUpsampleLayerKernel::upsample_f16_nhwc;
350  break;
351 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
352  default:
353  ARM_COMPUTE_ERROR("Not implemented");
354  }
355  break;
356  }
357  default:
358  ARM_COMPUTE_ERROR("Not implemented");
359  }
360 
361  // Configure window
362  std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
363  output->info(),
364  _num_elems_processed_per_iteration_x,
365  info);
366  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
367  INEKernel::configure(win_config.second);
368 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const DataLayout data_layout
Definition: Im2Col.cpp:146
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &info, const InterpolationPolicy policy)
Static function to check if given info will lead to a valid configuration of NEUpsampleLayerKernel.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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...
Definition: Helpers.inl:201
1 channel, 1 F16 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
quantized, asymmetric fixed-point 8-bit number
Num samples, channels, height, width.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
TensorShape compute_upsample_shape(const ITensorInfo &input, const Size2D &info)
Calculate the upsampled shape of a tensor.
Num samples, height, width, channels.
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::auto_init_if_empty(), arm_compute::misc::shape_calculator::compute_upsample_shape(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::element_size(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::test::validation::info, arm_compute::NCHW, arm_compute::NHWC, arm_compute::test::validation::output_shape, arm_compute::test::validation::policy, arm_compute::QASYMM8, ITensorInfo::set_data_layout(), NEUpsampleLayerKernel::validate(), and arm_compute::validate_and_configure_window().

Referenced by NEUpsampleLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file NEUpsampleLayerKernel.h.

38  {
39  return "NEUpsampleLayerKernel";
40  }

◆ operator=() [1/2]

NEUpsampleLayerKernel& operator= ( const NEUpsampleLayerKernel )
delete

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

◆ operator=() [2/2]

NEUpsampleLayerKernel& operator= ( NEUpsampleLayerKernel &&  )
default

Default move assignment operator.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 370 of file NEUpsampleLayerKernel.cpp.

371 {
375  ARM_COMPUTE_ERROR_ON(_func == nullptr);
376 
377  (this->*_func)(window);
378 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const Size2D info,
const InterpolationPolicy  policy 
)
static

Static function to check if given info will lead to a valid configuration of NEUpsampleLayerKernel.

Parameters
[in]inputSource tensor info. Data types supported: QASYMM8/F16/F32.
[in]outputDestination tensor info. Data types supported: same as input.
[in]infoContains stride information described in Size2D.
[in]policyDefines the policy to fill the intermediate pixels.
Returns
a status

Definition at line 90 of file NEUpsampleLayerKernel.cpp.

91 {
94 
95  const DataLayout data_layout = input->data_layout();
98 
101  ARM_COMPUTE_RETURN_ERROR_ON_MSG(info.x() != 2 || info.y() != 2, "Only stride 2 is supported");
102  ARM_COMPUTE_RETURN_ERROR_ON_MSG(policy != InterpolationPolicy::NEAREST_NEIGHBOR, "Only nearest neighbor policy supported");
103 
104  // Check output if configured
105  if(output->total_size() != 0)
106  {
109  ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(idx_width) != info.x() * input->dimension(idx_width));
110  ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(idx_height) != info.y() * input->dimension(idx_height));
112  }
113 
114  const int num_elems_processed_per_iteration_x = 16 / input->element_size();
116  output->clone().get(), num_elems_processed_per_iteration_x, info)
117  .first);
118  return Status{};
119 }
const DataLayout data_layout
Definition: Im2Col.cpp:146
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
Definition: Validate.h:494
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:791
1 channel, 1 F32 per channel
Output values are defined to match the source pixel whose center is nearest to the sample position.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:244
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:71
1 channel, 1 F16 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
quantized, asymmetric fixed-point 8-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond,...)
If the condition is true, an error is returned.
Definition: Error.h:214
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Definition: Validate.h:610
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:326
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO, ARM_COMPUTE_RETURN_ERROR_ON_MSG, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, ARM_COMPUTE_UNUSED, ICloneable< T >::clone(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), ITensorInfo::element_size(), arm_compute::F16, arm_compute::F32, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, arm_compute::NEAREST_NEIGHBOR, arm_compute::test::validation::policy, arm_compute::QASYMM8, ITensorInfo::total_size(), arm_compute::validate_and_configure_window(), and arm_compute::WIDTH.

Referenced by NEUpsampleLayerKernel::configure(), and NEUpsampleLayer::validate().


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