38 template <
bool IS_LOG>
40 : _permute_input(), _permute_output(), _max_kernel(), _softmax_kernel(), _max(nullptr), _tmp(nullptr), _input_permuted(nullptr), _output_permuted(nullptr), _needs_permute(false)
44 template <
bool IS_LOG>
51 const unsigned int actual_axis =
static_cast<unsigned int>(
wrap_around(axis, static_cast<int32_t>(src->
num_dimensions())));
53 _needs_permute = actual_axis > 0;
57 _input_permuted = std::make_unique<TensorInfo>();
63 const ITensorInfo *tmp_input = (_needs_permute ? _input_permuted.get() :
src);
67 max_sum_shape.
set(0, 1);
70 TensorInfo tensor_info_tmp(input_info.
clone()->set_data_type(tmp_data_type));
71 TensorInfo max_info(tmp_input->
clone()->set_tensor_shape(max_sum_shape));
74 _max = std::make_unique<TensorInfo>(max_info);
75 _tmp = std::make_unique<TensorInfo>(tensor_info_tmp);
78 auto mk = std::make_unique<kernels::CpuLogits1DMaxKernel>();
79 mk->configure(tmp_input, _max.get());
80 _max_kernel = std::move(mk);
82 auto sm = std::make_unique<kernels::CpuLogits1DSoftmaxKernel<IS_LOG>>();
85 _output_permuted = std::make_unique<TensorInfo>();
88 sm->configure(tmp_input, _max.get(), _output_permuted.get(), beta, _tmp.get());
96 sm->configure(tmp_input, _max.get(),
dst, beta, _tmp.get());
98 _softmax_kernel = std::move(sm);
101 template <
bool IS_LOG>
112 const TensorInfo tensor_info_tmp(src->
clone()->set_data_type(tmp_data_type).set_is_resizable(
true));
115 max_sum_shape.
set(0, 1);
116 const TensorInfo tensor_info_max_sum(src->
clone()->set_tensor_shape(max_sum_shape).set_data_type(tmp_data_type).set_quantization_info(src->
quantization_info()).set_is_resizable(
true));
119 const unsigned int actual_axis =
static_cast<unsigned int>(
wrap_around(axis, static_cast<int32_t>(src->
num_dimensions())));
121 const bool needs_permute = actual_axis > 0;
127 TensorInfo input_permuted(src->
clone()->set_tensor_shape(permuted_shape));
129 TensorInfo output_permuted(dst->
clone()->set_tensor_shape(permuted_shape));
139 template <
bool IS_LOG>
152 _permute_input.
run(permute_in_pack);
180 _permute_output.
run(permute_out_pack);
184 template <
bool IS_LOG>
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of CpuLogits1DMaxKernel.
TensorShape compute_permutation_output_shape(const ITensorInfo &input, const PermutationVector &perm)
Calculate the permuted shape of an input given a permutation vector.
std::unique_ptr< ITensorInfo > clone() const override
Provide a clone of the current object of class T.
PermutationVector get_permutation_vector_from_softmax_axis(size_t axis)
Given a softmax axis, this function returns the permutation vector required to put the axis to the fr...
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, float beta=1.0f, int32_t axis=0)
Static function to check if given info will lead to a valid configuration of CpuSoftmax.
bool empty() const
Checks if pack is empty.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
1 channel, 1 F32 per channel
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Interface for softmax computation for QASYMM8 with pre-computed max.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
std::vector< MemoryInfo > MemoryRequirements
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void configure(const ITensorInfo *src, ITensorInfo *dst, float beta=1.0f, int32_t axis=0)
Set the input and output tensors.
CpuSoftmaxGeneric()
Constructor.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PermutationVector &perm)
Static function to check if given info will lead to a valid configuration of CpuPermute.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Strides of an item in bytes.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
experimental::MemoryRequirements workspace() const override
Return the memory requirements required by the workspace.
void configure(const ITensorInfo *src, ITensorInfo *dst, const PermutationVector &perm)
Configure operator for a given list of arguments.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
DataType
Available data types.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Basic function to compute a SoftmaxLayer and a Log SoftmaxLayer.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
static IScheduler & get()
Access the scheduler singleton.