33 template <
bool IS_LOG>
34 struct NESoftmaxLayerGeneric<IS_LOG>::Impl
36 const ITensor *
src{
nullptr };
37 ITensor *
dst{
nullptr };
40 Tensor input_permuted{
nullptr };
41 Tensor output_permuted{
nullptr };
42 std::unique_ptr<cpu::CpuSoftmaxGeneric<IS_LOG>> op{
nullptr };
45 template <
bool IS_LOG>
47 : _memory_group(std::move(memory_manager)), _impl(std::make_unique<Impl>())
51 template <
bool IS_LOG>
53 template <
bool IS_LOG>
55 template <
bool IS_LOG>
58 template <
bool IS_LOG>
65 _impl->op = std::make_unique<cpu::CpuSoftmaxGeneric<IS_LOG>>();
66 _impl->op->configure(
input->info(), output->
info(), beta, axis);
68 const unsigned int actual_axis = static_cast<unsigned int>(
wrap_around(axis, static_cast<int32_t>(
input->info()->num_dimensions())));
69 const bool needs_permute = actual_axis > 0;
73 auto permute_input = std::make_unique<cpu::CpuPermute>();
74 _memory_group.manage(&_impl->input_permuted);
80 ITensor *tmp_input = (needs_permute ? &_impl->input_permuted :
input);
89 max_sum_shape.
set(0, 1);
90 _impl->max.allocator()->init(
input_info.clone()->set_tensor_shape(max_sum_shape));
91 _impl->tmp.allocator()->init(tensor_info_tmp);
94 _memory_group.manage(&_impl->max);
95 _memory_group.manage(&_impl->tmp);
98 auto max_kernel = std::make_unique<cpu::kernels::CpuLogits1DMaxKernel>();
99 auto softmax_kernel = std::make_unique<cpu::kernels::CpuLogits1DSoftmaxKernel<IS_LOG>>();
100 max_kernel->configure(tmp_input->
info(), _impl->max.info());
104 auto permute_output = std::make_unique<cpu::CpuPermute>();
106 _memory_group.manage(&_impl->output_permuted);
109 softmax_kernel->configure(tmp_input->
info(), _impl->max.info(), _impl->output_permuted.info(), beta, _impl->tmp.info());
110 _impl->input_permuted.allocator()->allocate();
116 _impl->output_permuted.allocator()->allocate();
120 softmax_kernel->configure(tmp_input->
info(), _impl->max.info(), output->
info(), beta, _impl->tmp.info());
124 _impl->max.allocator()->allocate();
125 _impl->tmp.allocator()->allocate();
128 template <
bool IS_LOG>
136 template <
bool IS_LOG>
147 _impl->op->run(pack);
~NESoftmaxLayerGeneric()
Default destructor.
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...
#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.
1 channel, 1 F32 per channel
Store the tensor's metadata.
Interface for CPU tensor.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
Basic function to compute a SoftmaxLayer and a Log SoftmaxLayer.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
void run() override
Run the kernels contained in the function.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(ITensor *input, ITensor *output, float beta=1.0f, int32_t axis=0)
Set the input and output tensors.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
NESoftmaxLayerGeneric & operator=(const NESoftmaxLayerGeneric &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
Memory group resources scope handling class.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, float beta=1.0f, int32_t axis=0)
Static function to check if given info will lead to a valid configuration of NESoftmaxLayer.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
DataType
Available data types.
NESoftmaxLayerGeneric(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
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.