Compute Library
 21.02
NERangeKernel Class Reference

Kernel class for Range. More...

#include <NERangeKernel.h>

Collaboration diagram for NERangeKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NERangeKernel ()
 Default constructor. More...
 
 NERangeKernel (const NERangeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NERangeKerneloperator= (const NERangeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NERangeKernel (NERangeKernel &&)=default
 Allow instances of this class to be moved. More...
 
NERangeKerneloperator= (NERangeKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NERangeKernel ()=default
 Default destructor. More...
 
void configure (ITensor *output, float start, float end, float step)
 Initialize the kernel's output tensor, start, end and step of the sequence. 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...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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 *output, float start, float end, float step)
 Static function to check if given info will lead to a valid configuration of NERangeKernel. More...
 

Detailed Description

Kernel class for Range.

range generates a 1-D tensor containing a sequence of numbers that begins at 'start' and extends by increments of 'step' up to but not including 'end'.

Definition at line 39 of file NERangeKernel.h.

Constructor & Destructor Documentation

◆ NERangeKernel() [1/3]

Default constructor.

Definition at line 114 of file NERangeKernel.cpp.

Referenced by NERangeKernel::name().

115  : _func(nullptr), _start(0), _end(1), _step(1), _output(nullptr)
116 {
117 }

◆ NERangeKernel() [2/3]

NERangeKernel ( const NERangeKernel )
delete

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

◆ NERangeKernel() [3/3]

NERangeKernel ( NERangeKernel &&  )
default

Allow instances of this class to be moved.

◆ ~NERangeKernel()

~NERangeKernel ( )
default

Default destructor.

Referenced by NERangeKernel::name().

Member Function Documentation

◆ configure()

void configure ( ITensor output,
float  start,
float  end,
float  step 
)

Initialize the kernel's output tensor, start, end and step of the sequence.

Parameters
[out]outputOutput tensor. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
[in]startThe starting value of the sequence.
[in]endThe ending (not including) value of the sequence.
[in]stepThe gap between each pair of values in the sequence.

Definition at line 119 of file NERangeKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::mlgo::parser::end(), arm_compute::F16, arm_compute::F32, ITensor::info(), ITensorInfo::num_dimensions(), arm_compute::num_of_elements_in_range(), ITensorInfo::quantization_info(), arm_compute::S16, arm_compute::S32, arm_compute::S8, Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), enable_tracing::start, arm_compute::cpu::step, ITensorInfo::tensor_shape(), arm_compute::U16, arm_compute::U32, arm_compute::U8, and arm_compute::validate_arguments().

Referenced by NERangeKernel::name().

120 {
122 
124 
125  // Auto initialize output if not initialized
126  auto_init_if_empty(*output->info(), TensorShape(num_of_elements_in_range(start, end, step)), 1, output->info()->data_type(), output->info()->quantization_info());
127 
128  // Configure kernel window
129  Window win = calculate_max_window(*output->info(), Steps());
130  Coordinates coord;
131  coord.set_num_dimensions(output->info()->num_dimensions());
132  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
133 
134  _start = start;
135  _end = end;
136  _step = step;
137  _output = output;
138  switch(_output->info()->data_type())
139  {
140  case DataType::U8:
141  _func = &range_function<uint8_t>;
142  break;
143  case DataType::U16:
144  _func = &range_function<uint16_t>;
145  break;
146  case DataType::U32:
147  _func = &range_function<uint32_t>;
148  break;
149  case DataType::S8:
150  _func = &range_function<int8_t>;
151  break;
152  case DataType::S16:
153  _func = &range_function<int16_t>;
154  break;
155  case DataType::S32:
156  _func = &range_function<int32_t>;
157  break;
158  case DataType::F32:
159  _func = &range_function<float>;
160  break;
161 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
162  case DataType::F16:
163  _func = &range_function<float16_t>;
164  break;
165 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
166  default:
167  ARM_COMPUTE_ERROR("Unsupported data type.");
168  break;
169  }
170 
171  INEKernel::configure(win);
172 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#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
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
1 channel, 1 U16 per channel
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
1 channel, 1 U32 per channel
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 end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
size_t num_of_elements_in_range(const float start, const float end, const float step)
Returns the number of elements required to go from start to end with the wanted step.
Definition: Utils.h:1284
1 channel, 1 S16 per channel
constexpr int step
Definition: fp32.cpp:35
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
signed 8-bit number

◆ name()

◆ operator=() [1/2]

NERangeKernel& operator= ( const NERangeKernel )
delete

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

Referenced by NERangeKernel::name().

◆ operator=() [2/2]

NERangeKernel& operator= ( NERangeKernel &&  )
default

Allow instances of this class to be moved.

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 183 of file NERangeKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NERangeKernel::name().

184 {
188  ARM_COMPUTE_ERROR_ON(_func == nullptr);
189 
190  (*_func)(_output, _start, _step, window);
191 }
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:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo output,
float  start,
float  end,
float  step 
)
static

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

Parameters
[in]outputOutput tensor info. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
[in]startThe starting value of the sequence.
[in]endThe ending (not including) value of the sequence.
[in]stepThe gap between each pair of values in the sequence.
Returns
a status

Definition at line 174 of file NERangeKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by NERangeKernel::name(), and NERange::validate().

175 {
177 
179 
180  return Status{};
181 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
constexpr int step
Definition: fp32.cpp:35
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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