whisper.rn 0.4.0-rc.2 → 0.4.0-rc.4

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/android/src/main/CMakeLists.txt +2 -0
  2. package/android/src/main/java/com/rnwhisper/RNWhisper.java +6 -1
  3. package/android/src/main/java/com/rnwhisper/WhisperContext.java +29 -15
  4. package/android/src/main/jni.cpp +6 -2
  5. package/cpp/ggml-alloc.c +413 -280
  6. package/cpp/ggml-alloc.h +67 -8
  7. package/cpp/ggml-backend-impl.h +87 -0
  8. package/cpp/ggml-backend.c +950 -0
  9. package/cpp/ggml-backend.h +136 -0
  10. package/cpp/ggml-impl.h +243 -0
  11. package/cpp/{ggml-metal.metal → ggml-metal-whisper.metal} +591 -121
  12. package/cpp/ggml-metal.h +21 -0
  13. package/cpp/ggml-metal.m +623 -234
  14. package/cpp/ggml-quants.c +7377 -0
  15. package/cpp/ggml-quants.h +224 -0
  16. package/cpp/ggml.c +3773 -4455
  17. package/cpp/ggml.h +279 -146
  18. package/cpp/whisper.cpp +182 -103
  19. package/cpp/whisper.h +48 -11
  20. package/ios/RNWhisper.mm +8 -2
  21. package/ios/RNWhisperContext.h +6 -2
  22. package/ios/RNWhisperContext.mm +97 -26
  23. package/jest/mock.js +1 -1
  24. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  25. package/lib/commonjs/index.js +28 -9
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/version.json +1 -1
  28. package/lib/module/NativeRNWhisper.js.map +1 -1
  29. package/lib/module/index.js +28 -9
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/module/version.json +1 -1
  32. package/lib/typescript/NativeRNWhisper.d.ts +7 -1
  33. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  34. package/lib/typescript/index.d.ts +8 -3
  35. package/lib/typescript/index.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/NativeRNWhisper.ts +8 -1
  38. package/src/index.ts +30 -18
  39. package/src/version.json +1 -1
  40. package/whisper-rn.podspec +1 -2
