Compute Library
 19.08
NEActivationLayerKernel Class Reference

Interface for the activation layer kernel. More...

#include <NEActivationLayerKernel.h>

Collaboration diagram for NEActivationLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEActivationLayerKernel ()
 Constructor. More...
 
 NEActivationLayerKernel (const NEActivationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEActivationLayerKernel (NEActivationLayerKernel &&)=default
 Default move constructor. More...
 
NEActivationLayerKerneloperator= (const NEActivationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEActivationLayerKerneloperator= (NEActivationLayerKernel &&)=default
 Default move assignment operator. More...
 
void configure (ITensor *input, ITensor *output, ActivationLayerInfo activation_info)
 Set the input and output tensor. 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 ActivationLayerInfo &act_info)
 Static function to check if given info will lead to a valid configuration of NEActivationLayerKernel. More...
 

Detailed Description

Interface for the activation layer kernel.

Definition at line 39 of file NEActivationLayerKernel.h.

Constructor & Destructor Documentation

◆ NEActivationLayerKernel() [1/3]

Constructor.

Definition at line 111 of file NEActivationLayerKernel.cpp.

112  : _input(nullptr), _output(nullptr), _func(nullptr), _act_info(ActivationFunction::LOGISTIC)
113 {
114 }

◆ NEActivationLayerKernel() [2/3]

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

◆ NEActivationLayerKernel() [3/3]

Default move constructor.

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
ActivationLayerInfo  activation_info 
)

Set the input and output tensor.

Note
If the output tensor is a nullptr, the activation function will be performed in-place
Parameters
[in,out]inputSource tensor. In case of output tensor = nullptr, this tensor will store the result of the activation function. Data types supported: QASYMM8/QSYMM16/F16/F32.
[out]outputDestination tensor. Data type supported: same as input
[in]activation_infoActivation layer information.

Definition at line 116 of file NEActivationLayerKernel.cpp.

117 {
119 
120  _input = input;
121  _act_info = activation_info;
122  _output = input;
123 
124  if(output != nullptr)
125  {
126  _output = output;
127  }
128 
129  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr, activation_info));
130 
131  // Activation functions : FP32
132  static std::map<ActivationFunction, ActivationFunctionExecutorPtr> act_map_f32 =
133  {
134  { ActivationFunction::ABS, &NEActivationLayerKernel::activation<ActivationFunction::ABS, float> },
135  { ActivationFunction::LINEAR, &NEActivationLayerKernel::activation<ActivationFunction::LINEAR, float> },
136  { ActivationFunction::LOGISTIC, &NEActivationLayerKernel::activation<ActivationFunction::LOGISTIC, float> },
137  { ActivationFunction::RELU, &NEActivationLayerKernel::activation<ActivationFunction::RELU, float> },
138  { ActivationFunction::BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::BOUNDED_RELU, float> },
139  { ActivationFunction::LU_BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::LU_BOUNDED_RELU, float> },
140  { ActivationFunction::LEAKY_RELU, &NEActivationLayerKernel::activation<ActivationFunction::LEAKY_RELU, float> },
141  { ActivationFunction::SOFT_RELU, &NEActivationLayerKernel::activation<ActivationFunction::SOFT_RELU, float> },
142  { ActivationFunction::SQRT, &NEActivationLayerKernel::activation<ActivationFunction::SQRT, float> },
143  { ActivationFunction::SQUARE, &NEActivationLayerKernel::activation<ActivationFunction::SQUARE, float> },
144  { ActivationFunction::TANH, &NEActivationLayerKernel::activation<ActivationFunction::TANH, float> },
145  { ActivationFunction::IDENTITY, &NEActivationLayerKernel::activation<ActivationFunction::IDENTITY, float> },
146  };
147 
148 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
149  // Activation functions : FP16
150  static std::map<ActivationFunction, ActivationFunctionExecutorPtr> act_map_f16 =
151  {
152  { ActivationFunction::ABS, &NEActivationLayerKernel::activation<ActivationFunction::ABS, float16_t> },
153  { ActivationFunction::LINEAR, &NEActivationLayerKernel::activation<ActivationFunction::LINEAR, float16_t> },
154  { ActivationFunction::LOGISTIC, &NEActivationLayerKernel::activation<ActivationFunction::LOGISTIC, float16_t> },
155  { ActivationFunction::RELU, &NEActivationLayerKernel::activation<ActivationFunction::RELU, float16_t> },
156  { ActivationFunction::BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::BOUNDED_RELU, float16_t> },
157  { ActivationFunction::LU_BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::LU_BOUNDED_RELU, float16_t> },
158  { ActivationFunction::LEAKY_RELU, &NEActivationLayerKernel::activation<ActivationFunction::LEAKY_RELU, float16_t> },
159  { ActivationFunction::SOFT_RELU, &NEActivationLayerKernel::activation<ActivationFunction::SOFT_RELU, float16_t> },
160  { ActivationFunction::SQRT, &NEActivationLayerKernel::activation<ActivationFunction::SQRT, float16_t> },
161  { ActivationFunction::SQUARE, &NEActivationLayerKernel::activation<ActivationFunction::SQUARE, float16_t> },
162  { ActivationFunction::TANH, &NEActivationLayerKernel::activation<ActivationFunction::TANH, float16_t> },
163  { ActivationFunction::IDENTITY, &NEActivationLayerKernel::activation<ActivationFunction::IDENTITY, float16_t> },
164  };
165 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC*/
166 
167  // Activation functions : QASYMM8
168  static std::map<ActivationFunction, ActivationFunctionExecutorPtr> act_map_qasymm8 =
169  {
170  { ActivationFunction::LOGISTIC, &NEActivationLayerKernel::activation<ActivationFunction::LOGISTIC, qasymm8_t> },
171  { ActivationFunction::BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::BOUNDED_RELU, qasymm8_t> },
172  { ActivationFunction::LU_BOUNDED_RELU, &NEActivationLayerKernel::activation<ActivationFunction::LU_BOUNDED_RELU, qasymm8_t> },
173  { ActivationFunction::RELU, &NEActivationLayerKernel::activation<ActivationFunction::RELU, qasymm8_t> },
174  { ActivationFunction::TANH, &NEActivationLayerKernel::activation<ActivationFunction::TANH, qasymm8_t> },
175  { ActivationFunction::IDENTITY, &NEActivationLayerKernel::activation<ActivationFunction::IDENTITY, qasymm8_t> },
176  };
177 
178  // Activation functions : QSYMM16
179  static std::map<ActivationFunction, ActivationFunctionExecutorPtr> act_map_qsymm16 =
180  {
181  { ActivationFunction::LOGISTIC, &NEActivationLayerKernel::activation<ActivationFunction::LOGISTIC, qsymm16_t> },
182  { ActivationFunction::TANH, &NEActivationLayerKernel::activation<ActivationFunction::TANH, qsymm16_t> },
183  };
184 
185  switch(input->info()->data_type())
186  {
187  case DataType::QASYMM8:
188  _func = act_map_qasymm8[activation_info.activation()];
189  break;
190  case DataType::QSYMM16:
191  _func = act_map_qsymm16[activation_info.activation()];
192  break;
193  case DataType::F32:
194  _func = act_map_f32[activation_info.activation()];
195  break;
196 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
197  case DataType::F16:
198  _func = act_map_f16[activation_info.activation()];
199  break;
200 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
201  default:
202  ARM_COMPUTE_ERROR("Unsupported data type.");
203  }
204 
205  // Configure kernel window
206  auto win_config = validate_and_configure_window(input->info(), (output != nullptr) ? output->info() : nullptr);
207  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
208  ICPPKernel::configure(win_config.second);
209 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
quantized, symmetric fixed-point 16-bit number
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)
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:327
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1550

