Compute Library
 19.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...
 
- 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...
 

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 96 of file CPPTopKVKernel.cpp.

97  : _predictions(nullptr), _targets(nullptr), _output(nullptr), _k(), _batch_size(), _num_classes()
98 {
99 }

◆ 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.

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
[in]targetsA batch_size 1D tensor of class ids. Data types supported: S32
[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 101 of file CPPTopKVKernel.cpp.

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

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.

◆ 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 126 of file CPPTopKVKernel.cpp.

127 {
128  return false;
129 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file CPPTopKVKernel.h.

38  {
39  return "CPPTopKVKernel";
40  }

◆ operator=() [1/2]

CPPTopKVKernel& operator= ( const CPPTopKVKernel )
delete

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

◆ 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.

Implements ICPPKernel.

Definition at line 131 of file CPPTopKVKernel.cpp.

132 {
134  switch(_predictions->info()->data_type())
135  {
136  case DataType::F32:
137  run_topkv<float>();
138  break;
139  case DataType::F16:
140  run_topkv<half>();
141  break;
142  case DataType::S32:
143  run_topkv<int>();
144  break;
145  case DataType::QASYMM8:
146  run_topkv<uint8_t>();
147  break;
148  default:
149  ARM_COMPUTE_ERROR("Not supported");
150  }
151 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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:160
quantized, asymmetric fixed-point 8-bit number
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_UNUSED, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::test::validation::info, arm_compute::QASYMM8, arm_compute::S32, and IKernel::window().

◆ 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
[in]targetsA batch_size 1D tensor info of class ids. Data types supported: S32
[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 120 of file CPPTopKVKernel.cpp.

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

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CPPTopKV::validate().


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