Skip to content

Commit dc8cc2d

Browse files
committed
whisper : disable CUDA mel + fix FFMPEG
1 parent 3efedb9 commit dc8cc2d

File tree

6 files changed

+68
-41
lines changed

6 files changed

+68
-41
lines changed

examples/CMakeLists.txt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (WHISPER_SDL2)
1111
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
1212

1313
message(STATUS "SDL2_INCLUDE_DIRS = ${SDL2_INCLUDE_DIRS}")
14-
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
14+
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
1515
endif()
1616

1717
if (WHISPER_CLBLAST)
@@ -22,10 +22,35 @@ endif()
2222

2323
set(TARGET common)
2424

25+
unset(COMMON_EXTRA_LIBS)
26+
2527
if (WHISPER_FFMPEG)
28+
# As of cmake 3.27, there is no official cmake support for FindFFmpeg.
29+
# Consequnelty we added a FindFFmpeg.cmake script the cmake subfolder:
30+
# whisper.cpp does not need the full ffmpeg libs, just AVFORMAT AVCODEC AVUTIL SWRESAMPLE
31+
# libswresample performs highly optimized audio resampling, rematrixing and sample format conversion operations
32+
# libavcodec provides a generic encoding/decoding framework and contains multiple decoders and encoders for audio, video and subtitle streams, and several bitstream filters.
33+
# libavformat provides a generic framework for multiplexing and demultiplexing (muxing and demuxing) audio, video and subtitle streams.
34+
find_package(FFmpeg REQUIRED)
35+
36+
if (NOT ${FFMPEG_FOUND})
37+
message(FATAL_ERROR "Cannot find ffmpeg libs/headers")
38+
endif()
39+
40+
message(STATUS "Found ffmpeg libs: ${FFMPEG_LIBRARIES}")
41+
message(STATUS "Found ffmpeg headers in: ${FFMPEG_INCLUDE_DIRS}")
42+
message(STATUS "ffmpeg definitions: ${FFMPEG_DEFINITIONS}")
43+
message(STATUS "Found avformat ${AVFORMAT_VERSION}")
44+
45+
include_directories(${FFMPEG_INCLUDE_DIRS})
46+
add_compile_definitions(WHISPER_FFMPEG)
47+
48+
list(APPEND COMMON_EXTRA_LIBS ${FFMPEG_LIBRARIES})
49+
2650
set(COMMON_SOURCES_FFMPEG ffmpeg-transcode.cpp)
2751
endif()
2852

53+
2954
add_library(${TARGET} STATIC
3055
common.h
3156
common.cpp
@@ -38,7 +63,7 @@ add_library(${TARGET} STATIC
3863

3964
include(DefaultTargetOptions)
4065

41-
target_link_libraries(${TARGET} PRIVATE whisper)
66+
target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS})
4267

4368
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
4469
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
@@ -55,8 +80,8 @@ if (WHISPER_SDL2)
5580

5681
include(DefaultTargetOptions)
5782

58-
target_include_directories(${TARGET} PUBLIC ${SDL2_INCLUDE_DIRS})
59-
target_link_libraries(${TARGET} PRIVATE ${SDL2_LIBRARIES})
83+
target_include_directories(${TARGET} PUBLIC ${SDL2_INCLUDE_DIRS})
84+
target_link_libraries (${TARGET} PRIVATE ${SDL2_LIBRARIES})
6085

6186
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
6287
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
@@ -108,7 +133,7 @@ if (WHISPER_SDL2)
108133
set_target_properties(talk-llama PROPERTIES FOLDER "examples")
109134
add_subdirectory(lsp)
110135
set_target_properties(lsp PROPERTIES FOLDER "examples")
111-
if (LLAMA_SYCL)
136+
if (GGML_SYCL)
112137
add_subdirectory(sycl)
113138
set_target_properties(sycl PROPERTIES FOLDER "examples")
114139
endif()

