mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-02-28 19:25:56 +00:00
whisper : restore big endian support (#2816)
* 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 <thichthat@gmail.com>
This commit is contained in:
parent
d682e15090
commit
47e14c0529
2
.github/workflows/docker.yml
vendored
2
.github/workflows/docker.yml
vendored
@ -28,6 +28,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
with:
|
||||||
|
image: tonistiigi/binfmt:qemu-v7.0.0-28
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
@ -94,6 +94,10 @@ set_target_properties(whisper PROPERTIES
|
|||||||
target_include_directories(whisper PUBLIC . ../include)
|
target_include_directories(whisper PUBLIC . ../include)
|
||||||
target_compile_features (whisper PUBLIC cxx_std_11) # don't bump
|
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)
|
if (WHISPER_EXTRA_FLAGS)
|
||||||
target_compile_options(whisper PRIVATE ${WHISPER_EXTRA_FLAGS})
|
target_compile_options(whisper PRIVATE ${WHISPER_EXTRA_FLAGS})
|
||||||
endif()
|
endif()
|
||||||
|
@ -39,17 +39,17 @@
|
|||||||
#pragma warning(disable: 4244 4267) // possible loss of data
|
#pragma warning(disable: 4244 4267) // possible loss of data
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GGML_BIG_ENDIAN)
|
#if defined(WHISPER_BIG_ENDIAN)
|
||||||
#include <bit>
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static T byteswap(T value) {
|
static T byteswap(T value) {
|
||||||
return std::byteswap(value);
|
T value_swapped;
|
||||||
}
|
char * source = reinterpret_cast<char *>(&value);
|
||||||
|
char * target = reinterpret_cast<char *>(&value_swapped);
|
||||||
template<>
|
int size = sizeof(T);
|
||||||
float byteswap(float value) {
|
for (int i = 0; i < size; i++) {
|
||||||
return std::bit_cast<float>(byteswap(std::bit_cast<std::uint32_t>(value)));
|
target[size - 1 - i] = source[i];
|
||||||
|
}
|
||||||
|
return value_swapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -85,14 +85,14 @@ static void byteswap_tensor(ggml_tensor * tensor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define BYTESWAP_VALUE(d) d = byteswap(d)
|
#define BYTESWAP_VALUE(d) d = byteswap(d)
|
||||||
#define BYTESWAP_FILTERS(f) \
|
#define BYTESWAP_FILTERS(f) \
|
||||||
do { \
|
do { \
|
||||||
for (auto & datum : f.data) { \
|
for (auto & datum : f.data) { \
|
||||||
datum = byteswap(datum); \
|
datum = byteswap(datum); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define BYTESWAP_TENSOR(t) \
|
#define BYTESWAP_TENSOR(t) \
|
||||||
do { \
|
do { \
|
||||||
byteswap_tensor(t); \
|
byteswap_tensor(t); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user