Skip to content

Commit 162e5f2

Browse files
committed
Let custom_ops_aot_lib depend on portable_lib
1 parent 7ceb369 commit 162e5f2

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

CMakeLists.txt

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ option(EXECUTORCH_BUILD_KERNELS_QUANTIZED "Build the quantized kernels" OFF)
179179

180180
option(EXECUTORCH_BUILD_SDK "Build the ExecuTorch SDK")
181181

182-
option(EXECUTORCH_BUILD_SHARED_LIB "Build libexecutorch as a shared lib" OFF)
183-
184182
option(EXECUTORCH_BUILD_SIZE_TEST "Build the size test" OFF)
185183

186184
option(EXECUTORCH_BUILD_XNNPACK "Build the XNNPACK backend" OFF)
@@ -205,7 +203,6 @@ cmake_dependent_option(
205203

206204
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
207205
set(EXECUTORCH_BUILD_KERNELS_CUSTOM ON)
208-
set(EXECUTORCH_BUILD_SHARED_LIB ON)
209206
endif()
210207

211208
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
@@ -432,11 +429,7 @@ add_subdirectory(schema)
432429
# Only contains primitive operators; does not contain portable kernels or other
433430
# full operators. Does not contain any backends.
434431
#
435-
if(EXECUTORCH_BUILD_SHARED_LIB)
436-
add_library(executorch_no_prim_ops SHARED ${_executorch_no_prim_ops__srcs})
437-
else()
438-
add_library(executorch_no_prim_ops STATIC ${_executorch_no_prim_ops__srcs})
439-
endif()
432+
add_library(executorch_no_prim_ops ${_executorch_no_prim_ops__srcs})
440433
target_link_libraries(executorch_no_prim_ops PRIVATE program_schema)
441434
# Check if dl exists for this toolchain and only then link it.
442435
find_library(DL_LIBRARY_EXISTS NAMES dl)
@@ -470,13 +463,6 @@ target_link_options_shared_lib(executorch)
470463
#
471464
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
472465

473-
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
474-
# TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom
475-
add_subdirectory(
476-
${CMAKE_CURRENT_SOURCE_DIR}/examples/models/llama2/custom_ops
477-
)
478-
endif()
479-
480466
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
481467
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
482468
endif()
@@ -592,8 +578,6 @@ if(EXECUTORCH_BUILD_COREML)
592578
endif()
593579

594580
if(EXECUTORCH_BUILD_PYBIND)
595-
set(EXECUTORCH_BUILD_SHARED_LIB ON)
596-
597581
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/pybind11)
598582

599583
if(NOT EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
@@ -664,7 +648,7 @@ if(EXECUTORCH_BUILD_PYBIND)
664648
target_link_libraries(util PRIVATE torch c10 executorch)
665649

666650
# pybind portable_lib
667-
pybind11_add_module(portable_lib extension/pybindings/pybindings.cpp)
651+
pybind11_add_module(portable_lib SHARED extension/pybindings/pybindings.cpp)
668652
# The actual output file needs a leading underscore so it can coexist with
669653
# portable_lib.py in the same python package.
670654
set_target_properties(portable_lib PROPERTIES OUTPUT_NAME "_portable_lib")
@@ -673,7 +657,7 @@ if(EXECUTORCH_BUILD_PYBIND)
673657
)
674658
target_include_directories(portable_lib PRIVATE ${TORCH_INCLUDE_DIRS})
675659
target_compile_options(portable_lib PUBLIC ${_pybind_compile_options})
676-
target_link_libraries(portable_lib PUBLIC ${_dep_libs})
660+
target_link_libraries(portable_lib PRIVATE ${_dep_libs})
677661
if(APPLE)
678662
# pip wheels will need to be able to find the torch libraries. On Linux, the
679663
# .so has non-absolute dependencies on libs like "libtorch.so" without
@@ -699,5 +683,12 @@ if(EXECUTORCH_BUILD_PYBIND)
699683
)
700684
endif()
701685

686+
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
687+
# TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom
688+
add_subdirectory(
689+
${CMAKE_CURRENT_SOURCE_DIR}/examples/models/llama2/custom_ops
690+
)
691+
endif()
692+
702693
# Print all summary
703694
executorch_print_configuration_summary()

examples/models/llama2/custom_ops/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ include(${EXECUTORCH_SRCS_FILE})
4040
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
4141

4242
# Custom op libraries
43-
set(custom_ops_libs executorch_no_prim_ops)
44-
list(APPEND custom_ops_libs pthreadpool)
43+
set(custom_ops_libs pthreadpool)
4544
list(APPEND custom_ops_libs cpuinfo)
4645
list(APPEND custom_ops_libs cpublas)
4746
list(APPEND custom_ops_libs eigen_blas)
@@ -67,19 +66,19 @@ target_include_directories(custom_ops PUBLIC "${_common_include_directories}")
6766
target_include_directories(
6867
custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include"
6968
)
70-
target_link_libraries(custom_ops PUBLIC ${custom_ops_libs})
69+
target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_no_prim_ops)
7170

7271
target_compile_options(
7372
custom_ops PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL
7473
)
7574

7675
install(TARGETS custom_ops DESTINATION lib)
7776

78-
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
77+
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT AND EXECUTORCH_BUILD_PYBIND)
7978
# Add a AOT library
8079
find_package(Torch CONFIG REQUIRED)
8180
add_library(
82-
custom_ops_aot_lib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/op_sdpa_aot.cpp
81+
custom_ops_aot_lib SHARED ${_custom_ops__srcs} ${CMAKE_CURRENT_SOURCE_DIR}/op_sdpa_aot.cpp
8382
)
8483
target_include_directories(
8584
custom_ops_aot_lib PUBLIC "${_common_include_directories}"
@@ -88,10 +87,10 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
8887
custom_ops_aot_lib
8988
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include"
9089
)
91-
target_link_libraries(custom_ops_aot_lib PUBLIC custom_ops torch)
90+
target_link_libraries(custom_ops_aot_lib PUBLIC portable_lib cpublas torch)
9291
target_compile_options(
9392
custom_ops_aot_lib PUBLIC -Wno-deprecated-declarations -fPIC -frtti
94-
-fexceptions
93+
-fexceptions ${_common_compile_options} -DET_USE_THREADPOOL
9594
)
9695

9796
install(TARGETS custom_ops_aot_lib DESTINATION lib)

0 commit comments

Comments
 (0)