From 41d909f5ef7baf434f3ddce5e3c2493e26c2a5f1 Mon Sep 17 00:00:00 2001 From: flavio Date: Fri, 31 May 2024 09:58:48 +0200 Subject: [PATCH 1/3] rocm linux support --- Cargo.toml | 1 + README.md | 1 + sys/Cargo.toml | 1 + sys/build.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8b8c8fb..c03b7fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ default = [] raw-api = [] coreml = ["whisper-rs-sys/coreml"] cuda = ["whisper-rs-sys/cuda", "_gpu"] +hipblas = ["whisper-rs-sys/hipblas", "_gpu"] opencl = ["whisper-rs-sys/opencl"] openblas = ["whisper-rs-sys/openblas"] metal = ["whisper-rs-sys/metal", "_gpu"] diff --git a/README.md b/README.md index 9cdcdaa..6b1bb6b 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ All disabled by default unless otherwise specified. **NOTE**: enabling this no longer guarantees semver compliance, as whisper-rs-sys may be upgraded to a breaking version in a patch release of whisper-rs. * `cuda`: enable CUDA support. Implicitly enables hidden GPU flag at runtime. +* `hipblas`: enable ROCm/hipBLAS support. Only available on linux. Implicitly enables hidden GPU flag at runtime. * `opencl`: enable OpenCL support. Upstream whisper.cpp does not treat OpenCL as a GPU, so it is always enabled at runtime. * `openblas`: enable OpenBLAS support. diff --git a/sys/Cargo.toml b/sys/Cargo.toml index d0ebdd2..b74a8ea 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -43,6 +43,7 @@ include = [ [features] coreml = [] cuda = [] +hipblas = [] opencl = [] openblas = [] metal = [] diff --git a/sys/build.rs b/sys/build.rs index 05996a6..846189b 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -58,6 +58,29 @@ fn main() { } } } + #[cfg(feature = "hipblas")] + { + println!("cargo:rustc-link-lib=hipblas"); + println!("cargo:rustc-link-lib=rocblas"); + println!("cargo:rustc-link-lib=amdhip64"); + + cfg_if::cfg_if! { + if #[cfg(target_os = "windows")] { + panic!("Not supported yet!!!") + } else { + println!("cargo:rerun-if-env-changed=HIP_PATH"); + + let hip_path = match env::var("HIP_PATH") { + Ok(path) =>PathBuf::from(path), + Err(_) => PathBuf::from("/opt/rocm"), + }; + let hip_lib_path = hip_path.join("lib"); + + println!("cargo:rustc-link-search={}",hip_lib_path.display()); + } + } + } + println!("cargo:rerun-if-changed=wrapper.h"); let out = PathBuf::from(env::var("OUT_DIR").unwrap()); @@ -126,6 +149,16 @@ fn main() { config.define("WHISPER_CUDA", "ON"); } + if cfg!(feature = "hipblas") { + config.define("WHISPER_HIPBLAS", "ON"); + config.define("CMAKE_C_COMPILER", "hipcc"); + config.define("CMAKE_CXX_COMPILER", "hipcc"); + println!("cargo:rerun-if-env-changed=AMDGPU_TARGETS"); + if let Ok(gpu_targets) = env::var("AMDGPU_TARGETS") { + config.define("AMDGPU_TARGETS", gpu_targets); + } + } + if cfg!(feature = "openblas") { config.define("WHISPER_OPENBLAS", "ON"); } From 18d8a96d6e9ff9d3ffda2448fb3b4bad25e9542a Mon Sep 17 00:00:00 2001 From: flavio Date: Sun, 2 Jun 2024 12:43:14 +0200 Subject: [PATCH 2/3] improved panic message --- sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/build.rs b/sys/build.rs index 846189b..0ac474a 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -66,7 +66,7 @@ fn main() { cfg_if::cfg_if! { if #[cfg(target_os = "windows")] { - panic!("Not supported yet!!!") + panic!("Due to a problem with the last revision of the ROCm 5.7 library, it is not possible to compile the library for the windows environment.\nSee https://github.com/ggerganov/whisper.cpp/issues/2202 for more details.") } else { println!("cargo:rerun-if-env-changed=HIP_PATH"); From ce71477a37c48e37d1118b7a69cc592b62dc6240 Mon Sep 17 00:00:00 2001 From: flavio Date: Sun, 2 Jun 2024 20:46:12 +0200 Subject: [PATCH 3/3] fix: fmt --- sys/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/build.rs b/sys/build.rs index 0ac474a..248fa11 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -63,7 +63,7 @@ fn main() { println!("cargo:rustc-link-lib=hipblas"); println!("cargo:rustc-link-lib=rocblas"); println!("cargo:rustc-link-lib=amdhip64"); - + cfg_if::cfg_if! { if #[cfg(target_os = "windows")] { panic!("Due to a problem with the last revision of the ROCm 5.7 library, it is not possible to compile the library for the windows environment.\nSee https://github.com/ggerganov/whisper.cpp/issues/2202 for more details.") @@ -80,7 +80,7 @@ fn main() { } } } - + println!("cargo:rerun-if-changed=wrapper.h"); let out = PathBuf::from(env::var("OUT_DIR").unwrap());