Compute Library
 23.08
CpuAddKernel Class Reference

Interface for the kernel to perform addition between two tensors. More...

#include <CpuAddKernel.h>

Collaboration diagram for CpuAddKernel:
[legend]

Data Structures

struct  AddKernel
 

Public Member Functions

 CpuAddKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuAddKernel)
 
void configure (const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ConvertPolicy policy)
 Initialise the kernel's input, dst and border mode. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
size_t get_mws (const CPUInfo &platform, size_t thread_count) const override
 Return minimum workload size of the relevant kernel. More...
 
size_t get_split_dimension () const
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. 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 *src0, const ITensorInfo *src1, const ITensorInfo *dst, ConvertPolicy policy)
 Static function to check if given info will lead to a valid configuration. More...
 
static const std::vector< AddKernel > & get_available_kernels ()
 
- Static Public Member Functions inherited from ICpuKernel< CpuAddKernel >
static const auto * get_implementation (const SelectorType &selector, KernelSelectionType selection_type=KernelSelectionType::Supported)
 Micro-kernel selector. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ICPPKernel
static constexpr size_t default_mws = 1
 

Detailed Description

Interface for the kernel to perform addition between two tensors.

Definition at line 37 of file CpuAddKernel.h.

Constructor & Destructor Documentation

◆ CpuAddKernel()

CpuAddKernel ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuAddKernel  )

◆ configure()

void configure ( const ITensorInfo src0,
const ITensorInfo src1,
ITensorInfo dst,
ConvertPolicy  policy 
)

Initialise the kernel's input, dst and border mode.

Valid configurations (src0,src1) -> dst :

  • (U8,U8) -> U8
  • (S16,S16) -> S16
  • (S32,S32) -> S32
  • (F16,F16) -> F16
  • (F32,F32) -> F32
  • (QASYMM8,QASYMM8) -> QASYMM8
  • (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
  • (QSYMM16,QSYMM16) -> QSYMM16
Parameters
[in]src0First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/S32/F32
[in]src1Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/S32/F32
[out]dstThe dst tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/S32/F32.
[in]policyOverflow policy.

Definition at line 213 of file CpuAddKernel.cpp.

214 {
215  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
216  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*src0, *src1, *dst, policy));
217 
218  const auto can_use_fixedpoint = add_q8_neon_fixedpoint_possible(src0, src1, dst);
219  const auto uk = CpuAddKernel::get_implementation<CpuAddKernelDataTypeISASelectorData>(CpuAddKernelDataTypeISASelectorData{ src0->data_type(),
220  CPUInfo::get().get_isa(), can_use_fixedpoint });
221 
223 
224  _policy = policy;
225  _run_method = uk->ukernel;
226  _name = std::string("CpuAddKernel").append("/").append(uk->name);
227 
228  // Auto initialize dst if not initialized
229  const TensorShape &out_shape = TensorShape::broadcast_shape(src0->tensor_shape(), src1->tensor_shape());
230  set_shape_if_empty(*dst, out_shape);
231  set_data_type_if_unknown(*dst, src0->data_type());
232 
233  // Configure kernel window
234  Window win;
235  std::tie(win, _split_dimension) = calculate_squashed_or_max_window(*src0, *src1);
236 
237  ICpuKernel::configure(win);
238 }

References arm_compute::cpu::add_q8_neon_fixedpoint_possible(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, TensorShape::broadcast_shape(), arm_compute::calculate_squashed_or_max_window(), ITensorInfo::data_type(), arm_compute::test::validation::dst, CPUInfo::get(), arm_compute::set_data_type_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), and arm_compute::cpu::kernels::validate_arguments().

◆ get_available_kernels()

const std::vector< CpuAddKernel::AddKernel > & get_available_kernels ( )
static

Definition at line 270 of file CpuAddKernel.cpp.

271 {
272  return available_kernels;
273 }

◆ get_mws()

size_t get_mws ( const CPUInfo platform,
size_t  thread_count 
) const
overridevirtual

Return minimum workload size of the relevant kernel.

Parameters
[in]platformThe CPU platform used to create the context.
[in]thread_countNumber of threads in the execution.
Returns
[out] mws Minimum workload size for requested configuration.

Reimplemented from ICPPKernel.

Definition at line 275 of file CpuAddKernel.cpp.

