Skip to content

Commit 918c6ab

Browse files
mcremon-metafacebook-github-bot
authored andcommitted
Fix missing things from OSS kernels updates
Summary: Add a few missing pieces from a previous change Differential Revision: D81863822
1 parent 2845fd3 commit 918c6ab

File tree

7 files changed

+64
-56
lines changed

7 files changed

+64
-56
lines changed

backends/cadence/hifi/operators/op_quantized_add_asym8sxasym8s_asym8s_per_tensor_out.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace native {
1616

1717
using ::executorch::aten::Tensor;
1818
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
20+
using ::impl::reference::kernels::quantize;
1921

2022
void quantized_add_asym8sxasym8s_asym8s_per_tensor_out(
2123
KernelRuntimeContext& ctx,
@@ -62,24 +64,24 @@ void quantized_add_asym8sxasym8s_asym8s_per_tensor_out(
6264
} /* if Y is a scalar Tensor */
6365
else if (Y_numel == 1) {
6466
float y =
65-
kernels::dequantize<int8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
67+
dequantize<int8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
6668
for (size_t i = 0; i < X_numel; ++i) {
6769
float x =
68-
kernels::dequantize<int8_t>(X_data[i], X_scale_f, X_zero_point_i32);
70+
dequantize<int8_t>(X_data[i], X_scale_f, X_zero_point_i32);
6971
float z = x + y;
7072
out_data[i] =
71-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
73+
quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
7274
}
7375
} /* if X is a scalar Tensor */
7476
else if (X_numel == 1) {
7577
float x =
76-
kernels::dequantize<int8_t>(X_data[0], X_scale_f, X_zero_point_i32);
78+
dequantize<int8_t>(X_data[0], X_scale_f, X_zero_point_i32);
7779
for (size_t i = 0; i < Y_numel; ++i) {
7880
float y =
79-
kernels::dequantize<int8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
81+
dequantize<int8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
8082
float z = x + y;
8183
out_data[i] =
82-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
84+
quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
8385
}
8486
} /* other broadcasting cases */
8587
else {
@@ -162,13 +164,13 @@ void quantized_add_asym8sxasym8s_asym8s_per_tensor_out(
162164
}
163165

164166
/* Apply the operation */
165-
float x = kernels::dequantize<int8_t>(
167+
float x = dequantize<int8_t>(
166168
X_data[X_idx], X_scale_f, X_zero_point_i32);
167-
float y = kernels::dequantize<int8_t>(
169+
float y = dequantize<int8_t>(
168170
Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
169171
float z = x + y;
170172
out_data[i] =
171-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
173+
quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
172174
}
173175
}
174176
}

backends/cadence/hifi/operators/op_quantized_add_asym8uxasym8u_asym8u_per_tensor_out.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace native {
1616

1717
using ::executorch::aten::Tensor;
1818
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
20+
using ::impl::reference::kernels::quantize;
1921

2022
void quantized_add_asym8uxasym8u_asym8u_per_tensor_out(
2123
KernelRuntimeContext& ctx,
@@ -62,24 +64,24 @@ void quantized_add_asym8uxasym8u_asym8u_per_tensor_out(
6264
} /* if Y is a scalar Tensor */
6365
else if (Y_numel == 1) {
6466
float y =
65-
kernels::dequantize<uint8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
67+
dequantize<uint8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
6668
for (size_t i = 0; i < X_numel; ++i) {
6769
float x =
68-
kernels::dequantize<uint8_t>(X_data[i], X_scale_f, X_zero_point_i32);
70+
dequantize<uint8_t>(X_data[i], X_scale_f, X_zero_point_i32);
6971
float z = x + y;
7072
out_data[i] =
71-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
73+
quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
7274
}
7375
} /* if X is a scalar Tensor */
7476
else if (X_numel == 1) {
7577
float x =
76-
kernels::dequantize<uint8_t>(X_data[0], X_scale_f, X_zero_point_i32);
78+
dequantize<uint8_t>(X_data[0], X_scale_f, X_zero_point_i32);
7779
for (size_t i = 0; i < Y_numel; ++i) {
7880
float y =
79-
kernels::dequantize<uint8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
81+
dequantize<uint8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
8082
float z = x + y;
8183
out_data[i] =
82-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
84+
quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
8385
}
8486
} /* other broadcasting cases */
8587
else {
@@ -162,13 +164,13 @@ void quantized_add_asym8uxasym8u_asym8u_per_tensor_out(
162164
}
163165

164166
/* Apply the operation */
165-
float x = kernels::dequantize<uint8_t>(
167+
float x = dequantize<uint8_t>(
166168
X_data[X_idx], X_scale_f, X_zero_point_i32);
167-
float y = kernels::dequantize<uint8_t>(
169+
float y = dequantize<uint8_t>(
168170
Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
169171
float z = x + y;
170172
out_data[i] =
171-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
173+
quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
172174
}
173175
}
174176
}

backends/cadence/hifi/operators/op_quantized_layer_norm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ using ::executorch::aten::ScalarType;
1818
using ::executorch::aten::Tensor;
1919
using ::executorch::runtime::getLeadingDims;
2020
using ::executorch::runtime::KernelRuntimeContext;
21+
using ::cadence::impl::HiFi::kernels::dequantize;
22+
using ::cadence::impl::HiFi::kernels::quantize;
2123

2224
namespace cadence {
2325
namespace impl {
@@ -80,11 +82,9 @@ void quantized_layer_norm_per_tensor_(
8082
for (size_t j = 0; j < last_dim; ++j) {
8183
// Since X is quantized, we dequantize it, compute fp32 result, and
8284
// quantize the result to an int8/uint8 value.
83-
float val = ::cadence::impl::HiFi::kernels::dequantize<T>(
84-
x[j], input_scale, input_zero_point);
85+
float val = dequantize<T>(x[j], input_scale, input_zero_point);
8586
val = (val - mean) * inv_std * weight_data[j] + bias_data[j];
86-
y[j] = ::cadence::impl::HiFi::kernels::quantize<T>(
87-
val, output_inv_scale, output_zero_point);
87+
y[j] = quantize<T>(val, output_inv_scale, output_zero_point);
8888
}
8989
}
9090
}

backends/cadence/reference/operators/dequantize_per_tensor.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ namespace impl {
1313
namespace reference {
1414
namespace native {
1515

16-
using executorch::aten::ScalarType;
17-
using executorch::aten::Tensor;
18-
using executorch::runtime::KernelRuntimeContext;
16+
using ::executorch::aten::ScalarType;
17+
using ::executorch::aten::Tensor;
18+
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
1920

2021
void dequantize_per_tensor_out(
2122
KernelRuntimeContext& context,
@@ -31,22 +32,18 @@ void dequantize_per_tensor_out(
3132

3233
if (input.scalar_type() == ScalarType::Byte) {
3334
const uint8_t* input_data = input.const_data_ptr<uint8_t>();
34-
impl::reference::kernels::dequantize<uint8_t>(
35-
out_data, input_data, scale, zero_point, numel);
35+
dequantize<uint8_t>(out_data, input_data, scale, zero_point, numel);
3636
} else if (input.scalar_type() == ScalarType::Char) {
3737
const int8_t* input_data = input.const_data_ptr<int8_t>();
38-
impl::reference::kernels::dequantize<int8_t>(
39-
out_data, input_data, scale, zero_point, numel);
38+
dequantize<int8_t>(out_data, input_data, scale, zero_point, numel);
4039
} else if (
4140
input.scalar_type() == ScalarType::Bits16 ||
4241
input.scalar_type() == ScalarType::UInt16) {
4342
const uint16_t* input_data = input.const_data_ptr<uint16_t>();
44-
impl::reference::kernels::dequantize<uint16_t>(
45-
out_data, input_data, scale, zero_point, numel);
43+
dequantize<uint16_t>(out_data, input_data, scale, zero_point, numel);
4644
} else if (input.scalar_type() == ScalarType::Short) {
4745
const int16_t* input_data = input.const_data_ptr<int16_t>();
48-
impl::reference::kernels::dequantize<int16_t>(
49-
out_data, input_data, scale, zero_point, numel);
46+
dequantize<int16_t>(out_data, input_data, scale, zero_point, numel);
5047
} else {
5148
ET_CHECK_MSG(
5249
false,

backends/cadence/reference/operators/op_requantize_out.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ namespace impl {
1313
namespace reference {
1414
namespace native {
1515

16-
using executorch::aten::ScalarType;
17-
using executorch::aten::Tensor;
18-
using executorch::runtime::KernelRuntimeContext;
16+
using ::executorch::aten::ScalarType;
17+
using ::executorch::aten::Tensor;
18+
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
20+
using ::impl::reference::kernels::quantize;
1921

2022
// Requantize the int8_t/uint8_t input tensor to a uint8_t/int8_t out tensor.
2123
// The scale and zero_point for requantization are in the args.
@@ -91,9 +93,9 @@ Tensor& requantize_out(
9193
dtype* out_data = out.mutable_data_ptr<dtype>(); \
9294
for (size_t i = 0; i < numel; ++i) { \
9395
float dequant = \
94-
kernels::dequantize<ctype>(input_data[i], in_scale, in_zero_point); \
96+
dequantize<ctype>(input_data[i], in_scale, in_zero_point); \
9597
out_data[i] = \
96-
kernels::quantize<dtype>(dequant, 1 / out_scale, out_zero_point); \
98+
quantize<dtype>(dequant, 1 / out_scale, out_zero_point); \
9799
};
98100

99101
#define typed_requantize_in(ctype) \
@@ -193,9 +195,9 @@ Tensor& requantize_per_tensor_out(
193195
dtype* out_data = out.mutable_data_ptr<dtype>(); \
194196
for (size_t i = 0; i < numel; ++i) { \
195197
float dequant = \
196-
kernels::dequantize<ctype>(input_data[i], in_scale, in_zero_point); \
198+
dequantize<ctype>(input_data[i], in_scale, in_zero_point); \
197199
out_data[i] = \
198-
kernels::quantize<dtype>(dequant, 1 / out_scale, out_zero_point); \
200+
quantize<dtype>(dequant, 1 / out_scale, out_zero_point); \
199201
};
200202

201203
#define typed_requantize_in(ctype) \

backends/cadence/reference/operators/quantized_add_out.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ namespace impl {
1414
namespace reference {
1515
namespace native {
1616

17-
using executorch::aten::Tensor;
18-
using executorch::runtime::KernelRuntimeContext;
17+
using ::executorch::aten::Tensor;
18+
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
20+
using ::impl::reference::kernels::quantize;
1921

2022
template <typename T>
2123
void quantized_add_per_tensor_impl(
@@ -48,28 +50,28 @@ void quantized_add_per_tensor_impl(
4850
// Simple case: tensors have the same shape, no broadcasting
4951
if (X_numel == Y_numel && Y_numel == out_numel) {
5052
for (size_t i = 0; i < X_numel; ++i) {
51-
float x = kernels::dequantize<T>(X_data[i], X_scale_f, X_zero_point_i32);
52-
float y = kernels::dequantize<T>(Y_data[i], Y_scale_f, Y_zero_point_i32);
53+
float x = dequantize<T>(X_data[i], X_scale_f, X_zero_point_i32);
54+
float y = dequantize<T>(Y_data[i], Y_scale_f, Y_zero_point_i32);
5355
float z = x + y;
54-
out_data[i] = kernels::quantize<T>(z, inv_out_scale, out_zero_point_i32);
56+
out_data[i] = quantize<T>(z, inv_out_scale, out_zero_point_i32);
5557
}
5658
}
5759
// Y is a scalar tensor
5860
else if (Y_numel == 1) {
59-
float y = kernels::dequantize<T>(Y_data[0], Y_scale_f, Y_zero_point_i32);
61+
float y = dequantize<T>(Y_data[0], Y_scale_f, Y_zero_point_i32);
6062
for (size_t i = 0; i < X_numel; ++i) {
61-
float x = kernels::dequantize<T>(X_data[i], X_scale_f, X_zero_point_i32);
63+
float x = dequantize<T>(X_data[i], X_scale_f, X_zero_point_i32);
6264
float z = x + y;
63-
out_data[i] = kernels::quantize<T>(z, inv_out_scale, out_zero_point_i32);
65+
out_data[i] = quantize<T>(z, inv_out_scale, out_zero_point_i32);
6466
}
6567
}
6668
// X is a scalar tensor
6769
else if (X_numel == 1) {
68-
float x = kernels::dequantize<T>(X_data[0], X_scale_f, X_zero_point_i32);
70+
float x = dequantize<T>(X_data[0], X_scale_f, X_zero_point_i32);
6971
for (size_t i = 0; i < Y_numel; ++i) {
70-
float y = kernels::dequantize<T>(Y_data[i], Y_scale_f, Y_zero_point_i32);
72+
float y = dequantize<T>(Y_data[i], Y_scale_f, Y_zero_point_i32);
7173
float z = x + y;
72-
out_data[i] = kernels::quantize<T>(z, inv_out_scale, out_zero_point_i32);
74+
out_data[i] = quantize<T>(z, inv_out_scale, out_zero_point_i32);
7375
}
7476
}
7577
// General broadcasting case - simplified implementation
@@ -80,11 +82,11 @@ void quantized_add_per_tensor_impl(
8082
size_t y_idx = (Y_numel == 1) ? 0 : i % Y_numel;
8183

8284
float x =
83-
kernels::dequantize<T>(X_data[x_idx], X_scale_f, X_zero_point_i32);
85+
dequantize<T>(X_data[x_idx], X_scale_f, X_zero_point_i32);
8486
float y =
85-
kernels::dequantize<T>(Y_data[y_idx], Y_scale_f, Y_zero_point_i32);
87+
dequantize<T>(Y_data[y_idx], Y_scale_f, Y_zero_point_i32);
8688
float z = x + y;
87-
out_data[i] = kernels::quantize<T>(z, inv_out_scale, out_zero_point_i32);
89+
out_data[i] = quantize<T>(z, inv_out_scale, out_zero_point_i32);
8890
}
8991
}
9092
}

backends/cadence/reference/operators/quantized_layer_norm.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ using ::executorch::aten::ScalarType;
1616
using ::executorch::aten::Tensor;
1717
using ::executorch::runtime::getLeadingDims;
1818
using ::executorch::runtime::KernelRuntimeContext;
19+
using ::impl::reference::kernels::dequantize;
20+
using ::impl::reference::kernels::quantize;
21+
1922

2023
namespace impl {
2124
namespace reference {
@@ -74,10 +77,10 @@ void quantized_layer_norm_per_tensor_(
7477
// y[j] = (x[j] - mean) / std * kGamma + kBeta;
7578
// Since X is quantized, we dequantize it, compute fp32 result, and
7679
// quantize the result to an int8/uint8 value.
77-
float val = kernels::dequantize<T>(x[j], input_scale, input_zero_point);
80+
float val = dequantize<T>(x[j], input_scale, input_zero_point);
7881

7982
val = (val - mean) * inv_std * weight_data[j] + bias_data[j];
80-
y[j] = kernels::quantize<T>(val, output_inv_scale, output_zero_point);
83+
y[j] = quantize<T>(val, output_inv_scale, output_zero_point);
8184
}
8285
}
8386
}

0 commit comments

Comments
 (0)