Skip to content

Commit

Permalink
Add: nnapiを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Sep 17, 2023
1 parent bf70839 commit a77e120
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 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"]
nnapi = ["onnxruntime/nnapi"]

[dependencies]
anyhow.workspace = true
Expand Down Expand Up @@ -35,8 +36,8 @@ tracing.workspace = true
uuid.workspace = true

[dependencies.onnxruntime]
git = "https://github.com/VOICEVOX/onnxruntime-rs.git"
rev = "ebb9dcb9b26ee681889b52b6db3b4f642b04a250"
git = "https://github.com/sevenc-nanashi/onnxruntime-rs.git"
rev = "c92be02d675b53d48ea77bd52bd6074dd770494a"

[dependencies.open_jtalk]
git = "https://github.com/VOICEVOX/open_jtalk-rs.git"
Expand Down
10 changes: 10 additions & 0 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ pub struct SupportedDevices {
///
/// [DirectML Execution Provider]: https://onnxruntime.ai/docs/execution-providers/DirectML-ExecutionProvider.html
dml: bool,
/// NNAPIが利用可能。
///
/// ONNX Runtimeの[NNAPI Execution Provider] (`NnapiExecutionProvider`)に対応する。必要な環境に
/// ついてはそちらを参照。
///
/// [NNAPI Execution Provider]: https://onnxruntime.ai/docs/execution-providers/NNAPI-ExecutionProvider.html
nnapi: 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 nnapi_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,
"NnapiExecutionProvider" => nnapi_support = true,
_ => {}
}
}
Expand All @@ -59,6 +68,7 @@ impl SupportedDevices {
cpu: true,
cuda: cuda_support,
dml: dml_support,
nnapi: nnapi_support,
})
}

Expand Down
6 changes: 4 additions & 2 deletions crates/voicevox_core/src/inference_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ impl InferenceCore {
let supported_devices = SupportedDevices::create()?;

cfg_if! {
if #[cfg(feature = "directml")]{
if #[cfg(feature = "directml")] {
Ok(*supported_devices.dml())
} else{
} else if #[cfg(feature = "nnapi")] {
Ok(*supported_devices.nnapi())
} else {
Ok(*supported_devices.cuda())
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/voicevox_core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use tracing::error;
mod model_file;

cfg_if! {
if #[cfg(not(feature="directml"))]{
if #[cfg(feature="nnapi")] {
use onnxruntime::NnapiProviderOptions;
} else if #[cfg(not(feature="directml"))] {
use onnxruntime::CudaProviderOptions;
}
}
Expand Down Expand Up @@ -143,11 +145,14 @@ impl Status {

let session_builder = if *session_options.use_gpu() {
cfg_if! {
if #[cfg(feature = "directml")]{
if #[cfg(feature = "directml")] {
session_builder
.with_disable_mem_pattern()?
.with_execution_mode(onnxruntime::ExecutionMode::ORT_SEQUENTIAL)?
.with_append_execution_provider_directml(0)?
} else if #[cfg(feature = "nnapi")] {
let options = NnapiProviderOptions::default();
session_builder.with_append_execution_provider_nnapi(&options)?
} else {
let options = CudaProviderOptions::default();
session_builder.with_append_execution_provider_cuda(options)?
Expand Down
5 changes: 3 additions & 2 deletions crates/voicevox_core/src/voice_synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ impl Synthesizer {
let supported_devices = SupportedDevices::create()?;

cfg_if! {
if #[cfg(feature="directml")]{
if #[cfg(feature="directml")] {
*supported_devices.dml()

} else if #[cfg(feature="nnapi")] {
*supported_devices.nnapi()
} else {
*supported_devices.cuda()
}
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"]
nnapi = ["voicevox_core/nnapi"]

[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"]
nnapi = ["voicevox_core/nnapi"]

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

0 comments on commit a77e120

Please sign in to comment.