Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: rework GPU features #810

Merged
merged 10 commits into from
Aug 4, 2024
18 changes: 8 additions & 10 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,20 @@ impl SupportedDevices {
/// assert!(!SupportedDevices::THIS.cuda);
/// assert!(!SupportedDevices::THIS.dml);
/// ```
pub const THIS: Self = {
#[cfg(feature = "load-onnxruntime")]
{
Self {
cpu: true,
cuda: true,
dml: true,
}
pub const THIS: Self = if cfg!(feature = "load-onnxruntime") {
Self {
cpu: true,
cuda: true,
dml: true,
}

#[cfg(all(not(doc), feature = "link-onnxruntime"))]
} else if cfg!(feature = "link-onnxruntime") {
Self {
cpu: true,
cuda: false,
dml: false,
}
} else {
panic!("either `load-onnxruntime` or `link-onnxruntime` must be enabled");
};

pub fn to_json(self) -> serde_json::Value {
Expand Down
12 changes: 5 additions & 7 deletions crates/voicevox_core/src/infer/runtimes/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ impl InferenceRuntime for self::blocking::Onnxruntime {
type Session = ort::Session;
type RunContext<'a> = OnnxruntimeRunContext<'a>;

const DISPLAY_NAME: &'static str = {
#[cfg(feature = "load-onnxruntime")]
{
"現在ロードされているONNX Runtime"
}

#[cfg(feature = "link-onnxruntime")]
const DISPLAY_NAME: &'static str = if cfg!(feature = "load-onnxruntime") {
"現在ロードされているONNX Runtime"
} else if cfg!(feature = "link-onnxruntime") {
"現在リンクされているONNX Runtime"
} else {
panic!("either `load-onnxruntime` or `link-onnxruntime` must be enabled");
};

fn supported_devices(&self) -> crate::Result<SupportedDevices> {
Expand Down
5 changes: 4 additions & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
//! ません。両方の有効化はコンパイルエラーとなります。[`Onnxruntime`]の初期化方法はこれらの
//! フィーチャによって決まります。
//!
//! - **`load-onnxruntime`**: ONNX Runtimeを`dlopen`/`LoadLibraryExW`で開きます。
//! - **`load-onnxruntime`**: ONNX Runtimeを`dlopen`/`LoadLibraryExW`で
//! 開きます。[CUDA]と[DirectML]が利用できます。
Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これをダウンロードするだけじゃなくproviderが必要なので若干語弊があるかもですが、まあ・・・。

//! - **`link-onnxruntime`**: ONNX Runtimeをロード時動的リンクします。iOSのような`dlopen`の利用が
//! 困難な環境でのみこちらを利用するべきです。_Note_:
//! [動的リンク対象のライブラリ名]は`onnxruntime`で固定です。変更
//! は`patchelf(1)`や`install_name_tool(1)`で行ってください。また、[ONNX RuntimeのGPU機能]を使う
//! ことはできません。
//!
//! [Cargoフィーチャ]: https://doc.rust-lang.org/stable/cargo/reference/features.html
//! [CUDA]: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
//! [DirectML]: https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html
//! [動的リンク対象のライブラリ名]:
//! https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib
//! [`Onnxruntime`]: blocking::Onnxruntime
Expand Down
Loading