Skip to content

Commit 3614354

Browse files
gjasnyczoido
andauthored
whisper-cpp: add option to enable CUDA, fixed BLAS integration, and stop publishing revisions for older versions (#27320)
* whisper-cpp: add option to enable CUDA * fixup! whisper-cpp: add option to enable CUDA * wip * add openblas patch * wip * minor changes --------- Co-authored-by: Carlos Zoido <[email protected]>
1 parent 024a357 commit 3614354

File tree

7 files changed

+77
-79
lines changed

7 files changed

+77
-79
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
sources:
2+
"1.7.6":
3+
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.7.6.tar.gz"
4+
sha256: "166140e9a6d8a36f787a2bd77f8f44dd64874f12dd8359ff7c1f4f9acb86202e"
25
"1.7.5":
36
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.7.5.tar.gz"
47
sha256: "2fda42b57b7b8427d724551bd041616d85401fb9382e42b0349132a28920a34f"
58
"1.7.4":
69
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.7.4.tar.gz"
710
sha256: "9ce7b33028793fcbf62f81f1fd087af7778dace8772eaba8c43c66bf0c8a3eed"
8-
"1.7.2":
9-
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.7.2.tar.gz"
10-
sha256: "d48e1b5b6ee18b931e98ac791eba838f83eb3b81bb8917db37fe9a79fa5e3ccb"
11-
"1.6.2":
12-
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.6.2.tar.gz"
13-
sha256: "da7988072022acc3cfa61b370b3c51baad017f1900c3dc4e68cb276499f66894"
14-
"1.5.2":
15-
url: "https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v1.5.2.tar.gz"
16-
sha256: "be9c4d5d4b5f28f02e36f28e602b7d2dcfd734dd1c834ddae91ae8db601e951f"
1711
patches:
18-
"1.6.2":
19-
- patch_file: "patches/1.6.2-0001-remove_hardcoded_cxxstd.patch"
20-
patch_description: "Remove hardcoded CMAKE_CXX_STANDARD"
21-
patch_type: "conan"
12+
"1.7.6":
13+
- patch_file: "patches/1.7.4-0001-fix-quoting.patch"
14+
"1.7.5":
15+
- patch_file: "patches/1.7.4-0001-fix-quoting.patch"
16+
"1.7.4":
17+
- patch_file: "patches/1.7.4-0001-fix-quoting.patch"

recipes/whisper-cpp/all/conanfile.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2+
import textwrap
23

34
from conan import ConanFile
45
from conan.errors import ConanInvalidConfiguration
56
from conan.tools.apple import is_apple_os
67
from conan.tools.build import check_min_cppstd
78
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
8-
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm
9+
from conan.tools.files import copy, apply_conandata_patches, export_conandata_patches, get, rm, save
910
from conan.tools.scm import Version
1011

1112
required_conan_version = ">=2.1"
@@ -36,6 +37,7 @@ class WhisperCppConan(ConanFile):
3637
"coreml_allow_fallback": [True, False],
3738
"with_blas": [True, False],
3839
"with_openvino": [True, False],
40+
"with_cuda": [True, False],
3941
}
4042
default_options = {
4143
"shared": False,
@@ -54,6 +56,7 @@ class WhisperCppConan(ConanFile):
5456
"coreml_allow_fallback": False,
5557
"with_blas": False,
5658
"with_openvino": False,
59+
"with_cuda": False,
5760
}
5861
package_type = "library"
5962

@@ -74,12 +77,23 @@ def _compilers_minimum_version(self):
7477
}.get(self._min_cppstd, {})
7578

7679
@property
77-
def _is_openvino_option_available(self):
78-
return Version(self.version) >= "1.5.2"
80+
def _cuda_build_module(self):
81+
# Adding this to the package info is necessary if we want consumers of whisper to link correctly when
82+
# they activate the CUDA option. In the future, when we have a CUDA recipe this could be removed.
83+
return textwrap.dedent("""\
84+
find_dependency(CUDAToolkit REQUIRED)
85+
if (WIN32)
86+
# As of CUDA 12.3.1, Windows does not offer a static cublas library
87+
target_link_libraries(whisper-cpp::whisper-cpp INTERFACE CUDA::cudart_static CUDA::cublas CUDA::cublasLt CUDA::cuda_driver)
88+
else ()
89+
target_link_libraries(whisper-cpp::whisper-cpp INTERFACE CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static CUDA::cuda_driver)
90+
endif()
91+
""")
7992

