fix(nix): enable Vulkan GPU inference for pywhispercpp (#942)
Nice work, Vulkan acceleration on Nix has been a long time coming.
This commit is contained in:
@@ -38,14 +38,14 @@
|
||||
});
|
||||
|
||||
overlays.default = final: prev: {
|
||||
vocalinux = self.packages.${prev.system}.vocalinux;
|
||||
vocalinux = self.packages.${prev.stdenv.hostPlatform.system}.vocalinux;
|
||||
};
|
||||
|
||||
nixosModules.vocalinux =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ ./packaging/nix/module.nix ];
|
||||
programs.vocalinux.package = lib.mkDefault self.packages.${pkgs.system}.vocalinux;
|
||||
programs.vocalinux.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.vocalinux;
|
||||
};
|
||||
nixosModules.default = self.nixosModules.vocalinux;
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ ./packaging/nix/home-manager.nix ];
|
||||
programs.vocalinux.package = lib.mkDefault self.packages.${pkgs.system}.vocalinux;
|
||||
programs.vocalinux.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.vocalinux;
|
||||
};
|
||||
homeManagerModules.default = self.homeManagerModules.vocalinux;
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
setxkbmap,
|
||||
pulseaudio,
|
||||
alsa-utils,
|
||||
vulkan-tools,
|
||||
src,
|
||||
}:
|
||||
|
||||
@@ -70,6 +71,7 @@ let
|
||||
pulseaudio # paplay
|
||||
alsa-utils # aplay
|
||||
(lib.getBin glib) # gdbus
|
||||
vulkan-tools # vulkaninfo for Vulkan GPU discovery and selection
|
||||
];
|
||||
in
|
||||
buildPythonApplication {
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
setuptools,
|
||||
wheel,
|
||||
cmake,
|
||||
shaderc,
|
||||
spirv-headers,
|
||||
vulkan-headers,
|
||||
vulkan-loader,
|
||||
numpy,
|
||||
requests,
|
||||
tqdm,
|
||||
@@ -48,10 +52,10 @@ buildPythonPackage rec {
|
||||
env = {
|
||||
# The sdist ships no version.txt; setup.py falls back to this env var.
|
||||
PYWHISPERCPP_VERSION = version;
|
||||
# One static extension module (BUILD_SHARED_LIBS defaults ON upstream and
|
||||
# would need $ORIGIN rpath repair that never runs outside cibuildwheel) and
|
||||
# a portable baseline instead of -march=native.
|
||||
CMAKE_ARGS = "-DBUILD_SHARED_LIBS=OFF -DGGML_NATIVE=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON";
|
||||
# Build Vulkan as a shared backend: Vocalinux's GPU detector looks for
|
||||
# libggml-vulkan.so. CMake's build-tree RPATH can leak /build into the
|
||||
# wheel; disable CMake RPATHs and let autoPatchelfHook set Nix runtime paths.
|
||||
CMAKE_ARGS = "-DBUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DGGML_VULKAN=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_SKIP_RPATH=ON";
|
||||
};
|
||||
|
||||
# env attrs are exported verbatim; expanding the core count needs a shell
|
||||
@@ -67,6 +71,7 @@ buildPythonPackage rec {
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
shaderc # provides glslc, used to compile whisper.cpp's Vulkan shaders
|
||||
autoPatchelfHook
|
||||
];
|
||||
|
||||
@@ -75,8 +80,14 @@ buildPythonPackage rec {
|
||||
wheel
|
||||
];
|
||||
|
||||
# libstdc++/libgomp for the compiled extension.
|
||||
buildInputs = [ stdenv.cc.cc.lib ];
|
||||
# CMake's Vulkan backend calls find_package(SPIRV-Headers CONFIG REQUIRED),
|
||||
# so expose the package configuration as well as the Vulkan headers/loader.
|
||||
buildInputs = [
|
||||
stdenv.cc.cc.lib
|
||||
spirv-headers
|
||||
vulkan-headers
|
||||
vulkan-loader
|
||||
];
|
||||
|
||||
dependencies = [
|
||||
numpy
|
||||
|
||||
Reference in New Issue
Block a user