Compute Library
 21.05
ClPooling.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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 
27 
31 
32 namespace arm_compute
33 {
34 namespace opencl
35 {
37 {
39  // Configure pooling kernel
40  auto k = std::make_unique<kernels::ClPoolingKernel>();
41  k->set_target(CLScheduler::get().target());
42  k->configure(compile_context, src, dst, info, indices);
43  _pooling = std::move(k);
44 
45  const DataType data_type = src->data_type();
46 
47  // Configure border depending on operation required (quantize border in case of asymmetric data_type)
48  BorderMode border_mode{};
49  PixelValue pixel_value(0.f);
50  if(is_data_type_quantized_asymmetric(data_type) && !info.exclude_padding)
51  {
52  pixel_value = PixelValue(0, data_type, src->quantization_info());
53  }
54 
55  // Data layout
56  const auto data_layout = info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : info.data_layout;
57 
58  switch(data_layout)
59  {
60  case DataLayout::NCHW:
61  border_mode = (PoolingType::MAX == info.pool_type) ? BorderMode::REPLICATE : BorderMode::CONSTANT;
62  break;
63  case DataLayout::NHWC:
64  border_mode = BorderMode::CONSTANT;
65  if(PoolingType::MAX == info.pool_type)
66  {
68  {
69  std::tie(pixel_value, std::ignore) = get_min_max(data_type);
70  }
71  else
72  {
74  }
75  }
76  break;
77  default:
78  ARM_COMPUTE_ERROR("Data layout not supported");
79  }
80  auto b = std::make_unique<CLFillBorderKernel>();
81  b->configure(compile_context, src, _pooling->border_size(), border_mode, pixel_value);
82  _border_handler = std::move(b);
83 
84  // Tune kernels
86 }
87 
89 {
91 }
92 
94 {
95  ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No inputs provided");
96 
97  CLScheduler::get().enqueue_op(*_border_handler.get(), tensors, false);
98  CLScheduler::get().enqueue_op(*_pooling.get(), tensors, false);
99 }
100 } // namespace opencl
101 } // namespace arm_compute
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info, const ITensorInfo *indices=nullptr)
Static function to check if given info will lead to a valid configuration of ClPooling.
Definition: ClPooling.cpp:88
BorderMode
Methods available to handle borders.
Definition: Types.h:259
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:967
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: ClPooling.cpp:93
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
SimpleTensor< float > b
Definition: DFT.cpp:157
static CLScheduler & get()
Access the scheduler singleton.
bool empty() const
Checks if pack is empty.
Definition: ITensorPack.cpp:66
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
const DataLayout data_layout
Definition: Im2Col.cpp:151
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
const DataType data_type
Definition: Im2Col.cpp:150
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.
Pooling Layer Information struct.
Definition: Types.h:1142
Num samples, channels, height, width.
CLCompileContext class.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:989
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, ITensorInfo *indices=nullptr)
Configure operator for a given list of arguments.
Definition: ClPooling.cpp:36
Pixels outside the image are assumed to have the same value as the closest image pixel.
Num samples, height, width, channels.
Tensor packing service.
Definition: ITensorPack.h:37
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &pool_info, const ITensorInfo *indices=nullptr)
Static function to check if given info will lead to a valid configuration of ClPoolingKernel.
void tune_kernel_static(ICLKernel &kernel)
Tunes OpenCL kernel.
Definition: CLScheduler.cpp:82
DataLayout data_layout
Data layout to use.
DataType
Available data types.
Definition: Types.h:77
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
Definition: Utils.h:564