whisper.rn 0.5.0 → 0.5.2
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/android/build.gradle +2 -1
- package/android/gradle.properties +1 -1
- package/android/src/main/jni.cpp +12 -3
- package/cpp/ggml-alloc.c +292 -130
- package/cpp/ggml-backend-impl.h +4 -4
- package/cpp/ggml-backend-reg.cpp +13 -5
- package/cpp/ggml-backend.cpp +207 -17
- package/cpp/ggml-backend.h +19 -1
- package/cpp/ggml-cpu/amx/amx.cpp +5 -2
- package/cpp/ggml-cpu/arch/x86/repack.cpp +2 -2
- package/cpp/ggml-cpu/arch-fallback.h +0 -4
- package/cpp/ggml-cpu/common.h +14 -0
- package/cpp/ggml-cpu/ggml-cpu-impl.h +14 -7
- package/cpp/ggml-cpu/ggml-cpu.c +65 -44
- package/cpp/ggml-cpu/ggml-cpu.cpp +14 -4
- package/cpp/ggml-cpu/ops.cpp +542 -775
- package/cpp/ggml-cpu/ops.h +2 -0
- package/cpp/ggml-cpu/simd-mappings.h +88 -59
- package/cpp/ggml-cpu/unary-ops.cpp +135 -0
- package/cpp/ggml-cpu/unary-ops.h +5 -0
- package/cpp/ggml-cpu/vec.cpp +227 -20
- package/cpp/ggml-cpu/vec.h +407 -56
- package/cpp/ggml-cpu.h +1 -1
- package/cpp/ggml-impl.h +94 -12
- package/cpp/ggml-metal/ggml-metal-common.cpp +446 -0
- package/cpp/ggml-metal/ggml-metal-common.h +52 -0
- package/cpp/ggml-metal/ggml-metal-context.h +33 -0
- package/cpp/ggml-metal/ggml-metal-context.m +600 -0
- package/cpp/ggml-metal/ggml-metal-device.cpp +1565 -0
- package/cpp/ggml-metal/ggml-metal-device.h +244 -0
- package/cpp/ggml-metal/ggml-metal-device.m +1325 -0
- package/cpp/ggml-metal/ggml-metal-impl.h +802 -0
- package/cpp/ggml-metal/ggml-metal-ops.cpp +3583 -0
- package/cpp/ggml-metal/ggml-metal-ops.h +88 -0
- package/cpp/ggml-metal/ggml-metal.cpp +718 -0
- package/cpp/ggml-metal/ggml-whisper-sim.metallib +0 -0
- package/cpp/ggml-metal/ggml-whisper.metallib +0 -0
- package/cpp/ggml-metal-impl.h +40 -40
- package/cpp/ggml-metal.h +1 -6
- package/cpp/ggml-quants.c +1 -0
- package/cpp/ggml.c +341 -15
- package/cpp/ggml.h +150 -5
- package/cpp/jsi/RNWhisperJSI.cpp +9 -2
- package/cpp/jsi/ThreadPool.h +3 -3
- package/cpp/rn-whisper.h +1 -0
- package/cpp/whisper.cpp +89 -72
- package/cpp/whisper.h +1 -0
- package/ios/CMakeLists.txt +6 -1
- package/ios/RNWhisperContext.mm +3 -1
- package/ios/RNWhisperVadContext.mm +14 -13
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +4 -4
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +19 -1
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -1
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +94 -12
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +40 -40
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal.h +1 -6
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +150 -5
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper.h +1 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper.h +1 -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-backend-impl.h +4 -4
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +19 -1
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -1
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +94 -12
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +40 -40
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +1 -6
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +150 -5
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +1 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +1 -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 +1 -1
- 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-backend-impl.h +4 -4
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +19 -1
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +1 -1
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +94 -12
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +40 -40
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal.h +1 -6
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +150 -5
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper.h +1 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper.h +1 -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-backend-impl.h +4 -4
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +19 -1
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +1 -1
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +94 -12
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +40 -40
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +1 -6
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +150 -5
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +1 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +1 -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 +1 -1
- 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/lib/commonjs/NativeRNWhisper.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/NativeRNWhisper.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/NativeRNWhisper.d.ts +2 -0
- package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeRNWhisper.ts +2 -0
- package/src/version.json +1 -1
- package/whisper-rn.podspec +8 -9
- package/cpp/ggml-metal.m +0 -6779
- package/cpp/ggml-whisper-sim.metallib +0 -0
- package/cpp/ggml-whisper.metallib +0 -0
package/cpp/ggml-cpu/ops.h
CHANGED
|
@@ -69,7 +69,9 @@ void wsp_ggml_compute_forward_clamp(const struct wsp_ggml_compute_params * param
|
|
|
69
69
|
void wsp_ggml_compute_forward_conv_transpose_1d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
70
70
|
void wsp_ggml_compute_forward_im2col(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
71
71
|
void wsp_ggml_compute_forward_im2col_back_f32(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
72
|
+
void wsp_ggml_compute_forward_im2col_3d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
72
73
|
void wsp_ggml_compute_forward_conv_2d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
74
|
+
void wsp_ggml_compute_forward_conv_3d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
73
75
|
void wsp_ggml_compute_forward_conv_transpose_2d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
74
76
|
void wsp_ggml_compute_forward_conv_2d_dw(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
75
77
|
void wsp_ggml_compute_forward_pool_1d(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
#include <immintrin.h>
|
|
19
19
|
#endif
|
|
20
20
|
|
|
21
|
+
#if defined(__riscv_v_intrinsic)
|
|
22
|
+
#include <riscv_vector.h>
|
|
23
|
+
#endif
|
|
24
|
+
|
|
21
25
|
#ifdef __cplusplus
|
|
22
26
|
extern "C" {
|
|
23
27
|
#endif
|
|
@@ -94,24 +98,15 @@ extern "C" {
|
|
|
94
98
|
}
|
|
95
99
|
#elif defined(__riscv) && defined(__riscv_zfhmin)
|
|
96
100
|
static inline float riscv_compute_fp16_to_fp32(wsp_ggml_fp16_t h) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"fcvt.s.h %[f], %[f]"
|
|
101
|
-
: [f] "=&f" (f)
|
|
102
|
-
: [h] "r" (h)
|
|
103
|
-
);
|
|
104
|
-
return f;
|
|
101
|
+
_Float16 hf;
|
|
102
|
+
memcpy(&hf, &h, sizeof(wsp_ggml_fp16_t));
|
|
103
|
+
return hf;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
static inline wsp_ggml_fp16_t riscv_compute_fp32_to_fp16(float f) {
|
|
108
107
|
wsp_ggml_fp16_t res;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"fmv.x.h %[h], %[f]"
|
|
112
|
-
: [h] "=&r" (res)
|
|
113
|
-
: [f] "f" (f)
|
|
114
|
-
);
|
|
108
|
+
_Float16 hf = (_Float16)f;
|
|
109
|
+
memcpy(&res, &hf, sizeof(wsp_ggml_fp16_t));
|
|
115
110
|
return res;
|
|
116
111
|
}
|
|
117
112
|
|
|
@@ -119,26 +114,6 @@ extern "C" {
|
|
|
119
114
|
#define WSP_GGML_CPU_COMPUTE_FP32_TO_FP16(x) riscv_compute_fp32_to_fp16(x)
|
|
120
115
|
#define WSP_GGML_CPU_FP16_TO_FP32(x) WSP_GGML_CPU_COMPUTE_FP16_TO_FP32(x)
|
|
121
116
|
#define WSP_GGML_CPU_FP32_TO_FP16(x) WSP_GGML_CPU_COMPUTE_FP32_TO_FP16(x)
|
|
122
|
-
#elif defined(__NNPA__)
|
|
123
|
-
#define WSP_GGML_CPU_COMPUTE_FP16_TO_FP32(x) nnpa_compute_fp16_to_fp32(x)
|
|
124
|
-
#define WSP_GGML_CPU_COMPUTE_FP32_TO_FP16(x) nnpa_compute_fp32_to_fp16(x)
|
|
125
|
-
|
|
126
|
-
#define WSP_GGML_CPU_FP16_TO_FP32(x) WSP_GGML_CPU_COMPUTE_FP16_TO_FP32(x)
|
|
127
|
-
#define WSP_GGML_CPU_FP32_TO_FP16(x) WSP_GGML_CPU_COMPUTE_FP32_TO_FP16(x)
|
|
128
|
-
|
|
129
|
-
static inline float nnpa_compute_fp16_to_fp32(wsp_ggml_fp16_t h) {
|
|
130
|
-
uint16x8_t v_h = vec_splats(h);
|
|
131
|
-
uint16x8_t v_hd = vec_convert_from_fp16(v_h, 0);
|
|
132
|
-
return vec_extend_to_fp32_hi(v_hd, 0)[0];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
static inline wsp_ggml_fp16_t nnpa_compute_fp32_to_fp16(float f) {
|
|
136
|
-
float32x4_t v_f = vec_splats(f);
|
|
137
|
-
float32x4_t v_zero = vec_splats(0.0f);
|
|
138
|
-
uint16x8_t v_hd = vec_round_from_fp32(v_f, v_zero, 0);
|
|
139
|
-
uint16x8_t v_h = vec_convert_to_fp16(v_hd, 0);
|
|
140
|
-
return vec_extract(v_h, 0);
|
|
141
|
-
}
|
|
142
117
|
#endif
|
|
143
118
|
|
|
144
119
|
// precomputed f32 table for f16 (256 KB)
|
|
@@ -220,6 +195,47 @@ inline static float wsp_ggml_lookup_fp16_to_fp32(wsp_ggml_fp16_t f) {
|
|
|
220
195
|
#define WSP_GGML_F32_VEC_MUL WSP_GGML_F32xt_MUL
|
|
221
196
|
#define WSP_GGML_F32_VEC_REDUCE WSP_GGML_F32xt_REDUCE
|
|
222
197
|
|
|
198
|
+
// F16 SVE
|
|
199
|
+
#define DEFAULT_PG32 svptrue_b32()
|
|
200
|
+
#define DEFAULT_PG16 svptrue_b16()
|
|
201
|
+
|
|
202
|
+
#define WSP_GGML_F32Cxt svfloat16_t
|
|
203
|
+
#define WSP_GGML_F32Cxt_ZERO svdup_n_f16(0.0f)
|
|
204
|
+
#define WSP_GGML_F32Cxt_SET1(x) svdup_n_f16(x)
|
|
205
|
+
#define WSP_GGML_F32Cxt_LOAD(p) svld1_f16(DEFAULT_PG16, (const __fp16 *)(p))
|
|
206
|
+
#define WSP_GGML_F32Cxt_STORE(dst_ptr, src_vec) svst1_f16(DEFAULT_PG16, (__fp16 *)(dst_ptr), (src_vec))
|
|
207
|
+
|
|
208
|
+
#define WSP_GGML_F32Cxt_FMA_IMPL(pg, a, b, c) svmad_f16_x(pg, b, c, a)
|
|
209
|
+
#define WSP_GGML_F32Cxt_FMA(...) WSP_GGML_F32Cxt_FMA_IMPL(DEFAULT_PG16, __VA_ARGS__)
|
|
210
|
+
#define WSP_GGML_F32Cxt_ADD_IMPL(pg, a, b) svadd_f16_x(pg, a, b)
|
|
211
|
+
#define WSP_GGML_F32Cxt_ADD(...) WSP_GGML_F32Cxt_ADD_IMPL(DEFAULT_PG16, __VA_ARGS__)
|
|
212
|
+
#define WSP_GGML_F32Cxt_MUL_IMPL(pg, a, b) svmul_f16_x(pg, a, b)
|
|
213
|
+
#define WSP_GGML_F32Cxt_MUL(...) WSP_GGML_F32Cxt_MUL_IMPL(DEFAULT_PG16, __VA_ARGS__)
|
|
214
|
+
#define WSP_GGML_F32Cxt_REDUCE WSP_GGML_F16xt_REDUCE_MIXED
|
|
215
|
+
|
|
216
|
+
#define WSP_GGML_F16x_VEC WSP_GGML_F32Cxt
|
|
217
|
+
#define WSP_GGML_F16x_VEC_ZERO WSP_GGML_F32Cxt_ZERO
|
|
218
|
+
#define WSP_GGML_F16x_VEC_SET1 WSP_GGML_F32Cxt_SET1
|
|
219
|
+
#define WSP_GGML_F16x_VEC_LOAD(p, i) WSP_GGML_F32Cxt_LOAD(p)
|
|
220
|
+
#define WSP_GGML_F16x_VEC_STORE(p, r, i) WSP_GGML_F32Cxt_STORE((__fp16 *)(p), r)
|
|
221
|
+
#define WSP_GGML_F16x_VEC_FMA WSP_GGML_F32Cxt_FMA
|
|
222
|
+
#define WSP_GGML_F16x_VEC_ADD WSP_GGML_F32Cxt_ADD
|
|
223
|
+
#define WSP_GGML_F16x_VEC_MUL WSP_GGML_F32Cxt_MUL
|
|
224
|
+
#define WSP_GGML_F16x_VEC_REDUCE WSP_GGML_F32Cxt_REDUCE
|
|
225
|
+
|
|
226
|
+
#define WSP_GGML_F16xt_REDUCE_ONE_IMPL(pg, a) svaddv_f16(pg, a)
|
|
227
|
+
#define WSP_GGML_F16xt_REDUCE_ONE(...) WSP_GGML_F16xt_REDUCE_ONE_IMPL(DEFAULT_PG16, __VA_ARGS__)
|
|
228
|
+
|
|
229
|
+
#define WSP_GGML_F16xt_REDUCE_MIXED_IMPL(pg16, res, sum1, sum2, sum3, sum4) \
|
|
230
|
+
{ \
|
|
231
|
+
sum1 = svadd_f16_x(pg16, sum1, sum2); \
|
|
232
|
+
sum3 = svadd_f16_x(pg16, sum3, sum4); \
|
|
233
|
+
sum1 = svadd_f16_x(pg16, sum1, sum3); \
|
|
234
|
+
__fp16 sum_f16 = svaddv_f16(pg16, sum1); \
|
|
235
|
+
(res) = (wsp_ggml_float) sum_f16; \
|
|
236
|
+
}
|
|
237
|
+
#define WSP_GGML_F16xt_REDUCE_MIXED(...) WSP_GGML_F16xt_REDUCE_MIXED_IMPL(DEFAULT_PG16, __VA_ARGS__)
|
|
238
|
+
|
|
223
239
|
// F16 NEON
|
|
224
240
|
|
|
225
241
|
#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
|
|
@@ -982,9 +998,9 @@ static inline void __lasx_f32cx8_store(wsp_ggml_fp16_t * x, __m256 y) {
|
|
|
982
998
|
#define WSP_GGML_F32_EPR 4
|
|
983
999
|
|
|
984
1000
|
#define WSP_GGML_F32x4 __m128
|
|
985
|
-
#define WSP_GGML_F32x4_ZERO __lsx_vldi(0)
|
|
986
|
-
#define WSP_GGML_F32x4_SET1(x) __lsx_vinsgr2vr_w(__lsx_vldi(0),(x), 0)
|
|
987
|
-
#define WSP_GGML_F32x4_LOAD(x) __lsx_vld((x), 0)
|
|
1001
|
+
#define WSP_GGML_F32x4_ZERO (__m128)__lsx_vldi(0)
|
|
1002
|
+
#define WSP_GGML_F32x4_SET1(x) (__m128)__lsx_vinsgr2vr_w(__lsx_vldi(0),(x), 0)
|
|
1003
|
+
#define WSP_GGML_F32x4_LOAD(x) (__m128)__lsx_vld((x), 0)
|
|
988
1004
|
#define WSP_GGML_F32x4_STORE(x, y) __lsx_vst(y, x, 0)
|
|
989
1005
|
#define WSP_GGML_F32x4_FMA(a, b, c) __lsx_vfmadd_s(b, c, a)
|
|
990
1006
|
#define WSP_GGML_F32x4_ADD __lsx_vfadd_s
|
|
@@ -1006,7 +1022,7 @@ static inline void __lasx_f32cx8_store(wsp_ggml_fp16_t * x, __m256 y) {
|
|
|
1006
1022
|
__m128i tmp = __lsx_vsrli_d((__m128i) x[0], 32); \
|
|
1007
1023
|
tmp = (__m128i) __lsx_vfadd_s((__m128) tmp, x[0]); \
|
|
1008
1024
|
tmp = __lsx_vpickev_w(__lsx_vldi(0), tmp); \
|
|
1009
|
-
const __m128 t0 = __lsx_vshuf4i_w(tmp, 0x88); \
|
|
1025
|
+
const __m128 t0 = (__m128)__lsx_vshuf4i_w(tmp, 0x88); \
|
|
1010
1026
|
tmp = __lsx_vsrli_d((__m128i) t0, 32); \
|
|
1011
1027
|
tmp = (__m128i) __lsx_vfadd_s((__m128) tmp, t0); \
|
|
1012
1028
|
tmp = __lsx_vpickev_w(__lsx_vldi(0), tmp); \
|
|
@@ -1036,7 +1052,7 @@ static inline __m128 __lsx_f16x4_load(const wsp_ggml_fp16_t * x) {
|
|
|
1036
1052
|
tmp[2] = WSP_GGML_CPU_FP16_TO_FP32(x[2]);
|
|
1037
1053
|
tmp[3] = WSP_GGML_CPU_FP16_TO_FP32(x[3]);
|
|
1038
1054
|
|
|
1039
|
-
return __lsx_vld(tmp, 0);
|
|
1055
|
+
return (__m128)__lsx_vld(tmp, 0);
|
|
1040
1056
|
}
|
|
1041
1057
|
|
|
1042
1058
|
static inline void __lsx_f16x4_store(wsp_ggml_fp16_t * x, __m128 y) {
|
|
@@ -1051,9 +1067,9 @@ static inline void __lsx_f16x4_store(wsp_ggml_fp16_t * x, __m128 y) {
|
|
|
1051
1067
|
}
|
|
1052
1068
|
|
|
1053
1069
|
#define WSP_GGML_F32Cx4 __m128
|
|
1054
|
-
#define WSP_GGML_F32Cx4_ZERO __lsx_vldi(0)
|
|
1055
|
-
#define WSP_GGML_F32Cx4_SET1(x) __lsx_vinsgr2vr_w(__lsx_vldi(0),(x), 0)
|
|
1056
|
-
#define WSP_GGML_F32Cx4_LOAD(x) __lsx_f16x4_load(x)
|
|
1070
|
+
#define WSP_GGML_F32Cx4_ZERO (__m128)__lsx_vldi(0)
|
|
1071
|
+
#define WSP_GGML_F32Cx4_SET1(x) (__m128)__lsx_vinsgr2vr_w(__lsx_vldi(0),(x), 0)
|
|
1072
|
+
#define WSP_GGML_F32Cx4_LOAD(x) (__m128)__lsx_f16x4_load(x)
|
|
1057
1073
|
#define WSP_GGML_F32Cx4_STORE(x, y) __lsx_f16x4_store(x, y)
|
|
1058
1074
|
#define WSP_GGML_F32Cx4_FMA WSP_GGML_F32x4_FMA
|
|
1059
1075
|
#define WSP_GGML_F32Cx4_ADD __lsx_vfadd_s
|
|
@@ -1120,11 +1136,6 @@ static inline void __lsx_f16x4_store(wsp_ggml_fp16_t * x, __m128 y) {
|
|
|
1120
1136
|
#define WSP_GGML_F16_EPR WSP_GGML_F32_EPR
|
|
1121
1137
|
|
|
1122
1138
|
static inline float32x4_t __lzs_f16cx4_load(const wsp_ggml_fp16_t * x) {
|
|
1123
|
-
#if defined(__NNPA__)
|
|
1124
|
-
uint16x8_t v_x = vec_xl(0, (const wsp_ggml_fp16_t *)x);
|
|
1125
|
-
uint16x8_t v_xd = vec_convert_from_fp16(v_x, 0);
|
|
1126
|
-
return vec_extend_to_fp32_hi(v_xd, 0);
|
|
1127
|
-
#else
|
|
1128
1139
|
float tmp[4];
|
|
1129
1140
|
|
|
1130
1141
|
for (int i = 0; i < 4; i++) {
|
|
@@ -1134,20 +1145,9 @@ static inline float32x4_t __lzs_f16cx4_load(const wsp_ggml_fp16_t * x) {
|
|
|
1134
1145
|
// note: keep type-cast here to prevent compiler bugs
|
|
1135
1146
|
// see: https://github.com/ggml-org/llama.cpp/issues/12846
|
|
1136
1147
|
return vec_xl(0, (const float *)(tmp));
|
|
1137
|
-
#endif
|
|
1138
1148
|
}
|
|
1139
1149
|
|
|
1140
1150
|
static inline void __lzs_f16cx4_store(wsp_ggml_fp16_t * x, float32x4_t v_y) {
|
|
1141
|
-
#if defined(__NNPA__)
|
|
1142
|
-
float32x4_t v_zero = vec_splats(0.0f);
|
|
1143
|
-
uint16x8_t v_xd = vec_round_from_fp32(v_y, v_zero, 0);
|
|
1144
|
-
uint16x8_t v_x = vec_convert_to_fp16(v_xd, 0);
|
|
1145
|
-
|
|
1146
|
-
x[0] = vec_extract(v_x, 0);
|
|
1147
|
-
x[1] = vec_extract(v_x, 1);
|
|
1148
|
-
x[2] = vec_extract(v_x, 2);
|
|
1149
|
-
x[3] = vec_extract(v_x, 3);
|
|
1150
|
-
#else
|
|
1151
1151
|
float arr[4];
|
|
1152
1152
|
|
|
1153
1153
|
// note: keep type-cast here to prevent compiler bugs
|
|
@@ -1157,7 +1157,6 @@ static inline void __lzs_f16cx4_store(wsp_ggml_fp16_t * x, float32x4_t v_y) {
|
|
|
1157
1157
|
for (int i = 0; i < 4; i++) {
|
|
1158
1158
|
x[i] = WSP_GGML_CPU_FP32_TO_FP16(arr[i]);
|
|
1159
1159
|
}
|
|
1160
|
-
#endif
|
|
1161
1160
|
}
|
|
1162
1161
|
|
|
1163
1162
|
#define WSP_GGML_F16_VEC WSP_GGML_F32x4
|
|
@@ -1170,6 +1169,36 @@ static inline void __lzs_f16cx4_store(wsp_ggml_fp16_t * x, float32x4_t v_y) {
|
|
|
1170
1169
|
#define WSP_GGML_F16_VEC_MUL WSP_GGML_F32x4_MUL
|
|
1171
1170
|
#define WSP_GGML_F16_VEC_REDUCE WSP_GGML_F32x4_REDUCE
|
|
1172
1171
|
|
|
1172
|
+
#elif defined(__riscv_v_intrinsic)
|
|
1173
|
+
|
|
1174
|
+
// compatible with vlen >= 128
|
|
1175
|
+
|
|
1176
|
+
#define WSP_GGML_SIMD
|
|
1177
|
+
|
|
1178
|
+
// F32
|
|
1179
|
+
|
|
1180
|
+
#define WSP_GGML_F32_STEP 16
|
|
1181
|
+
#define WSP_GGML_F32_EPR 4
|
|
1182
|
+
|
|
1183
|
+
#define WSP_GGML_F32x4 vfloat32m1_t
|
|
1184
|
+
#define WSP_GGML_F32x4_ZERO __riscv_vfmv_v_f_f32m1(0.0f, WSP_GGML_F32_EPR)
|
|
1185
|
+
#define WSP_GGML_F32x4_SET1(x) __riscv_vfmv_v_f_f32m1(x, WSP_GGML_F32_EPR)
|
|
1186
|
+
#define WSP_GGML_F32x4_LOAD(x) __riscv_vle32_v_f32m1(x, WSP_GGML_F32_EPR)
|
|
1187
|
+
#define WSP_GGML_F32x4_STORE(b, v) __riscv_vse32_v_f32m1(b, v, WSP_GGML_F32_EPR)
|
|
1188
|
+
#define WSP_GGML_F32x4_FMA(a, b, c) __riscv_vfmacc_vv_f32m1(a, b, c, WSP_GGML_F32_EPR)
|
|
1189
|
+
#define WSP_GGML_F32x4_ADD(a, b) __riscv_vfadd_vv_f32m1(a, b, WSP_GGML_F32_EPR)
|
|
1190
|
+
#define WSP_GGML_F32x4_MUL(a, b) __riscv_vfmul_vv_f32m1(a, b, WSP_GGML_F32_EPR)
|
|
1191
|
+
|
|
1192
|
+
#define WSP_GGML_F32_VEC WSP_GGML_F32x4
|
|
1193
|
+
#define WSP_GGML_F32_VEC_ZERO WSP_GGML_F32x4_ZERO
|
|
1194
|
+
#define WSP_GGML_F32_VEC_SET1 WSP_GGML_F32x4_SET1
|
|
1195
|
+
#define WSP_GGML_F32_VEC_LOAD WSP_GGML_F32x4_LOAD
|
|
1196
|
+
#define WSP_GGML_F32_VEC_STORE WSP_GGML_F32x4_STORE
|
|
1197
|
+
#define WSP_GGML_F32_VEC_FMA WSP_GGML_F32x4_FMA
|
|
1198
|
+
#define WSP_GGML_F32_VEC_ADD WSP_GGML_F32x4_ADD
|
|
1199
|
+
#define WSP_GGML_F32_VEC_MUL WSP_GGML_F32x4_MUL
|
|
1200
|
+
#define WSP_GGML_F32_VEC_REDUCE WSP_GGML_F32x4_REDUCE
|
|
1201
|
+
|
|
1173
1202
|
#endif
|
|
1174
1203
|
|
|
1175
1204
|
// WSP_GGML_F32_ARR / WSP_GGML_F16_ARR
|
|
@@ -52,6 +52,15 @@ static inline float op_sqrt(float x) {
|
|
|
52
52
|
return sqrtf(x);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
static inline float op_xielu(float x, float alpha_n, float alpha_p, float beta, float eps) {
|
|
56
|
+
if (x > 0.0f) {
|
|
57
|
+
return alpha_p * x * x + beta * x;
|
|
58
|
+
} else {
|
|
59
|
+
const float min_x_eps = fminf(x, eps);
|
|
60
|
+
return (expm1f(min_x_eps) - x) * alpha_n + beta * x;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
static inline float op_sin(float x) {
|
|
56
65
|
return sinf(x);
|
|
57
66
|
}
|
|
@@ -64,6 +73,22 @@ static inline float op_log(float x) {
|
|
|
64
73
|
return logf(x);
|
|
65
74
|
}
|
|
66
75
|
|
|
76
|
+
static inline float op_floor(float x) {
|
|
77
|
+
return floorf(x);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static inline float op_ceil(float x) {
|
|
81
|
+
return ceilf(x);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static inline float op_round(float x) {
|
|
85
|
+
return roundf(x);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static inline float op_trunc(float x) {
|
|
89
|
+
return truncf(x);
|
|
90
|
+
}
|
|
91
|
+
|
|
67
92
|
template <float (*op)(float), typename src0_t, typename dst_t>
|
|
68
93
|
static inline void vec_unary_op(int64_t n, dst_t * y, const src0_t * x) {
|
|
69
94
|
constexpr auto src0_to_f32 = type_conversion_table<src0_t>::to_f32;
|
|
@@ -121,6 +146,86 @@ static void unary_op(const wsp_ggml_compute_params * params, wsp_ggml_tensor * d
|
|
|
121
146
|
}
|
|
122
147
|
}
|
|
123
148
|
|
|
149
|
+
template <float (*op)(float, wsp_ggml_tensor *)>
|
|
150
|
+
static void unary_op_params(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
151
|
+
const wsp_ggml_tensor * src0 = dst->src[0];
|
|
152
|
+
|
|
153
|
+
/* */ if (src0->type == WSP_GGML_TYPE_F32 && dst->type == WSP_GGML_TYPE_F32) { // all f32
|
|
154
|
+
apply_unary_op<op, float, float>(params, dst);
|
|
155
|
+
} else if (src0->type == WSP_GGML_TYPE_F16 && dst->type == WSP_GGML_TYPE_F16) { // all f16
|
|
156
|
+
apply_unary_op<op, wsp_ggml_fp16_t, wsp_ggml_fp16_t>(params, dst);
|
|
157
|
+
} else if (src0->type == WSP_GGML_TYPE_BF16 && dst->type == WSP_GGML_TYPE_BF16) { // all bf16
|
|
158
|
+
apply_unary_op<op, wsp_ggml_bf16_t, wsp_ggml_bf16_t>(params, dst);
|
|
159
|
+
} else if (src0->type == WSP_GGML_TYPE_BF16 && dst->type == WSP_GGML_TYPE_F32) {
|
|
160
|
+
apply_unary_op<op, wsp_ggml_bf16_t, float>(params, dst);
|
|
161
|
+
} else if (src0->type == WSP_GGML_TYPE_F16 && dst->type == WSP_GGML_TYPE_F32) {
|
|
162
|
+
apply_unary_op<op, wsp_ggml_fp16_t, float>(params, dst);
|
|
163
|
+
} else {
|
|
164
|
+
fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s\n", __func__,
|
|
165
|
+
wsp_ggml_type_name(dst->type), wsp_ggml_type_name(src0->type));
|
|
166
|
+
WSP_GGML_ABORT("fatal error");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Extend vec_unary_op to support functors
|
|
171
|
+
template <typename Op, typename src0_t, typename dst_t>
|
|
172
|
+
static inline void vec_unary_op_functor(int64_t n, dst_t * y, const src0_t * x, Op op) {
|
|
173
|
+
constexpr auto src0_to_f32 = type_conversion_table<src0_t>::to_f32;
|
|
174
|
+
constexpr auto f32_to_dst = type_conversion_table<dst_t >::from_f32;
|
|
175
|
+
|
|
176
|
+
for (int i = 0; i < n; i++) {
|
|
177
|
+
y[i] = f32_to_dst(op(src0_to_f32(x[i])));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Extend apply_unary_op to support functors
|
|
182
|
+
template <typename Op, typename src0_t, typename dst_t>
|
|
183
|
+
static void apply_unary_op_functor(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst, Op op) {
|
|
184
|
+
const wsp_ggml_tensor * src0 = dst->src[0];
|
|
185
|
+
|
|
186
|
+
WSP_GGML_ASSERT(wsp_ggml_is_contiguous_1(src0) && wsp_ggml_is_contiguous_1(dst) && wsp_ggml_are_same_shape(src0, dst));
|
|
187
|
+
|
|
188
|
+
WSP_GGML_TENSOR_UNARY_OP_LOCALS
|
|
189
|
+
|
|
190
|
+
WSP_GGML_ASSERT( nb0 == sizeof(dst_t));
|
|
191
|
+
WSP_GGML_ASSERT(nb00 == sizeof(src0_t));
|
|
192
|
+
|
|
193
|
+
const auto [ir0, ir1] = get_thread_range(params, src0);
|
|
194
|
+
|
|
195
|
+
for (int64_t ir = ir0; ir < ir1; ++ir) {
|
|
196
|
+
const int64_t i03 = ir/(ne02*ne01);
|
|
197
|
+
const int64_t i02 = (ir - i03*ne02*ne01)/ne01;
|
|
198
|
+
const int64_t i01 = (ir - i03*ne02*ne01 - i02*ne01);
|
|
199
|
+
|
|
200
|
+
dst_t * dst_ptr = (dst_t *) ((char *) dst->data + i03*nb3 + i02*nb2 + i01*nb1 );
|
|
201
|
+
const src0_t * src0_ptr = (const src0_t *) ((const char *) src0->data + i03*nb03 + i02*nb02 + i01*nb01);
|
|
202
|
+
|
|
203
|
+
vec_unary_op_functor(ne0, dst_ptr, src0_ptr, op);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Generic dispatcher for functors
|
|
208
|
+
template <typename Op>
|
|
209
|
+
static void unary_op_functor(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst, Op op) {
|
|
210
|
+
const wsp_ggml_tensor * src0 = dst->src[0];
|
|
211
|
+
|
|
212
|
+
/* */ if (src0->type == WSP_GGML_TYPE_F32 && dst->type == WSP_GGML_TYPE_F32) { // all f32
|
|
213
|
+
apply_unary_op_functor<Op, float, float>(params, dst, op);
|
|
214
|
+
} else if (src0->type == WSP_GGML_TYPE_F16 && dst->type == WSP_GGML_TYPE_F16) { // all f16
|
|
215
|
+
apply_unary_op_functor<Op, wsp_ggml_fp16_t, wsp_ggml_fp16_t>(params, dst, op);
|
|
216
|
+
} else if (src0->type == WSP_GGML_TYPE_BF16 && dst->type == WSP_GGML_TYPE_BF16) { // all bf16
|
|
217
|
+
apply_unary_op_functor<Op, wsp_ggml_bf16_t, wsp_ggml_bf16_t>(params, dst, op);
|
|
218
|
+
} else if (src0->type == WSP_GGML_TYPE_BF16 && dst->type == WSP_GGML_TYPE_F32) {
|
|
219
|
+
apply_unary_op_functor<Op, wsp_ggml_bf16_t, float>(params, dst, op);
|
|
220
|
+
} else if (src0->type == WSP_GGML_TYPE_F16 && dst->type == WSP_GGML_TYPE_F32) {
|
|
221
|
+
apply_unary_op_functor<Op, wsp_ggml_fp16_t, float>(params, dst, op);
|
|
222
|
+
} else {
|
|
223
|
+
fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s\n", __func__,
|
|
224
|
+
wsp_ggml_type_name(dst->type), wsp_ggml_type_name(src0->type));
|
|
225
|
+
WSP_GGML_ABORT("fatal error");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
124
229
|
void wsp_ggml_compute_forward_abs(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
125
230
|
unary_op<op_abs>(params, dst);
|
|
126
231
|
}
|
|
@@ -184,3 +289,33 @@ void wsp_ggml_compute_forward_cos(const wsp_ggml_compute_params * params, wsp_gg
|
|
|
184
289
|
void wsp_ggml_compute_forward_log(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
185
290
|
unary_op<op_log>(params, dst);
|
|
186
291
|
}
|
|
292
|
+
|
|
293
|
+
void wsp_ggml_compute_forward_floor(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
294
|
+
unary_op<op_floor>(params, dst);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
void wsp_ggml_compute_forward_ceil(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
298
|
+
unary_op<op_ceil>(params, dst);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
void wsp_ggml_compute_forward_round(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
302
|
+
unary_op<op_round>(params, dst);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
void wsp_ggml_compute_forward_trunc(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
306
|
+
unary_op<op_trunc>(params, dst);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
void wsp_ggml_compute_forward_xielu(const wsp_ggml_compute_params * params, wsp_ggml_tensor * dst) {
|
|
310
|
+
const float alpha_n = wsp_ggml_get_op_params_f32(dst, 1);
|
|
311
|
+
const float alpha_p = wsp_ggml_get_op_params_f32(dst, 2);
|
|
312
|
+
const float beta = wsp_ggml_get_op_params_f32(dst, 3);
|
|
313
|
+
const float eps = wsp_ggml_get_op_params_f32(dst, 4);
|
|
314
|
+
|
|
315
|
+
const auto xielu_op_params = [alpha_n, alpha_p, beta, eps](float f) {
|
|
316
|
+
return op_xielu(f, alpha_n, alpha_p, beta, eps);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
unary_op_functor(params, dst, xielu_op_params);
|
|
320
|
+
}
|
|
321
|
+
|
package/cpp/ggml-cpu/unary-ops.h
CHANGED
|
@@ -22,6 +22,11 @@ void wsp_ggml_compute_forward_sqrt(const struct wsp_ggml_compute_params * params
|
|
|
22
22
|
void wsp_ggml_compute_forward_sin(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
23
23
|
void wsp_ggml_compute_forward_cos(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
24
24
|
void wsp_ggml_compute_forward_log(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
25
|
+
void wsp_ggml_compute_forward_floor(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
26
|
+
void wsp_ggml_compute_forward_ceil(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
27
|
+
void wsp_ggml_compute_forward_round(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
28
|
+
void wsp_ggml_compute_forward_trunc(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
29
|
+
void wsp_ggml_compute_forward_xielu(const struct wsp_ggml_compute_params * params, struct wsp_ggml_tensor * dst);
|
|
25
30
|
|
|
26
31
|
#ifdef __cplusplus
|
|
27
32
|
}
|