@@ -227,11 +227,15 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
227227 static facebook::jni::local_ref<jhybriddata> initHybrid (
228228 facebook::jni::alias_ref<jclass>,
229229 facebook::jni::alias_ref<jstring> modelPath,
230- jint loadMode) {
231- return makeCxxInstance (modelPath, loadMode);
230+ jint loadMode,
231+ jint numThreads) {
232+ return makeCxxInstance (modelPath, loadMode, numThreads);
232233 }
233234
234- ExecuTorchJni (facebook::jni::alias_ref<jstring> modelPath, jint loadMode) {
235+ ExecuTorchJni (
236+ facebook::jni::alias_ref<jstring> modelPath,
237+ jint loadMode,
238+ jint numThreads) {
235239 Module::LoadMode load_mode = Module::LoadMode::Mmap;
236240 if (loadMode == 0 ) {
237241 load_mode = Module::LoadMode::File;
@@ -258,11 +262,10 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
258262 // Based on testing, this is almost universally faster than using all
259263 // cores, as efficiency cores can be quite slow. In extreme cases, using
260264 // all cores can be 10x slower than using cores/2.
261- //
262- // TODO Allow overriding this default from Java.
263265 auto threadpool = executorch::extension::threadpool::get_threadpool ();
264266 if (threadpool) {
265- int thread_count = cpuinfo_get_processors_count () / 2 ;
267+ int thread_count =
268+ numThreads != 0 ? numThreads : cpuinfo_get_processors_count () / 2 ;
266269 if (thread_count > 0 ) {
267270 threadpool->_unsafe_reset_threadpool (thread_count);
268271 }
0 commit comments