Skip to content

Commit 00b50b2

Browse files
authored
Fix missing things from OSS kernels updates
Differential Revision: D81863822 Pull Request resolved: pytorch#14067
1 parent 855c083 commit 00b50b2

7 files changed

+54
-70
lines changed

backends/cadence/hifi/operators/op_quantized_add_asym8sxasym8s_asym8s_per_tensor_out.cpp

Lines changed: 11 additions & 18 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,
@@ -61,25 +63,19 @@ void quantized_add_asym8sxasym8s_asym8s_per_tensor_out(
6163
}
6264
} /* if Y is a scalar Tensor */
6365
else if (Y_numel == 1) {
64-
float y =
65-
kernels::dequantize<int8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
66+
float y = dequantize<int8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
6667
for (size_t i = 0; i < X_numel; ++i) {
67-
float x =
68-
kernels::dequantize<int8_t>(X_data[i], X_scale_f, X_zero_point_i32);
68+
float x = dequantize<int8_t>(X_data[i], X_scale_f, X_zero_point_i32);
6969
float z = x + y;
70-
out_data[i] =
71-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
70+
out_data[i] = quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
7271
}
7372
} /* if X is a scalar Tensor */
7473
else if (X_numel == 1) {
75-
float x =
76-
kernels::dequantize<int8_t>(X_data[0], X_scale_f, X_zero_point_i32);
74+
float x = dequantize<int8_t>(X_data[0], X_scale_f, X_zero_point_i32);
7775
for (size_t i = 0; i < Y_numel; ++i) {
78-
float y =
79-
kernels::dequantize<int8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
76+
float y = dequantize<int8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
8077
float z = x + y;
81-
out_data[i] =
82-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
78+
out_data[i] = quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
8379
}
8480
} /* other broadcasting cases */
8581
else {
@@ -162,13 +158,10 @@ void quantized_add_asym8sxasym8s_asym8s_per_tensor_out(
162158
}
163159

164160
/* Apply the operation */
165-
float x = kernels::dequantize<int8_t>(
166-
X_data[X_idx], X_scale_f, X_zero_point_i32);
167-
float y = kernels::dequantize<int8_t>(
168-
Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
161+
float x = dequantize<int8_t>(X_data[X_idx], X_scale_f, X_zero_point_i32);
162+
float y = dequantize<int8_t>(Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
169163
float z = x + y;
170-
out_data[i] =
171-
kernels::quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
164+
out_data[i] = quantize<int8_t>(z, inv_out_scale, out_zero_point_i32);
172165
}
173166
}
174167
}

backends/cadence/hifi/operators/op_quantized_add_asym8uxasym8u_asym8u_per_tensor_out.cpp

Lines changed: 11 additions & 18 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,
@@ -61,25 +63,19 @@ void quantized_add_asym8uxasym8u_asym8u_per_tensor_out(
6163
}
6264
} /* if Y is a scalar Tensor */
6365
else if (Y_numel == 1) {
64-
float y =
65-
kernels::dequantize<uint8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
66+
float y = dequantize<uint8_t>(Y_data[0], Y_scale_f, Y_zero_point_i32);
6667
for (size_t i = 0; i < X_numel; ++i) {
67-
float x =
68-
kernels::dequantize<uint8_t>(X_data[i], X_scale_f, X_zero_point_i32);
68+
float x = dequantize<uint8_t>(X_data[i], X_scale_f, X_zero_point_i32);
6969
float z = x + y;
70-
out_data[i] =
71-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
70+
out_data[i] = quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
7271
}
7372
} /* if X is a scalar Tensor */
7473
else if (X_numel == 1) {
75-
float x =
76-
kernels::dequantize<uint8_t>(X_data[0], X_scale_f, X_zero_point_i32);
74+
float x = dequantize<uint8_t>(X_data[0], X_scale_f, X_zero_point_i32);
7775
for (size_t i = 0; i < Y_numel; ++i) {
78-
float y =
79-
kernels::dequantize<uint8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
76+
float y = dequantize<uint8_t>(Y_data[i], Y_scale_f, Y_zero_point_i32);
8077
float z = x + y;
81-
out_data[i] =
82-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
78+
out_data[i] = quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
8379
}
8480
} /* other broadcasting cases */
8581
else {
@@ -162,13 +158,10 @@ void quantized_add_asym8uxasym8u_asym8u_per_tensor_out(
162158
}
163159

164160
/* Apply the operation */
165-
float x = kernels::dequantize<uint8_t>(
166-
X_data[X_idx], X_scale_f, X_zero_point_i32);
167-
float y = kernels::dequantize<uint8_t>(
168-
Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
161+
float x = dequantize<uint8_t>(X_data[X_idx], X_scale_f, X_zero_point_i32);
162+
float y = dequantize<uint8_t>(Y_data[Y_idx], Y_scale_f, Y_zero_point_i32);
169163
float z = x + y;
170-
out_data[i] =
171-
kernels::quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
164+
out_data[i] = quantize<uint8_t>(z, inv_out_scale, out_zero_point_i32);
172165
}
173166
}
174167
}

