Thomas Fitzsimmons Xuan-Son Nguyen commited on
Commit
7631e20
·
unverified ·
1 Parent(s): 9f0fbdf

whisper : restore big endian support (#2816)

Browse files

* 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 <[email protected]>

.github/workflows/docker.yml CHANGED
@@ -28,6 +28,8 @@ jobs:
28
 
29
  - name: Set up QEMU
30
  uses: docker/setup-qemu-action@v3
 
 
31
 
32
  - name: Set up Docker Buildx
33
  uses: docker/setup-buildx-action@v3
 
28
 
29
  - name: Set up QEMU
30
  uses: docker/setup-qemu-action@v3
31
+ with:
32
+ image: tonistiigi/binfmt:qemu-v7.0.0-28
33
 
34
  - name: Set up Docker Buildx
35
  uses: docker/setup-buildx-action@v3
src/CMakeLists.txt CHANGED
@@ -94,6 +94,10 @@ set_target_properties(whisper PROPERTIES
94
  target_include_directories(whisper PUBLIC . ../include)
95
  target_compile_features (whisper PUBLIC cxx_std_11) # don't bump
96
 
 
 
 
 
97
  if (WHISPER_EXTRA_FLAGS)
98
  target_compile_options(whisper PRIVATE ${WHISPER_EXTRA_FLAGS})
99
  endif()
 
94
  target_include_directories(whisper PUBLIC . ../include)
95
  target_compile_features (whisper PUBLIC cxx_std_11) # don't bump
96
 
97
+ if (CMAKE_CXX_BYTE_ORDER STREQUAL "BIG_ENDIAN")
98
+ set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_BIG_ENDIAN)
99
+ endif()
100
+
101
  if (WHISPER_EXTRA_FLAGS)
102
  target_compile_options(whisper PRIVATE ${WHISPER_EXTRA_FLAGS})
103
  endif()
src/whisper.cpp CHANGED
@@ -39,17 +39,17 @@
39
  #pragma warning(disable: 4244 4267) // possible loss of data
40
  #endif
41
 
42
- #if defined(GGML_BIG_ENDIAN)
43
- #include <bit>
44
-
45
  template<typename T>
46
  static T byteswap(T value) {
47
- return std::byteswap(value);
48
- }
49
-
50
- template<>
51
- float byteswap(float value) {
52
- return std::bit_cast<float>(byteswap(std::bit_cast<std::uint32_t>(value)));
 
 
53
  }
54
 
55
  template<typename T>
@@ -85,14 +85,14 @@ static void byteswap_tensor(ggml_tensor * tensor) {
85
  }
86
 
87
  #define BYTESWAP_VALUE(d) d = byteswap(d)
88
- #define BYTESWAP_FILTERS(f) \
89
  do { \
90
  for (auto & datum : f.data) { \
91
  datum = byteswap(datum); \
92
  } \
93
  } while (0)
94
- #define BYTESWAP_TENSOR(t) \
95
- do { \
96
  byteswap_tensor(t); \
97
  } while (0)
98
  #else
 
39
  #pragma warning(disable: 4244 4267) // possible loss of data
40
  #endif
41
 
42
+ #if defined(WHISPER_BIG_ENDIAN)
 
 
43
  template<typename T>
44
  static T byteswap(T value) {
45
+ T value_swapped;
46
+ char * source = reinterpret_cast<char *>(&value);
47
+ char * target = reinterpret_cast<char *>(&value_swapped);
48
+ int size = sizeof(T);
49
+ for (int i = 0; i < size; i++) {
50
+ target[size - 1 - i] = source[i];
51
+ }
52
+ return value_swapped;
53
  }
54
 
55
  template<typename T>
 
85
  }
86
 
87
  #define BYTESWAP_VALUE(d) d = byteswap(d)
88
+ #define BYTESWAP_FILTERS(f) \
89
  do { \
90
  for (auto & datum : f.data) { \
91
  datum = byteswap(datum); \
92
  } \
93
  } while (0)
94
+ #define BYTESWAP_TENSOR(t) \
95
+ do { \
96
  byteswap_tensor(t); \
97
  } while (0)
98
  #else