File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,19 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
66
66
set_property (TARGET custom_ops PROPERTY IMPORTED_LOCATION ${CUSTOM_OPS_PATH} )
67
67
target_link_options_shared_lib (custom_ops_lib )
68
68
69
- add_library (executorch_llama_jni SHARED jni/jni_layer_llama.cpp )
69
+ if (TARGET pthreadpool )
70
+ set (LLAMA_JNI_SRCS jni/jni_layer_llama.cpp ../../backends/xnnpack/threadpool/cpuinfo_utils.cpp )
71
+ else ()
72
+ set (LLAMA_JNI_SRCS jni/jni_layer_llama.cpp )
73
+ endif ()
74
+ add_library (executorch_llama_jni SHARED ${LLAMA_JNI_SRCS} )
75
+ if (TARGET pthreadpool )
76
+ target_compile_definitions (executorch_llama_jni PRIVATE ET_USE_THREADPOOL=1 )
77
+ target_include_directories (executorch_llama_jni PUBLIC
78
+ ${CMAKE_CURRENT_SOURCE_DIR} /../../backends/xnnpack/third-party/cpuinfo/include )
79
+ target_include_directories (executorch_llama_jni PUBLIC
80
+ ${CMAKE_CURRENT_SOURCE_DIR} /../../backends/xnnpack/third-party/pthreadpool/include )
81
+ endif ()
70
82
target_include_directories (executorch_llama_jni PRIVATE ${_common_include_directories} )
71
83
target_link_libraries (executorch_llama_jni ${link_libraries} llama_runner
72
84
custom_ops custom_ops_lib cpublas eigen_blas )
Original file line number Diff line number Diff line change 20
20
#include < executorch/runtime/platform/platform.h>
21
21
#include < executorch/runtime/platform/runtime.h>
22
22
23
+ #if defined(ET_USE_THREADPOOL)
24
+ #include < executorch/backends/xnnpack/threadpool/cpuinfo_utils.h>
25
+ #include < executorch/backends/xnnpack/threadpool/threadpool.h>
26
+ #endif
27
+
23
28
#include < fbjni/ByteBuffer.h>
24
29
#include < fbjni/fbjni.h>
25
30
@@ -91,6 +96,17 @@ class ExecuTorchLlamaJni
91
96
facebook::jni::alias_ref<jstring> model_path,
92
97
facebook::jni::alias_ref<jstring> tokenizer_path,
93
98
jfloat temperature) {
99
+ #if defined(ET_USE_THREADPOOL)
100
+ // Reserve 1 thread for the main thread.
101
+ uint32_t num_performant_cores =
102
+ torch::executorch::cpuinfo::get_num_performant_cores () - 1 ;
103
+ if (num_performant_cores > 0 ) {
104
+ ET_LOG (Info, " Resetting threadpool to %d threads" , num_performant_cores);
105
+ torch::executorch::threadpool::get_threadpool ()->_unsafe_reset_threadpool (
106
+ num_performant_cores);
107
+ }
108
+ #endif
109
+
94
110
runner_ = std::make_unique<Runner>(
95
111
model_path->toStdString ().c_str (),
96
112
tokenizer_path->toStdString ().c_str (),
You can’t perform that action at this time.
0 commit comments