whisper.rn 0.5.3 → 0.5.5

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.
Files changed (102) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/com/rnwhisper/WhisperContext.java +5 -0
  3. package/android/src/main/jni.cpp +13 -0
  4. package/cpp/ggml-alloc.c +78 -26
  5. package/cpp/ggml-alloc.h +9 -0
  6. package/cpp/ggml-backend-impl.h +1 -1
  7. package/cpp/ggml-backend-reg.cpp +19 -3
  8. package/cpp/ggml-backend.cpp +72 -20
  9. package/cpp/ggml-backend.h +2 -1
  10. package/cpp/ggml-cpu/arch/arm/cpu-feats.cpp +4 -0
  11. package/cpp/ggml-cpu/arch/arm/repack.cpp +1004 -0
  12. package/cpp/ggml-cpu/arch/x86/repack.cpp +6 -6
  13. package/cpp/ggml-cpu/arch-fallback.h +50 -2
  14. package/cpp/ggml-cpu/ggml-cpu-impl.h +1 -1
  15. package/cpp/ggml-cpu/ggml-cpu.c +139 -58
  16. package/cpp/ggml-cpu/ggml-cpu.cpp +4 -0
  17. package/cpp/ggml-cpu/ops.cpp +170 -18
  18. package/cpp/ggml-cpu/ops.h +1 -0
  19. package/cpp/ggml-cpu/repack.cpp +531 -5
  20. package/cpp/ggml-cpu/repack.h +14 -0
  21. package/cpp/ggml-cpu/simd-mappings.h +16 -18
  22. package/cpp/ggml-cpu/vec.cpp +41 -1
  23. package/cpp/ggml-cpu/vec.h +241 -138
  24. package/cpp/ggml-cpu.h +1 -0
  25. package/cpp/ggml-impl.h +0 -4
  26. package/cpp/ggml-metal/ggml-metal-context.m +26 -16
  27. package/cpp/ggml-metal/ggml-metal-device.cpp +452 -371
  28. package/cpp/ggml-metal/ggml-metal-device.h +87 -65
  29. package/cpp/ggml-metal/ggml-metal-device.m +263 -104
  30. package/cpp/ggml-metal/ggml-metal-impl.h +58 -4
  31. package/cpp/ggml-metal/ggml-metal-ops.cpp +415 -98
  32. package/cpp/ggml-metal/ggml-metal-ops.h +4 -0
  33. package/cpp/ggml-metal/ggml-metal.cpp +6 -5
  34. package/cpp/ggml-metal/ggml-metal.metal +404 -34
  35. package/cpp/ggml.c +110 -31
  36. package/cpp/ggml.h +51 -12
  37. package/cpp/jsi/RNWhisperJSI.cpp +1 -0
  38. package/cpp/whisper.cpp +17 -4
  39. package/ios/CMakeLists.txt +21 -1
  40. package/ios/RNWhisperContext.mm +5 -0
  41. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  42. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  43. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  44. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  45. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  46. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +51 -12
  47. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Info.plist +0 -0
  48. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/ggml-metal.metal +404 -34
  49. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/rnwhisper +0 -0
  50. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  51. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  52. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  53. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  54. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  55. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +51 -12
  56. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  57. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +1 -1
  58. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/ggml-metal.metal +404 -34
  59. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  60. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  61. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  62. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  63. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  64. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  65. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +51 -12
  66. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Info.plist +0 -0
  67. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/ggml-metal.metal +404 -34
  68. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/rnwhisper +0 -0
  69. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +9 -0
  70. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +1 -1
  71. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +2 -1
  72. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -0
  73. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +0 -4
  74. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +51 -12
  75. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  76. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +1 -1
  77. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/ggml-metal.metal +404 -34
  78. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  79. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  80. package/lib/commonjs/jest-mock.js +2 -0
  81. package/lib/commonjs/jest-mock.js.map +1 -1
  82. package/lib/commonjs/realtime-transcription/RealtimeTranscriber.js +156 -12
  83. package/lib/commonjs/realtime-transcription/RealtimeTranscriber.js.map +1 -1
  84. package/lib/commonjs/version.json +1 -1
  85. package/lib/module/NativeRNWhisper.js.map +1 -1
  86. package/lib/module/jest-mock.js +2 -0
  87. package/lib/module/jest-mock.js.map +1 -1
  88. package/lib/module/realtime-transcription/RealtimeTranscriber.js +155 -12
  89. package/lib/module/realtime-transcription/RealtimeTranscriber.js.map +1 -1
  90. package/lib/module/version.json +1 -1
  91. package/lib/typescript/NativeRNWhisper.d.ts +1 -0
  92. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  93. package/lib/typescript/realtime-transcription/RealtimeTranscriber.d.ts +29 -0
  94. package/lib/typescript/realtime-transcription/RealtimeTranscriber.d.ts.map +1 -1
  95. package/lib/typescript/realtime-transcription/types.d.ts +7 -0
  96. package/lib/typescript/realtime-transcription/types.d.ts.map +1 -1
  97. package/package.json +1 -1
  98. package/src/NativeRNWhisper.ts +1 -0
  99. package/src/jest-mock.ts +2 -0
  100. package/src/realtime-transcription/RealtimeTranscriber.ts +179 -9
  101. package/src/realtime-transcription/types.ts +9 -0
  102. package/src/version.json +1 -1
