whisper.rn 0.4.0-rc.9 → 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 +43 -13
- package/android/src/main/java/com/rnwhisper/WhisperContext.java +33 -35
- package/android/src/main/jni.cpp +9 -0
- 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/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 +39 -37
- package/cpp/ggml-alloc.h +1 -1
- package/cpp/ggml-backend-impl.h +55 -27
- package/cpp/ggml-backend-reg.cpp +591 -0
- package/cpp/ggml-backend.cpp +336 -955
- package/cpp/ggml-backend.h +70 -42
- package/cpp/ggml-common.h +57 -49
- 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 +417 -23
- package/cpp/ggml-metal-impl.h +622 -0
- package/cpp/ggml-metal.h +9 -9
- package/cpp/ggml-metal.m +3451 -1344
- package/cpp/ggml-opt.cpp +1037 -0
- package/cpp/ggml-opt.h +237 -0
- package/cpp/ggml-quants.c +296 -10818
- package/cpp/ggml-quants.h +78 -125
- 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 +4633 -21450
- package/cpp/ggml.h +320 -661
- package/cpp/gguf.cpp +1347 -0
- package/cpp/gguf.h +202 -0
- package/cpp/rn-whisper.cpp +4 -11
- package/cpp/whisper-arch.h +197 -0
- package/cpp/whisper.cpp +2022 -495
- package/cpp/whisper.h +75 -18
- package/ios/CMakeLists.txt +95 -0
- package/ios/RNWhisper.h +5 -0
- package/ios/RNWhisperAudioUtils.m +4 -0
- package/ios/RNWhisperContext.h +5 -0
- package/ios/RNWhisperContext.mm +4 -2
- 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 +5 -0
- package/lib/commonjs/version.json +1 -1
- package/lib/module/version.json +1 -1
- package/package.json +10 -6
- package/src/version.json +1 -1
- package/whisper-rn.podspec +11 -18
- package/cpp/README.md +0 -4
- package/cpp/ggml-aarch64.c +0 -3209
- package/cpp/ggml-aarch64.h +0 -39
- package/cpp/ggml-cpu-impl.h +0 -614
package/cpp/ggml-aarch64.h
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: Copyright 2024 Arm Ltd.
|
|
2
|
-
#pragma once
|
|
3
|
-
|
|
4
|
-
#define WSP_GGML_COMMON_DECL_C
|
|
5
|
-
#include "ggml-common.h"
|
|
6
|
-
|
|
7
|
-
#include "ggml.h"
|
|
8
|
-
|
|
9
|
-
// GGML internal header
|
|
10
|
-
|
|
11
|
-
#ifdef __cplusplus
|
|
12
|
-
extern "C" {
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
// Quantization
|
|
16
|
-
void wsp_quantize_q8_0_4x4(const float * WSP_GGML_RESTRICT x, void * WSP_GGML_RESTRICT y, int64_t k);
|
|
17
|
-
void wsp_quantize_q8_0_4x8(const float * WSP_GGML_RESTRICT x, void * WSP_GGML_RESTRICT y, int64_t k);
|
|
18
|
-
|
|
19
|
-
void wsp_quantize_mat_q8_0(const float * WSP_GGML_RESTRICT x, void * WSP_GGML_RESTRICT y, int64_t nrows, int64_t n_per_row, int64_t blck_size_interleave);
|
|
20
|
-
|
|
21
|
-
// Quantization utilizing an importance matrix (a.k.a. "Activation aWare Quantization")
|
|
22
|
-
size_t wsp_quantize_q4_0_4x4(const float * WSP_GGML_RESTRICT src, void * WSP_GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
|
23
|
-
size_t wsp_quantize_q4_0_4x8(const float * WSP_GGML_RESTRICT src, void * WSP_GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
|
24
|
-
size_t wsp_quantize_q4_0_8x8(const float * WSP_GGML_RESTRICT src, void * WSP_GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
|
25
|
-
|
|
26
|
-
// GEMV
|
|
27
|
-
void wsp_ggml_gemv_q4_0_4x4_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
28
|
-
void wsp_ggml_gemv_q4_0_4x8_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
29
|
-
void wsp_ggml_gemv_q4_0_8x8_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
30
|
-
|
|
31
|
-
// GEMM
|
|
32
|
-
void wsp_ggml_gemm_q4_0_4x4_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
33
|
-
void wsp_ggml_gemm_q4_0_4x8_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
34
|
-
void wsp_ggml_gemm_q4_0_8x8_q8_0(int n, float * WSP_GGML_RESTRICT s, size_t bs, const void * WSP_GGML_RESTRICT vx, const void * WSP_GGML_RESTRICT vy, int nr, int nc);
|
|
35
|
-
|
|
36
|
-
#ifdef __cplusplus
|
|
37
|
-
}
|
|
38
|
-
#endif
|
|
39
|
-
|
package/cpp/ggml-cpu-impl.h
DELETED
|
@@ -1,614 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
// GGML CPU internal header
|
|
4
|
-
|
|
5
|
-
#include "ggml.h"
|
|
6
|
-
#include "ggml-impl.h"
|
|
7
|
-
#include <stdlib.h> // load `stdlib.h` before other headers to work around MinGW bug: https://sourceforge.net/p/mingw-w64/bugs/192/
|
|
8
|
-
//#include <stddef.h>
|
|
9
|
-
#include <stdbool.h>
|
|
10
|
-
#include <string.h> // memcpy
|
|
11
|
-
#include <math.h> // fabsf
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#ifdef __cplusplus
|
|
15
|
-
extern "C" {
|
|
16
|
-
#endif
|
|
17
|
-
|
|
18
|
-
#if defined(_MSC_VER)
|
|
19
|
-
|
|
20
|
-
#define m512bh(p) p
|
|
21
|
-
#define m512i(p) p
|
|
22
|
-
|
|
23
|
-
#else
|
|
24
|
-
|
|
25
|
-
#define m512bh(p) (__m512bh)(p)
|
|
26
|
-
#define m512i(p) (__m512i)(p)
|
|
27
|
-
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Converts brain16 to float32.
|
|
32
|
-
*
|
|
33
|
-
* The bfloat16 floating point format has the following structure:
|
|
34
|
-
*
|
|
35
|
-
* ┌sign
|
|
36
|
-
* │
|
|
37
|
-
* │ ┌exponent
|
|
38
|
-
* │ │
|
|
39
|
-
* │ │ ┌mantissa
|
|
40
|
-
* │ │ │
|
|
41
|
-
* │┌──┴───┐┌─┴───┐
|
|
42
|
-
* 0b0000000000000000 brain16
|
|
43
|
-
*
|
|
44
|
-
* Since bf16 has the same number of exponent bits as a 32bit float,
|
|
45
|
-
* encoding and decoding numbers becomes relatively straightforward.
|
|
46
|
-
*
|
|
47
|
-
* ┌sign
|
|
48
|
-
* │
|
|
49
|
-
* │ ┌exponent
|
|
50
|
-
* │ │
|
|
51
|
-
* │ │ ┌mantissa
|
|
52
|
-
* │ │ │
|
|
53
|
-
* │┌──┴───┐┌─┴───────────────────┐
|
|
54
|
-
* 0b00000000000000000000000000000000 IEEE binary32
|
|
55
|
-
*
|
|
56
|
-
* For comparison, the standard fp16 format has fewer exponent bits.
|
|
57
|
-
*
|
|
58
|
-
* ┌sign
|
|
59
|
-
* │
|
|
60
|
-
* │ ┌exponent
|
|
61
|
-
* │ │
|
|
62
|
-
* │ │ ┌mantissa
|
|
63
|
-
* │ │ │
|
|
64
|
-
* │┌─┴─┐┌─┴──────┐
|
|
65
|
-
* 0b0000000000000000 IEEE binary16
|
|
66
|
-
*
|
|
67
|
-
* @see IEEE 754-2008
|
|
68
|
-
*/
|
|
69
|
-
static inline float wsp_ggml_compute_bf16_to_fp32(wsp_ggml_bf16_t h) {
|
|
70
|
-
union {
|
|
71
|
-
float f;
|
|
72
|
-
uint32_t i;
|
|
73
|
-
} u;
|
|
74
|
-
u.i = (uint32_t)h.bits << 16;
|
|
75
|
-
return u.f;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Converts float32 to brain16.
|
|
80
|
-
*
|
|
81
|
-
* This is binary identical with Google Brain float conversion.
|
|
82
|
-
* Floats shall round to nearest even, and NANs shall be quiet.
|
|
83
|
-
* Subnormals aren't flushed to zero, except perhaps when used.
|
|
84
|
-
* This code should vectorize nicely if using modern compilers.
|
|
85
|
-
*/
|
|
86
|
-
static inline wsp_ggml_bf16_t wsp_ggml_compute_fp32_to_bf16(float s) {
|
|
87
|
-
wsp_ggml_bf16_t h;
|
|
88
|
-
union {
|
|
89
|
-
float f;
|
|
90
|
-
uint32_t i;
|
|
91
|
-
} u;
|
|
92
|
-
u.f = s;
|
|
93
|
-
if ((u.i & 0x7fffffff) > 0x7f800000) { /* nan */
|
|
94
|
-
h.bits = (u.i >> 16) | 64; /* force to quiet */
|
|
95
|
-
return h;
|
|
96
|
-
}
|
|
97
|
-
h.bits = (u.i + (0x7fff + ((u.i >> 16) & 1))) >> 16;
|
|
98
|
-
return h;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
#define WSP_GGML_FP32_TO_BF16(x) wsp_ggml_compute_fp32_to_bf16(x)
|
|
102
|
-
#define WSP_GGML_BF16_TO_FP32(x) wsp_ggml_compute_bf16_to_fp32(x)
|
|
103
|
-
|
|
104
|
-
// __FMA__ and __F16C__ are not defined in MSVC, however they are implied with AVX2/AVX512
|
|
105
|
-
#if defined(_MSC_VER) && (defined(__AVX2__) || defined(__AVX512F__))
|
|
106
|
-
#ifndef __FMA__
|
|
107
|
-
#define __FMA__
|
|
108
|
-
#endif
|
|
109
|
-
#ifndef __F16C__
|
|
110
|
-
#define __F16C__
|
|
111
|
-
#endif
|
|
112
|
-
#endif
|
|
113
|
-
|
|
114
|
-
// __SSE3__ and __SSSE3__ are not defined in MSVC, but SSE3/SSSE3 are present when AVX/AVX2/AVX512 are available
|
|
115
|
-
#if defined(_MSC_VER) && (defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__))
|
|
116
|
-
#ifndef __SSE3__
|
|
117
|
-
#define __SSE3__
|
|
118
|
-
#endif
|
|
119
|
-
#ifndef __SSSE3__
|
|
120
|
-
#define __SSSE3__
|
|
121
|
-
#endif
|
|
122
|
-
#endif
|
|
123
|
-
|
|
124
|
-
#if defined(__ARM_FEATURE_SVE)
|
|
125
|
-
#include <arm_sve.h>
|
|
126
|
-
#include <sys/prctl.h>
|
|
127
|
-
#endif
|
|
128
|
-
|
|
129
|
-
// 16-bit float
|
|
130
|
-
// on Arm, we use __fp16
|
|
131
|
-
// on x86, we use uint16_t
|
|
132
|
-
#if defined(__ARM_NEON)
|
|
133
|
-
|
|
134
|
-
// if YCM cannot find <arm_neon.h>, make a symbolic link to it, for example:
|
|
135
|
-
//
|
|
136
|
-
// $ ln -sfn /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/arm_neon.h ./src/
|
|
137
|
-
//
|
|
138
|
-
#include <arm_neon.h>
|
|
139
|
-
|
|
140
|
-
#ifdef _MSC_VER
|
|
141
|
-
|
|
142
|
-
typedef uint16_t wsp_ggml_fp16_internal_t;
|
|
143
|
-
|
|
144
|
-
#define wsp_ggml_vld1q_u32(w,x,y,z) { ((w) + ((uint64_t)(x) << 32)), ((y) + ((uint64_t)(z) << 32)) }
|
|
145
|
-
|
|
146
|
-
#else
|
|
147
|
-
|
|
148
|
-
typedef __fp16 wsp_ggml_fp16_internal_t;
|
|
149
|
-
|
|
150
|
-
#define wsp_ggml_vld1q_u32(w,x,y,z) { (w), (x), (y), (z) }
|
|
151
|
-
|
|
152
|
-
#endif // _MSC_VER
|
|
153
|
-
|
|
154
|
-
#if !defined(__aarch64__)
|
|
155
|
-
|
|
156
|
-
// 32-bit ARM compatibility
|
|
157
|
-
|
|
158
|
-
// vaddlvq_s16
|
|
159
|
-
// vpaddq_s16
|
|
160
|
-
// vpaddq_s32
|
|
161
|
-
// vaddvq_s32
|
|
162
|
-
// vaddvq_f32
|
|
163
|
-
// vmaxvq_f32
|
|
164
|
-
// vcvtnq_s32_f32
|
|
165
|
-
// vzip1_u8
|
|
166
|
-
// vzip2_u8
|
|
167
|
-
|
|
168
|
-
inline static int32_t vaddlvq_s16(int16x8_t v) {
|
|
169
|
-
int32x4_t v0 = vreinterpretq_s32_s64(vpaddlq_s32(vpaddlq_s16(v)));
|
|
170
|
-
return vgetq_lane_s32(v0, 0) + vgetq_lane_s32(v0, 2);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
inline static int16x8_t vpaddq_s16(int16x8_t a, int16x8_t b) {
|
|
174
|
-
int16x4_t a0 = vpadd_s16(vget_low_s16(a), vget_high_s16(a));
|
|
175
|
-
int16x4_t b0 = vpadd_s16(vget_low_s16(b), vget_high_s16(b));
|
|
176
|
-
return vcombine_s16(a0, b0);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
inline static int32x4_t vpaddq_s32(int32x4_t a, int32x4_t b) {
|
|
180
|
-
int32x2_t a0 = vpadd_s32(vget_low_s32(a), vget_high_s32(a));
|
|
181
|
-
int32x2_t b0 = vpadd_s32(vget_low_s32(b), vget_high_s32(b));
|
|
182
|
-
return vcombine_s32(a0, b0);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
inline static int32_t vaddvq_s32(int32x4_t v) {
|
|
186
|
-
return vgetq_lane_s32(v, 0) + vgetq_lane_s32(v, 1) + vgetq_lane_s32(v, 2) + vgetq_lane_s32(v, 3);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
inline static float vaddvq_f32(float32x4_t v) {
|
|
190
|
-
return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
inline static float vmaxvq_f32(float32x4_t v) {
|
|
194
|
-
return
|
|
195
|
-
MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
|
|
196
|
-
MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
inline static int32x4_t vcvtnq_s32_f32(float32x4_t v) {
|
|
200
|
-
int32x4_t res;
|
|
201
|
-
|
|
202
|
-
res[0] = roundf(vgetq_lane_f32(v, 0));
|
|
203
|
-
res[1] = roundf(vgetq_lane_f32(v, 1));
|
|
204
|
-
res[2] = roundf(vgetq_lane_f32(v, 2));
|
|
205
|
-
res[3] = roundf(vgetq_lane_f32(v, 3));
|
|
206
|
-
|
|
207
|
-
return res;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
inline static uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
|
|
211
|
-
uint8x8_t res;
|
|
212
|
-
|
|
213
|
-
res[0] = a[0]; res[1] = b[0];
|
|
214
|
-
res[2] = a[1]; res[3] = b[1];
|
|
215
|
-
res[4] = a[2]; res[5] = b[2];
|
|
216
|
-
res[6] = a[3]; res[7] = b[3];
|
|
217
|
-
|
|
218
|
-
return res;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
inline static uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
|
|
222
|
-
uint8x8_t res;
|
|
223
|
-
|
|
224
|
-
res[0] = a[4]; res[1] = b[4];
|
|
225
|
-
res[2] = a[5]; res[3] = b[5];
|
|
226
|
-
res[4] = a[6]; res[5] = b[6];
|
|
227
|
-
res[6] = a[7]; res[7] = b[7];
|
|
228
|
-
|
|
229
|
-
return res;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// vld1q_s16_x2
|
|
233
|
-
// vld1q_u8_x2
|
|
234
|
-
// vld1q_u8_x4
|
|
235
|
-
// vld1q_s8_x2
|
|
236
|
-
// vld1q_s8_x4
|
|
237
|
-
// TODO: double-check these work correctly
|
|
238
|
-
|
|
239
|
-
typedef struct wsp_ggml_int16x8x2_t {
|
|
240
|
-
int16x8_t val[2];
|
|
241
|
-
} wsp_ggml_int16x8x2_t;
|
|
242
|
-
|
|
243
|
-
inline static wsp_ggml_int16x8x2_t wsp_ggml_vld1q_s16_x2(const int16_t * ptr) {
|
|
244
|
-
wsp_ggml_int16x8x2_t res;
|
|
245
|
-
|
|
246
|
-
res.val[0] = vld1q_s16(ptr + 0);
|
|
247
|
-
res.val[1] = vld1q_s16(ptr + 8);
|
|
248
|
-
|
|
249
|
-
return res;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
typedef struct wsp_ggml_uint8x16x2_t {
|
|
253
|
-
uint8x16_t val[2];
|
|
254
|
-
} wsp_ggml_uint8x16x2_t;
|
|
255
|
-
|
|
256
|
-
inline static wsp_ggml_uint8x16x2_t wsp_ggml_vld1q_u8_x2(const uint8_t * ptr) {
|
|
257
|
-
wsp_ggml_uint8x16x2_t res;
|
|
258
|
-
|
|
259
|
-
res.val[0] = vld1q_u8(ptr + 0);
|
|
260
|
-
res.val[1] = vld1q_u8(ptr + 16);
|
|
261
|
-
|
|
262
|
-
return res;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
typedef struct wsp_ggml_uint8x16x4_t {
|
|
266
|
-
uint8x16_t val[4];
|
|
267
|
-
} wsp_ggml_uint8x16x4_t;
|
|
268
|
-
|
|
269
|
-
inline static wsp_ggml_uint8x16x4_t wsp_ggml_vld1q_u8_x4(const uint8_t * ptr) {
|
|
270
|
-
wsp_ggml_uint8x16x4_t res;
|
|
271
|
-
|
|
272
|
-
res.val[0] = vld1q_u8(ptr + 0);
|
|
273
|
-
res.val[1] = vld1q_u8(ptr + 16);
|
|
274
|
-
res.val[2] = vld1q_u8(ptr + 32);
|
|
275
|
-
res.val[3] = vld1q_u8(ptr + 48);
|
|
276
|
-
|
|
277
|
-
return res;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
typedef struct wsp_ggml_int8x16x2_t {
|
|
281
|
-
int8x16_t val[2];
|
|
282
|
-
} wsp_ggml_int8x16x2_t;
|
|
283
|
-
|
|
284
|
-
inline static wsp_ggml_int8x16x2_t wsp_ggml_vld1q_s8_x2(const int8_t * ptr) {
|
|
285
|
-
wsp_ggml_int8x16x2_t res;
|
|
286
|
-
|
|
287
|
-
res.val[0] = vld1q_s8(ptr + 0);
|
|
288
|
-
res.val[1] = vld1q_s8(ptr + 16);
|
|
289
|
-
|
|
290
|
-
return res;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
typedef struct wsp_ggml_int8x16x4_t {
|
|
294
|
-
int8x16_t val[4];
|
|
295
|
-
} wsp_ggml_int8x16x4_t;
|
|
296
|
-
|
|
297
|
-
inline static wsp_ggml_int8x16x4_t wsp_ggml_vld1q_s8_x4(const int8_t * ptr) {
|
|
298
|
-
wsp_ggml_int8x16x4_t res;
|
|
299
|
-
|
|
300
|
-
res.val[0] = vld1q_s8(ptr + 0);
|
|
301
|
-
res.val[1] = vld1q_s8(ptr + 16);
|
|
302
|
-
res.val[2] = vld1q_s8(ptr + 32);
|
|
303
|
-
res.val[3] = vld1q_s8(ptr + 48);
|
|
304
|
-
|
|
305
|
-
return res;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// NOTE: not tested
|
|
309
|
-
inline static int8x16_t wsp_ggml_vqtbl1q_s8(int8x16_t a, uint8x16_t b) {
|
|
310
|
-
int8x16_t res;
|
|
311
|
-
|
|
312
|
-
res[ 0] = a[b[ 0]];
|
|
313
|
-
res[ 1] = a[b[ 1]];
|
|
314
|
-
res[ 2] = a[b[ 2]];
|
|
315
|
-
res[ 3] = a[b[ 3]];
|
|
316
|
-
res[ 4] = a[b[ 4]];
|
|
317
|
-
res[ 5] = a[b[ 5]];
|
|
318
|
-
res[ 6] = a[b[ 6]];
|
|
319
|
-
res[ 7] = a[b[ 7]];
|
|
320
|
-
res[ 8] = a[b[ 8]];
|
|
321
|
-
res[ 9] = a[b[ 9]];
|
|
322
|
-
res[10] = a[b[10]];
|
|
323
|
-
res[11] = a[b[11]];
|
|
324
|
-
res[12] = a[b[12]];
|
|
325
|
-
res[13] = a[b[13]];
|
|
326
|
-
res[14] = a[b[14]];
|
|
327
|
-
res[15] = a[b[15]];
|
|
328
|
-
|
|
329
|
-
return res;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// NOTE: not tested
|
|
333
|
-
inline static uint8x16_t wsp_ggml_vqtbl1q_u8(uint8x16_t a, uint8x16_t b) {
|
|
334
|
-
uint8x16_t res;
|
|
335
|
-
|
|
336
|
-
res[ 0] = a[b[ 0]];
|
|
337
|
-
res[ 1] = a[b[ 1]];
|
|
338
|
-
res[ 2] = a[b[ 2]];
|
|
339
|
-
res[ 3] = a[b[ 3]];
|
|
340
|
-
res[ 4] = a[b[ 4]];
|
|
341
|
-
res[ 5] = a[b[ 5]];
|
|
342
|
-
res[ 6] = a[b[ 6]];
|
|
343
|
-
res[ 7] = a[b[ 7]];
|
|
344
|
-
res[ 8] = a[b[ 8]];
|
|
345
|
-
res[ 9] = a[b[ 9]];
|
|
346
|
-
res[10] = a[b[10]];
|
|
347
|
-
res[11] = a[b[11]];
|
|
348
|
-
res[12] = a[b[12]];
|
|
349
|
-
res[13] = a[b[13]];
|
|
350
|
-
res[14] = a[b[14]];
|
|
351
|
-
res[15] = a[b[15]];
|
|
352
|
-
|
|
353
|
-
return res;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
#else
|
|
357
|
-
|
|
358
|
-
#define wsp_ggml_int16x8x2_t int16x8x2_t
|
|
359
|
-
#define wsp_ggml_uint8x16x2_t uint8x16x2_t
|
|
360
|
-
#define wsp_ggml_uint8x16x4_t uint8x16x4_t
|
|
361
|
-
#define wsp_ggml_int8x16x2_t int8x16x2_t
|
|
362
|
-
#define wsp_ggml_int8x16x4_t int8x16x4_t
|
|
363
|
-
|
|
364
|
-
#define wsp_ggml_vld1q_s16_x2 vld1q_s16_x2
|
|
365
|
-
#define wsp_ggml_vld1q_u8_x2 vld1q_u8_x2
|
|
366
|
-
#define wsp_ggml_vld1q_u8_x4 vld1q_u8_x4
|
|
367
|
-
#define wsp_ggml_vld1q_s8_x2 vld1q_s8_x2
|
|
368
|
-
#define wsp_ggml_vld1q_s8_x4 vld1q_s8_x4
|
|
369
|
-
#define wsp_ggml_vqtbl1q_s8 vqtbl1q_s8
|
|
370
|
-
#define wsp_ggml_vqtbl1q_u8 vqtbl1q_u8
|
|
371
|
-
|
|
372
|
-
#endif // !defined(__aarch64__)
|
|
373
|
-
|
|
374
|
-
#if !defined(__ARM_FEATURE_DOTPROD)
|
|
375
|
-
|
|
376
|
-
inline static int32x4_t wsp_ggml_vdotq_s32(int32x4_t acc, int8x16_t a, int8x16_t b) {
|
|
377
|
-
const int16x8_t p0 = vmull_s8(vget_low_s8 (a), vget_low_s8 (b));
|
|
378
|
-
const int16x8_t p1 = vmull_s8(vget_high_s8(a), vget_high_s8(b));
|
|
379
|
-
|
|
380
|
-
return vaddq_s32(acc, vaddq_s32(vpaddlq_s16(p0), vpaddlq_s16(p1)));
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
#else
|
|
384
|
-
|
|
385
|
-
#define wsp_ggml_vdotq_s32(a, b, c) vdotq_s32(a, b, c)
|
|
386
|
-
|
|
387
|
-
#endif // !defined(__ARM_FEATURE_DOTPROD)
|
|
388
|
-
|
|
389
|
-
#endif // defined(__ARM_NEON)
|
|
390
|
-
|
|
391
|
-
#if defined(__ARM_NEON) && !defined(_MSC_VER)
|
|
392
|
-
|
|
393
|
-
#define WSP_GGML_COMPUTE_FP16_TO_FP32(x) wsp_ggml_compute_fp16_to_fp32(x)
|
|
394
|
-
#define WSP_GGML_COMPUTE_FP32_TO_FP16(x) wsp_ggml_compute_fp32_to_fp16(x)
|
|
395
|
-
|
|
396
|
-
#define WSP_GGML_FP16_TO_FP32(x) wsp_ggml_compute_fp16_to_fp32(x)
|
|
397
|
-
|
|
398
|
-
static inline float wsp_ggml_compute_fp16_to_fp32(wsp_ggml_fp16_t h) {
|
|
399
|
-
wsp_ggml_fp16_internal_t tmp;
|
|
400
|
-
memcpy(&tmp, &h, sizeof(wsp_ggml_fp16_t));
|
|
401
|
-
return (float)tmp;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
static inline wsp_ggml_fp16_t wsp_ggml_compute_fp32_to_fp16(float f) {
|
|
405
|
-
wsp_ggml_fp16_t res;
|
|
406
|
-
wsp_ggml_fp16_internal_t tmp = f;
|
|
407
|
-
memcpy(&res, &tmp, sizeof(wsp_ggml_fp16_t));
|
|
408
|
-
return res;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
#else
|
|
412
|
-
|
|
413
|
-
#ifdef __wasm_simd128__
|
|
414
|
-
#include <wasm_simd128.h>
|
|
415
|
-
#else
|
|
416
|
-
#ifdef __POWER9_VECTOR__
|
|
417
|
-
#include <altivec.h>
|
|
418
|
-
#undef bool
|
|
419
|
-
#define bool _Bool
|
|
420
|
-
#else
|
|
421
|
-
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
422
|
-
#include <intrin.h>
|
|
423
|
-
#else
|
|
424
|
-
#if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__) || defined(__SSSE3__) || defined(__SSE3__) || defined(__SSE__)
|
|
425
|
-
#if !defined(__riscv)
|
|
426
|
-
#include <immintrin.h>
|
|
427
|
-
#endif
|
|
428
|
-
#endif
|
|
429
|
-
#endif
|
|
430
|
-
#endif
|
|
431
|
-
#endif
|
|
432
|
-
|
|
433
|
-
#ifdef __riscv_v_intrinsic
|
|
434
|
-
#include <riscv_vector.h>
|
|
435
|
-
#endif
|
|
436
|
-
|
|
437
|
-
#if defined(__loongarch64)
|
|
438
|
-
#if defined(__loongarch_asx)
|
|
439
|
-
#include <lasxintrin.h>
|
|
440
|
-
#endif
|
|
441
|
-
#if defined(__loongarch_sx)
|
|
442
|
-
#include <lsxintrin.h>
|
|
443
|
-
#endif
|
|
444
|
-
#endif
|
|
445
|
-
|
|
446
|
-
#if defined(__loongarch_asx)
|
|
447
|
-
|
|
448
|
-
typedef union {
|
|
449
|
-
int32_t i;
|
|
450
|
-
float f;
|
|
451
|
-
} ft_union;
|
|
452
|
-
|
|
453
|
-
/* float type data load instructions */
|
|
454
|
-
static __m128 __lsx_vreplfr2vr_s(float val) {
|
|
455
|
-
ft_union fi_tmpval = {.f = val};
|
|
456
|
-
return (__m128)__lsx_vreplgr2vr_w(fi_tmpval.i);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
static __m256 __lasx_xvreplfr2vr_s(float val) {
|
|
460
|
-
ft_union fi_tmpval = {.f = val};
|
|
461
|
-
return (__m256)__lasx_xvreplgr2vr_w(fi_tmpval.i);
|
|
462
|
-
}
|
|
463
|
-
#endif
|
|
464
|
-
|
|
465
|
-
#ifdef __F16C__
|
|
466
|
-
|
|
467
|
-
#ifdef _MSC_VER
|
|
468
|
-
#define WSP_GGML_COMPUTE_FP16_TO_FP32(x) _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128(x)))
|
|
469
|
-
#define WSP_GGML_COMPUTE_FP32_TO_FP16(x) _mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(x), 0), 0)
|
|
470
|
-
#else
|
|
471
|
-
#define WSP_GGML_COMPUTE_FP16_TO_FP32(x) _cvtsh_ss(x)
|
|
472
|
-
#define WSP_GGML_COMPUTE_FP32_TO_FP16(x) _cvtss_sh(x, 0)
|
|
473
|
-
#endif
|
|
474
|
-
|
|
475
|
-
#elif defined(__POWER9_VECTOR__)
|
|
476
|
-
|
|
477
|
-
#define WSP_GGML_COMPUTE_FP16_TO_FP32(x) wsp_ggml_compute_fp16_to_fp32(x)
|
|
478
|
-
#define WSP_GGML_COMPUTE_FP32_TO_FP16(x) wsp_ggml_compute_fp32_to_fp16(x)
|
|
479
|
-
/* the inline asm below is about 12% faster than the lookup method */
|
|
480
|
-
#define WSP_GGML_FP16_TO_FP32(x) WSP_GGML_COMPUTE_FP16_TO_FP32(x)
|
|
481
|
-
#define WSP_GGML_FP32_TO_FP16(x) WSP_GGML_COMPUTE_FP32_TO_FP16(x)
|
|
482
|
-
|
|
483
|
-
static inline float wsp_ggml_compute_fp16_to_fp32(wsp_ggml_fp16_t h) {
|
|
484
|
-
register float f;
|
|
485
|
-
register double d;
|
|
486
|
-
__asm__(
|
|
487
|
-
"mtfprd %0,%2\n"
|
|
488
|
-
"xscvhpdp %0,%0\n"
|
|
489
|
-
"frsp %1,%0\n" :
|
|
490
|
-
/* temp */ "=d"(d),
|
|
491
|
-
/* out */ "=f"(f):
|
|
492
|
-
/* in */ "r"(h));
|
|
493
|
-
return f;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
static inline wsp_ggml_fp16_t wsp_ggml_compute_fp32_to_fp16(float f) {
|
|
497
|
-
register double d;
|
|
498
|
-
register wsp_ggml_fp16_t r;
|
|
499
|
-
__asm__( /* xscvdphp can work on double or single precision */
|
|
500
|
-
"xscvdphp %0,%2\n"
|
|
501
|
-
"mffprd %1,%0\n" :
|
|
502
|
-
/* temp */ "=d"(d),
|
|
503
|
-
/* out */ "=r"(r):
|
|
504
|
-
/* in */ "f"(f));
|
|
505
|
-
return r;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
#else
|
|
509
|
-
|
|
510
|
-
// FP16 <-> FP32
|
|
511
|
-
// ref: https://github.com/Maratyszcza/FP16
|
|
512
|
-
|
|
513
|
-
static inline float fp32_from_bits(uint32_t w) {
|
|
514
|
-
union {
|
|
515
|
-
uint32_t as_bits;
|
|
516
|
-
float as_value;
|
|
517
|
-
} fp32;
|
|
518
|
-
fp32.as_bits = w;
|
|
519
|
-
return fp32.as_value;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
static inline uint32_t fp32_to_bits(float f) {
|
|
523
|
-
union {
|
|
524
|
-
float as_value;
|
|
525
|
-
uint32_t as_bits;
|
|
526
|
-
} fp32;
|
|
527
|
-
fp32.as_value = f;
|
|
528
|
-
return fp32.as_bits;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
static inline float wsp_ggml_compute_fp16_to_fp32(wsp_ggml_fp16_t h) {
|
|
532
|
-
const uint32_t w = (uint32_t) h << 16;
|
|
533
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
534
|
-
const uint32_t two_w = w + w;
|
|
535
|
-
|
|
536
|
-
const uint32_t exp_offset = UINT32_C(0xE0) << 23;
|
|
537
|
-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
538
|
-
const float exp_scale = 0x1.0p-112f;
|
|
539
|
-
#else
|
|
540
|
-
const float exp_scale = fp32_from_bits(UINT32_C(0x7800000));
|
|
541
|
-
#endif
|
|
542
|
-
const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale;
|
|
543
|
-
|
|
544
|
-
const uint32_t magic_mask = UINT32_C(126) << 23;
|
|
545
|
-
const float magic_bias = 0.5f;
|
|
546
|
-
const float denormalized_value = fp32_from_bits((two_w >> 17) | magic_mask) - magic_bias;
|
|
547
|
-
|
|
548
|
-
const uint32_t denormalized_cutoff = UINT32_C(1) << 27;
|
|
549
|
-
const uint32_t result = sign |
|
|
550
|
-
(two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) : fp32_to_bits(normalized_value));
|
|
551
|
-
return fp32_from_bits(result);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
static inline wsp_ggml_fp16_t wsp_ggml_compute_fp32_to_fp16(float f) {
|
|
555
|
-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
556
|
-
const float scale_to_inf = 0x1.0p+112f;
|
|
557
|
-
const float scale_to_zero = 0x1.0p-110f;
|
|
558
|
-
#else
|
|
559
|
-
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
|
|
560
|
-
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
|
|
561
|
-
#endif
|
|
562
|
-
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
|
|
563
|
-
|
|
564
|
-
const uint32_t w = fp32_to_bits(f);
|
|
565
|
-
const uint32_t shl1_w = w + w;
|
|
566
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
567
|
-
uint32_t bias = shl1_w & UINT32_C(0xFF000000);
|
|
568
|
-
if (bias < UINT32_C(0x71000000)) {
|
|
569
|
-
bias = UINT32_C(0x71000000);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
base = fp32_from_bits((bias >> 1) + UINT32_C(0x07800000)) + base;
|
|
573
|
-
const uint32_t bits = fp32_to_bits(base);
|
|
574
|
-
const uint32_t exp_bits = (bits >> 13) & UINT32_C(0x00007C00);
|
|
575
|
-
const uint32_t mantissa_bits = bits & UINT32_C(0x00000FFF);
|
|
576
|
-
const uint32_t nonsign = exp_bits + mantissa_bits;
|
|
577
|
-
return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
#define WSP_GGML_COMPUTE_FP16_TO_FP32(x) wsp_ggml_compute_fp16_to_fp32(x)
|
|
581
|
-
#define WSP_GGML_COMPUTE_FP32_TO_FP16(x) wsp_ggml_compute_fp32_to_fp16(x)
|
|
582
|
-
|
|
583
|
-
#endif // __F16C__
|
|
584
|
-
|
|
585
|
-
#endif // defined(__ARM_NEON) && (!defined(__MSC_VER)
|
|
586
|
-
|
|
587
|
-
#ifdef __ARM_FEATURE_SVE
|
|
588
|
-
#include <arm_sve.h>
|
|
589
|
-
#endif // __ARM_FEATURE_SVE
|
|
590
|
-
|
|
591
|
-
// precomputed f32 table for f16 (256 KB)
|
|
592
|
-
// defined in ggml.c, initialized in wsp_ggml_init()
|
|
593
|
-
extern float wsp_ggml_table_f32_f16[1 << 16];
|
|
594
|
-
|
|
595
|
-
// On ARM NEON, it's quicker to directly convert x -> x instead of calling into wsp_ggml_lookup_fp16_to_fp32,
|
|
596
|
-
// so we define WSP_GGML_FP16_TO_FP32 and WSP_GGML_FP32_TO_FP16 elsewhere for NEON.
|
|
597
|
-
// This is also true for POWER9.
|
|
598
|
-
#if !defined(WSP_GGML_FP16_TO_FP32)
|
|
599
|
-
inline static float wsp_ggml_lookup_fp16_to_fp32(wsp_ggml_fp16_t f) {
|
|
600
|
-
uint16_t s;
|
|
601
|
-
memcpy(&s, &f, sizeof(uint16_t));
|
|
602
|
-
return wsp_ggml_table_f32_f16[s];
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
#define WSP_GGML_FP16_TO_FP32(x) wsp_ggml_lookup_fp16_to_fp32(x)
|
|
606
|
-
#endif
|
|
607
|
-
|
|
608
|
-
#if !defined(WSP_GGML_FP32_TO_FP16)
|
|
609
|
-
#define WSP_GGML_FP32_TO_FP16(x) WSP_GGML_COMPUTE_FP32_TO_FP16(x)
|
|
610
|
-
#endif
|
|
611
|
-
|
|
612
|
-
#ifdef __cplusplus
|
|
613
|
-
}
|
|
614
|
-
#endif
|