Skip to content

Commit fa18250

Browse files
committed
Handle EXECUTORCH_BUILD_PYBIND=False
1 parent 162e5f2 commit fa18250

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

examples/models/llama2/custom_ops/CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,22 @@ target_include_directories(custom_ops PUBLIC "${_common_include_directories}")
6666
target_include_directories(
6767
custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include"
6868
)
69-
target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_no_prim_ops)
69+
target_link_libraries(
70+
custom_ops PUBLIC ${custom_ops_libs} executorch_no_prim_ops
71+
)
7072

7173
target_compile_options(
7274
custom_ops PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL
7375
)
7476

7577
install(TARGETS custom_ops DESTINATION lib)
7678

77-
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT AND EXECUTORCH_BUILD_PYBIND)
79+
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
7880
# Add a AOT library
7981
find_package(Torch CONFIG REQUIRED)
8082
add_library(
81-
custom_ops_aot_lib SHARED ${_custom_ops__srcs} ${CMAKE_CURRENT_SOURCE_DIR}/op_sdpa_aot.cpp
83+
custom_ops_aot_lib SHARED ${_custom_ops__srcs}
84+
${CMAKE_CURRENT_SOURCE_DIR}/op_sdpa_aot.cpp
8285
)
8386
target_include_directories(
8487
custom_ops_aot_lib PUBLIC "${_common_include_directories}"
@@ -87,10 +90,21 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT AND EXECUTORCH_BUILD_PYBIND)
8790
custom_ops_aot_lib
8891
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include"
8992
)
90-
target_link_libraries(custom_ops_aot_lib PUBLIC portable_lib cpublas torch)
93+
if(TARGET portable_lib)
94+
# If we have portable_lib built, custom_ops_aot_lib gives the ability to use
95+
# the ops in PyTorch and ExecuTorch through pybind
96+
target_link_libraries(custom_ops_aot_lib PUBLIC portable_lib)
97+
else()
98+
# If no portable_lib, custom_ops_aot_lib still gives the ability to use the
99+
# ops in PyTorch
100+
target_link_libraries(custom_ops_aot_lib PUBLIC executorch_no_prim_ops)
101+
endif()
102+
103+
target_link_libraries(custom_ops_aot_lib PUBLIC cpublas torch)
91104
target_compile_options(
92-
custom_ops_aot_lib PUBLIC -Wno-deprecated-declarations -fPIC -frtti
93-
-fexceptions ${_common_compile_options} -DET_USE_THREADPOOL
105+
custom_ops_aot_lib
106+
PUBLIC -Wno-deprecated-declarations -fPIC -frtti -fexceptions
107+
${_common_compile_options} -DET_USE_THREADPOOL
94108
)
95109

96110
install(TARGETS custom_ops_aot_lib DESTINATION lib)

0 commit comments

Comments
 (0)