@@ -24,9 +24,6 @@ struct wsp_ggml_metal_command_buffer {
24
24
  };
25
25
 
26
26
  struct wsp_ggml_metal {
27
- id<MTLDevice> device;
28
- id<MTLCommandQueue> queue; // currently a pointer to the device queue, but might become separate queue [TAG_QUEUE_PER_BACKEND]
29
-
30
27
  wsp_ggml_metal_device_t dev;
31
28
  wsp_ggml_metal_library_t lib;
32
29
 
@@ -91,15 +88,15 @@ wsp_ggml_metal_t wsp_ggml_metal_init(wsp_ggml_metal_device_t dev) {
91
88
  // init context
92
89
  wsp_ggml_metal_t res = calloc(1, sizeof(struct wsp_ggml_metal));
93
90
 
94
- res->device = wsp_ggml_metal_device_get_obj(dev);
91
+ id<MTLDevice> device = wsp_ggml_metal_device_get_obj(dev);
95
92
 
96
- WSP_GGML_LOG_INFO("%s: picking default device: %s\n", __func__, [[res->device name] UTF8String]);
93
+ WSP_GGML_LOG_INFO("%s: picking default device: %s\n", __func__, [[device name] UTF8String]);
97
94
 
98
95
  // TODO: would it be better to have one queue for the backend and one queue for the device?
99
96
  // the graph encoders and async ops would use the backend queue while the sync ops would use the device queue?
100
97
  //res->queue = [device newCommandQueue]; [TAG_QUEUE_PER_BACKEND]
101
- res->queue = wsp_ggml_metal_device_get_queue(dev);
102
- if (res->queue == nil) {
98
+ id<MTLCommandQueue> queue = wsp_ggml_metal_device_get_queue(dev);
99
+ if (queue == nil) {
103
100
  WSP_GGML_LOG_ERROR("%s: error: failed to create command queue\n", __func__);
104
101
  return NULL;
105
102
  }
@@ -274,7 +271,8 @@ static struct wsp_ggml_metal_buffer_id wsp_ggml_metal_get_buffer_id(const struct
274
271
  void wsp_ggml_metal_set_tensor_async(wsp_ggml_metal_t ctx, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size) {
275
272
  @autoreleasepool {
276
273
  // wrap the source data into a Metal buffer
277
- id<MTLBuffer> buf_src = [ctx->device newBufferWithBytes:data
274
+ id<MTLDevice> device = wsp_ggml_metal_device_get_obj(ctx->dev);
275
+ id<MTLBuffer> buf_src = [device newBufferWithBytes:data
278
276
  length:size
279
277
  options:MTLResourceStorageModeShared];
280
278
 
@@ -289,7 +287,8 @@ void wsp_ggml_metal_set_tensor_async(wsp_ggml_metal_t ctx, struct wsp_ggml_tenso
289
287
 
290
288
  // queue the copy operation into the queue of the Metal context
291
289
  // this will be queued at the end, after any currently ongoing GPU operations
292
- id<MTLCommandBuffer> cmd_buf = [ctx->queue commandBuffer];
290
+ id<MTLCommandQueue> queue = wsp_ggml_metal_device_get_queue(ctx->dev);
291
+ id<MTLCommandBuffer> cmd_buf = [queue commandBuffer];
293
292
  id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
294
293
 
295
294
  [encoder copyFromBuffer:buf_src
@@ -315,7 +314,8 @@ void wsp_ggml_metal_set_tensor_async(wsp_ggml_metal_t ctx, struct wsp_ggml_tenso
315
314
 
316
315
  void wsp_ggml_metal_get_tensor_async(wsp_ggml_metal_t ctx, const struct wsp_ggml_tensor * tensor, void * data, size_t offset, size_t size) {
317
316
  @autoreleasepool {
318
- id<MTLBuffer> buf_dst = [ctx->device newBufferWithBytesNoCopy:data
317
+ id<MTLDevice> device = wsp_ggml_metal_device_get_obj(ctx->dev);
318
+ id<MTLBuffer> buf_dst = [device newBufferWithBytesNoCopy:data
319
319
  length:size
320
320
  options:MTLResourceStorageModeShared
321
321
  deallocator:nil];
@@ -331,7 +331,8 @@ void wsp_ggml_metal_get_tensor_async(wsp_ggml_metal_t ctx, const struct wsp_ggml
331
331
 
332
332
  // queue the copy operation into the queue of the Metal context
333
333
  // this will be queued at the end, after any currently ongoing GPU operations
334
- id<MTLCommandBuffer> cmd_buf = [ctx->queue commandBuffer];
334
+ id<MTLCommandQueue> queue = wsp_ggml_metal_device_get_queue(ctx->dev);
335
+ id<MTLCommandBuffer> cmd_buf = [queue commandBuffer];
335
336
  id<MTLBlitCommandEncoder> encoder = [cmd_buf blitCommandEncoder];
336
337
 
337
338
  [encoder copyFromBuffer:bid_src.metal
@@ -362,6 +363,9 @@ enum wsp_ggml_status wsp_ggml_metal_graph_compute(wsp_ggml_metal_t ctx, struct w
362
363
  // number of threads in addition to the main thread
363
364
  const int n_cb = ctx->n_cb;
364
365
 
366
+ // keep the memory wired
367
+ wsp_ggml_metal_device_rsets_keep_alive(ctx->dev);
368
+
365
369
  // submit the ggml compute graph to the GPU by creating command buffers and encoding the ops in them
366
370
  // the first n_nodes_0 are encoded and submitted for processing directly by the calling thread
367
371
  // while these nodes are processing, we start n_cb threads to enqueue the rest of the nodes
@@ -389,7 +393,8 @@ enum wsp_ggml_status wsp_ggml_metal_graph_compute(wsp_ggml_metal_t ctx, struct w
389
393
 
390
394
  if (!ctx->capture_started) {
391
395
  // create capture scope
392
- ctx->capture_scope = [[MTLCaptureManager sharedCaptureManager] newCaptureScopeWithDevice:ctx->device];
396
+ id<MTLDevice> device = wsp_ggml_metal_device_get_obj(ctx->dev);
397
+ ctx->capture_scope = [[MTLCaptureManager sharedCaptureManager] newCaptureScopeWithDevice:device];
393
398
 
394
399
  MTLCaptureDescriptor * descriptor = [MTLCaptureDescriptor new];
395
400
  descriptor.captureObject = ctx->capture_scope;
@@ -406,10 +411,13 @@ enum wsp_ggml_status wsp_ggml_metal_graph_compute(wsp_ggml_metal_t ctx, struct w
406
411
  }
407
412
  }
408
413
 
414
+ // short-hand
415
+ id<MTLCommandQueue> queue = wsp_ggml_metal_device_get_queue(ctx->dev);
416
+
409
417
  // the main thread commits the first few commands immediately
410
418
  // cmd_buf[n_cb]
411
419
  {
412
- id<MTLCommandBuffer> cmd_buf = [ctx->queue commandBufferWithUnretainedReferences];
420
+ id<MTLCommandBuffer> cmd_buf = [queue commandBufferWithUnretainedReferences];
413
421
  [cmd_buf retain];
414
422
 
415
423
  if (ctx->cmd_bufs[n_cb].obj) {
@@ -428,7 +436,7 @@ enum wsp_ggml_status wsp_ggml_metal_graph_compute(wsp_ggml_metal_t ctx, struct w
428
436
  // prepare the rest of the command buffers asynchronously (optional)
429
437
  // cmd_buf[0.. n_cb)
430
438
  for (int cb_idx = 0; cb_idx < n_cb; ++cb_idx) {
431
- id<MTLCommandBuffer> cmd_buf = [ctx->queue commandBufferWithUnretainedReferences];
439
+ id<MTLCommandBuffer> cmd_buf = [queue commandBufferWithUnretainedReferences];
432
440
  [cmd_buf retain];
433
441
 
434
442
  if (ctx->cmd_bufs[cb_idx].obj) {
@@ -589,9 +597,11 @@ void wsp_ggml_metal_set_abort_callback(wsp_ggml_metal_t ctx, wsp_ggml_abort_call
589
597
  }
590
598
 
591
599
  bool wsp_ggml_metal_supports_family(wsp_ggml_metal_t ctx, int family) {
592
- WSP_GGML_ASSERT(ctx->device != nil);
600
+ WSP_GGML_ASSERT(ctx->dev != nil);
601
+
602
+ id<MTLDevice> device = wsp_ggml_metal_device_get_obj(ctx->dev);
593
603
 
594
- return [ctx->device supportsFamily:(MTLGPUFamilyApple1 + family - 1)];
604
+ return [device supportsFamily:(MTLGPUFamilyApple1 + family - 1)];
595
605
  }
596
606
 
597
607
  void wsp_ggml_metal_capture_next_compute(wsp_ggml_metal_t ctx) {