Skip to content

[cadence] add reference quantized_fully_connected_out #9020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backends/cadence/aot/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,13 @@
kernels:
- arg_meta: null
kernel_name: impl::reference::quantized_conv_per_tensor_out

- func: cadence::quantized_fully_connected.out(Tensor src, Tensor weight, Tensor bias, int src_zero_point, Tensor weight_zero_point, Tensor out_multiplier, Tensor out_shift, int out_zero_point, Tensor? offset, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: impl::reference::quantized_fully_connected_out

- func: cadence::quantized_fully_connected.per_tensor_out(Tensor src, Tensor weight, Tensor bias, int src_zero_point, int weight_zero_point, int out_multiplier, int out_shift, int out_zero_point, Tensor? offset, *, Tensor(a!) out) -> Tensor(a!)
kernels:
- arg_meta: null
kernel_name: impl::reference::quantized_fully_connected_per_tensor_out
1 change: 1 addition & 0 deletions backends/cadence/reference/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ add_library(
"quantized_relu_out.cpp"
"quantized_layer_norm.cpp"
"quantize_per_tensor.cpp"
"quantized_fully_connected_out.cpp"
"dequantize_per_tensor.cpp"
"quantized_matmul_out.cpp"
"im2row_out.cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <executorch/backends/cadence/reference/kernels/kernels.h>
#include <executorch/backends/cadence/reference/operators/operators.h>
#include <executorch/backends/cadence/reference/operators/quantized_ops.h>

namespace impl {
namespace reference {
namespace native {

using ::executorch::aten::optional;
using ::executorch::aten::ScalarType;
using ::executorch::aten::Tensor;
using ::executorch::runtime::KernelRuntimeContext;

void quantized_fully_connected_out(
__ET_UNUSED KernelRuntimeContext& ctx,
const Tensor& in,
const Tensor& weight,
const Tensor& bias,
int64_t in_zero_point,
const Tensor& weight_zero_point_t,
const Tensor& out_multiplier,
const Tensor& out_shift,
int64_t out_zero_point,
__ET_UNUSED const optional<Tensor>& offset,
Tensor& out) {
#define typed_quantized_linear(ctype, dtype) \
case ScalarType::dtype: { \
quantized_linear_<ctype>( \
in, \
weight, \
bias, \
in_zero_point, \
weight_zero_point_t, \
out_multiplier, \
out_shift, \
out_zero_point, \
out); \
break; \
}

ScalarType dtype = out.scalar_type();
switch (dtype) {
ET_FORALL_CADENCE_QUANTIZED_TYPES(typed_quantized_linear);
default:
ET_DCHECK_MSG(
false, "Unhandled dtype %s", torch::executor::toString(dtype));
}
#undef typed_quantized_linear
}

void quantized_fully_connected_per_tensor_out(
__ET_UNUSED KernelRuntimeContext& ctx,
const Tensor& in,
const Tensor& weight,
const Tensor& bias,
int64_t in_zero_point,
int64_t weight_zero_point,
int64_t out_multiplier,
int64_t out_shift,
int64_t out_zero_point,
__ET_UNUSED const optional<Tensor>& offset,
Tensor& out) {
#define typed_quantized_linear(ctype, dtype) \
case ScalarType::dtype: { \
quantized_linear_per_tensor_<ctype>( \
in, \
weight, \
bias, \
in_zero_point, \
weight_zero_point, \
out_multiplier, \
out_shift, \
out_zero_point, \
out); \
break; \
}

ScalarType dtype = out.scalar_type();
switch (dtype) {
ET_FORALL_CADENCE_QUANTIZED_TYPES(typed_quantized_linear);
default:
ET_DCHECK_MSG(
false, "Unhandled dtype %s", torch::executor::toString(dtype));
}
#undef typed_quantized_linear
}

}; // namespace native
}; // namespace reference
}; // namespace impl
Loading