Compute Library
 21.08
CPPTopKVKernel Class Reference

CPP kernel to perform tensor TopKV operation. More...

#include <CPPTopKVKernel.h>

Collaboration diagram for CPPTopKVKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CPPTopKVKernel ()
 Default constructor. More...
 
 CPPTopKVKernel (const CPPTopKVKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CPPTopKVKerneloperator= (const CPPTopKVKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CPPTopKVKernel (CPPTopKVKernel &&)=default
 Allow instances of this class to be moved. More...
 
CPPTopKVKerneloperator= (CPPTopKVKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CPPTopKVKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *predictions, const ITensor *targets, ITensor *output, const unsigned int k)
 Set the input and output of the kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
bool is_parallelisable () const override
 Indicates whether or not the kernel is parallelisable. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. 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 *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. More...
 

Detailed Description

CPP kernel to perform tensor TopKV operation.

Definition at line 34 of file CPPTopKVKernel.h.

Constructor & Destructor Documentation

◆ CPPTopKVKernel() [1/3]

Default constructor.

Definition at line 94 of file CPPTopKVKernel.cpp.

Referenced by CPPTopKVKernel::name().

95  : _predictions(nullptr), _targets(nullptr), _output(nullptr), _k(), _batch_size(), _num_classes()
96 {
97 }

◆ CPPTopKVKernel() [2/3]

CPPTopKVKernel ( const CPPTopKVKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CPPTopKVKernel() [3/3]

CPPTopKVKernel ( CPPTopKVKernel &&  )
default

Allow instances of this class to be moved.

◆ ~CPPTopKVKernel()

~CPPTopKVKernel ( )
default

Default destructor.

Referenced by CPPTopKVKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor predictions,
const ITensor targets,
ITensor output,
const unsigned int  k 
)

Set the input and output of the kernel.

Parameters
[in]predictionsA batch_size x classes tensor. Data types supported: F16/S32/F32/QASYMM8/QASYMM8_SIGNED
[in]targetsA batch_size 1D tensor of class ids. Data types supported: U32
[out]outputComputed precision at k as a bool 1D tensor. Data types supported: U8
[in]kNumber of top elements to look at for computing precision.

Definition at line 99 of file CPPTopKVKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::dimension(), ITensor::info(), ITensorInfo::tensor_shape(), and arm_compute::U8.

Referenced by CPPTopKVKernel::name().

100 {
101  ARM_COMPUTE_ERROR_ON_NULLPTR(predictions, targets, output);
102 
103  // Perform validation step
104  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(predictions->info(), targets->info(), output->info(), k));
105  auto_init_if_empty(*output->info(), targets->info()->tensor_shape(), 1, DataType::U8);
106 
107  _predictions = predictions;
108  _targets = targets;
109  _output = output;
110 
111  _k = k;
112  _batch_size = predictions->info()->dimension(1);
113  _num_classes = predictions->info()->dimension(0);
114 
115  ICPPKernel::configure(Window()); // Default 1 iteration window
116 }
1 channel, 1 U8 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ is_parallelisable()

bool is_parallelisable ( ) const
overridevirtual

Indicates whether or not the kernel is parallelisable.

If the kernel is parallelisable then the window returned by window() can be split into sub-windows which can then be run in parallel.

If the kernel is not parallelisable then only the window returned by window() can be passed to run()

Returns
True if the kernel is parallelisable

Reimplemented from IKernel.

Definition at line 124 of file CPPTopKVKernel.cpp.

Referenced by CPPTopKVKernel::name().

125 {
126  return false;
127 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

CPPTopKVKernel& operator= ( const CPPTopKVKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by CPPTopKVKernel::name().

◆ operator=() [2/2]

CPPTopKVKernel& operator= ( CPPTopKVKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( 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]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 129 of file CPPTopKVKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_UNUSED, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, and arm_compute::S32.

Referenced by CPPTopKVKernel::name().

130 {
132  switch(_predictions->info()->data_type())
133  {
134  case DataType::F32:
135  run_topkv<float>();
136  break;
137  case DataType::F16:
138  run_topkv<half>();
139  break;
140  case DataType::S32:
141  run_topkv<int>();
142  break;
143  case DataType::QASYMM8:
144  run_topkv<uint8_t>();
145  break;
147  run_topkv<int8_t>();
148  break;
149  default:
150  ARM_COMPUTE_ERROR("Not supported");
151  }
152 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
quantized, asymmetric fixed-point 8-bit number unsigned
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
quantized, asymmetric fixed-point 8-bit number signed

◆ validate()

Status validate ( const ITensorInfo predictions,
const ITensorInfo targets,
ITensorInfo output,
const unsigned int  k 
)
static

Static function to check if given info will lead to a valid configuration of CPPTopKVKernel.

Parameters
[in]predictionsA batch_size x classes tensor info. Data types supported: F16/S32/F32/QASYMM8/QASYMM8_SIGNED
[in]targetsA batch_size 1D tensor info of class ids. Data types supported: U32
[in]outputComputed precision at k as a bool 1D tensor info. Data types supported: U8
[in]kNumber of top elements to look at for computing precision.
Returns
a status

Definition at line 118 of file CPPTopKVKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CPPTopKVKernel::name(), and CPPTopKV::validate().

119 {
120  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(predictions, targets, output, k));
121  return Status{};
122 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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