package/cpp/ggml-alloc.h CHANGED
@@ -6,20 +6,79 @@
6
6
  extern "C" {
7
7
  #endif
8
8
 
9
+ struct wsp_ggml_backend;
10
+ struct wsp_ggml_backend_buffer;
9
11
 
10
- WSP_GGML_API struct wsp_ggml_allocr * wsp_ggml_allocr_new(void * data, size_t size, size_t alignment);
11
- WSP_GGML_API struct wsp_ggml_allocr * wsp_ggml_allocr_new_measure(size_t alignment);
12
+ //
13
+ // Legacy API
14
+ //
15
+
16
+ typedef struct wsp_ggml_allocr * wsp_ggml_allocr_t;
17
+
18
+ // initialize allocator for use with CPU backend only
19
+ WSP_GGML_API wsp_ggml_allocr_t wsp_ggml_allocr_new(void * data, size_t size, size_t alignment);
20
+ WSP_GGML_API wsp_ggml_allocr_t wsp_ggml_allocr_new_measure(size_t alignment);
21
+
22
+ // initialize allocator for use with ggml-backend
23
+ WSP_GGML_API wsp_ggml_allocr_t wsp_ggml_allocr_new_from_buffer(struct wsp_ggml_backend_buffer * buffer);
24
+ WSP_GGML_API wsp_ggml_allocr_t wsp_ggml_allocr_new_from_backend(struct wsp_ggml_backend * backend, size_t size); // allocates an owned buffer
25
+ WSP_GGML_API wsp_ggml_allocr_t wsp_ggml_allocr_new_measure_from_backend(struct wsp_ggml_backend * backend);
26
+
27
+ WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_allocr_get_buffer(wsp_ggml_allocr_t alloc);
12
28
 
13
29
  // tell the allocator to parse nodes following the order described in the list
14
30
  // you should call this if your graph are optimized to execute out-of-order
15
- WSP_GGML_API void wsp_ggml_allocr_set_parse_seq(struct wsp_ggml_allocr * alloc, const int * list, int n);
31
+ WSP_GGML_API void wsp_ggml_allocr_set_parse_seq(wsp_ggml_allocr_t alloc, const int * list, int n);
32
+
33
+ WSP_GGML_API void wsp_ggml_allocr_free (wsp_ggml_allocr_t alloc);
34
+ WSP_GGML_API bool wsp_ggml_allocr_is_measure (wsp_ggml_allocr_t alloc);
35
+ WSP_GGML_API void wsp_ggml_allocr_reset (wsp_ggml_allocr_t alloc);
36
+ WSP_GGML_API void wsp_ggml_allocr_alloc (wsp_ggml_allocr_t alloc, struct wsp_ggml_tensor * tensor);
37
+ WSP_GGML_API size_t wsp_ggml_allocr_max_size (wsp_ggml_allocr_t alloc);
38
+
39
+ WSP_GGML_API size_t wsp_ggml_allocr_alloc_graph(wsp_ggml_allocr_t alloc, struct wsp_ggml_cgraph * graph);
40
+
41
+ //
42
+ // ggml-backend v2 API
43
+ //
44
+
45
+ // Seperate tensor and graph allocator objects
46
+ // This is necessary for multi-backend allocation because the graph allocator needs to use multiple tensor allocators
47
+ // The original API is kept as a wrapper around the new API
48
+
49
+ // Tensor allocator
50
+ typedef struct wsp_ggml_tallocr * wsp_ggml_tallocr_t;
51
+
52
+ WSP_GGML_API wsp_ggml_tallocr_t wsp_ggml_tallocr_new(void * data, size_t size, size_t alignment);
53
+ WSP_GGML_API wsp_ggml_tallocr_t wsp_ggml_tallocr_new_measure(size_t alignment);
54
+ WSP_GGML_API wsp_ggml_tallocr_t wsp_ggml_tallocr_new_from_buffer(struct wsp_ggml_backend_buffer * buffer);
55
+ WSP_GGML_API wsp_ggml_tallocr_t wsp_ggml_tallocr_new_from_backend(struct wsp_ggml_backend * backend, size_t size); // allocates an owned buffer
56
+ WSP_GGML_API wsp_ggml_tallocr_t wsp_ggml_tallocr_new_measure_from_backend(struct wsp_ggml_backend * backend);
57
+
58
+ WSP_GGML_API struct wsp_ggml_backend_buffer * wsp_ggml_tallocr_get_buffer(wsp_ggml_tallocr_t talloc);
59
+
60
+ WSP_GGML_API void wsp_ggml_tallocr_free (wsp_ggml_tallocr_t talloc);
61
+ WSP_GGML_API bool wsp_ggml_tallocr_is_measure (wsp_ggml_tallocr_t talloc);
62
+ WSP_GGML_API void wsp_ggml_tallocr_reset (wsp_ggml_tallocr_t talloc);
63
+ WSP_GGML_API void wsp_ggml_tallocr_alloc (wsp_ggml_tallocr_t talloc, struct wsp_ggml_tensor * tensor);
64
+ WSP_GGML_API size_t wsp_ggml_tallocr_max_size (wsp_ggml_tallocr_t talloc);
65
+
66
+
67
+ // Graph allocator
68
+ typedef struct wsp_ggml_gallocr * wsp_ggml_gallocr_t;
69
+
70
+ WSP_GGML_API wsp_ggml_gallocr_t wsp_ggml_gallocr_new(void);
71
+ WSP_GGML_API void wsp_ggml_gallocr_free(wsp_ggml_gallocr_t galloc);
16
72
 
17
- WSP_GGML_API void wsp_ggml_allocr_free(struct wsp_ggml_allocr * alloc);
18
- WSP_GGML_API bool wsp_ggml_allocr_is_measure(struct wsp_ggml_allocr * alloc);
19
- WSP_GGML_API void wsp_ggml_allocr_reset(struct wsp_ggml_allocr * alloc);
20
- WSP_GGML_API void wsp_ggml_allocr_alloc(struct wsp_ggml_allocr * alloc, struct wsp_ggml_tensor * tensor);
21
- WSP_GGML_API size_t wsp_ggml_allocr_alloc_graph(struct wsp_ggml_allocr * alloc, struct wsp_ggml_cgraph * graph);
73
+ WSP_GGML_API void wsp_ggml_gallocr_set_parse_seq(wsp_ggml_gallocr_t galloc, const int * list, int n);
74
+ WSP_GGML_API size_t wsp_ggml_gallocr_alloc_graph(wsp_ggml_gallocr_t galloc, wsp_ggml_tallocr_t talloc, struct wsp_ggml_cgraph * graph);
22
75
 
76
+ // Allocate tensors from the allocators given by the hash table
77
+ WSP_GGML_API void wsp_ggml_gallocr_alloc_graph_n(
78
+ wsp_ggml_gallocr_t galloc,
79
+ struct wsp_ggml_cgraph * graph,
80
+ struct wsp_ggml_hash_set hash_set,
81
+ wsp_ggml_tallocr_t * hash_node_talloc);
23
82
 
24
83
  #ifdef __cplusplus
25
84
  }
