Compute Library
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 >:

Public Member Functions

 CpuLogits1DSoftmaxKernel ()=default
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...
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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. 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 70 of file CpuSoftmaxKernel.h.

Constructor & Destructor Documentation

◆ CpuLogits1DSoftmaxKernel()

Member Function Documentation



◆ configure()

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

Set the input and output tensors.

[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 304 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, CPUInfo::get(), arm_compute::get_softmax_output_quantization_info(), arm_compute::is_data_type_quantized_asymmetric(), kernel_name, ITensorInfo::quantization_info(), ITensorInfo::reset_padding(), TensorInfo::set_data_type(), and TensorInfo::set_quantization_info().

305 {
307  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_logits_softmax(*src, *max, *dst, beta, *tmp, IS_LOG));
309  // Configure kernel window
310  const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(src->data_type());
312  // Output auto initialization if not yet initialized
313  const QuantizationInfo output_quantization = is_quantized_asymmetric ? arm_compute::get_softmax_output_quantization_info(src->data_type(), IS_LOG) : dst->quantization_info();
314  auto_init_if_empty(*dst, TensorInfo(*src).set_quantization_info(output_quantization).reset_padding());
316  // Tmp auto initialization if not yet initialized
317  const DataType tmp_data_type = is_quantized_asymmetric ? DataType::F32 : src->data_type();
318  auto_init_if_empty(*tmp, TensorInfo(*src).set_data_type(tmp_data_type).reset_padding());
320  const auto *uk = get_implementation_logits(SoftmaxSelectorData{ src->data_type(), CPUInfo::get() });
323  std::string kernel_name = IS_LOG ? std::string("CpuLogits1DLogSoftmaxKernel") : std::string("CpuLogits1DSoftmaxKernel");
325  _beta = beta;
326  _run_method = uk->ukernel;
327  _name = kernel_name.append("/").append(uk->name);
329  // Configure kernel window
330  Window win = calculate_max_window(*max, Steps());
332  ICpuKernel::configure(win);
333 }
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:467
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:1003
Definition: Validate.h:157
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:39
std::string kernel_name
Available data types.
Definition: Types.h:77

◆ name()

const char * name ( ) const

Name of the kernel.

Kernel name

Implements ICPPKernel.

Definition at line 368 of file CpuSoftmaxKernel.cpp.

369 {
370  return _name.c_str();
371 }

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
const ThreadInfo info 

Execute the kernel on the passed window.

If is_parallelisable() returns false then the passed window must be equal to window()
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().
[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 346 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().

347 {
351  ARM_COMPUTE_ERROR_ON(_run_method == nullptr);
353  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC_0);
354  auto max = tensors.get_tensor(TensorType::ACL_SRC_1);
355  auto dst = tensors.get_tensor(TensorType::ACL_DST_0);
356  auto tmp = tensors.get_tensor(TensorType::ACL_DST_1);
358  const unsigned int num_elems_processed_per_iteration = src->info()->valid_region().shape.x();
359  const unsigned int tmp_size_for_thread = tmp->info()->element_size() * num_elems_processed_per_iteration;
361  ARM_COMPUTE_ERROR_ON(tmp->info()->total_size() < (info.num_threads * tmp_size_for_thread));
363  void *tmp_for_thread = tmp->buffer() + (info.thread_id * tmp_size_for_thread);
364  _run_method(src, max, tmp_for_thread, dst, _beta, IS_LOG, window);
365 }
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
To avoid unused variables warnings.
Definition: Error.h:152
unsigned int num_elems_processed_per_iteration
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Definition: Validate.h:201

◆ validate()

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.

Similar to CpuLogits1DSoftmaxKernel::configure()

a status

Definition at line 336 of file CpuSoftmaxKernel.cpp.


338 {
340  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_logits_softmax(*src, *max, *dst, beta, *tmp, IS_LOG));
342  return Status{};
343 }
Checks if a status contains an error and returns it.
Definition: Error.h:204
SimpleTensor< float > src
Definition: DFT.cpp:155
Definition: Validate.h:157

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