Skip to content

Commit dd43f16

Browse files
authored
Update CMake to enable building ops on iOS (#2274)
init
1 parent abb309a commit dd43f16

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

torchao/experimental/CMakeLists.txt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (NOT CMAKE_BUILD_TYPE)
1616
endif()
1717

1818
# Platform options
19+
option(TORCHAO_BUILD_ATEN_OPS "Building torchao ops for ATen." ON)
1920
option(TORCHAO_BUILD_EXECUTORCH_OPS "Building torchao ops for ExecuTorch." OFF)
2021
option(TORCHAO_BUILD_MPS_OPS "Building torchao MPS ops" OFF)
2122
option(TORCHAO_BUILD_CPU_AARCH64 "Build torchao's CPU aarch64 kernels" OFF)
@@ -32,7 +33,7 @@ if(NOT DEFINED TORCHAO_PARALLEL_BACKEND)
3233
endif()
3334

3435
# Set default compiler options
35-
add_compile_options("-Wall" "-Werror" "-Wno-deprecated")
36+
add_compile_options("-Wall" "-Werror" "-Wno-deprecated" "-Wno-shorten-64-to-32")
3637

3738
include(CMakePrintHelpers)
3839
message("TORCHAO_INCLUDE_DIRS: ${TORCHAO_INCLUDE_DIRS}")
@@ -68,6 +69,7 @@ if(TORCHAO_BUILD_CPU_AARCH64)
6869
if(TORCHAO_ENABLE_ARM_NEON_DOT)
6970
message(STATUS "Building with ARM NEON dot product support")
7071
add_compile_definitions(TORCHAO_ENABLE_ARM_NEON_DOT)
72+
add_compile_options("-march=armv8.4-a+dotprod")
7173
endif()
7274

7375
if(TORCHAO_ENABLE_ARM_I8MM)
@@ -89,26 +91,28 @@ add_subdirectory(ops/linear_8bit_act_xbit_weight)
8991
add_subdirectory(ops/embedding_xbit)
9092

9193
# ATen ops lib
92-
add_library(torchao_ops_aten SHARED)
93-
target_link_libraries(
94-
torchao_ops_aten PRIVATE
95-
torchao_ops_linear_8bit_act_xbit_weight_aten
96-
torchao_ops_embedding_xbit_aten
97-
)
98-
99-
# Add MPS support if enabled
100-
if (TORCHAO_BUILD_MPS_OPS)
101-
message(STATUS "Building with MPS support")
102-
add_subdirectory(ops/mps)
103-
target_link_libraries(torchao_ops_aten PRIVATE torchao_ops_mps_aten)
104-
endif()
94+
if (TORCHAO_BUILD_ATEN_OPS)
95+
add_library(torchao_ops_aten SHARED)
96+
target_link_libraries(
97+
torchao_ops_aten PRIVATE
98+
torchao_ops_linear_8bit_act_xbit_weight_aten
99+
torchao_ops_embedding_xbit_aten
100+
)
105101

106-
# Install ATen targets
107-
install(
108-
TARGETS torchao_ops_aten
109-
EXPORT _targets
110-
DESTINATION lib
111-
)
102+
# Add MPS support if enabled
103+
if (TORCHAO_BUILD_MPS_OPS)
104+
message(STATUS "Building with MPS support")
105+
add_subdirectory(ops/mps)
106+
target_link_libraries(torchao_ops_aten PRIVATE torchao_ops_mps_aten)
107+
endif()
108+
109+
# Install ATen targets
110+
install(
111+
TARGETS torchao_ops_aten
112+
EXPORT _targets
113+
DESTINATION lib
114+
)
115+
endif()
112116

113117
# Build executorch lib if enabled
114118
if(TORCHAO_BUILD_EXECUTORCH_OPS)

torchao/experimental/ops/embedding_xbit/CMakeLists.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ cmake_minimum_required(VERSION 3.19)
88

99
include(${CMAKE_CURRENT_SOURCE_DIR}/../../Utils.cmake)
1010

11-
find_package(Torch REQUIRED)
12-
add_library(torchao_ops_embedding_xbit_aten OBJECT
13-
op_embedding_xbit_aten.cpp
14-
)
15-
target_link_torchao_parallel_backend(torchao_ops_embedding_xbit_aten "${TORCHAO_PARALLEL_BACKEND}")
16-
if (TORCHAO_BUILD_CPU_AARCH64)
17-
target_link_libraries(torchao_ops_embedding_xbit_aten PRIVATE torchao_kernels_aarch64)
11+
if(TORCHAO_BUILD_ATEN_OPS)
12+
find_package(Torch REQUIRED)
13+
add_library(torchao_ops_embedding_xbit_aten OBJECT
14+
op_embedding_xbit_aten.cpp
15+
)
16+
target_link_torchao_parallel_backend(torchao_ops_embedding_xbit_aten "${TORCHAO_PARALLEL_BACKEND}")
17+
if (TORCHAO_BUILD_CPU_AARCH64)
18+
target_link_libraries(torchao_ops_embedding_xbit_aten PRIVATE torchao_kernels_aarch64)
19+
endif()
20+
target_include_directories(torchao_ops_embedding_xbit_aten PRIVATE "${TORCH_INCLUDE_DIRS}")
21+
target_link_libraries(torchao_ops_embedding_xbit_aten PRIVATE "${TORCH_LIBRARIES}")
22+
target_compile_definitions(torchao_ops_embedding_xbit_aten PRIVATE USE_ATEN=1)
1823
endif()
19-
target_include_directories(torchao_ops_embedding_xbit_aten PRIVATE "${TORCH_INCLUDE_DIRS}")
20-
target_link_libraries(torchao_ops_embedding_xbit_aten PRIVATE "${TORCH_LIBRARIES}")
21-
target_compile_definitions(torchao_ops_embedding_xbit_aten PRIVATE USE_ATEN=1)
2224

2325
if(TORCHAO_BUILD_EXECUTORCH_OPS)
2426
# ExecuTorch package is not required, but EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES must

torchao/experimental/ops/linear_8bit_act_xbit_weight/CMakeLists.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ if (NOT TARGET cpuinfo)
2020
cpuinfo)
2121
endif()
2222