examples/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern bool ffmpeg_decode_audio(const std::string & ifname, std::vector<uint8_t>
3030
#endif
3131

3232
// Function to check if the next argument exists
33-
std::string get_next_arg(int& i, int argc, char** argv, const std::string& flag, gpt_params& params) {
33+
static std::string get_next_arg(int& i, int argc, char** argv, const std::string& flag, gpt_params& params) {
3434
if (i + 1 < argc && argv[i + 1][0] != '-') {
3535
return argv[++i];
3636
} else {
@@ -346,7 +346,7 @@ std::vector<gpt_vocab::id> gpt_tokenize(const gpt_vocab & vocab, const std::stri
346346
return tokens;
347347
}
348348

349-
std::vector<gpt_vocab::id> parse_tokens_from_string(const std::string& input, char delimiter) {
349+
static std::vector<gpt_vocab::id> parse_tokens_from_string(const std::string& input, char delimiter) {
350350
std::vector<gpt_vocab::id> output;
351351
std::stringstream ss(input);
352352
std::string token;
@@ -358,7 +358,7 @@ std::vector<gpt_vocab::id> parse_tokens_from_string(const std::string& input, ch
358358
return output;
359359
}
360360

361-
std::map<std::string, std::vector<gpt_vocab::id>> extract_tests_from_file(const std::string & fpath_test){
361+
static std::map<std::string, std::vector<gpt_vocab::id>> extract_tests_from_file(const std::string & fpath_test){
362362
if (fpath_test.empty()){
363363
fprintf(stderr, "%s : No test file found.\n", __func__);
364364
return std::map<std::string, std::vector<gpt_vocab::id>>();

scripts/build-info.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if out=$($CC -dumpmachine); then
2424
build_target=$out
2525
fi
2626

27-
echo "int LLAMA_BUILD_NUMBER = ${build_number};"
28-
echo "char const *LLAMA_COMMIT = \"${build_commit}\";"
29-
echo "char const *LLAMA_COMPILER = \"${build_compiler}\";"
30-
echo "char const *LLAMA_BUILD_TARGET = \"${build_target}\";"
27+
echo "int WHISPER_BUILD_NUMBER = ${build_number};"
28+
echo "char const *WHISPER_COMMIT = \"${build_commit}\";"
29+
echo "char const *WHISPER_COMPILER = \"${build_compiler}\";"
30+
echo "char const *WHISPER_BUILD_TARGET = \"${build_target}\";"

src/CMakeLists.txt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@ if (WHISPER_OPENVINO)
7777
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
7878
endif()
7979

80-
if (GGML_CUDA)
81-
cmake_minimum_required(VERSION 3.18) # for CMAKE_CUDA_ARCHITECTURES
82-
83-
find_package(CUDAToolkit)
84-
if (CUDAToolkit_FOUND)
85-
message(STATUS "CUDA found")
86-
87-
if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
88-
# 52 == lowest CUDA 12 standard
89-
# 60 == f16 CUDA intrinsics
90-
# 61 == integer CUDA intrinsics
91-
# 70 == compute capability at which unrolling a loop in mul_mat_q kernels is faster
92-
set(CMAKE_CUDA_ARCHITECTURES "52;61;70") # lowest CUDA 12 standard + lowest for integer intrinsics
93-
endif()
94-
message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
95-
96-
enable_language(CUDA)
97-
else()
98-
message(WARNING "CUDA not found")
99-
endif()
100-
endif()
80+
#if (GGML_CUDA)
81+
# cmake_minimum_required(VERSION 3.18) # for CMAKE_CUDA_ARCHITECTURES
82+
#
83+
# find_package(CUDAToolkit)
84+
# if (CUDAToolkit_FOUND)
85+
# message(STATUS "CUDA found")
86+
#
87+
# if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
88+
# # 52 == lowest CUDA 12 standard
89+
# # 60 == f16 CUDA intrinsics
90+
# # 61 == integer CUDA intrinsics
91+
# # 70 == compute capability at which unrolling a loop in mul_mat_q kernels is faster
92+
# set(CMAKE_CUDA_ARCHITECTURES "52;61;70") # lowest CUDA 12 standard + lowest for integer intrinsics
93+
# endif()
94+
# message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
95+
#
96+
# enable_language(CUDA)
97+
# else()
98+
# message(WARNING "CUDA not found")
99+
# endif()
100+
#endif()
101101

102102
# whisper
103103

@@ -107,11 +107,12 @@ add_library(whisper
107107
whisper-mel.hpp
108108
)
109109

110-
if (GGML_CUDA)
111-
target_sources(whisper PRIVATE whisper-mel-cuda.cu)
112-
113-
target_link_libraries(whisper PRIVATE CUDA::cufft)
114-
endif()
110+
# TODO: disabled because it relies on ggml internals that are no longer accessible (ggml-backend-impl.h, ggml-cuda/common.cuh, ..)
111+
#if (GGML_CUDA)
112+
# target_sources(whisper PRIVATE whisper-mel-cuda.cu)
113+
#
114+
# target_link_libraries(whisper PRIVATE CUDA::cufft)
115+
#endif()
115116

116117
# Set the version numbers
117118
set_target_properties(whisper PROPERTIES

src/whisper-mel-cuda.cu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include "whisper-mel-cuda.hpp"
33
#include "whisper.h"
44

5-
#include <ggml-cuda/common.cuh>
6-
#include <ggml-backend-impl.h>
5+
#include <ggml-backend.h>
76

87
#include <cuda.h>
98
#include <cuda_runtime.h>

src/whisper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,9 @@ struct mel_calc_cpu : public whisper_mel_calc {
32153215
}
32163216

32173217
static whisper_mel_calc * whisper_mel_calc_create(ggml_backend_t backend, const whisper_filters & filters) {
3218-
#if defined(GGML_USE_CUDA) && !defined(GGML_USE_HIPBLAS)
3218+
// TODO: disabled because it relies on ggml internals that are no longer accessible (ggml-backend-impl.h, ggml-cuda/common.cuh, ..)
3219+
//#if defined(GGML_USE_CUDA) && !defined(GGML_USE_HIPBLAS)
3220+
#if 0
32193221
if (ggml_backend_is_cuda(backend)) {
32203222
auto ret = whisper_mel_calc_create_cuda(backend, filters);
32213223
if (ret) {

0 commit comments

Comments
 (0)