24.02.1
|
Go to the documentation of this file.
37 template <typename T, typename std::enable_if<utils::traits::is_floating_point<T>::value,
int>
::type = 0>
38 inline bool greater_than(T a, T
b)
44 template <typename T, typename std::enable_if<!utils::traits::is_floating_point<T>::value,
int>
::type = 0>
45 inline bool greater_than(T a, T
b)
51 const ITensorInfo *targets,
64 if (output->total_size() != 0)
75 void CPPTopKVKernel::run_topkv()
77 for (
unsigned int i = 0; i < _batch_size; ++i)
79 const auto target_class_id = *
reinterpret_cast<uint32_t *
>(_targets->
ptr_to_element(Coordinates{i}));
80 const auto predicted_value =
81 *
reinterpret_cast<T *
>(_predictions->
ptr_to_element(Coordinates{target_class_id, i}));
84 unsigned int rank = 0;
85 for (
unsigned int j = 0; (j < _num_classes) && (rank < _k); ++j)
87 const auto current_prediction = *
reinterpret_cast<T *
>(_predictions->
ptr_to_element(Coordinates{j, i}));
88 if (greater_than(current_prediction, predicted_value))
93 *(_output->
ptr_to_element(Coordinates{i})) =
static_cast<uint8_t
>(rank < _k);
98 : _predictions(nullptr), _targets(nullptr), _output(nullptr), _k(), _batch_size(), _num_classes()
105 const unsigned int k)
113 _predictions = predictions;
121 ICPPKernel::configure(
Window());
127 const unsigned int k)
153 run_topkv<uint8_t>();
decltype(strategy::transforms) typedef type
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Interface for CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
static Status validate(const ITensorInfo *predictions, const ITensorInfo *targets, ITensorInfo *output, const unsigned int k)
Static function to check if given info will lead to a valid configuration of CPPTopKVKernel.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
@ U32
unsigned 32-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
@ U8
unsigned 8-bit number
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
void configure(const ITensor *predictions, const ITensor *targets, ITensor *output, const unsigned int k)
Set the input and output of the kernel.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
bool is_parallelisable() const override
Indicates whether or not the kernel is parallelisable.
const Window & window() const
The maximum window the kernel can be executed on.
Information about executing thread and CPU.
Describe a multidimensional execution window.
CPPTopKVKernel()
Default constructor.
Copyright (c) 2017-2024 Arm Limited.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
@ F16
16-bit floating-point number
@ S32
signed 32-bit number
Store the tensor's metadata.
@ F32
32-bit floating-point number
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)