Skip to content

Commit 1c3b5ae

Browse files
committed
Last fix I swear
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 3784e95 commit 1c3b5ae

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

examples/models/llama2/CMakeLists.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ find_package(gflags REQUIRED)
5757
#
5858
# llama_main: test binary to run llama, with tokenizer and sampler integrated
5959
#
60-
add_executable(
61-
llama_main
62-
main.cpp
63-
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/threadpool/cpuinfo_utils.cpp
64-
)
65-
if(CMAKE_BUILD_TYPE EQUAL "RELEASE")
66-
target_link_options(llama_main PRIVATE "LINKER:--gc-sections")
67-
endif()
6860

6961
# find `executorch` libraries Same as for gflags
7062
set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../lib/cmake/ExecuTorch)
@@ -81,18 +73,8 @@ endif()
8173
# llama_runner library
8274
add_subdirectory(runner)
8375

84-
target_include_directories(
85-
llama_main
86-
PUBLIC
87-
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/third-party/cpuinfo/include
88-
)
89-
target_include_directories(
90-
llama_main
91-
PUBLIC
92-
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/third-party/pthreadpool/include
93-
)
94-
9576
set(link_libraries)
77+
set(_srcs main.cpp)
9678

9779
if(EXECUTORCH_BUILD_OPTIMIZED)
9880
list(
@@ -114,12 +96,25 @@ if(EXECUTORCH_BUILD_CUSTOM)
11496
list(APPEND link_libraries custom_ops)
11597
endif()
11698

117-
target_link_libraries(llama_main PUBLIC gflags llama_runner)
118-
11999
# XNNPACK pthreadpool cpuinfo
120100
if(TARGET xnnpack_backend)
121101
set(xnnpack_backend_libs xnnpack_backend XNNPACK pthreadpool cpuinfo)
122102
list(APPEND link_libraries ${xnnpack_backend_libs})
103+
# HACK: main only include these when xnnpack backend is availabe, so that we
104+
# have all the threadpool sources under xnnpack.
105+
list(APPEND _common_compile_options -DET_USE_THREADPOOL)
106+
list(
107+
APPEND
108+
_srcs
109+
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/threadpool/cpuinfo_utils.cpp
110+
)
111+
list(
112+
APPEND
113+
_common_include_directories
114+
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/third-party/cpuinfo/include
115+
${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack/third-party/pthreadpool/include
116+
)
117+
# end of hack
123118
target_link_options_shared_lib(xnnpack_backend)
124119
endif()
125120

@@ -140,9 +135,14 @@ if(ANDROID)
140135
list(APPEND link_libraries log)
141136
endif()
142137

143-
target_compile_options(llama_main PUBLIC ${_common_compile_options}
144-
-DET_USE_THREADPOOL)
145-
target_link_libraries(llama_main PUBLIC ${link_libraries})
138+
add_executable(llama_main ${_srcs})
139+
if(CMAKE_BUILD_TYPE EQUAL "RELEASE")
140+
target_link_options(llama_main PRIVATE "LINKER:--gc-sections")
141+
endif()
142+
143+
target_include_directories(llama_main PUBLIC ${_common_include_directories})
144+
target_link_libraries(llama_main PUBLIC gflags llama_runner ${link_libraries})
145+
target_compile_options(llama_main PUBLIC ${_common_compile_options})
146146

147147
if(APPLE)
148148
target_link_options_shared_lib(executorch)

examples/models/llama2/custom_ops/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ if(NOT EXECUTORCH_BUILD_XNNPACK)
6161
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../backends/xnnpack/threadpool/threadpool.cpp"
6262
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../backends/xnnpack/threadpool/threadpool_guard.cpp"
6363
)
64+
else()
65+
list(APPEND custom_ops_libs xnnpack_backend)
6466
endif()
6567

6668
add_library(custom_ops ${_custom_ops__srcs})

0 commit comments

Comments
 (0)