Compute Library
 21.02
CpuSubKernel Class Reference

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

#include <CpuSubKernel.h>

Collaboration diagram for CpuSubKernel:
[legend]

Public Member Functions

 CpuSubKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuSubKernel)
 
void configure (const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ConvertPolicy policy)
 Initialise the kernel's src and dst. 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...
 
- 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...
 

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 of CpuSubKernel. More...
 

Detailed Description

Interface for the kernel to perform subtraction between two tensors.

Definition at line 37 of file CpuSubKernel.h.

Constructor & Destructor Documentation

◆ CpuSubKernel()

CpuSubKernel ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuSubKernel  )

◆ configure()

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

Initialise the kernel's src and dst.

Valid configurations (src0,src1) -> dst :

  • (U8,U8) -> U8
  • (U8,U8) -> S16
  • (QASYMM8, QASYMM8) -> QASYMM8
  • (QASYMM8_SIGNED, QASYMM8_SIGNED) -> QASYMM8_SIGNED
  • (S16,U8) -> S16
  • (U8,S16) -> S16
  • (S16,S16) -> S16
  • (S32,S32) -> S32
  • (F16,F16) -> F16
  • (F32,F32) -> F32
Parameters
[in]src0An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32
[in]src1An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32
[out]dstThe dst tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32.
[in]policyOverflow policy. Convert policy cannot be WRAP if datatype is quantized.

Definition at line 199 of file CpuSubKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ITensorInfo::broadcast_shape_and_valid_region(), arm_compute::calculate_max_window(), ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), arm_compute::set_shape_if_empty(), ITensorInfo::set_valid_region(), arm_compute::test::validation::valid_region, and arm_compute::validate_arguments().

200 {
201  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
202  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*src0, *src1, *dst, policy));
203 
204  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(*src0, *src1);
205  const TensorShape &out_shape = broadcast_pair.first;
206  const ValidRegion &valid_region = broadcast_pair.second;
207 
208  // Auto initialize dst if not initialized
209  set_shape_if_empty(*dst, out_shape);
210 
211  _policy = policy;
212 
213  // CpuSubKernel doesn't need padding so update_window_and_padding() can be skipped
214  Coordinates coord;
215  coord.set_num_dimensions(dst->num_dimensions());
216  dst->set_valid_region(valid_region);
217  Window win = calculate_max_window(valid_region, Steps());
218 
219  ICpuKernel::configure(win);
220 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
const ValidRegion valid_region
Definition: Scale.cpp:221
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &... infos)
If infos are broadcast compatible tensor info&#39;s, return the broadcasted shape and the intersection of...
Definition: ITensorInfo.h:271
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 245 of file CpuSubKernel.cpp.

246 {
247  return "CpuSubKernel";
248 }

◆ 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 230 of file CpuSubKernel.cpp.

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

231 {
235 
236  const ITensor *src0 = tensors.get_const_tensor(TensorType::ACL_SRC_0);
237  const ITensor *src1 = tensors.get_const_tensor(TensorType::ACL_SRC_1);
238  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
239 
240  // Dispatch kernel
241  const auto *uk = get_implementation(src0->info()->data_type(), src1->info()->data_type(), dst->info()->data_type());
242  uk->ukernel(src0, src1, dst, _policy, window);
243 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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

Valid configurations (src0,src1) -> dst :

  • (U8,U8) -> U8
  • (U8,U8) -> S16
  • (QASYMM8, QASYMM8) -> QASYMM8
  • (QASYMM8_SIGNED, QASYMM8_SIGNED) -> QASYMM8_SIGNED
  • (S16,U8) -> S16
  • (U8,S16) -> S16
  • (S16,S16) -> S16
  • (S32,S32) -> S32
  • (F16,F16) -> F16
  • (F32,F32) -> F32
Parameters
[in]src0An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32
[in]src1An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32
[in]dstThe dst tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/QSYMM16/S16/S32/F16/F32.
[in]policyPolicy to use to handle overflow. Convert policy cannot be WRAP if datatype is quantized.
Returns
a status

Definition at line 222 of file CpuSubKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by CpuSub::validate().

223 {
225  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*src0, *src1, *dst, policy));
226 
227  return Status{};
228 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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