References ActivationLayerInfo::ABS, ActivationLayerInfo::activation(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ActivationLayerInfo::BOUNDED_RELU, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ActivationLayerInfo::IDENTITY, ITensor::info(), ActivationLayerInfo::LEAKY_RELU, ActivationLayerInfo::LINEAR, ActivationLayerInfo::LOGISTIC, ActivationLayerInfo::LU_BOUNDED_RELU, arm_compute::QASYMM8, arm_compute::QSYMM16, ActivationLayerInfo::RELU, ActivationLayerInfo::SOFT_RELU, ActivationLayerInfo::SQRT, ActivationLayerInfo::SQUARE, ActivationLayerInfo::TANH, and arm_compute::validate_and_configure_window().

Referenced by NERNNLayer::configure(), and NELSTMLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 42 of file NEActivationLayerKernel.h.

43  {
44  return "NEActivationLayerKernel";
45  }

◆ operator=() [1/2]

NEActivationLayerKernel& operator= ( const NEActivationLayerKernel )
delete

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

◆ operator=() [2/2]

NEActivationLayerKernel& operator= ( NEActivationLayerKernel &&  )
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 602 of file NEActivationLayerKernel.cpp.

603 {
607  ARM_COMPUTE_ERROR_ON(_func == nullptr);
608 
609  (this->*_func)(window);
610 }
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 ActivationLayerInfo act_info 
)
static

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

Parameters
[in]inputSource tensor info. In case of output tensor info = nullptr, this tensor will store the result of the activation function. Data types supported: QASYMM8/QSYMM16/F16/F32.
[in]outputDestination tensor info. Data type supported: same as input
[in]act_infoActivation layer information.
Returns
a status

Definition at line 593 of file NEActivationLayerKernel.cpp.

594 {
596  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, act_info));
597  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), (output != nullptr) ? output->clone().get() : nullptr).first);
598 
599  return Status{};
600 }
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
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

References arm_compute::test::validation::act_info, ARM_COMPUTE_RETURN_ON_ERROR, ARM_COMPUTE_UNUSED, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by NEActivationLayer::validate(), NERNNLayer::validate(), and NELSTMLayer::validate().


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