Skip to content

Commit

Permalink
Add: CoreMLを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 16, 2023
1 parent bf70839 commit e3e7151
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish.workspace = true
[features]
default = []
directml = ["onnxruntime/directml"]
coreml = ["onnxruntime/coreml"]

[dependencies]
anyhow.workspace = true
Expand Down
12 changes: 11 additions & 1 deletion crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
/// このライブラリで利用可能なデバイスの情報。
///
/// あくまで本ライブラリが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったと
/// しても`cuda``dml`は`true`を示しうる
/// しても`cuda``dml`、`coreml`が`true`になることがある
#[derive(Getters, Debug, Serialize, Deserialize)]
pub struct SupportedDevices {
/// CPUが利用可能。
Expand All @@ -26,6 +26,13 @@ pub struct SupportedDevices {
///
/// [DirectML Execution Provider]: https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html
dml: bool,
/// CoreMLが利用可能。
///
/// ONNX Runtimeの[CoreML Execution Provider] (`CoreMLExecutionProvider`)に対応する。必要な環境に
/// ついてはそちらを参照。
///
/// [CoreML Execution Provider]: https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html
coreml: bool,
}

impl SupportedDevices {
Expand All @@ -44,13 +51,15 @@ impl SupportedDevices {
pub fn create() -> Result<Self> {
let mut cuda_support = false;
let mut dml_support = false;
let mut coreml_support = false;
for provider in onnxruntime::session::get_available_providers()
.map_err(|e| ErrorRepr::GetSupportedDevices(e.into()))?
.iter()
{
match provider.as_str() {
"CUDAExecutionProvider" => cuda_support = true,
"DmlExecutionProvider" => dml_support = true,
"CoreMlExecutionProvider" => coreml_support = true,
_ => {}
}
}
Expand All @@ -59,6 +68,7 @@ impl SupportedDevices {
cpu: true,
cuda: cuda_support,
dml: dml_support,
coreml: coreml_support,
})
}

Expand Down
8 changes: 7 additions & 1 deletion crates/voicevox_core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ use tracing::error;
mod model_file;

cfg_if! {
if #[cfg(not(feature="directml"))]{
if #[cfg(not(feature="directml", feature="coreml"))] {
use onnxruntime::CudaProviderOptions;
} else if #[cfg(feature="coreml")] {
use onnxruntime::CoreMLProviderOptions;
}

}
use std::collections::BTreeMap;

Expand Down Expand Up @@ -148,6 +151,9 @@ impl Status {
.with_disable_mem_pattern()?
.with_execution_mode(onnxruntime::ExecutionMode::ORT_SEQUENTIAL)?
.with_append_execution_provider_directml(0)?
} else if #[cfg(feature = "coreml")] {
let options = CoreMlProviderOptions::default();
session_builder.with_append_execution_provider_coreml(options)?
} else {
let options = CudaProviderOptions::default();
session_builder.with_append_execution_provider_cuda(options)?
Expand Down
1 change: 1 addition & 0 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ name = "e2e"

[features]
directml = ["voicevox_core/directml"]
coreml = ["voicevox_core/coreml"]

[dependencies]
cstr = "0.2.11"
Expand Down
1 change: 1 addition & 0 deletions crates/voicevox_core_python_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crate-type = ["cdylib"]

[features]
directml = ["voicevox_core/directml"]
coreml = ["voicevox_core/coreml"]

[dependencies]
easy-ext.workspace = true
Expand Down

0 comments on commit e3e7151

Please sign in to comment.