whisper.rn 0.4.0-rc.4 → 0.4.0-rc.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 (40) hide show
  1. package/README.md +6 -6
  2. package/android/build.gradle +4 -0
  3. package/android/src/main/CMakeLists.txt +5 -0
  4. package/android/src/main/java/com/rnwhisper/AudioUtils.java +0 -80
  5. package/android/src/main/java/com/rnwhisper/WhisperContext.java +51 -133
  6. package/android/src/main/jni-utils.h +76 -0
  7. package/android/src/main/jni.cpp +187 -112
  8. package/cpp/README.md +1 -1
  9. package/cpp/coreml/whisper-encoder-impl.h +1 -1
  10. package/cpp/coreml/whisper-encoder.h +4 -0
  11. package/cpp/coreml/whisper-encoder.mm +4 -2
  12. package/cpp/ggml-alloc.c +55 -19
  13. package/cpp/ggml-alloc.h +7 -0
  14. package/cpp/ggml-backend-impl.h +46 -21
  15. package/cpp/ggml-backend.c +563 -156
  16. package/cpp/ggml-backend.h +62 -17
  17. package/cpp/ggml-impl.h +1 -1
  18. package/cpp/ggml-metal-whisper.metal +1010 -253
  19. package/cpp/ggml-metal.h +7 -1
  20. package/cpp/ggml-metal.m +618 -187
  21. package/cpp/ggml-quants.c +64 -59
  22. package/cpp/ggml-quants.h +40 -40
  23. package/cpp/ggml.c +751 -1466
  24. package/cpp/ggml.h +90 -25
  25. package/cpp/rn-audioutils.cpp +68 -0
  26. package/cpp/rn-audioutils.h +14 -0
  27. package/cpp/rn-whisper-log.h +11 -0
  28. package/cpp/rn-whisper.cpp +141 -59
  29. package/cpp/rn-whisper.h +47 -15
  30. package/cpp/whisper.cpp +1635 -928
  31. package/cpp/whisper.h +55 -10
  32. package/ios/RNWhisper.mm +7 -7
  33. package/ios/RNWhisperAudioUtils.h +0 -2
  34. package/ios/RNWhisperAudioUtils.m +0 -56
  35. package/ios/RNWhisperContext.h +3 -11
  36. package/ios/RNWhisperContext.mm +62 -134
  37. package/lib/commonjs/version.json +1 -1
  38. package/lib/module/version.json +1 -1
  39. package/package.json +6 -5
  40. package/src/version.json +1 -1
