Compute Library
 21.02
CpuLogits1DSoftmaxKernel< IS_LOG > Class Template Reference

Interface for softmax computation for QASYMM8 with pre-computed max. More...

#include <CpuSoftmaxKernel.h>

Collaboration diagram for CpuLogits1DSoftmaxKernel< IS_LOG >:
[legend]

Public Member Functions

 CpuLogits1DSoftmaxKernel ()
 Default constructor. More...
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuLogits1DSoftmaxKernel)
 
void configure (const ITensorInfo *src, const ITensorInfo *max, ITensorInfo *dst, const float beta, ITensorInfo *tmp)
 Set the input and output tensors. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- 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 *src, const ITensorInfo *max, const ITensorInfo *dst, const float beta, const ITensorInfo *tmp)
 Static function to check if given info will lead to a valid configuration of CpuLogits1DSoftmaxKernel. More...
 

Detailed Description

template<bool IS_LOG = false>
class arm_compute::cpu::kernels::CpuLogits1DSoftmaxKernel< IS_LOG >

Interface for softmax computation for QASYMM8 with pre-computed max.

Definition at line 65 of file CpuSoftmaxKernel.h.

Constructor & Destructor Documentation

◆ CpuLogits1DSoftmaxKernel()

Default constructor.

Definition at line 306 of file CpuSoftmaxKernel.cpp.

307  : _beta(1.0f)
308 {
309 }

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuLogits1DSoftmaxKernel< IS_LOG >  )

◆ configure()

void configure ( const ITensorInfo src,
const ITensorInfo max,
ITensorInfo dst,
const float  beta,
ITensorInfo tmp 
)

Set the input and output tensors.

Parameters
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]maxMax values tensor info. Same shape as input with dimension 0 set to 1. Data types supported: same as input.
[out]dstDestination tensor info. Data types supported: same as input.
[in]betaA scaling factor for the exponent.
tmpAuxiliary tensor info. Must be type F32 and same shape as the input.

Definition at line 312 of file CpuSoftmaxKernel.cpp.

References 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::F32, arm_compute::get_softmax_output_quantization_info(), arm_compute::is_data_type_quantized_asymmetric(), ITensorInfo::num_dimensions(), ITensorInfo::quantization_info(), ITensorInfo::reset_padding(), TensorInfo::set_data_type(), Dimensions< T >::set_num_dimensions(), TensorInfo::set_quantization_info(), ITensorInfo::set_valid_region(), and ITensorInfo::tensor_shape().

313 {
316  // Perform validation step
317  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_logits_softmax(*src, *max, *dst, beta, *tmp, IS_LOG));
318 
319  _beta = beta;
320 
321  // Configure kernel window
322  const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(src->data_type());
323 
324  // Output auto initialization if not yet initialized
325  const QuantizationInfo output_quantization = is_quantized_asymmetric ? arm_compute::get_softmax_output_quantization_info(src->data_type(), IS_LOG) : dst->quantization_info();
326  auto_init_if_empty(*dst, TensorInfo(*src).set_quantization_info(output_quantization).reset_padding());
327 
328  // Tmp auto initialization if not yet initialized
329  const DataType tmp_data_type = is_quantized_asymmetric ? DataType::F32 : src->data_type();
330  auto_init_if_empty(*tmp, TensorInfo(*src).set_data_type(tmp_data_type).reset_padding());
331 
332  // Configure kernel window
333  Window win = calculate_max_window(*max, Steps());
334  Coordinates coord;
335  coord.set_num_dimensions(dst->num_dimensions());
336  dst->set_valid_region(ValidRegion(coord, dst->tensor_shape()));
337 
338  ICpuKernel::configure(win);
339 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
1 channel, 1 F32 per channel
QuantizationInfo get_softmax_output_quantization_info(DataType input_type, bool is_log)
Returns output quantization information for softmax layer.
Definition: Utils.cpp:462
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
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...
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1190
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
DataType
Available data types.
Definition: Types.h:77

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 375 of file CpuSoftmaxKernel.cpp.

376 {
377  if(IS_LOG)
378  {
379  return "CpuLogits1DSoftmaxKernel";
380  }
381  else
382  {
383  return "CpuLogits1DLogSoftmaxKernel";
384  }
385 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 352 of file CpuSoftmaxKernel.cpp.

References arm_compute::ACL_DST_0, arm_compute::ACL_DST_1, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), num_elems_processed_per_iteration, ThreadInfo::num_threads, arm_compute::test::validation::src, ThreadInfo::thread_id, and IKernel::window().

353 {
357 
358  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC_0);
359  auto max = tensors.get_tensor(TensorType::ACL_SRC_1);
360  auto dst = tensors.get_tensor(TensorType::ACL_DST_0);
361  auto tmp = tensors.get_tensor(TensorType::ACL_DST_1);
362 
363  const unsigned int num_elems_processed_per_iteration = src->info()->valid_region().shape.x();
364  const unsigned int tmp_size_for_thread = tmp->info()->element_size() * num_elems_processed_per_iteration;
365 
366  ARM_COMPUTE_ERROR_ON(tmp->info()->total_size() < (info.num_threads * tmp_size_for_thread));
367 
368  void *tmp_for_thread = tmp->buffer() + (info.thread_id * tmp_size_for_thread);
369 
370  const auto *uk = get_implementation_logits(SoftmaxSelectorData{ src->info()->data_type() });
371  uk->ukernel(src, max, tmp_for_thread, dst, _beta, IS_LOG, window);
372 }
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
SimpleTensor< float > src
Definition: DFT.cpp:155
#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)
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo max,
const ITensorInfo dst,
const float  beta,
const ITensorInfo tmp 
)
static

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

Parameters
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]maxMax values tensor info. Same shape as input with dimension 0 set to 1. Data types supported: same as input.
[in]dstDestination tensor info. Data types supported: same as input.
[in]betaA scaling factor for the exponent.
[in]tmpTensor info of auxiliary. Must be type F32 and same shape as the input.
Returns
a status

Definition at line 342 of file CpuSoftmaxKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.

344 {
346  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_logits_softmax(*src, *max, *dst, beta, *tmp, IS_LOG));
347 
348  return Status{};
349 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

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