@@ -36,9 +36,13 @@ endif()
36
36
add_compile_options ("-Wall" "-Werror" "-Wno-deprecated" "-Wno-shorten-64-to-32" )
37
37
38
38
include (CMakePrintHelpers )
39
+ include (${CMAKE_CURRENT_SOURCE_DIR} /Utils.cmake )
40
+
39
41
message ("TORCHAO_INCLUDE_DIRS: ${TORCHAO_INCLUDE_DIRS} " )
40
42
include_directories (${TORCHAO_INCLUDE_DIRS} )
41
43
44
+
45
+ # Build cpu/aarch64 kernels
42
46
if (TORCHAO_BUILD_CPU_AARCH64 )
43
47
message (STATUS "Building with cpu/aarch64" )
44
48
add_compile_definitions (TORCHAO_BUILD_CPU_AARCH64 )
@@ -77,29 +81,50 @@ if(TORCHAO_BUILD_CPU_AARCH64)
77
81
add_compile_definitions (TORCHAO_ENABLE_ARM_I8MM )
78
82
endif ()
79
83
80
- # Defines torchao_kernels_aarch64
81
- add_subdirectory (kernels/cpu/aarch64 )
82
-
83
84
if (TORCHAO_BUILD_KLEIDIAI )
84
85
message (STATUS "Building with Arm KleidiAI library" )
85
86
add_compile_definitions (TORCHAO_ENABLE_KLEIDI )
86
87
endif ()
88
+
89
+ # Defines torchao_kernels_aarch64
90
+ add_subdirectory (kernels/cpu/aarch64 )
87
91
endif ()
88
92
89
- # Add quantized operation dir
90
- add_subdirectory (ops/linear_8bit_act_xbit_weight )
91
- add_subdirectory (ops/embedding_xbit )
92
-
93
- # ATen ops lib
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
93
+
94
+
95
+ if (NOT TARGET cpuinfo )
96
+ # For some reason cpuinfo package has unused functions/variables
97
+ # TODO (T215533422): fix upstream
98
+ add_compile_options (-Wno-unused-function -Wno-unused-variable )
99
+ include (FetchContent )
100
+ FetchContent_Declare (cpuinfo
101
+ GIT_REPOSITORY https://github.com/pytorch/cpuinfo.git
102
+ GIT_TAG c61fe919607bbc534d7a5a5707bdd7041e72c5ff )
103
+ FetchContent_MakeAvailable (
104
+ cpuinfo )
105
+ endif ()
106
+
107
+ # Build ATen ops
108
+ if (TORCHAO_BUILD_ATEN_OPS )
109
+ find_package (Torch REQUIRED )
110
+ set (_torchao_op_srcs_aten )
111
+ list (APPEND _torchao_op_srcs_aten
112
+ ops/embedding_xbit/op_embedding_xbit_aten.cpp
113
+ ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.cpp
114
+ ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_aten.cpp
100
115
)
116
+ list (TRANSFORM _torchao_op_srcs_aten PREPEND "${CMAKE_CURRENT_SOURCE_DIR} /" )
117
+ add_library (torchao_ops_aten SHARED ${_torchao_op_srcs_aten} )
118
+ target_link_torchao_parallel_backend (torchao_ops_aten "${TORCHAO_PARALLEL_BACKEND} " )
119
+ if (TORCHAO_BUILD_CPU_AARCH64 )
120
+ target_link_libraries (torchao_ops_aten PRIVATE torchao_kernels_aarch64 )
121
+ endif ()
122
+ target_link_libraries (torchao_ops_aten PRIVATE cpuinfo )
123
+ target_include_directories (torchao_ops_aten PRIVATE "${TORCH_INCLUDE_DIRS} " )
124
+ target_link_libraries (torchao_ops_aten PRIVATE "${TORCH_LIBRARIES} " )
125
+ target_compile_definitions (torchao_ops_aten PRIVATE USE_ATEN=1 )
101
126
102
- # Add MPS support if enabled
127
+ # Add MPS support if enabled
103
128
if (TORCHAO_BUILD_MPS_OPS )
104
129
message (STATUS "Building with MPS support" )
105
130
add_subdirectory (ops/mps )
@@ -114,18 +139,38 @@ if (TORCHAO_BUILD_ATEN_OPS)
114
139
)
115
140
endif ()
116
141
117
- # Build executorch lib if enabled
142
+
143
+ # Build ExecuTorch ops
118
144
if (TORCHAO_BUILD_EXECUTORCH_OPS )
119
- add_library (torchao_ops_executorch STATIC )
120
- target_link_libraries (torchao_ops_executorch PRIVATE
121
- torchao_ops_linear_8bit_act_xbit_weight_executorch
122
- torchao_ops_embedding_xbit_executorch
145
+ # ExecuTorch package is not required, but EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES must
146
+ # be defined and EXECUTORCH_LIBRARIES must include the following libraries installed by ExecuTorch:
147
+ # libexecutorch.a
148
+ # libextension_threadpool.a
149
+ # libcpuinfo.a
150
+ # libpthreadpool.a
151
+ if (NOT DEFINED EXECUTORCH_INCLUDE_DIRS AND NOT DEFINED EXECUTORCH_LIBRARIES )
152
+ message (WARNING "EXECUTORCH_INCLUDE_DIRS and EXECUTORCH_LIBRARIES are not defined. Looking for ExecuTorch." )
153
+ find_package (ExecuTorch HINTS ${CMAKE_PREFIX_PATH} /executorch/share/cmake )
154
+ endif ()
155
+ set (_torchao_op_srcs_executorch )
156
+ list (APPEND _torchao_op_srcs_executorch
157
+ ops/embedding_xbit/op_embedding_xbit_executorch.cpp
158
+ ops/linear_8bit_act_xbit_weight/linear_8bit_act_xbit_weight.cpp
159
+ ops/linear_8bit_act_xbit_weight/op_linear_8bit_act_xbit_weight_executorch.cpp
123
160
)
161
+ list (TRANSFORM _torchao_op_srcs_executorch PREPEND "${CMAKE_CURRENT_SOURCE_DIR} /" )
162
+ add_library (torchao_ops_executorch STATIC ${_torchao_op_srcs_executorch} )
163
+ target_link_torchao_parallel_backend (torchao_ops_executorch executorch )
164
+ target_include_directories (torchao_ops_executorch PRIVATE "${EXECUTORCH_INCLUDE_DIRS} " )
165
+ target_compile_definitions (torchao_ops_executorch PRIVATE USE_EXECUTORCH=1 )
166
+ target_link_libraries (torchao_ops_executorch PRIVATE "${EXECUTORCH_LIBRARIES} " )
167
+ if (TORCHAO_BUILD_CPU_AARCH64 )
168
+ target_link_libraries (torchao_ops_executorch PRIVATE torchao_kernels_aarch64 )
169
+ endif ()
170
+ target_link_libraries (torchao_ops_executorch PRIVATE cpuinfo )
124
171
install (
125
172
TARGETS
126
173
torchao_ops_executorch
127
- torchao_ops_linear_8bit_act_xbit_weight_executorch
128
- torchao_ops_embedding_xbit_executorch
129
174
EXPORT _targets
130
175
DESTINATION lib
131
176
)
0 commit comments