Skip to content

[cadence][hifi] update quantized_relu_per_tensor_out signature to match internal flow #8143

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
merged 1 commit into from
Feb 5, 2025
Merged
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
56 changes: 41 additions & 15 deletions backends/cadence/hifi/operators/op_quantized_relu_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,27 @@ void quantized_relu_(
void quantized_relu_per_tensor_out(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not the operator called by ET? If so, please move this inside an anonymous namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realized most of hifi ops are not in anonymous namespace yet. Will do separately

KernelRuntimeContext& ctx,
const Tensor& input,
const Tensor& in_zero_point,
const int64_t in_zero_point,
const int64_t out_zero_point,
const Tensor& out_multiplier,
const Tensor& out_shift,
const int64_t out_multiplier,
const int64_t out_shift,
Tensor& output) {
const uint8_t _in_zero_point = static_cast<uint8_t>(in_zero_point);
const uint8_t _out_zero_point = static_cast<uint8_t>(out_zero_point);
const int32_t _out_multiplier = static_cast<int32_t>(out_multiplier);
const int32_t _out_shift = static_cast<int32_t>(out_shift);
if (input.scalar_type() == executorch::aten::ScalarType::Byte) {
const uint8_t* p_in = input.const_data_ptr<uint8_t>();
uint8_t* p_out = output.mutable_data_ptr<uint8_t>();
uint8_t q_zero_point = in_zero_point.const_data_ptr<uint8_t>()[0];

WORD32 ret_val = xa_nn_vec_relu_asym8u_asym8u(
p_out,
p_in,
(int)q_zero_point,
out_multiplier.const_data_ptr<int32_t>()[0],
out_shift.const_data_ptr<int32_t>()[0],
(int)out_zero_point,
(int)out_zero_point,
_in_zero_point,
_out_multiplier,
_out_shift,
_out_zero_point,
_out_zero_point,
255,
input.numel());

Expand All @@ -74,16 +77,15 @@ void quantized_relu_per_tensor_out(
} else if (input.scalar_type() == executorch::aten::ScalarType::Char) {
const int8_t* p_in = input.const_data_ptr<int8_t>();
int8_t* p_out = output.mutable_data_ptr<int8_t>();
int8_t q_zero_point = in_zero_point.const_data_ptr<int8_t>()[0];

WORD32 ret_val = xa_nn_vec_relu_asym8s_asym8s(
p_out,
p_in,
(int)q_zero_point,
out_multiplier.const_data_ptr<int32_t>()[0],
out_shift.const_data_ptr<int32_t>()[0],
(int)out_zero_point,
(int)out_zero_point,
_in_zero_point,
_out_multiplier,
_out_shift,
_out_zero_point,
_out_zero_point,
127,
input.numel());

Expand All @@ -97,6 +99,30 @@ void quantized_relu_per_tensor_out(
}
}

void quantized_relu_per_tensor_out(
KernelRuntimeContext& ctx,
const Tensor& input,
const Tensor& in_zero_point,
const int64_t out_zero_point,
const Tensor& out_multiplier,
const Tensor& out_shift,
Tensor& output) {
const uint8_t* p_in = input.const_data_ptr<uint8_t>();
uint8_t* p_out = output.mutable_data_ptr<uint8_t>();
uint8_t _in_zero_point = in_zero_point.const_data_ptr<uint8_t>()[0];
int32_t _out_multiplier = out_multiplier.const_data_ptr<int32_t>()[0];
int32_t _out_shift = out_shift.const_data_ptr<int32_t>()[0];

quantized_relu_per_tensor_out(
ctx,
input,
_in_zero_point,
out_zero_point,
_out_multiplier,
_out_shift,
output);
}

} // namespace native
} // namespace HiFi
} // namespace impl
Expand Down
Loading