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

整理: ランタイム DLL ロードのコメント付け #1132

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions voicevox_engine/core/core_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class CoreError(Exception):


def load_runtime_lib(runtime_dirs: list[Path]) -> None:
"""
コアの実行に必要な依存 DLL をロードする。検索対象ディレクトリは引数 `runtime_dirs` およびシステム検索対象ディレクトリ。

Args:
runtime_dirs - 直下に DLL が存在するディレクトリの一覧
"""
# `lib_file_names`は「ENGINE が利用可能な DLL のファイル名一覧」である
# `lib_names` は「ENGINE が利用可能な DLL のライブラリ名一覧」である(ライブラリ名は `libtorch.so.1.0` の `torch` 部分)
if platform.system() == "Windows":
# DirectML.dllはonnxruntimeと互換性のないWindows標準搭載のものを優先して読み込むことがあるため、明示的に読み込む
# 参考 1. https://github.com/microsoft/onnxruntime/issues/3360
Expand All @@ -40,12 +48,16 @@ def load_runtime_lib(runtime_dirs: list[Path]) -> None:
lib_names = ["onnxruntime"]
else:
raise RuntimeError("不明なOSです")
for lib_path in runtime_dirs:
for file_name in lib_file_names:

# 引数指定ディレクトリ直下の DLL をロードする
for runtime_dir in runtime_dirs:
for lib_file_name in lib_file_names:
try:
CDLL(str((lib_path / file_name).resolve(strict=True)))
CDLL(str((runtime_dir / lib_file_name).resolve(strict=True)))
except OSError:
pass

# システム検索ディレクトリ直下の DLL をロードする
for lib_name in lib_names:
try:
CDLL(find_library(lib_name))
Expand Down
Loading