Skip to content

Commit 6bedb7a

Browse files
psaabpytorchmergebot
authored andcommitted
[aarch64] Fix aarch64 build so that quantize_val_arm is defined (pytorch#84564)
Summary: quantize_val_arm is used in the kernels when building under aarch64 Test Plan: CI Differential Revision: D39272746 Pull Request resolved: pytorch#84564 Approved by: https://github.com/kimishpatel
1 parent a6e6276 commit 6bedb7a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

aten/src/ATen/native/quantized/AffineQuantizerBase.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ void quantize_vec(
7171
(float)scale, (int32_t)zero_point, precision});
7272
}
7373

74+
#if defined(__ARM_NEON__) || defined(__aarch64__)
75+
// For use when compiling FBGEMM on aarch64 but still supporting x86
76+
// intrinsics via simde
77+
template <typename T>
78+
T quantize_val_arm(
79+
const float scale,
80+
const int32_t zero_point,
81+
const float value) {
82+
constexpr int32_t qmin = std::numeric_limits<T>::min();
83+
constexpr int32_t qmax = std::numeric_limits<T>::max();
84+
float inv_scale = 1.0f / scale;
85+
auto r = zero_point + static_cast<int32_t>(std::nearbyint(value * inv_scale));
86+
r = std::max(r, qmin);
87+
r = std::min(r, qmax);
88+
return static_cast<T>(r);
89+
}
90+
91+
template uint8_t quantize_val_arm<uint8_t>(
92+
const float scale,
93+
const int32_t zero_point,
94+
const float value);
95+
template int8_t quantize_val_arm<int8_t>(
96+
const float scale,
97+
const int32_t zero_point,
98+
const float value);
99+
#endif
100+
74101
template <typename T>
75102
inline float dequantize_val(double scale, int64_t zero_point, T value) {
76103
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)

0 commit comments

Comments
 (0)