From 87d0b024914b24fb959fcfe4b877dc1917b0eaa7 Mon Sep 17 00:00:00 2001 From: Jhen Date: Wed, 22 Mar 2023 18:29:31 +0800 Subject: [PATCH] feat: set default n_threads to min(4, proc_count) --- android/src/main/jni/whisper/jni.cpp | 6 +----- example/ios/Podfile.lock | 2 +- ios/RNWhisper.mm | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/android/src/main/jni/whisper/jni.cpp b/android/src/main/jni/whisper/jni.cpp index 67c672d..0e60346 100644 --- a/android/src/main/jni/whisper/jni.cpp +++ b/android/src/main/jni/whisper/jni.cpp @@ -19,10 +19,6 @@ static inline int min(int a, int b) { return (a < b) ? a : b; } -static inline int max(int a, int b) { - return (a > b) ? a : b; -} - extern "C" { JNIEXPORT jlong JNICALL @@ -63,7 +59,7 @@ Java_com_rnwhisper_WhisperContext_fullTranscribe( jfloat *audio_data_arr = env->GetFloatArrayElements(audio_data, nullptr); const jsize audio_data_length = env->GetArrayLength(audio_data); - int max_threads = max(1, min(8, get_nprocs() - 2)); + int max_threads = min(4, get_nprocs()); LOGI("About to create params"); diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 12cb1a3..2389424 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -626,7 +626,7 @@ SPEC CHECKSUMS: ReactCommon: b49a4b00ca6d181ff74b17c12b2d59ac4add0bde RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 - whisper-rn: 76657e7d6abe0d1a1a6a0ab6726eb10918bd29f0 + whisper-rn: e29e387a3a39d9573246e444d55a1c39fe657135 Yoga: 79dd7410de6f8ad73a77c868d3d368843f0c93e0 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/ios/RNWhisper.mm b/ios/RNWhisper.mm index 44b3310..58dc9cc 100644 --- a/ios/RNWhisper.mm +++ b/ios/RNWhisper.mm @@ -75,7 +75,7 @@ @implementation RNWhisper const int max_threads = options[@"maxThreads"] != nil ? [options[@"maxThreads"] intValue] : - MIN(8, (int)[[NSProcessInfo processInfo] processorCount]) - 2; + MIN(4, (int)[[NSProcessInfo processInfo] processorCount]); if (options[@"beamSize"] != nil) { params.strategy = WHISPER_SAMPLING_BEAM_SEARCH;