whisper.rn 0.4.0-rc.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/android/build.gradle +12 -3
- package/android/src/main/CMakeLists.txt +44 -13
- package/android/src/main/java/com/rnwhisper/AudioUtils.java +27 -12
- package/android/src/main/java/com/rnwhisper/RNWhisper.java +75 -34
- package/android/src/main/java/com/rnwhisper/WhisperContext.java +53 -38
- package/android/src/main/jni.cpp +38 -1
- package/android/src/main/jniLibs/arm64-v8a/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnwhisper_v8fp16_va_2.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/librnwhisper_vfpv4.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnwhisper_x86_64.so +0 -0
- package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/android/src/oldarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/cpp/coreml/whisper-compat.h +10 -0
- package/cpp/coreml/whisper-compat.m +35 -0
- package/cpp/coreml/whisper-decoder-impl.h +27 -15
- package/cpp/coreml/whisper-decoder-impl.m +36 -10
- package/cpp/coreml/whisper-encoder-impl.h +21 -9
- package/cpp/coreml/whisper-encoder-impl.m +29 -3
- package/cpp/ggml-alloc.c +727 -517
- package/cpp/ggml-alloc.h +47 -65
- package/cpp/ggml-backend-impl.h +196 -57
- package/cpp/ggml-backend-reg.cpp +591 -0
- package/cpp/ggml-backend.cpp +2016 -0
- package/cpp/ggml-backend.h +234 -89
- package/cpp/ggml-common.h +1861 -0
- package/cpp/ggml-cpp.h +39 -0
- package/cpp/ggml-cpu/amx/amx.cpp +221 -0
- package/cpp/ggml-cpu/amx/amx.h +8 -0
- package/cpp/ggml-cpu/amx/common.h +91 -0
- package/cpp/ggml-cpu/amx/mmq.cpp +2511 -0
- package/cpp/ggml-cpu/amx/mmq.h +10 -0
- package/cpp/ggml-cpu/arch/arm/cpu-feats.cpp +94 -0
- package/cpp/ggml-cpu/arch/arm/quants.c +4113 -0
- package/cpp/ggml-cpu/arch/arm/repack.cpp +2162 -0
- package/cpp/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- package/cpp/ggml-cpu/arch/x86/quants.c +4310 -0
- package/cpp/ggml-cpu/arch/x86/repack.cpp +3284 -0
- package/cpp/ggml-cpu/arch-fallback.h +184 -0
- package/cpp/ggml-cpu/binary-ops.cpp +158 -0
- package/cpp/ggml-cpu/binary-ops.h +16 -0
- package/cpp/ggml-cpu/common.h +72 -0
- package/cpp/ggml-cpu/ggml-cpu-impl.h +511 -0
- package/cpp/ggml-cpu/ggml-cpu.c +3473 -0
- package/cpp/ggml-cpu/ggml-cpu.cpp +671 -0
- package/cpp/ggml-cpu/ops.cpp +9085 -0
- package/cpp/ggml-cpu/ops.h +111 -0
- package/cpp/ggml-cpu/quants.c +1157 -0
- package/cpp/ggml-cpu/quants.h +89 -0
- package/cpp/ggml-cpu/repack.cpp +1570 -0
- package/cpp/ggml-cpu/repack.h +98 -0
- package/cpp/ggml-cpu/simd-mappings.h +1006 -0
- package/cpp/ggml-cpu/traits.cpp +36 -0
- package/cpp/ggml-cpu/traits.h +38 -0
- package/cpp/ggml-cpu/unary-ops.cpp +186 -0
- package/cpp/ggml-cpu/unary-ops.h +28 -0
- package/cpp/ggml-cpu/vec.cpp +321 -0
- package/cpp/ggml-cpu/vec.h +973 -0
- package/cpp/ggml-cpu.h +143 -0
- package/cpp/ggml-impl.h +525 -168
- package/cpp/ggml-metal-impl.h +622 -0
- package/cpp/ggml-metal.h +16 -14
- package/cpp/ggml-metal.m +5289 -1859
- package/cpp/ggml-opt.cpp +1037 -0
- package/cpp/ggml-opt.h +237 -0
- package/cpp/ggml-quants.c +2916 -6877
- package/cpp/ggml-quants.h +87 -249
- package/cpp/ggml-threading.cpp +12 -0
- package/cpp/ggml-threading.h +14 -0
- package/cpp/ggml-whisper-sim.metallib +0 -0
- package/cpp/ggml-whisper.metallib +0 -0
- package/cpp/ggml.c +3293 -16770
- package/cpp/ggml.h +778 -835
- package/cpp/gguf.cpp +1347 -0
- package/cpp/gguf.h +202 -0
- package/cpp/rn-whisper.cpp +84 -0
- package/cpp/rn-whisper.h +2 -0
- package/cpp/whisper-arch.h +197 -0
- package/cpp/whisper.cpp +3240 -944
- package/cpp/whisper.h +144 -31
- package/ios/CMakeLists.txt +95 -0
- package/ios/RNWhisper.h +5 -0
- package/ios/RNWhisper.mm +124 -37
- package/ios/RNWhisperAudioUtils.h +1 -0
- package/ios/RNWhisperAudioUtils.m +24 -13
- package/ios/RNWhisperContext.h +8 -2
- package/ios/RNWhisperContext.mm +42 -8
- package/ios/rnwhisper.xcframework/Info.plist +74 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
- package/jest/mock.js +14 -1
- package/lib/commonjs/NativeRNWhisper.js.map +1 -1
- package/lib/commonjs/index.js +48 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/NativeRNWhisper.js.map +1 -1
- package/lib/module/index.js +48 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/NativeRNWhisper.d.ts +6 -3
- package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +25 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +15 -10
- package/src/NativeRNWhisper.ts +12 -3
- package/src/index.ts +63 -24
- package/src/version.json +1 -1
- package/whisper-rn.podspec +18 -18
- package/cpp/README.md +0 -4
- package/cpp/ggml-backend.c +0 -1718
- package/cpp/ggml-metal-whisper.metal +0 -5820
package/ios/RNWhisperContext.h
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#ifdef __cplusplus
|
|
2
|
+
#if RNWHISPER_BUILD_FROM_SOURCE
|
|
2
3
|
#import "whisper.h"
|
|
3
4
|
#import "rn-whisper.h"
|
|
5
|
+
#else
|
|
6
|
+
#import <rnwhisper/whisper.h>
|
|
7
|
+
#import <rnwhisper/rn-whisper.h>
|
|
8
|
+
#endif
|
|
4
9
|
#endif
|
|
5
10
|
|
|
6
11
|
#import <AVFoundation/AVFoundation.h>
|
|
@@ -42,7 +47,7 @@ typedef struct {
|
|
|
42
47
|
bool isMetalEnabled;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
+ (instancetype)initWithModelPath:(NSString *)modelPath contextId:(int)contextId noCoreML:(BOOL)noCoreML noMetal:(BOOL)noMetal;
|
|
50
|
+
+ (instancetype)initWithModelPath:(NSString *)modelPath contextId:(int)contextId noCoreML:(BOOL)noCoreML noMetal:(BOOL)noMetal useFlashAttn:(BOOL)useFlashAttn;
|
|
46
51
|
- (bool)isMetalEnabled;
|
|
47
52
|
- (NSString *)reasonNoMetal;
|
|
48
53
|
- (struct whisper_context *)getContext;
|
|
@@ -50,7 +55,7 @@ typedef struct {
|
|
|
50
55
|
- (OSStatus)transcribeRealtime:(int)jobId
|
|
51
56
|
options:(NSDictionary *)options
|
|
52
57
|
onTranscribe:(void (^)(int, NSString *, NSDictionary *))onTranscribe;
|
|
53
|
-
- (void)
|
|
58
|
+
- (void)transcribeData:(int)jobId
|
|
54
59
|
audioData:(float *)audioData
|
|
55
60
|
audioDataCount:(int)audioDataCount
|
|
56
61
|
options:(NSDictionary *)options
|
|
@@ -63,6 +68,7 @@ typedef struct {
|
|
|
63
68
|
- (bool)isTranscribing;
|
|
64
69
|
- (bool)isStoppedByAction;
|
|
65
70
|
- (NSMutableDictionary *)getTextSegments;
|
|
71
|
+
- (NSString *)bench:(int)maxThreads;
|
|
66
72
|
- (void)invalidate;
|
|
67
73
|
|
|
68
74
|
@end
|
package/ios/RNWhisperContext.mm
CHANGED
|
@@ -10,12 +10,18 @@
|
|
|
10
10
|
contextId:(int)contextId
|
|
11
11
|
noCoreML:(BOOL)noCoreML
|
|
12
12
|
noMetal:(BOOL)noMetal
|
|
13
|
+
useFlashAttn:(BOOL)useFlashAttn
|
|
13
14
|
{
|
|
14
15
|
RNWhisperContext *context = [[RNWhisperContext alloc] init];
|
|
15
16
|
context->contextId = contextId;
|
|
16
17
|
struct whisper_context_params cparams;
|
|
17
18
|
NSString *reasonNoMetal = @"";
|
|
18
19
|
cparams.use_gpu = !noMetal;
|
|
20
|
+
cparams.flash_attn = useFlashAttn;
|
|
21
|
+
|
|
22
|
+
// TODO: Expose dtw_token_timestamps and dtw_aheads_preset
|
|
23
|
+
cparams.dtw_token_timestamps = false;
|
|
24
|
+
// cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
|
|
19
25
|
|
|
20
26
|
cparams.use_coreml = !noCoreML;
|
|
21
27
|
#ifndef WHISPER_USE_COREML
|
|
@@ -353,9 +359,10 @@ void AudioInputCallback(void * inUserData,
|
|
|
353
359
|
struct rnwhisper_segments_callback_data {
|
|
354
360
|
void (^onNewSegments)(NSDictionary *);
|
|
355
361
|
int total_n_new;
|
|
362
|
+
bool tdrzEnable;
|
|
356
363
|
};
|
|
357
364
|
|
|
358
|
-
- (void)
|
|
365
|
+
- (void)transcribeData:(int)jobId
|
|
359
366
|
audioData:(float *)audioData
|
|
360
367
|
audioDataCount:(int)audioDataCount
|
|
361
368
|
options:(NSDictionary *)options
|
|
@@ -386,12 +393,18 @@ struct rnwhisper_segments_callback_data {
|
|
|
386
393
|
NSMutableArray *segments = [[NSMutableArray alloc] init];
|
|
387
394
|
for (int i = data->total_n_new - n_new; i < data->total_n_new; i++) {
|
|
388
395
|
const char * text_cur = whisper_full_get_segment_text(ctx, i);
|
|
389
|
-
|
|
396
|
+
NSMutableString *mutable_ns_text = [NSMutableString stringWithUTF8String:text_cur];
|
|
397
|
+
|
|
398
|
+
if (data->tdrzEnable && whisper_full_get_segment_speaker_turn_next(ctx, i)) {
|
|
399
|
+
[mutable_ns_text appendString:@" [SPEAKER_TURN]"];
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
text = [text stringByAppendingString:mutable_ns_text];
|
|
390
403
|
|
|
391
404
|
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
|
|
392
405
|
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
|
393
406
|
NSDictionary *segment = @{
|
|
394
|
-
@"text": [NSString
|
|
407
|
+
@"text": [NSString stringWithString:mutable_ns_text],
|
|
395
408
|
@"t0": [NSNumber numberWithLongLong:t0],
|
|
396
409
|
@"t1": [NSNumber numberWithLongLong:t1]
|
|
397
410
|
};
|
|
@@ -409,7 +422,8 @@ struct rnwhisper_segments_callback_data {
|
|
|
409
422
|
};
|
|
410
423
|
struct rnwhisper_segments_callback_data user_data = {
|
|
411
424
|
.onNewSegments = onNewSegments,
|
|
412
|
-
.
|
|
425
|
+
.tdrzEnable = options[@"tdrzEnable"] && [options[@"tdrzEnable"] boolValue],
|
|
426
|
+
.total_n_new = 0,
|
|
413
427
|
};
|
|
414
428
|
params.new_segment_callback_user_data = &user_data;
|
|
415
429
|
}
|
|
@@ -418,6 +432,7 @@ struct rnwhisper_segments_callback_data {
|
|
|
418
432
|
self->recordState.job = job;
|
|
419
433
|
int code = [self fullTranscribe:job audioData:audioData audioDataCount:audioDataCount];
|
|
420
434
|
rnwhisper::job_remove(jobId);
|
|
435
|
+
self->recordState.job = nullptr;
|
|
421
436
|
self->recordState.isTranscribing = false;
|
|
422
437
|
onEnd(code);
|
|
423
438
|
});
|
|
@@ -432,7 +447,7 @@ struct rnwhisper_segments_callback_data {
|
|
|
432
447
|
}
|
|
433
448
|
|
|
434
449
|
- (void)stopTranscribe:(int)jobId {
|
|
435
|
-
if (self->recordState.job) self->recordState.job->abort();
|
|
450
|
+
if (self->recordState.job != nullptr) self->recordState.job->abort();
|
|
436
451
|
if (self->recordState.isRealtime && self->recordState.isCapturing) {
|
|
437
452
|
[self stopAudio];
|
|
438
453
|
if (!self->recordState.isTranscribing) {
|
|
@@ -469,7 +484,6 @@ struct rnwhisper_segments_callback_data {
|
|
|
469
484
|
params.print_progress = false;
|
|
470
485
|
params.print_timestamps = false;
|
|
471
486
|
params.print_special = false;
|
|
472
|
-
params.speed_up = options[@"speedUp"] != nil ? [options[@"speedUp"] boolValue] : false;
|
|
473
487
|
params.translate = options[@"translate"] != nil ? [options[@"translate"] boolValue] : false;
|
|
474
488
|
params.language = options[@"language"] != nil ? strdup([options[@"language"] UTF8String]) : "auto";
|
|
475
489
|
params.n_threads = n_threads > 0 ? n_threads : default_n_threads;
|
|
@@ -481,6 +495,7 @@ struct rnwhisper_segments_callback_data {
|
|
|
481
495
|
params.max_len = [options[@"maxLen"] intValue];
|
|
482
496
|
}
|
|
483
497
|
params.token_timestamps = options[@"tokenTimestamps"] != nil ? [options[@"tokenTimestamps"] boolValue] : false;
|
|
498
|
+
params.tdrz_enable = options[@"tdrzEnable"] != nil ? [options[@"tdrzEnable"] boolValue] : false;
|
|
484
499
|
|
|
485
500
|
if (options[@"bestOf"] != nil) {
|
|
486
501
|
params.greedy.best_of = [options[@"bestOf"] intValue];
|
|
@@ -530,12 +545,21 @@ struct rnwhisper_segments_callback_data {
|
|
|
530
545
|
NSMutableArray *segments = [[NSMutableArray alloc] init];
|
|
531
546
|
for (int i = 0; i < n_segments; i++) {
|
|
532
547
|
const char * text_cur = whisper_full_get_segment_text(self->ctx, i);
|
|
533
|
-
|
|
548
|
+
NSMutableString *mutable_ns_text = [NSMutableString stringWithUTF8String:text_cur];
|
|
549
|
+
|
|
550
|
+
// Simplified condition
|
|
551
|
+
if (self->recordState.options[@"tdrzEnable"] &&
|
|
552
|
+
[self->recordState.options[@"tdrzEnable"] boolValue] &&
|
|
553
|
+
whisper_full_get_segment_speaker_turn_next(self->ctx, i)) {
|
|
554
|
+
[mutable_ns_text appendString:@" [SPEAKER_TURN]"];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
text = [text stringByAppendingString:mutable_ns_text];
|
|
534
558
|
|
|
535
559
|
const int64_t t0 = whisper_full_get_segment_t0(self->ctx, i);
|
|
536
560
|
const int64_t t1 = whisper_full_get_segment_t1(self->ctx, i);
|
|
537
561
|
NSDictionary *segment = @{
|
|
538
|
-
@"text": [NSString
|
|
562
|
+
@"text": [NSString stringWithString:mutable_ns_text],
|
|
539
563
|
@"t0": [NSNumber numberWithLongLong:t0],
|
|
540
564
|
@"t1": [NSNumber numberWithLongLong:t1]
|
|
541
565
|
};
|
|
@@ -547,6 +571,16 @@ struct rnwhisper_segments_callback_data {
|
|
|
547
571
|
return result;
|
|
548
572
|
}
|
|
549
573
|
|
|
574
|
+
- (NSString *)bench:(int)maxThreads {
|
|
575
|
+
const int n_threads = maxThreads > 0 ? maxThreads : 0;
|
|
576
|
+
|
|
577
|
+
const int max_threads = (int) [[NSProcessInfo processInfo] processorCount];
|
|
578
|
+
// Use 2 threads by default on 4-core devices, 4 threads on more cores
|
|
579
|
+
const int default_n_threads = max_threads == 4 ? 2 : MIN(4, max_threads);
|
|
580
|
+
NSString *result = [NSString stringWithUTF8String:rnwhisper::bench(self->ctx, n_threads).c_str()];
|
|
581
|
+
return result;
|
|
582
|
+
}
|
|
583
|
+
|
|
550
584
|
- (void)invalidate {
|
|
551
585
|
[self stopCurrentTranscribe];
|
|
552
586
|
whisper_free(self->ctx);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>LibraryIdentifier</key>
|
|
9
|
+
<string>ios-arm64</string>
|
|
10
|
+
<key>LibraryPath</key>
|
|
11
|
+
<string>rnwhisper.framework</string>
|
|
12
|
+
<key>SupportedArchitectures</key>
|
|
13
|
+
<array>
|
|
14
|
+
<string>arm64</string>
|
|
15
|
+
</array>
|
|
16
|
+
<key>SupportedPlatform</key>
|
|
17
|
+
<string>ios</string>
|
|
18
|
+
</dict>
|
|
19
|
+
<dict>
|
|
20
|
+
<key>LibraryIdentifier</key>
|
|
21
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
22
|
+
<key>LibraryPath</key>
|
|
23
|
+
<string>rnwhisper.framework</string>
|
|
24
|
+
<key>SupportedArchitectures</key>
|
|
25
|
+
<array>
|
|
26
|
+
<string>arm64</string>
|
|
27
|
+
<string>x86_64</string>
|
|
28
|
+
</array>
|
|
29
|
+
<key>SupportedPlatform</key>
|
|
30
|
+
<string>ios</string>
|
|
31
|
+
<key>SupportedPlatformVariant</key>
|
|
32
|
+
<string>simulator</string>
|
|
33
|
+
</dict>
|
|
34
|
+
<dict>
|
|
35
|
+
<key>LibraryIdentifier</key>
|
|
36
|
+
<string>tvos-arm64</string>
|
|
37
|
+
<key>LibraryPath</key>
|
|
38
|
+
<string>rnwhisper.framework</string>
|
|
39
|
+
<key>SupportedArchitectures</key>
|
|
40
|
+
<array>
|
|
41
|
+
<string>arm64</string>
|
|
42
|
+
</array>
|
|
43
|
+
<key>SupportedPlatform</key>
|
|
44
|
+
<string>tvos</string>
|
|
45
|
+
</dict>
|
|
46
|
+
<dict>
|
|
47
|
+
<key>LibraryIdentifier</key>
|
|
48
|
+
<string>tvos-arm64_x86_64-simulator</string>
|
|
49
|
+
<key>LibraryPath</key>
|
|
50
|
+
<string>rnwhisper.framework</string>
|
|
51
|
+
<key>SupportedArchitectures</key>
|
|
52
|
+
<array>
|
|
53
|
+
<string>arm64</string>
|
|
54
|
+
<string>x86_64</string>
|
|
55
|
+
</array>
|
|
56
|
+
<key>SupportedPlatform</key>
|
|
57
|
+
<string>tvos</string>
|
|
58
|
+
<key>SupportedPlatformVariant</key>
|
|
59
|
+
<string>simulator</string>
|
|
60
|
+
</dict>
|
|
61
|
+
|
|
62
|
+
</array>
|
|
63
|
+
<key>CFBundlePackageType</key>
|
|
64
|
+
<string>XFWK</string>
|
|
65
|
+
<key>XCFrameworkFormatVersion</key>
|
|
66
|
+
<string>1.0</string>
|
|
67
|
+
<key>CFBundleVersion</key>
|
|
68
|
+
<string>1.0.0</string>
|
|
69
|
+
<key>CFBundleShortVersionString</key>
|
|
70
|
+
<string>1.0.0</string>
|
|
71
|
+
<key>CFBundleIdentifier</key>
|
|
72
|
+
<string>com.rnwhisper</string>
|
|
73
|
+
</dict>
|
|
74
|
+
</plist>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "ggml.h"
|
|
4
|
+
|
|
5
|
+
#ifdef __cplusplus
|
|
6
|
+
extern "C" {
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
typedef struct wsp_ggml_backend_buffer_type * wsp_ggml_backend_buffer_type_t;
|
|
10
|
+
typedef struct wsp_ggml_backend_buffer * wsp_ggml_backend_buffer_t;
|
|
11
|
+
typedef struct wsp_ggml_backend * wsp_ggml_backend_t;
|
|
12
|
+
|
|
13
|
+
// Tensor allocator
|
|
14
|
+
struct wsp_ggml_tallocr {
|
|
15
|
+
wsp_ggml_backend_buffer_t buffer;
|
|
16
|
+
void * base;
|
|
17
|
+
size_t alignment;
|
|
18
|
+
size_t offset;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
WSP_GGML_API struct wsp_ggml_tallocr wsp_ggml_tallocr_new(wsp_ggml_backend_buffer_t buffer);
|
|
22
|
+
WSP_GGML_API enum wsp_ggml_status wsp_ggml_tallocr_alloc(struct wsp_ggml_tallocr * talloc, struct wsp_ggml_tensor * tensor);
|
|
23
|
+
|
|
24
|
+
// Graph allocator
|
|
25
|
+
/*
|
|
26
|
+
Example usage:
|
|
27
|
+
wsp_ggml_gallocr_t galloc = wsp_ggml_gallocr_new(wsp_ggml_backend_cpu_buffer_type());
|
|
28
|
+
|
|
29
|
+
// optional: create a worst-case graph and reserve the buffers to avoid reallocations
|
|
30
|
+
wsp_ggml_gallocr_reserve(galloc, build_graph(max_batch));
|
|
31
|
+
|
|
32
|
+
// allocate the graph
|
|
33
|
+
struct wsp_ggml_cgraph * graph = build_graph(batch);
|
|
34
|
+
wsp_ggml_gallocr_alloc_graph(galloc, graph);
|
|
35
|
+
|
|
36
|
+
printf("compute buffer size: %zu bytes\n", wsp_ggml_gallocr_get_buffer_size(galloc, 0));
|
|
37
|
+
|
|
38
|
+
// evaluate the graph
|
|
39
|
+
wsp_ggml_backend_graph_compute(backend, graph);
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// special tensor flags for use with the graph allocator:
|
|
43
|
+
// wsp_ggml_set_input(): all input tensors are allocated at the beginning of the graph in non-overlapping addresses
|
|
44
|
+
// wsp_ggml_set_output(): output tensors are never freed and never overwritten
|
|
45
|
+
|
|
46
|
+
typedef struct wsp_ggml_gallocr * wsp_ggml_gallocr_t;
|
|
47
|
+
|
|
48
|
+
WSP_GGML_API wsp_ggml_gallocr_t wsp_ggml_gallocr_new(wsp_ggml_backend_buffer_type_t buft);
|
|
49
|
+
WSP_GGML_API wsp_ggml_gallocr_t wsp_ggml_gallocr_new_n(wsp_ggml_backend_buffer_type_t * bufts, int n_bufs);
|
|
50
|
+
WSP_GGML_API void wsp_ggml_gallocr_free(wsp_ggml_gallocr_t galloc);
|
|
51
|
+
|
|
52
|
+
// pre-allocate buffers from a measure graph - does not allocate or modify the graph
|
|
53
|
+
// call with a worst-case graph to avoid buffer reallocations
|
|
54
|
+
// not strictly required for single buffer usage: wsp_ggml_gallocr_alloc_graph will reallocate the buffers automatically if needed
|
|
55
|
+
// returns false if the buffer allocation failed
|
|
56
|
+
WSP_GGML_API bool wsp_ggml_gallocr_reserve(wsp_ggml_gallocr_t galloc, struct wsp_ggml_cgraph * graph);
|
|
57
|
+
WSP_GGML_API bool wsp_ggml_gallocr_reserve_n(
|
|
58
|
+
wsp_ggml_gallocr_t galloc,
|
|
59
|
+
struct wsp_ggml_cgraph * graph,
|
|
60
|
+
const int * node_buffer_ids,
|
|
61
|
+
const int * leaf_buffer_ids);
|
|
62
|
+
|
|
63
|
+
// automatic reallocation if the topology changes when using a single buffer
|
|
64
|
+
// returns false if using multiple buffers and a re-allocation is needed (call wsp_ggml_gallocr_reserve_n first to set the node buffers)
|
|
65
|
+
WSP_GGML_API bool wsp_ggml_gallocr_alloc_graph(wsp_ggml_gallocr_t galloc, struct wsp_ggml_cgraph * graph);
|
|
66
|
+
|
|
67
|
+
WSP_GGML_API size_t wsp_ggml_gallocr_get_buffer_size(wsp_ggml_gallocr_t galloc, int buffer_id);
|
|
68
|
+
|
|
69
|
+
// Utils
|
|
70
|
+
// Create a buffer and allocate all the tensors in a wsp_ggml_context
|
|
71
|
+
WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_backend_alloc_ctx_tensors_from_buft(struct wsp_ggml_context * ctx, wsp_ggml_backend_buffer_type_t buft);
|
|
72
|
+
WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_backend_alloc_ctx_tensors(struct wsp_ggml_context * ctx, wsp_ggml_backend_t backend);
|
|
73
|
+
|
|
74
|
+
#ifdef __cplusplus
|
|
75
|
+
}
|
|
76
|
+
#endif
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// ggml-backend internal header
|
|
4
|
+
|
|
5
|
+
#include "ggml-backend.h"
|
|
6
|
+
|
|
7
|
+
#ifdef __cplusplus
|
|
8
|
+
extern "C" {
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
#define WSP_GGML_BACKEND_API_VERSION 1
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
// Backend buffer type
|
|
15
|
+
//
|
|
16
|
+
|
|
17
|
+
struct wsp_ggml_backend_buffer_type_i {
|
|
18
|
+
const char * (*get_name) (wsp_ggml_backend_buffer_type_t buft);
|
|
19
|
+
// allocate a buffer of this type
|
|
20
|
+
wsp_ggml_backend_buffer_t (*alloc_buffer) (wsp_ggml_backend_buffer_type_t buft, size_t size);
|
|
21
|
+
// tensor alignment
|
|
22
|
+
size_t (*get_alignment) (wsp_ggml_backend_buffer_type_t buft);
|
|
23
|
+
// (optional) max buffer size that can be allocated (defaults to SIZE_MAX)
|
|
24
|
+
size_t (*get_max_size) (wsp_ggml_backend_buffer_type_t buft);
|
|
25
|
+
// (optional) data size needed to allocate the tensor, including padding (defaults to wsp_ggml_nbytes)
|
|
26
|
+
size_t (*get_alloc_size)(wsp_ggml_backend_buffer_type_t buft, const struct wsp_ggml_tensor * tensor);
|
|
27
|
+
// (optional) check if tensor data is in host memory and uses standard ggml tensor layout (defaults to false)
|
|
28
|
+
bool (*is_host) (wsp_ggml_backend_buffer_type_t buft);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
struct wsp_ggml_backend_buffer_type {
|
|
32
|
+
struct wsp_ggml_backend_buffer_type_i iface;
|
|
33
|
+
wsp_ggml_backend_dev_t device;
|
|
34
|
+
void * context;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// Backend buffer
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
struct wsp_ggml_backend_buffer_i {
|
|
42
|
+
// (optional) free the buffer
|
|
43
|
+
void (*free_buffer) (wsp_ggml_backend_buffer_t buffer);
|
|
44
|
+
// base address of the buffer
|
|
45
|
+
void * (*get_base) (wsp_ggml_backend_buffer_t buffer);
|
|
46
|
+
// (optional) initialize a tensor in the buffer (eg. add tensor extras)
|
|
47
|
+
enum wsp_ggml_status (*init_tensor)(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor);
|
|
48
|
+
// tensor data access
|
|
49
|
+
void (*memset_tensor)(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor, uint8_t value, size_t offset, size_t size);
|
|
50
|
+
void (*set_tensor) (wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size);
|
|
51
|
+
void (*get_tensor) (wsp_ggml_backend_buffer_t buffer, const struct wsp_ggml_tensor * tensor, void * data, size_t offset, size_t size);
|
|
52
|
+
// (optional) tensor copy: dst is in the buffer, src may be in any buffer, including buffers from a different backend (return false if not supported)
|
|
53
|
+
bool (*cpy_tensor) (wsp_ggml_backend_buffer_t buffer, const struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
|
|
54
|
+
// clear the entire buffer
|
|
55
|
+
void (*clear) (wsp_ggml_backend_buffer_t buffer, uint8_t value);
|
|
56
|
+
// (optional) reset any internal state due to tensor initialization, such as tensor extras
|
|
57
|
+
void (*reset) (wsp_ggml_backend_buffer_t buffer);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
struct wsp_ggml_backend_buffer {
|
|
61
|
+
struct wsp_ggml_backend_buffer_i iface;
|
|
62
|
+
wsp_ggml_backend_buffer_type_t buft;
|
|
63
|
+
void * context;
|
|
64
|
+
size_t size;
|
|
65
|
+
enum wsp_ggml_backend_buffer_usage usage;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
WSP_GGML_API wsp_ggml_backend_buffer_t wsp_ggml_backend_buffer_init(
|
|
69
|
+
wsp_ggml_backend_buffer_type_t buft,
|
|
70
|
+
struct wsp_ggml_backend_buffer_i iface,
|
|
71
|
+
void * context,
|
|
72
|
+
size_t size);
|
|
73
|
+
|
|
74
|
+
// do not use directly, use wsp_ggml_backend_tensor_copy instead
|
|
75
|
+
WSP_GGML_API bool wsp_ggml_backend_buffer_copy_tensor(const struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
|
|
76
|
+
|
|
77
|
+
// multi-buffer
|
|
78
|
+
// buffer that contains a collection of buffers
|
|
79
|
+
WSP_GGML_API wsp_ggml_backend_buffer_t wsp_ggml_backend_multi_buffer_alloc_buffer(wsp_ggml_backend_buffer_t * buffers, size_t n_buffers);
|
|
80
|
+
WSP_GGML_API bool wsp_ggml_backend_buffer_is_multi_buffer(wsp_ggml_backend_buffer_t buffer);
|
|
81
|
+
WSP_GGML_API void wsp_ggml_backend_multi_buffer_set_usage(wsp_ggml_backend_buffer_t buffer, enum wsp_ggml_backend_buffer_usage usage);
|
|
82
|
+
|
|
83
|
+
//
|
|
84
|
+
// Backend (stream)
|
|
85
|
+
//
|
|
86
|
+
|
|
87
|
+
struct wsp_ggml_backend_i {
|
|
88
|
+
const char * (*get_name)(wsp_ggml_backend_t backend);
|
|
89
|
+
|
|
90
|
+
void (*free)(wsp_ggml_backend_t backend);
|
|
91
|
+
|
|
92
|
+
// (optional) asynchronous tensor data access
|
|
93
|
+
void (*set_tensor_async)(wsp_ggml_backend_t backend, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size);
|
|
94
|
+
void (*get_tensor_async)(wsp_ggml_backend_t backend, const struct wsp_ggml_tensor * tensor, void * data, size_t offset, size_t size);
|
|
95
|
+
bool (*cpy_tensor_async)(wsp_ggml_backend_t backend_src, wsp_ggml_backend_t backend_dst, const struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
|
|
96
|
+
|
|
97
|
+
// (optional) complete all pending operations (required if the backend supports async operations)
|
|
98
|
+
void (*synchronize)(wsp_ggml_backend_t backend);
|
|
99
|
+
|
|
100
|
+
// (optional) graph plans (not used currently)
|
|
101
|
+
// compute graph with a plan
|
|
102
|
+
wsp_ggml_backend_graph_plan_t (*graph_plan_create) (wsp_ggml_backend_t backend, const struct wsp_ggml_cgraph * cgraph);
|
|
103
|
+
void (*graph_plan_free) (wsp_ggml_backend_t backend, wsp_ggml_backend_graph_plan_t plan);
|
|
104
|
+
// update the plan with a new graph - this should be faster than creating a new plan when the graph has the same topology
|
|
105
|
+
void (*graph_plan_update) (wsp_ggml_backend_t backend, wsp_ggml_backend_graph_plan_t plan, const struct wsp_ggml_cgraph * cgraph);
|
|
106
|
+
// compute the graph with the plan
|
|
107
|
+
enum wsp_ggml_status (*graph_plan_compute)(wsp_ggml_backend_t backend, wsp_ggml_backend_graph_plan_t plan);
|
|
108
|
+
|
|
109
|
+
// compute graph (always async if supported by the backend)
|
|
110
|
+
enum wsp_ggml_status (*graph_compute) (wsp_ggml_backend_t backend, struct wsp_ggml_cgraph * cgraph);
|
|
111
|
+
|
|
112
|
+
// (optional) event synchronization
|
|
113
|
+
// record an event on this stream
|
|
114
|
+
void (*event_record)(wsp_ggml_backend_t backend, wsp_ggml_backend_event_t event);
|
|
115
|
+
// wait for an event on on a different stream
|
|
116
|
+
void (*event_wait) (wsp_ggml_backend_t backend, wsp_ggml_backend_event_t event);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
struct wsp_ggml_backend {
|
|
120
|
+
wsp_ggml_guid_t guid;
|
|
121
|
+
struct wsp_ggml_backend_i iface;
|
|
122
|
+
wsp_ggml_backend_dev_t device;
|
|
123
|
+
void * context;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
struct wsp_ggml_backend_event {
|
|
127
|
+
struct wsp_ggml_backend_device * device;
|
|
128
|
+
void * context;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//
|
|
132
|
+
// Backend device
|
|
133
|
+
//
|
|
134
|
+
|
|
135
|
+
// Note: if additional properties are needed, we should add a struct with all of them
|
|
136
|
+
// the current functions to obtain the properties can remain, since they are more convenient for often used properties
|
|
137
|
+
struct wsp_ggml_backend_device_i {
|
|
138
|
+
// device name: short identifier for this device, such as "CPU" or "CUDA0"
|
|
139
|
+
const char * (*get_name)(wsp_ggml_backend_dev_t dev);
|
|
140
|
+
|
|
141
|
+
// device description: short informative description of the device, could be the model name
|
|
142
|
+
const char * (*get_description)(wsp_ggml_backend_dev_t dev);
|
|
143
|
+
|
|
144
|
+
// device memory in bytes
|
|
145
|
+
void (*get_memory)(wsp_ggml_backend_dev_t dev, size_t * free, size_t * total);
|
|
146
|
+
|
|
147
|
+
// device type
|
|
148
|
+
enum wsp_ggml_backend_dev_type (*get_type)(wsp_ggml_backend_dev_t dev);
|
|
149
|
+
|
|
150
|
+
// device properties
|
|
151
|
+
void (*get_props)(wsp_ggml_backend_dev_t dev, struct wsp_ggml_backend_dev_props * props);
|
|
152
|
+
|
|
153
|
+
// backend (stream) initialization
|
|
154
|
+
wsp_ggml_backend_t (*init_backend)(wsp_ggml_backend_dev_t dev, const char * params);
|
|
155
|
+
|
|
156
|
+
// preferred buffer type
|
|
157
|
+
wsp_ggml_backend_buffer_type_t (*get_buffer_type)(wsp_ggml_backend_dev_t dev);
|
|
158
|
+
|
|
159
|
+
// (optional) host buffer type (in system memory, typically this is a pinned memory buffer for faster transfers between host and device)
|
|
160
|
+
wsp_ggml_backend_buffer_type_t (*get_host_buffer_type)(wsp_ggml_backend_dev_t dev);
|
|
161
|
+
|
|
162
|
+
// (optional) buffer from pointer: create a buffer from a host pointer (useful for memory mapped models and importing data from other libraries)
|
|
163
|
+
wsp_ggml_backend_buffer_t (*buffer_from_host_ptr)(wsp_ggml_backend_dev_t dev, void * ptr, size_t size, size_t max_tensor_size);
|
|
164
|
+
|
|
165
|
+
// check if the backend can compute an operation
|
|
166
|
+
bool (*supports_op)(wsp_ggml_backend_dev_t dev, const struct wsp_ggml_tensor * op);
|
|
167
|
+
|
|
168
|
+
// check if the backend can use tensors allocated in a buffer type
|
|
169
|
+
bool (*supports_buft)(wsp_ggml_backend_dev_t dev, wsp_ggml_backend_buffer_type_t buft);
|
|
170
|
+
|
|
171
|
+
// (optional) check if the backend wants to run an operation, even if the weights are allocated in an incompatible buffer
|
|
172
|
+
// these should be expensive operations that may benefit from running on this backend instead of the CPU backend
|
|
173
|
+
bool (*offload_op)(wsp_ggml_backend_dev_t dev, const struct wsp_ggml_tensor * op);
|
|
174
|
+
|
|
175
|
+
// (optional) event synchronization
|
|
176
|
+
wsp_ggml_backend_event_t (*event_new) (wsp_ggml_backend_dev_t dev);
|
|
177
|
+
void (*event_free) (wsp_ggml_backend_dev_t dev, wsp_ggml_backend_event_t event);
|
|
178
|
+
void (*event_synchronize) (wsp_ggml_backend_dev_t dev, wsp_ggml_backend_event_t event);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
struct wsp_ggml_backend_device {
|
|
182
|
+
struct wsp_ggml_backend_device_i iface;
|
|
183
|
+
wsp_ggml_backend_reg_t reg;
|
|
184
|
+
void * context;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
//
|
|
188
|
+
// Backend (reg)
|
|
189
|
+
//
|
|
190
|
+
|
|
191
|
+
struct wsp_ggml_backend_reg_i {
|
|
192
|
+
const char * (*get_name)(wsp_ggml_backend_reg_t reg);
|
|
193
|
+
|
|
194
|
+
// enumerate available devices
|
|
195
|
+
size_t (*get_device_count)(wsp_ggml_backend_reg_t reg);
|
|
196
|
+
wsp_ggml_backend_dev_t (*get_device)(wsp_ggml_backend_reg_t reg, size_t index);
|
|
197
|
+
|
|
198
|
+
// (optional) get a pointer to a function in the backend
|
|
199
|
+
// backends can add custom functions that are not part of the standard ggml-backend interface
|
|
200
|
+
void * (*get_proc_address)(wsp_ggml_backend_reg_t reg, const char * name);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
struct wsp_ggml_backend_reg {
|
|
204
|
+
int api_version; // initialize to WSP_GGML_BACKEND_API_VERSION
|
|
205
|
+
struct wsp_ggml_backend_reg_i iface;
|
|
206
|
+
void * context;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// Internal backend registry API
|
|
210
|
+
WSP_GGML_API void wsp_ggml_backend_register(wsp_ggml_backend_reg_t reg);
|
|
211
|
+
|
|
212
|
+
// Add backend dynamic loading support to the backend
|
|
213
|
+
|
|
214
|
+
// Initialize the backend
|
|
215
|
+
typedef wsp_ggml_backend_reg_t (*wsp_ggml_backend_init_t)(void);
|
|
216
|
+
// Optional: obtain a score for the backend based on the system configuration
|
|
217
|
+
// Higher scores are preferred, 0 means the backend is not supported in the current system
|
|
218
|
+
typedef int (*wsp_ggml_backend_score_t)(void);
|
|
219
|
+
|
|
220
|
+
#ifdef WSP_GGML_BACKEND_DL
|
|
221
|
+
# ifdef __cplusplus
|
|
222
|
+
# define WSP_GGML_BACKEND_DL_IMPL(reg_fn) \
|
|
223
|
+
extern "C" { \
|
|
224
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_reg_t wsp_ggml_backend_init(void); \
|
|
225
|
+
} \
|
|
226
|
+
wsp_ggml_backend_reg_t wsp_ggml_backend_init(void) { \
|
|
227
|
+
return reg_fn(); \
|
|
228
|
+
}
|
|
229
|
+
# define WSP_GGML_BACKEND_DL_SCORE_IMPL(score_fn) \
|
|
230
|
+
extern "C" { \
|
|
231
|
+
WSP_GGML_BACKEND_API int wsp_ggml_backend_score(void); \
|
|
232
|
+
} \
|
|
233
|
+
int wsp_ggml_backend_score(void) { \
|
|
234
|
+
return score_fn(); \
|
|
235
|
+
}
|
|
236
|
+
# else
|
|
237
|
+
# define WSP_GGML_BACKEND_DL_IMPL(reg_fn) \
|
|
238
|
+
WSP_GGML_BACKEND_API wsp_ggml_backend_reg_t wsp_ggml_backend_init(void); \
|
|
239
|
+
wsp_ggml_backend_reg_t wsp_ggml_backend_init(void) { \
|
|
240
|
+
return reg_fn(); \
|
|
241
|
+
}
|
|
242
|
+
# define WSP_GGML_BACKEND_DL_SCORE_IMPL(score_fn) \
|
|
243
|
+
WSP_GGML_BACKEND_API int wsp_ggml_backend_score(void); \
|
|
244
|
+
int wsp_ggml_backend_score(void) { \
|
|
245
|
+
return score_fn(); \
|
|
246
|
+
}
|
|
247
|
+
# endif
|
|
248
|
+
#else
|
|
249
|
+
# define WSP_GGML_BACKEND_DL_IMPL(reg_fn)
|
|
250
|
+
# define WSP_GGML_BACKEND_DL_SCORE_IMPL(score_fn)
|
|
251
|
+
#endif
|
|
252
|
+
|
|
253
|
+
#ifdef __cplusplus
|
|
254
|
+
}
|
|
255
|
+
#endif
|