@@ -0,0 +1,87 @@
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
+ //
12
+ // Backend buffer
13
+ //
14
+
15
+ typedef void * wsp_ggml_backend_buffer_context_t;
16
+
17
+ 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
23
+ };
24
+
25
+ struct wsp_ggml_backend_buffer {
26
+ struct wsp_ggml_backend_buffer_i iface;
27
+
28
+ wsp_ggml_backend_t backend;
29
+ wsp_ggml_backend_buffer_context_t context;
30
+
31
+ size_t size;
32
+ };
33
+
34
+ WSP_GGML_API wsp_ggml_backend_buffer_t wsp_ggml_backend_buffer_init(
35
+ struct wsp_ggml_backend * backend,
36
+ struct wsp_ggml_backend_buffer_i iface,
37
+ wsp_ggml_backend_buffer_context_t context,
38
+ size_t size);
39
+
40
+ //
41
+ // Backend
42
+ //
43
+
44
+ typedef void * wsp_ggml_backend_context_t;
45
+
46
+ struct wsp_ggml_backend_i {
47
+ const char * (*get_name)(wsp_ggml_backend_t backend);
48
+
49
+ void (*free)(wsp_ggml_backend_t backend);
50
+
51
+ // buffer allocation
52
+ wsp_ggml_backend_buffer_t (*alloc_buffer)(wsp_ggml_backend_t backend, size_t size);
53
+
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
59
+ void (*set_tensor_async)(wsp_ggml_backend_t backend, struct wsp_ggml_tensor * tensor, const void * data, size_t offset, size_t size);
60
+ 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
+
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);
66
+
67
+ // compute graph with a plan
68
+ wsp_ggml_backend_graph_plan_t (*graph_plan_create) (wsp_ggml_backend_t backend, struct wsp_ggml_cgraph * cgraph);
69
+ void (*graph_plan_free) (wsp_ggml_backend_t backend, wsp_ggml_backend_graph_plan_t plan);
70
+ void (*graph_plan_compute)(wsp_ggml_backend_t backend, wsp_ggml_backend_graph_plan_t plan);
71
+
72
+ // compute graph without a plan
73
+ void (*graph_compute)(wsp_ggml_backend_t backend, struct wsp_ggml_cgraph * cgraph);
74
+
75
+ // check if the backend supports an operation
76
+ bool (*supports_op)(wsp_ggml_backend_t backend, const struct wsp_ggml_tensor * op);
77
+ };
78
+
79
+ struct wsp_ggml_backend {
80
+ struct wsp_ggml_backend_i iface;
81
+
82
+ wsp_ggml_backend_context_t context;
83
+ };
84
+
85
+ #ifdef __cplusplus
86
+ }
87
+ #endif