@@ -12,31 +12,50 @@ extern "C" {
12
12
  // Backend buffer
13
13
  //
14
14
 
15
+ // buffer type
16
+ typedef void * wsp_ggml_backend_buffer_type_context_t;
17
+
18
+ struct wsp_ggml_backend_buffer_type_i {
19
+ wsp_ggml_backend_buffer_t (*alloc_buffer) (wsp_ggml_backend_buffer_type_t buft, size_t size);
20
+ size_t (*get_alignment) (wsp_ggml_backend_buffer_type_t buft); // tensor alignment
21
+ size_t (*get_alloc_size) (wsp_ggml_backend_buffer_type_t buft, struct wsp_ggml_tensor * tensor); // data size needed to allocate the tensor, including padding
22
+ bool (*supports_backend)(wsp_ggml_backend_buffer_type_t buft, wsp_ggml_backend_t backend); // check if the buffer type is usable by the backend
23
+ };
24
+
25
+ struct wsp_ggml_backend_buffer_type {
26
+ struct wsp_ggml_backend_buffer_type_i iface;
27
+ wsp_ggml_backend_buffer_type_context_t context;
28
+ };
29
+
30
+ // buffer
15
31
  typedef void * wsp_ggml_backend_buffer_context_t;
16
32
 
17
33
  struct wsp_ggml_backend_buffer_i {
18
- void (*free_buffer) (wsp_ggml_backend_buffer_t buffer);
19
- void * (*get_base) (wsp_ggml_backend_buffer_t buffer); // get base pointer
20
- size_t (*get_alloc_size)(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor); // pre-allocation callback
21
- void (*init_tensor) (wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor); // post-allocation callback
22
- void (*free_tensor) (wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor); // pre-free callback
34
+ void (*free_buffer)(wsp_ggml_backend_buffer_t buffer);
35
+ //void (*reset) (wsp_ggml_backend_buffer_t buffer); // reset any internal state due to tensor initialization, such as tensor extras
36
+ void * (*get_base) (wsp_ggml_backend_buffer_t buffer);
37
+ void (*init_tensor)(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor);
38
+ void (*set_tensor) (wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size);
39
+ void (*get_tensor) (wsp_ggml_backend_buffer_t buffer, const struct wsp_ggml_tensor * tensor, void * data, size_t offset, size_t size);
40
+ // (optional) copy tensor between different buffer-type, allow for single-copy tranfers
41
+ void (*cpy_tensor_from)(wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
42
+ void (*cpy_tensor_to) (wsp_ggml_backend_buffer_t buffer, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
23
43
  };
24
44
 
25
45
  struct wsp_ggml_backend_buffer {
26
- struct wsp_ggml_backend_buffer_i iface;
27
-
28
- wsp_ggml_backend_t backend;
46
+ struct wsp_ggml_backend_buffer_i iface;
47
+ wsp_ggml_backend_buffer_type_t buft;
29
48
  wsp_ggml_backend_buffer_context_t context;
30
-
31
49
  size_t size;
32
50
  };
33
51
 
34
- WSP_GGML_API wsp_ggml_backend_buffer_t wsp_ggml_backend_buffer_init(
35
- struct wsp_ggml_backend * backend,
52
+ wsp_ggml_backend_buffer_t wsp_ggml_backend_buffer_init(
53
+ wsp_ggml_backend_buffer_type_t buft,
36
54
  struct wsp_ggml_backend_buffer_i iface,
37
55
  wsp_ggml_backend_buffer_context_t context,
38
56
  size_t size);
39
57
 
58
+
40
59
  //
41
60
  // Backend
42
61
  //
@@ -49,20 +68,17 @@ extern "C" {
49
68
  void (*free)(wsp_ggml_backend_t backend);
50
69
 
51
70
  // buffer allocation
52
- wsp_ggml_backend_buffer_t (*alloc_buffer)(wsp_ggml_backend_t backend, size_t size);
71
+ wsp_ggml_backend_buffer_type_t (*get_default_buffer_type)(wsp_ggml_backend_t backend);
53
72
 
54
- // get buffer alignment
55
- size_t (*get_alignment)(wsp_ggml_backend_t backend);
56
-
57
- // tensor data access
58
- // these functions can be asynchronous, helper functions are provided for synchronous access that automatically call synchronize
73
+ // (optional) asynchroneous tensor data access
59
74
  void (*set_tensor_async)(wsp_ggml_backend_t backend, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size);
60
75
  void (*get_tensor_async)(wsp_ggml_backend_t backend, const struct wsp_ggml_tensor * tensor, void * data, size_t offset, size_t size);
61
- void (*synchronize) (wsp_ggml_backend_t backend);
62
76
 
63
- // (optional) copy tensor between different backends, allow for single-copy tranfers
64
- void (*cpy_tensor_from)(wsp_ggml_backend_t backend, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
65
- void (*cpy_tensor_to) (wsp_ggml_backend_t backend, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
77
+ // (optional) asynchroneous tensor copy
78
+ void (*cpy_tensor_from_async)(wsp_ggml_backend_t backend, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
79
+ void (*cpy_tensor_to_async) (wsp_ggml_backend_t backend, struct wsp_ggml_tensor * src, struct wsp_ggml_tensor * dst);
80
+
81
+ void (*synchronize) (wsp_ggml_backend_t backend);
66
82
 
67
83
  // compute graph with a plan
68
84
  wsp_ggml_backend_graph_plan_t (*graph_plan_create) (wsp_ggml_backend_t backend, struct wsp_ggml_cgraph * cgraph);
@@ -82,6 +98,15 @@ extern "C" {
82
98
  wsp_ggml_backend_context_t context;
83
99
  };
84
100
 
101
+
102
+ //
103
+ // Backend registry
104
+ //
105
+
106
+ typedef wsp_ggml_backend_t (*wsp_ggml_backend_init_fn)(const char * params, void * user_data);
107
+
108
+ void wsp_ggml_backend_register(const char * name, wsp_ggml_backend_init_fn init_fn, wsp_ggml_backend_buffer_type_t default_buffer_type, void * user_data);
109
+
85
110
  #ifdef __cplusplus
86
111
  }
87
112
  #endif