backends/cadence/hifi/operators/op_quantized_layer_norm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <cmath>
1414
#include <tuple>
1515

16+
using ::cadence::impl::HiFi::kernels::dequantize;
17+
using ::cadence::impl::HiFi::kernels::quantize;
1618
using ::executorch::aten::IntArrayRef;
1719
using ::executorch::aten::ScalarType;
1820
using ::executorch::aten::Tensor;
@@ -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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Tensor& requantize_out(
9595
out_data[i] = \
9696
kernels::quantize<dtype>(dequant, 1 / out_scale, out_zero_point); \
9797
};
98-
9998
#define typed_requantize_in(ctype) \
10099
switch (out_dtype) { \
101100
case ScalarType::Byte: { \

backends/cadence/reference/operators/quantized_add_out.cpp

Lines changed: 16 additions & 16 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
@@ -79,12 +81,10 @@ void quantized_add_per_tensor_impl(
7981
size_t x_idx = (X_numel == 1) ? 0 : i % X_numel;
8082
size_t y_idx = (Y_numel == 1) ? 0 : i % Y_numel;
8183

82-
float x =
83-
kernels::dequantize<T>(X_data[x_idx], X_scale_f, X_zero_point_i32);
84-
float y =
85-
kernels::dequantize<T>(Y_data[y_idx], Y_scale_f, Y_zero_point_i32);
84+
float x = dequantize<T>(X_data[x_idx], X_scale_f, X_zero_point_i32);
85+
float y = dequantize<T>(Y_data[y_idx], Y_scale_f, Y_zero_point_i32);
8686
float z = x + y;
87-
out_data[i] = kernels::quantize<T>(z, inv_out_scale, out_zero_point_i32);
87+
out_data[i] = quantize<T>(z, inv_out_scale, out_zero_point_i32);
8888
}
8989
}
9090
}

backends/cadence/reference/operators/quantized_layer_norm.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ 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;
1921

2022
namespace impl {
2123
namespace reference {
@@ -74,10 +76,10 @@ void quantized_layer_norm_per_tensor_(
7476
// y[j] = (x[j] - mean) / std * kGamma + kBeta;
7577
// Since X is quantized, we dequantize it, compute fp32 result, and
7678
// quantize the result to an int8/uint8 value.
77-
float val = kernels::dequantize<T>(x[j], input_scale, input_zero_point);
79+
float val = dequantize<T>(x[j], input_scale, input_zero_point);
7880

7981
val = (val - mean) * inv_std * weight_data[j] + bias_data[j];
80-
y[j] = kernels::quantize<T>(val, output_inv_scale, output_zero_point);
82+
y[j] = quantize<T>(val, output_inv_scale, output_zero_point);
8183
}
8284
}
8385
}

0 commit comments

Comments
 (0)