@@ -144,6 +144,8 @@ option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF)
144
144
145
145
option (EXECUTORCH_BUILD_CUSTOM "Build the custom kernels" OFF )
146
146
147
+ option (EXECUTORCH_BUILD_CUSTOM_OPS_AOT "Build the custom ops lib for AOT" OFF )
148
+
147
149
option (EXECUTORCH_BUILD_EXTENSION_DATA_LOADER "Build the Data Loader extension"
148
150
OFF )
149
151
@@ -175,17 +177,29 @@ option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
175
177
#
176
178
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
177
179
#
178
- cmake_dependent_option(EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library."
179
- ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
180
+ cmake_dependent_option(
181
+ EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library." ON
182
+ "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
180
183
181
184
#
182
185
# cpuinfo: build cpuinfo library. Disable on unsupported platforms
183
186
#
184
187
cmake_dependent_option(EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON
185
188
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
186
189
190
+ if (EXECUTORCH_BUILD_CUSTOM_OPS_AOT)
191
+ set (EXECUTORCH_BUILD_CUSTOM ON )
192
+ endif ()
193
+
194
+ if (EXECUTORCH_BUILD_CUSTOM)
195
+ set (EXECUTORCH_BUILD_OPTIMIZED ON )
196
+ endif ()
197
+
187
198
if (EXECUTORCH_BUILD_CPUINFO)
188
199
# --- cpuinfo
200
+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
201
+ ${CMAKE_POSITION_INDEPENDENT_CODE} )
202
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
189
203
set (CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo" )
190
204
set (CPUINFO_BUILD_TOOLS
191
205
OFF
@@ -207,10 +221,15 @@ if(EXECUTORCH_BUILD_CPUINFO)
207
221
CACHE STRING "" )
208
222
set (CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR} /deps/clog" )
209
223
add_subdirectory ("${CPUINFO_SOURCE_DIR} " )
224
+ set (CMAKE_POSITION_INDEPENDENT_CODE
225
+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
210
226
endif ()
211
227
212
228
if (EXECUTORCH_BUILD_PTHREADPOOL)
213
229
# --- pthreadpool
230
+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
231
+ ${CMAKE_POSITION_INDEPENDENT_CODE} )
232
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
214
233
set (PTHREADPOOL_SOURCE_DIR "backends/xnnpack/third-party/pthreadpool" )
215
234
set (PTHREADPOOL_BUILD_TESTS
216
235
OFF
@@ -230,6 +249,8 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
230
249
CACHE STRING "" )
231
250
endif ()
232
251
add_subdirectory ("${PTHREADPOOL_SOURCE_DIR} " )
252
+ set (CMAKE_POSITION_INDEPENDENT_CODE
253
+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
233
254
endif ()
234
255
235
256
if (NOT PYTHON_EXECUTABLE)
@@ -352,23 +373,28 @@ add_subdirectory(schema)
352
373
# Only contains primitive operators; does not contain portable kernels or other
353
374
# full operators. Does not contain any backends.
354
375
#
355
-
356
- add_library (executorch ${_executorch__srcs} )
357
- target_link_libraries (executorch PRIVATE program_schema)
358
- target_link_options_shared_lib(executorch)
376
+ add_library (executorch_no_prim_ops ${_executorch_no_prim_ops__srcs} )
377
+ target_link_libraries (executorch_no_prim_ops PRIVATE program_schema)
359
378
# Check if dl exists for this toolchain and only then link it.
360
379
find_library (DL_LIBRARY_EXISTS NAMES dl)
361
380
# Check if the library was found
362
381
if (DL_LIBRARY_EXISTS)
363
- target_link_libraries (executorch PRIVATE dl) # For dladdr()
382
+ target_link_libraries (executorch_no_prim_ops PRIVATE dl) # For dladdr()
364
383
endif ()
365
- target_include_directories (executorch PUBLIC ${_common_include_directories} )
366
- target_compile_options (executorch PUBLIC ${_common_compile_options} )
384
+ target_include_directories (executorch_no_prim_ops PUBLIC ${_common_include_directories} )
385
+ target_compile_options (executorch_no_prim_ops PUBLIC ${_common_compile_options} )
367
386
if (MAX_KERNEL_NUM)
368
- target_compile_definitions (executorch
387
+ target_compile_definitions (executorch_no_prim_ops
369
388
PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM} )
370
389
endif ()
371
390
391
+ add_library (executorch ${_executorch__srcs} )
392
+ target_link_libraries (executorch PRIVATE executorch_no_prim_ops)
393
+ target_link_libraries (executorch INTERFACE program_schema)
394
+ target_include_directories (executorch PUBLIC ${_common_include_directories} )
395
+ target_compile_options (executorch PUBLIC ${_common_compile_options} )
396
+ target_link_options_shared_lib(executorch)
397
+
372
398
#
373
399
# portable_ops_lib: A library to register core ATen ops using portable kernels,
374
400
# see kernels/portable/CMakeLists.txt.
@@ -504,25 +530,42 @@ if(EXECUTORCH_BUILD_PYBIND)
504
530
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /sdk)
505
531
endif ()
506
532
533
+ # find pytorch lib, to allow pybind to take at::Tensor as input/output
534
+ find_package (Torch CONFIG REQUIRED)
535
+ find_library (TORCH_PYTHON_LIBRARY torch_python
536
+ PATHS "${TORCH_INSTALL_PREFIX} /lib" )
537
+
538
+ set (_dep_libs
539
+ ${TORCH_PYTHON_LIBRARY}
540
+ bundled_program
541
+ etdump
542
+ executorch
543
+ extension_data_loader
544
+ portable_ops_lib
545
+ util
546
+ torch)
547
+
507
548
if (EXECUTORCH_BUILD_COREML)
508
- set (PYBIND_LINK_COREML " coremldelegate" )
549
+ list ( APPEND _dep_libs coremldelegate)
509
550
endif ()
510
551
511
552
if (EXECUTORCH_BUILD_MPS)
512
- set (PYBIND_LINK_MPS " mpsdelegate" )
553
+ list ( APPEND _dep_libs mpsdelegate)
513
554
endif ()
514
555
515
556
if (EXECUTORCH_BUILD_XNNPACK)
516
- # need to explicitly specify XNNPACK here
517
- # otherwise uses XNNPACK symbols from libtorch_cpu
518
- set (PYBIND_LINK_XNNPACK xnnpack_backend XNNPACK)
557
+ # need to explicitly specify XNNPACK here otherwise uses XNNPACK symbols
558
+ # from libtorch_cpu
559
+ list ( APPEND _dep_libs xnnpack_backend XNNPACK)
519
560
endif ()
520
561
521
- # find pytorch lib, to allow pybind to take at::Tensor as input/output
522
- find_package (Torch CONFIG REQUIRED)
523
- find_library (TORCH_PYTHON_LIBRARY torch_python
524
- PATHS "${TORCH_INSTALL_PREFIX} /lib" )
562
+ if (EXECUTORCH_BUILD_CUSTOM)
563
+ list (APPEND _dep_libs custom_ops)
564
+ endif ()
525
565
566
+ if (EXECUTORCH_BUILD_CUSTOM_OPS_AOT)
567
+ list (APPEND _dep_libs custom_ops_aot_lib)
568
+ endif ()
526
569
# compile options for pybind
527
570
528
571
set (_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
@@ -544,19 +587,7 @@ if(EXECUTORCH_BUILD_PYBIND)
544
587
PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib)
545
588
target_include_directories (portable_lib PRIVATE ${TORCH_INCLUDE_DIRS} )
546
589
target_compile_options (portable_lib PUBLIC ${_pybind_compile_options} )
547
- target_link_libraries (
548
- portable_lib
549
- PUBLIC ${TORCH_PYTHON_LIBRARY}
550
- bundled_program
551
- etdump
552
- executorch
553
- extension_data_loader
554
- portable_ops_lib
555
- util
556
- torch
557
- ${PYBIND_LINK_COREML}
558
- ${PYBIND_LINK_MPS}
559
- ${PYBIND_LINK_XNNPACK} )
590
+ target_link_libraries (portable_lib PUBLIC ${_dep_libs} )
560
591
561
592
install (TARGETS portable_lib
562
593
LIBRARY DESTINATION executorch/extension/pybindings)
0 commit comments