Compute Library
 21.08
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
 
 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...
 
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

◆ 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 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));
308 
309  // Configure kernel window
310  const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(src->data_type());
311 
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());
315 
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());
319 
320  const auto *uk = get_implementation_logits(SoftmaxSelectorData{ src->data_type(), CPUInfo::get() });
322 
323  std::string kernel_name = IS_LOG ? std::string("CpuLogits1DLogSoftmaxKernel") : std::string("CpuLogits1DSoftmaxKernel");
324 
325  _beta = beta;
326  _run_method = uk->ukernel;
327  _name = kernel_name.append("/").append(uk->name);
328 
329  // Configure kernel window
330  Window win = calculate_max_window(*max, Steps());
331 
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
#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:1003
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:39
std::string kernel_name
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 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 
)
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 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);
352 
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);
357 
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;
360 
361  ARM_COMPUTE_ERROR_ON(tmp->info()->total_size() < (info.num_threads * tmp_size_for_thread));
362 
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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

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

Similar to CpuLogits1DSoftmaxKernel::configure()

Returns
a status

Definition at line 336 of file CpuSoftmaxKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.

338 {
340  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_logits_softmax(*src, *max, *dst, beta, *tmp, IS_LOG));
341 
342  return Status{};
343 }
#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:157

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