Compute Library
 22.11
CpuMaxUnpoolingLayerKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2022 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
30 #include "src/core/CPP/Validate.h"
36 
37 namespace arm_compute
38 {
39 namespace cpu
40 {
41 namespace kernels
42 {
43 using namespace misc::shape_calculator;
44 
45 namespace
46 {
47 static const std::vector<CpuMaxUnpoolingLayerKernel::MaxUnpoolingKernel> available_kernels =
48 {
49  {
50  "neon_fp32_maxunpooling",
51  [](const DataTypeISASelectorData & data) { return data.dt == DataType::F32; },
53  },
54  {
55  "neon_fp16_maxunpooling",
56  [](const DataTypeISASelectorData & data) { return data.dt == DataType::F16 && data.isa.fp16; },
58  },
59  {
60  "neon_qu8_maxunpooling",
61  [](const DataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8; },
63  },
64  {
65  "neon_qs8_maxunpooling",
66  [](const DataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8_SIGNED; },
68  },
69 };
70 
71 Status validate_arguments(const ITensorInfo *src, const ITensorInfo *indices, const ITensorInfo *dst, const PoolingLayerInfo &pool_info)
72 {
73  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, indices, dst);
78 
79  int pool_stride_x = 0;
80  int pool_stride_y = 0;
81  PoolingType pool_type = pool_info.pool_type;
82  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
83  std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride();
84  const int pool_size_x = pool_info.pool_size.width;
85  const int pool_size_y = pool_info.pool_size.height;
86  const Size2D pool_size(pool_size_x, pool_size_y);
87 
88  ARM_COMPUTE_RETURN_ERROR_ON_MSG(pool_type != PoolingType::MAX, "Pooling indices only supported for MAX pooling method");
89  ARM_COMPUTE_RETURN_ERROR_ON_MSG((pool_size != Size2D(2, 2)), "Pooling indices only supported for pool size 2x2");
90  if(dst->total_size() != 0)
91  {
94  }
95 
96  return Status{};
97 }
98 } // namespace
99 
100 void CpuMaxUnpoolingLayerKernel::configure(const ITensorInfo *src, const ITensorInfo *indices, ITensorInfo *dst, const PoolingLayerInfo &pool_info)
101 {
102  ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst, indices);
103  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, indices, dst, pool_info));
104  ARM_COMPUTE_UNUSED(indices);
105 
108  _run_method = uk->ukernel;
109 
110  const TensorShape output_shape = compute_unpool_shape(*src, pool_info);
111  auto_init_if_empty(*dst, src->clone()->set_tensor_shape(output_shape));
112 
113  auto window = calculate_max_window(*src, Steps());
114  ICpuKernel::configure(window);
115 }
116 
117 Status CpuMaxUnpoolingLayerKernel::validate(const ITensorInfo *src, const ITensorInfo *indices, const ITensorInfo *dst, const PoolingLayerInfo &pool_info)
118 {
119  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, indices, dst);
120  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, indices, dst, pool_info));
121  return Status{};
122 }
123 
125 {
126  ARM_COMPUTE_UNUSED(info);
129 
130  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC_0);
131  const auto indices = tensors.get_const_tensor(TensorType::ACL_SRC_1);
132  const auto dst = tensors.get_tensor(TensorType::ACL_DST);
133 
134  _run_method(src, indices, dst, window);
135 }
136 
138 {
139  return "CpuMaxUnpoolingLayerKernel";
140 }
141 
142 const std::vector<CpuMaxUnpoolingLayerKernel::MaxUnpoolingKernel> &CpuMaxUnpoolingLayerKernel::get_available_kernels()
143 {
144  return available_kernels;
145 }
146 } // namespace kernels
147 } // namespace cpu
148 } // namespace arm_compute
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void neon_qs8_maxunpooling(const ITensor *input, const ITensor *indices, ITensor *output, const Window &window)
Definition: qasymm8.cpp:29
Shape of a tensor.
Definition: TensorShape.h:39
static const std::vector< MaxUnpoolingKernel > & get_available_kernels()
static const auto * get_implementation(const SelectorType &selector, KernelSelectionType selection_type=KernelSelectionType::Supported)
Micro-kernel selector.
Definition: ICpuKernel.h:53
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
Definition: Validate.h:490
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:115
#define REGISTER_FP16_NEON(func_name)
Definition: Registrars.h:48
void neon_fp16_maxunpooling(const ITensor *input, const ITensor *indices, ITensor *output, const Window &window)
#define REGISTER_FP32_NEON(func_name)
Definition: Registrars.h:74
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define REGISTER_QASYMM8_SIGNED_NEON(func_name)
Definition: Registrars.h:96
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
const char * name() const override
Name of the kernel.
Status class.
Definition: Error.h:52
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2022 Arm Limited.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define REGISTER_QASYMM8_NEON(func_name)
Definition: Registrars.h:117
1 channel, 1 U32 per channel
TensorShape compute_unpool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output unpool shape of a tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
void configure(const ITensorInfo *src, const ITensorInfo *indices, ITensorInfo *dst, const PoolingLayerInfo &pool_info)
Configure kernel for a given list of arguments.
Pooling Layer Information struct.
Definition: Types.h:1200
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 std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
void neon_fp32_maxunpooling(const ITensor *input, const ITensor *indices, ITensor *output, const Window &window)
Definition: fp32.cpp:29
void neon_qu8_maxunpooling(const ITensor *input, const ITensor *indices, ITensor *output, const Window &window)
PoolingType
Available pooling types.
Definition: Types.h:557
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
Information about executing thread and CPU.
Definition: CPPTypes.h:179
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
static Status validate(const ITensorInfo *src, const ITensorInfo *indices, const ITensorInfo *dst, const PoolingLayerInfo &pool_info)
Static function to check if given info will lead to a valid configuration of CpuMaxUnpoolingLayerKern...
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
quantized, asymmetric fixed-point 8-bit number signed
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:40
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
cpuinfo::CpuIsaInfo get_isa() const
Gets the current cpu&#39;s ISA information.
Definition: CPPTypes.cpp:124