Fix Arm64 OSS pytorch build with FBGEMM (#161527)

Summary:
X-link: https://github.com/pytorch/FBGEMM/pull/4775

Without this change, Arm64 OSS pytorch build with FBGEMM failed with the following error.
Undefined symbols for architecture arm64:
  "fbgemm::FindMinMax(float const*, float*, float*, long long)", referenced from:
      at::native::fbgemm_linear_int8_weight_fp32_activation(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, c10::Scalar const&, c10::Scalar const&, at::Tensor const&) in QuantizedLinear.cpp.o
      at::native::fbgemm_linear_quantize_weight(at::Tensor const&) in QuantizedLinear.cpp.o
      PackedConvWeight<2>::apply_dynamic(at::Tensor const&, bool) in qconv_dynamic.cpp.o
      PackedConvWeight<3>::apply_dynamic(at::Tensor const&, bool) in qconv_dynamic.cpp.o
      at::Tensor PackedLinearWeight::apply_dynamic_impl<false>(at::Tensor, bool) in qlinear_dynamic.cpp.o
      at::Tensor PackedLinearWeight::apply_dynamic_impl<true>(at::Tensor, bool) in qlinear_dynamic.cpp.o
ld: symbol(s) not found for architecture arm64

This change fixed the issue by moving FindMinMax's implementation from QuantUtilsAvx2.cc to QuantUtils.cc. FindMinMax is a platform-agnostic function with AVX2-specific optimizations so conceptually it can be put in QuantUtils.cc.

Test Plan:
With this change, Arm64 OSS pytorch built successfully with FBGEMM enabled.

Rollback Plan:

Reviewed By: q10

Differential Revision: D81052327

Pull Request resolved: https://github.com/pytorch/pytorch/pull/161527
Approved by: https://github.com/q10
This commit is contained in:
Ben Niu 2025-09-04 20:01:13 +00:00 committed by PyTorch MergeBot
parent c3d54dea9f
commit dbec08729f

View File

@ -837,9 +837,11 @@ include(ExternalProject)
# ---[ Dependencies ---[ FBGEMM doesn't work on x86 32bit and # ---[ Dependencies ---[ FBGEMM doesn't work on x86 32bit and
# CMAKE_SYSTEM_PROCESSOR thinks its 64bit # CMAKE_SYSTEM_PROCESSOR thinks its 64bit
if(USE_FBGEMM AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") if(USE_FBGEMM AND
(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") AND
(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64"))
message(WARNING message(WARNING
"x64 operating system is required for FBGEMM. " "x64 or Arm64 operating systems are required for FBGEMM. "
"Not compiling with FBGEMM. " "Not compiling with FBGEMM. "
"Turn this warning off by USE_FBGEMM=OFF.") "Turn this warning off by USE_FBGEMM=OFF.")
set(USE_FBGEMM OFF) set(USE_FBGEMM OFF)