Compute Library
 21.11
CpuGemmLowpOutputStage.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 
29 #include "src/common/utils/Log.h"
34 
35 namespace arm_compute
36 {
37 namespace cpu
38 {
40 {
41  // Perform validate step
43  ARM_COMPUTE_LOG_PARAMS(src, bias, dst, info);
44 
45  switch(info.type)
46  {
48  {
49  switch(info.output_data_type)
50  {
51  case DataType::QASYMM8:
52  {
53  auto k = std::make_unique<kernels::CpuGemmLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel>();
54  k->configure(src, bias, dst, info.gemmlowp_multiplier, info.gemmlowp_shift, info.gemmlowp_offset, info.gemmlowp_min_bound, info.gemmlowp_max_bound);
55  _kernel = std::move(k);
56  break;
57  }
59  {
60  auto k = std::make_unique<kernels::CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel>();
61  k->configure(src, bias, dst, info.gemmlowp_multiplier, info.gemmlowp_shift, info.gemmlowp_offset, info.gemmlowp_min_bound, info.gemmlowp_max_bound);
62  _kernel = std::move(k);
63  break;
64  }
65  case DataType::QSYMM16:
66  {
67  auto k = std::make_unique<kernels::CpuGemmLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel>();
68  k->configure(src, bias, dst, info.gemmlowp_multiplier, info.gemmlowp_shift, info.gemmlowp_min_bound, info.gemmlowp_max_bound);
69  _kernel = std::move(k);
70  break;
71  }
72  default:
73  {
74  ARM_COMPUTE_ERROR("Unsupported output data type.");
75  break;
76  }
77  }
78  break;
79  }
81  {
82  switch(info.output_data_type)
83  {
84  case DataType::QASYMM8:
86  {
87  auto k = std::make_unique<kernels::CpuGemmLowpQuantizeDownInt32ScaleKernel>();
88  k->configure(src, bias, dst, &info);
89  _kernel = std::move(k);
90  break;
91  }
92  default:
93  {
94  ARM_COMPUTE_ERROR("Unsupported output data type.");
95  break;
96  }
97  }
98  break;
99  }
100  default:
101  ARM_COMPUTE_ERROR("Unsupported GEMMLowpOutputStage type.");
102  }
103 }
104 
106 {
108  ARM_COMPUTE_RETURN_ERROR_ON_MSG(dst->data_type() == DataType::UNKNOWN, "CpuGemmLowpOutputStage cannot be used with UNKNOWN output data type.");
111 
112  switch(info.type)
113  {
115  {
116  switch(dst->data_type())
117  {
118  case DataType::QASYMM8:
122  case DataType::QSYMM16:
124  default:
125  return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported output data type.");
126  }
127  }
129  {
130  switch(dst->data_type())
131  {
132  case DataType::QASYMM8:
135  default:
136  return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported output data type.");
137  }
138  }
139  default:
140  return ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported GEMMLowpOutputStage type.");
141  }
142 }
143 
145 {
146  NEScheduler::get().schedule_op(_kernel.get(), Window::DimY, _kernel->window(), tensors);
147 }
148 } // namespace cpu
149 } // namespace arm_compute
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, int min=0, int max=0)
Static function to check if given info will lead to a valid configuration.
void configure(ITensorInfo *src, ITensorInfo *bias, ITensorInfo *dst, const GEMMLowpOutputStageInfo &info)
Initialise the kernel&#39;s inputs, output.
int32_t gemmlowp_multiplier
GEMMLowp output stage multiplier used for quantizing to QASYMM8.
Definition: Types.h:1926
Quantize using a fixed point multiplication.
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual DataType data_type() const =0
Data type used for each element of the tensor.
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
int32_t gemmlowp_offset
GEMMLowp output stage offset used for quantizing to QASYMM8.
Definition: Types.h:1925
Status class.
Definition: Error.h:52
int32_t gemmlowp_max_bound
GEMMLowp max value used to saturate down the output result before converting back to QASYMM8...
Definition: Types.h:1929
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
GEMMLowpOutputStageType type
GEMMLowp output stage type.
Definition: Types.h:1924
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, int min=0, int max=0)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, const GEMMLowpOutputStageInfo &info)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, const GEMMLowpOutputStageInfo *output_stage)
Static function to check if given info will lead to a valid configuration.
quantized, asymmetric fixed-point 8-bit number unsigned
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
GEMMLowp output stage info.
Definition: Types.h:1922
Quantize using an integer multiplication.
int32_t gemmlowp_shift
GEMMLowp output stage shift used for quantizing to uint8.
Definition: Types.h:1927
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
Definition: Error.h:159
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
#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_LOG_PARAMS(...)
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, int min=0, int max=0)
Static function to check if given info will lead to a valid configuration.
quantized, asymmetric fixed-point 8-bit number signed
int32_t gemmlowp_min_bound
GEMMLowp min value used to saturate down the output result before converting back to QASYMM8...
Definition: Types.h:1928
DataType output_data_type
Output tensor data type to use if the output is not initialized.
Definition: Types.h:1934
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94