38 typename std::enable_if<utils::traits::is_floating_point<T>::value,
int>
::type = 0>
39 inline bool greater_than(T a, T
b)
42 return (a - b > epsilon);
45 template <
typename T,
46 typename std::enable_if < !utils::traits::is_floating_point<T>::value,
int >::type = 0 >
47 inline bool greater_than(T a, T b)
52 Status validate_arguments(
const ITensorInfo *predictions,
const ITensorInfo *targets, ITensorInfo *output,
const unsigned int k)
62 if(output->total_size() != 0)
73 void CPPTopKVKernel::run_topkv()
75 for(
unsigned int i = 0; i < _batch_size; ++i)
77 const auto target_class_id = *
reinterpret_cast<uint32_t *
>(_targets->
ptr_to_element(Coordinates{ i }));
78 const auto predicted_value = *
reinterpret_cast<T *
>(_predictions->
ptr_to_element(Coordinates{ target_class_id, i }));
81 unsigned int rank = 0;
82 for(
unsigned int j = 0; (j < _num_classes) && (rank < _k); ++j)
84 const auto current_prediction = *
reinterpret_cast<T *
>(_predictions->
ptr_to_element(Coordinates{ j, i }));
85 if(greater_than(current_prediction, predicted_value))
90 *(_output->
ptr_to_element(Coordinates{ i })) =
static_cast<uint8_t
>(rank < _k);
95 : _predictions(nullptr), _targets(nullptr), _output(nullptr), _k(), _batch_size(), _num_classes()
107 _predictions = predictions;
115 ICPPKernel::configure(
Window());
144 run_topkv<uint8_t>();
CPPTopKVKernel()
Default constructor.
const Window & window() const
The maximum window the kernel can be executed on.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
1 channel, 1 U8 per channel
#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.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
bool is_parallelisable() const override
Indicates whether or not the kernel is parallelisable.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
1 channel, 1 U32 per channel
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
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...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
void configure(const ITensor *predictions, const ITensor *targets, ITensor *output, const unsigned int k)
Set the input and output of the kernel.
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_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
quantized, asymmetric fixed-point 8-bit number signed
Describe a multidimensional execution window.