8093
def config_options(self):
8194
if is_apple_os(self):
8295
del self.options.with_blas
96+
del self.options.with_cuda
8397
else:
8498
del self.options.metal
8599
del self.options.metal_ndebug
@@ -90,9 +104,6 @@ def config_options(self):
90104
if self.settings.os == "Windows":
91105
del self.options.fPIC
92106

93-
if not self._is_openvino_option_available:
94-
del self.options.with_openvino
95-
96107
def configure(self):
97108
if self.options.shared:
98109
self.options.rm_safe("fPIC")
@@ -112,7 +123,7 @@ def validate(self):
112123

113124
def requirements(self):
114125
if not is_apple_os(self):
115-
if self.options.with_blas:
126+
if self.options.get_safe("with_blas"):
116127
self.requires("openblas/0.3.24")
117128
if self.options.get_safe("with_openvino"):
118129
self.requires("openvino/2023.2.0")
@@ -155,6 +166,12 @@ def generate(self):
155166
# TODO: Implement OpenMP support
156167
tc.variables["GGML_OPENMP"] = False
157168

169+
tc.variables["GGML_CUDA"] = bool(self.options.get_safe("with_cuda", False))
170+
171+
tc.variables["GGML_BLAS"] = bool(self.options.get_safe("with_blas", False))
172+
if self.options.get_safe("with_blas"):
173+
tc.variables["GGML_BLAS_VENDOR"] = "OpenBLAS"
174+
158175
if self.options.get_safe("with_openvino"):
159176
tc.variables["WHISPER_OPENVINO"] = True
160177
# TODO: remove with Conan 1.x support
@@ -169,16 +186,7 @@ def generate(self):
169186
tc.variables["WHISPER_COREML"] = True
170187
if self.options.coreml_allow_fallback:
171188
tc.variables["WHISPER_COREML_ALLOW_FALLBACK"] = True
172-
if Version(self.version) >= "1.7.0":
173-
tc.variables["GGML_METAL"] = self.options.metal
174-
else:
175-
tc.variables["WHISPER_METAL"] = self.options.metal
176-
else:
177-
if self.options.with_blas:
178-
if Version(self.version) >= "1.4.2":
179-
tc.variables["WHISPER_OPENBLAS"] = True
180-
else:
181-
tc.variables["WHISPER_SUPPORT_OPENBLAS"] = True
189+
tc.variables["GGML_METAL"] = bool(self.options.get_safe("metal", False))
182190

183191
tc.generate()
184192

@@ -195,21 +203,20 @@ def package(self):
195203
rm(self, "*.cmake", self.package_folder, recursive=True)
196204
rm(self, "*.pc", self.package_folder, recursive=True)
197205
copy(self, "*", os.path.join(self.source_folder, "models"), os.path.join(self.package_folder, "res", "models"))
206+
if self.options.get_safe("with_cuda") and not self.options.shared:
207+
save(self, os.path.join(self.package_folder, "lib", "cmake", "whisper-cpp-cuda-static.cmake"), self._cuda_build_module)
198208

199209
def package_info(self):
200210
self.cpp_info.libs = ["whisper"]
201-
if Version(self.version) >= "1.7.0":
202-
self.cpp_info.libs.append("ggml")
203-
if Version(self.version) >= "1.7.3":
204-
self.cpp_info.libs.extend(["ggml-base", "ggml-cpu"])
211+
self.cpp_info.libs.extend(["ggml", "ggml-base", "ggml-cpu"])
212+
if self.options.get_safe("with_cuda"):
213+
self.cpp_info.libs.append("ggml-cuda")
205214
self.cpp_info.resdirs = ["res"]
206-
if Version(self.version) < "1.7.0":
207-
self.cpp_info.libdirs = ["lib", "lib/static"]
208215

209216
if self.options.get_safe("with_blas"):
210-
self.cpp_info.requires = ["ggml-blas"]
217+
self.cpp_info.libs.extend(["ggml-blas"])
211218
if self.options.get_safe("with_openvino"):
212-
self.cpp_info.requires = ["openvino::Runtime"]
219+
self.cpp_info.requires.append("openvino::Runtime")
213220