276 {
277  ARM_COMPUTE_UNUSED(thread_count);
278 
279 #if defined(ENABLE_FP32_KERNELS)
280  if(this->_run_method == &add_fp32_neon)
281  {
282  size_t mws = ICPPKernel::default_mws;
283  if(platform.get_cpu_model() == CPUModel::N1)
284  {
285  mws = default_mws_N1_fp32_neon;
286  }
287  else if(platform.get_cpu_model() == CPUModel::V1)
288  {
289  mws = default_mws_V1_fp32_neon;
290  }
291  else
292  {
294  }
295 
296  // tensor is 1D or was re-interpreted as 1D
297  if(this->window().shape().num_dimensions() == 1)
298  {
299  return mws;
300  }
301  else
302  {
303  // scale mws down by the number of elements along all the dimensions (x, z, w, etc) except the one
304  // that we parallelize along (the y dimension). This allows for parallelization when the Y_SIZE is small
305  // but the other sizes are large, which boosts performance.
306  mws = static_cast<size_t>(mws / (this->window().num_iterations_total() / this->window().num_iterations(1)));
307  return std::max(static_cast<size_t>(1), mws);
308  }
309  }
310 #else /* ENABLE_FP32_KERNELS */
311  ARM_COMPUTE_UNUSED(platform);
312 #endif /* ENABLE_FP32_KERNELS */
314 }

References arm_compute::cpu::add_fp32_neon(), ARM_COMPUTE_UNUSED, ICPPKernel::default_mws, CPUInfo::get_cpu_model(), arm_compute::N1, Window::num_iterations(), Window::num_iterations_total(), arm_compute::test::validation::shape, arm_compute::V1, and IKernel::window().

◆ get_split_dimension()

size_t get_split_dimension ( ) const
inline

Definition at line 94 of file CpuAddKernel.h.

95  {
96  return _split_dimension;
97  }

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 265 of file CpuAddKernel.cpp.

266 {
267  return _name.c_str();
268 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 249 of file CpuAddKernel.cpp.

250 {
254 
255  ARM_COMPUTE_ERROR_ON(tensors.empty());
256  ARM_COMPUTE_ERROR_ON(_run_method == nullptr);
257 
258  const ITensor *src0 = tensors.get_const_tensor(TensorType::ACL_SRC_0);
259  const ITensor *src1 = tensors.get_const_tensor(TensorType::ACL_SRC_1);
260  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
261 
262  _run_method(src0, src1, dst, _policy, window);
263 }

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::empty(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo src0,
const ITensorInfo src1,
const ITensorInfo dst,
ConvertPolicy  policy 
)
static

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

Similar to CpuAddKernel::configure()

Returns
a status

Definition at line 240 of file CpuAddKernel.cpp.

241 {
243 
244  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*src0, *src1, *dst, policy));
245 
246  return Status{};
247 }

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::dst, and arm_compute::cpu::kernels::validate_arguments().

Referenced by CpuAdd::validate().


The documentation for this class was generated from the following files:
arm_compute::CPUModel::N1
@ N1
arm_compute::cpu::add_fp32_neon
void add_fp32_neon(const ITensor *src0, const ITensor *src1, ITensor *dst, const ConvertPolicy &policy, const Window &window)
Definition: fp32.cpp:31
arm_compute::CPUModel::V1
@ V1
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::set_data_type_if_unknown
bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type)
Set the data type and number of channels to the specified value if the current data type is unknown.
Definition: AutoConfiguration.h:132
arm_compute::cpu::kernels::validate_arguments
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Definition: CpuDirectConv2dKernel.cpp:60
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1004
arm_compute::CPUInfo::get
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:40
arm_compute::Window::num_iterations
constexpr size_t num_iterations(size_t dimension) const
Return the number of iterations needed to iterate through a given dimension.
Definition: Window.inl:182
arm_compute::ACL_SRC_0
@ ACL_SRC_0
Definition: Types.h:45
arm_compute::ACL_SRC_1
@ ACL_SRC_1
Definition: Types.h:46
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:456
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::TensorShape::broadcast_shape
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
Definition: TensorShape.h:215
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
arm_compute::set_shape_if_empty
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
Definition: AutoConfiguration.h:94
arm_compute::calculate_squashed_or_max_window
std::pair< Window, size_t > calculate_squashed_or_max_window(const ITensorInfo &src0, const ITensorInfo &src1)
Definition: WindowHelpers.cpp:235
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
arm_compute::Window::num_iterations_total
size_t num_iterations_total() const
Return the total number of iterations needed to iterate through the entire window.
Definition: Window.inl:294
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::ICPPKernel::default_mws
static constexpr size_t default_mws
Definition: ICPPKernel.h:41
arm_compute::cpu::add_q8_neon_fixedpoint_possible
bool add_q8_neon_fixedpoint_possible(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Definition: impl.cpp:138
arm_compute::CPUInfo::get_cpu_model
CPUModel get_cpu_model(unsigned int cpuid) const
Gets the cpu model for a given cpuid.
Definition: CPPTypes.cpp:119