23-
find_package(Torch REQUIRED)
24-
add_library(torchao_ops_linear_8bit_act_xbit_weight_aten OBJECT
25-
linear_8bit_act_xbit_weight.cpp
26-
op_linear_8bit_act_xbit_weight_aten.cpp
27-
)
28-
target_link_torchao_parallel_backend(torchao_ops_linear_8bit_act_xbit_weight_aten "${TORCHAO_PARALLEL_BACKEND}")
23+
if (TORCHAO_BUILD_ATEN_OPS)
24+
find_package(Torch REQUIRED)
25+
add_library(torchao_ops_linear_8bit_act_xbit_weight_aten OBJECT
26+
linear_8bit_act_xbit_weight.cpp
27+
op_linear_8bit_act_xbit_weight_aten.cpp
28+
)
29+
target_link_torchao_parallel_backend(torchao_ops_linear_8bit_act_xbit_weight_aten "${TORCHAO_PARALLEL_BACKEND}")
2930

30-
if(TORCHAO_BUILD_CPU_AARCH64)
31-
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE torchao_kernels_aarch64)
31+
if(TORCHAO_BUILD_CPU_AARCH64)
32+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE torchao_kernels_aarch64)
33+
endif()
34+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE cpuinfo)
35+
target_include_directories(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE "${TORCH_INCLUDE_DIRS}")
36+
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE "${TORCH_LIBRARIES}")
37+
target_compile_definitions(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE USE_ATEN=1)
3238
endif()
33-
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE cpuinfo)
34-
target_include_directories(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE "${TORCH_INCLUDE_DIRS}")
35-
target_link_libraries(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE "${TORCH_LIBRARIES}")
36-
target_compile_definitions(torchao_ops_linear_8bit_act_xbit_weight_aten PRIVATE USE_ATEN=1)
3739

3840
if(TORCHAO_BUILD_EXECUTORCH_OPS)
3941
# ExecuTorch package is not required, but EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES must

0 commit comments

Comments
 (0)