]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper : restore big endian support (#2816)
authorThomas Fitzsimmons <redacted>
Tue, 25 Feb 2025 09:38:13 +0000 (09:38 +0000)
committerGitHub <redacted>
Tue, 25 Feb 2025 09:38:13 +0000 (11:38 +0200)
* whisper : fix BYTESWAP whitespace

* whisper : make byteswap useable with C++17

* cmake : define WHISPER_BIG_ENDIAN for big-endian targets

* ci : fix (again) arm64 build fails

* docker : attempt fixing arm64 build on ci

* qemu v7.0.0-28

[imported from
https://github.com/ggml-org/llama.cpp
/commit/818a340ea8be55b3706e1772527cb8738e90a8c7
(#11895)]

---------

Co-authored-by: Xuan-Son Nguyen <redacted>
.github/workflows/docker.yml
src/CMakeLists.txt
src/whisper.cpp

index 30887e3248e55d533a0aa881c2c5efc117a6be06..55f75f0c83e425a6271de5f15479c324137c8f62 100644 (file)
@@ -28,6 +28,8 @@ jobs:
 
       - name: Set up QEMU
         uses: docker/setup-qemu-action@v3
+        with:
+          image: tonistiigi/binfmt:qemu-v7.0.0-28
 
       - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@v3
index ff54d6451651859f4fc253a45f71da8a4098a9be..ea3161dbdab9cfcd7e5f993a77bcd5c7264a1512 100644 (file)
@@ -94,6 +94,10 @@ set_target_properties(whisper PROPERTIES
 target_include_directories(whisper PUBLIC . ../include)
 target_compile_features   (whisper PUBLIC cxx_std_11) # don't bump
 
+if (CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
+    set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_BIG_ENDIAN)
+endif()
+
 if (WHISPER_EXTRA_FLAGS)
     target_compile_options(whisper PRIVATE ${WHISPER_EXTRA_FLAGS})
 endif()
index 069aa6e73b90d76c71826f58d80f3172a3e4b1ca..447846c99b221d8b6c96293049efa2585e369cb1 100644 (file)
 #pragma warning(disable: 4244 4267) // possible loss of data
 #endif
 
-#if defined(GGML_BIG_ENDIAN)
-#include <bit>
-
+#if defined(WHISPER_BIG_ENDIAN)
 template<typename T>
 static T byteswap(T value) {
-    return std::byteswap(value);
-}
-
-template<>
-float byteswap(float value) {
-    return std::bit_cast<float>(byteswap(std::bit_cast<std::uint32_t>(value)));
+    T value_swapped;
+    char * source = reinterpret_cast<char *>(&value);
+    char * target = reinterpret_cast<char *>(&value_swapped);
+    int size = sizeof(T);
+    for (int i = 0; i < size; i++) {
+        target[size - 1 - i] = source[i];
+    }
+    return value_swapped;
 }
 
 template<typename T>
@@ -85,14 +85,14 @@ static void byteswap_tensor(ggml_tensor * tensor) {
 }
 
 #define BYTESWAP_VALUE(d) d = byteswap(d)
-#define BYTESWAP_FILTERS(f)            \
+#define BYTESWAP_FILTERS(f)           \
     do {                              \
         for (auto & datum : f.data) { \
             datum = byteswap(datum);  \
         }                             \
     } while (0)
-#define BYTESWAP_TENSOR(t)       \
-    do {                         \
+#define BYTESWAP_TENSOR(t)  \
+    do {                    \
         byteswap_tensor(t); \
     } while (0)
 #else