Compute Library
 21.02
CLGEMMLowpOutputStage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020 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 #include "arm_compute/core/Types.h"
31 
32 #include <algorithm>
33 
34 namespace arm_compute
35 {
37  int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift,
38  int min, int max)
39 {
40  configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
41 }
42 
44  int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift,
45  int min, int max)
46 {
48  info.gemmlowp_multiplier = result_fixedpoint_multiplier;
49  info.gemmlowp_shift = result_shift;
50  info.gemmlowp_offset = result_offset_after_shift;
51  info.gemmlowp_min_bound = min;
52  info.gemmlowp_max_bound = max;
53  info.output_data_type = DataType::QASYMM8;
54  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel>();
55  k->configure(compile_context, input, bias, output, &info);
56  _kernel = std::move(k);
57 }
58 
60  int min, int max)
61 {
63  info.gemmlowp_min_bound = min;
64  info.gemmlowp_max_bound = max;
65  info.output_data_type = DataType::QASYMM8;
67 }
68 
70  int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift,
71  int min, int max)
72 {
73  configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
74 }
75 
77  int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift,
78  int min, int max)
79 {
81  info.gemmlowp_multiplier = result_fixedpoint_multiplier;
82  info.gemmlowp_shift = result_shift;
83  info.gemmlowp_offset = result_offset_after_shift;
84  info.gemmlowp_min_bound = min;
85  info.gemmlowp_max_bound = max;
86  info.output_data_type = DataType::QASYMM8_SIGNED;
87  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel>();
88  k->configure(compile_context, input, bias, output, &info);
89  _kernel = std::move(k);
90 }
91 
93  int min, int max)
94 {
96  info.gemmlowp_min_bound = min;
97  info.gemmlowp_max_bound = max;
98  info.output_data_type = DataType::QASYMM8_SIGNED;
100 }
101 
103  int result_fixedpoint_multiplier, int result_shift,
104  int min, int max)
105 {
106  configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, result_fixedpoint_multiplier, result_shift, min, max);
107 }
108 
110  int result_fixedpoint_multiplier, int result_shift,
111  int min, int max)
112 {
114  info.gemmlowp_multiplier = result_fixedpoint_multiplier;
115  info.gemmlowp_shift = result_shift;
116  info.gemmlowp_min_bound = min;
117  info.gemmlowp_max_bound = max;
118  info.output_data_type = DataType::QSYMM16;
119  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel>();
120  k->configure(compile_context, input, bias, output, &info);
121  _kernel = std::move(k);
122 }
123 
125  int min, int max)
126 {
128  info.gemmlowp_min_bound = min;
129  info.gemmlowp_max_bound = max;
130  info.output_data_type = DataType::QSYMM16;
132 }
133 
135 {
136  configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, info);
137 }
138 
139 void CLGEMMLowpOutputStage::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
140 {
141  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
142 
143  switch(info.type)
144  {
146  {
147  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel>();
148  k->configure(compile_context, input, bias, output, &info);
149  _kernel = std::move(k);
150  break;
151  }
153  {
154  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleKernel>();
155  k->configure(compile_context, input, bias, output, &info);
156  _kernel = std::move(k);
157  break;
158  }
160  {
161  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFloatKernel>();
162  k->configure(compile_context, input, bias, output, &info);
163  _kernel = std::move(k);
164  break;
165  }
166  default:
167  ARM_COMPUTE_ERROR("Unsupported GEMMLowpOutputStage type.");
168  }
169 }
170 
172 {
175 
176  switch(info.type)
177  {
179  return CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel::validate(input, bias, output, &info);
181  return CLGEMMLowpQuantizeDownInt32ScaleKernel::validate(input, bias, output, &info);
183  return CLGEMMLowpQuantizeDownInt32ScaleByFloatKernel::validate(input, bias, output, &info);
184  default:
185  return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported GEMMLowpOutputStage type.");
186  }
187 }
188 } // namespace arm_compute
Quantize using a fixed point multiplication.
quantized, symmetric fixed-point 16-bit number
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Initialise the kernel&#39;s inputs, output.
void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const GEMMLowpOutputStageInfo &info)
Initialise the kernel&#39;s inputs, output.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
GEMMLowpOutputStageType type
GEMMLowp output stage type.
Definition: Types.h:1954
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo &info)
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *info)
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Initialise the kernel&#39;s inputs, output.
quantized, asymmetric fixed-point 8-bit number unsigned
GEMMLowp output stage info.
Definition: Types.h:1952
Quantize using a floating point multiplication.
Quantize using an integer multiplication.
CLCompileContext class.
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
Definition: Error.h:159
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:792
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *info)
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
quantized, asymmetric fixed-point 8-bit number signed
void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Initialise the kernel&#39;s inputs, output.