From d1f21d8ec332fcce7007d427bec733a45c97f39f Mon Sep 17 00:00:00 2001 From: Fadi Arafeh Date: Thu, 6 Mar 2025 23:37:18 +0000 Subject: [PATCH] Enable Direct Use of Arm Compute Library (ACL) in ATen (#148584) ACL is already built with PyTorch as a shared library when USE_MKLDNN_ACL is set. Currently, it is only used indirectly in ATen via oneDNN for AArch64 targets. However there are cases where it makes sense to utilize ACL directly without oneDNN as an intermediary - e.g. quantization. See #145942, #147337, #146620. This patch enables such use cases by exposing ACL to ATen Pull Request resolved: https://github.com/pytorch/pytorch/pull/148584 Approved by: https://github.com/malfet --- aten/src/ATen/CMakeLists.txt | 5 +++ caffe2/CMakeLists.txt | 5 +++ cmake/Modules/FindACL.cmake | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 cmake/Modules/FindACL.cmake diff --git a/aten/src/ATen/CMakeLists.txt b/aten/src/ATen/CMakeLists.txt index 6a6aef8c8c3..085af373ec2 100644 --- a/aten/src/ATen/CMakeLists.txt +++ b/aten/src/ATen/CMakeLists.txt @@ -472,6 +472,11 @@ if(MKLDNN_FOUND) list(APPEND ATen_CPU_DEPENDENCY_LIBS ${MKLDNN_LIBRARIES}) endif(MKLDNN_FOUND) +if(USE_MKLDNN_ACL) + list(APPEND ATen_CPU_INCLUDE ${ACL_INCLUDE_DIRS}) + list(APPEND ATen_CPU_DEPENDENCY_LIBS ${ACL_LIBRARIES}) +endif() + if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$") list(APPEND ATen_CPU_DEPENDENCY_LIBS cpuinfo) endif() diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 54e486917f6..b5d46182591 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -1229,6 +1229,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/quantized/qlinear_unpack.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) endif() +if(USE_MKLDNN_ACL) + find_package(ACL REQUIRED) + target_include_directories(torch_cpu PRIVATE ${ACL_INCLUDE_DIRS}) +endif() + target_include_directories(torch_cpu PRIVATE ${ATen_CPU_INCLUDE}) target_include_directories(torch_cpu PRIVATE diff --git a/cmake/Modules/FindACL.cmake b/cmake/Modules/FindACL.cmake new file mode 100644 index 00000000000..0a0094de0cd --- /dev/null +++ b/cmake/Modules/FindACL.cmake @@ -0,0 +1,62 @@ +# Copied from: https://github.com/oneapi-src/oneDNN/blob/main/cmake/FindACL.cmake +# ---------- +# FindACL +# ---------- +# +# Finds the Arm Compute Library +# https://arm-software.github.io/ComputeLibrary/latest/ +# +# This module defines the following variables: +# +# ACL_FOUND - True if ACL was found +# ACL_INCLUDE_DIRS - include directories for ACL +# ACL_LIBRARIES - link against this library to use ACL +# +# The module will also define two cache variables: +# +# ACL_INCLUDE_DIR - the ACL include directory +# ACL_LIBRARY - the path to the ACL library +# + +# Use ACL_ROOT_DIR environment variable to find the library and headers +find_path(ACL_INCLUDE_DIR + NAMES arm_compute/graph.h + PATHS ENV ACL_ROOT_DIR + ) + +find_library(ACL_LIBRARY + NAMES arm_compute + PATHS ENV ACL_ROOT_DIR + PATH_SUFFIXES lib build + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ACL DEFAULT_MSG + ACL_INCLUDE_DIR + ACL_LIBRARY +) + +mark_as_advanced( + ACL_LIBRARY + ACL_INCLUDE_DIR + ) + +# Find the extra libraries and include dirs +if(ACL_FOUND) + find_path(ACL_EXTRA_INCLUDE_DIR + NAMES half/half.hpp + PATHS ENV ACL_ROOT_DIR + PATH_SUFFIXES include + ) + + find_library(ACL_GRAPH_LIBRARY + NAMES arm_compute_graph + PATHS ENV ACL_ROOT_DIR + PATH_SUFFIXES lib build + ) + + list(APPEND ACL_INCLUDE_DIRS + ${ACL_INCLUDE_DIR} ${ACL_EXTRA_INCLUDE_DIR}) + list(APPEND ACL_LIBRARIES + ${ACL_LIBRARY} ${ACL_GRAPH_LIBRARY}) +endif()