214221
if is_apple_os(self):
215222
if not self.options.no_accelerate:
@@ -218,7 +225,11 @@ def package_info(self):
218225
self.cpp_info.frameworks.append("CoreML")
219226
if self.options.get_safe("metal"):
220227
self.cpp_info.frameworks.extend(["CoreFoundation", "Foundation", "Metal", "MetalKit"])
221-
if Version(self.version) >= "1.7.3":
222-
self.cpp_info.libs.extend(["ggml-metal", "ggml-blas"])
228+
self.cpp_info.libs.extend(["ggml-metal"])
223229
elif self.settings.os in ("Linux", "FreeBSD"):
224230
self.cpp_info.system_libs.extend(["dl", "m", "pthread"])
231+
232+
if self.options.get_safe("with_cuda") and not self.options.shared:
233+
self.cpp_info.builddirs.append(os.path.join("lib", "cmake"))
234+
module_path = os.path.join("lib", "cmake", "whisper-cpp-cuda-static.cmake")
235+
self.cpp_info.set_property("cmake_build_modules", [module_path])

recipes/whisper-cpp/all/patches/1.6.2-0001-remove_hardcoded_cxxstd.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
From e0505a3f2363926c4d58a648700beb50c3133a38 Mon Sep 17 00:00:00 2001
2+
Date: Thu, 18 Sep 2025 13:12:05 +0200
3+
Subject: [PATCH] fix quoting
4+
5+
---
6+
ggml/src/ggml-blas/CMakeLists.txt | 2 +-
7+
1 file changed, 1 insertion(+), 1 deletion(-)
8+
9+
diff --git a/ggml/src/ggml-blas/CMakeLists.txt b/ggml/src/ggml-blas/CMakeLists.txt
10+
index 0bf3c05d..a2624487 100644
11+
--- a/ggml/src/ggml-blas/CMakeLists.txt
12+
+++ b/ggml/src/ggml-blas/CMakeLists.txt
13+
@@ -74,7 +74,7 @@ if (BLAS_FOUND)
14+
15+
target_compile_options(ggml-blas PRIVATE ${BLAS_LINKER_FLAGS})
16+
17+
- if (${BLAS_INCLUDE_DIRS} MATCHES "mkl" AND (${GGML_BLAS_VENDOR} MATCHES "Generic" OR ${GGML_BLAS_VENDOR} MATCHES "Intel"))
18+
+ if ("${BLAS_INCLUDE_DIRS}" MATCHES "mkl" AND (${GGML_BLAS_VENDOR} MATCHES "Generic" OR ${GGML_BLAS_VENDOR} MATCHES "Intel"))
19+
add_compile_definitions(GGML_BLAS_USE_MKL)
20+
endif()
21+
22+
--
23+
2.39.5 (Apple Git-154)
24+
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
cmake_minimum_required(VERSION 3.15)
22

3-
project(test_package CXX) # if the project uses c++
3+
project(test_package CXX)
44

55
find_package(whisper-cpp REQUIRED CONFIG)
66

77
add_executable(${PROJECT_NAME} test_package.cpp)
88
target_link_libraries(${PROJECT_NAME} PRIVATE whisper-cpp::whisper-cpp)
9-
10-
11-
add_custom_command(TARGET test_package POST_BUILD
12-
COMMAND ${CMAKE_COMMAND} -E copy_directory
13-
${whisper-cpp_INCLUDE_DIR}/../res/models
14-
${CMAKE_CURRENT_BINARY_DIR}/models)
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
#include <iostream>
2-
#include <memory>
3-
#include <vector>
4-
#include "whisper.h"
5-
2+
#include <whisper.h>
63

74
int main() {
8-
auto context = std::unique_ptr<whisper_context, void(*)(whisper_context*)>(
9-
whisper_init_from_file("models/for-tests-ggml-base.en.bin"), &whisper_free);
10-
11-
if (context == nullptr) {
12-
std::cout << "Failed to initialize whisper context!" << std::endl;
13-
return 3;
14-
}
15-
16-
return EXIT_SUCCESS;
5+
std::cout << whisper_print_system_info() << std::endl;
6+
return 0;
177
}

recipes/whisper-cpp/config.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
versions:
2+
"1.7.6":
3+
folder: "all"
24
"1.7.5":
35
folder: "all"
46
"1.7.4":
57
folder: "all"
6-
"1.7.2":
7-
folder: "all"
8-
"1.6.2":
9-
folder: "all"
10-
"1.5.2":
11-
folder: "all"

0 commit comments

Comments
 (0)