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

修正: cpu_num_threadsが未指定または0の場合に、論理コア数の半分をコアに渡すようにする #1113

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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: 18 additions & 0 deletions test/test_core_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest import TestCase
from unittest.mock import patch

from voicevox_engine.utility.core_utility import get_half_logical_cores


class TestHalfLogicalCores(TestCase):
@patch("os.cpu_count", return_value=8)
def test_half_logical_cores_even(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 4)

@patch("os.cpu_count", return_value=9)
def test_half_logical_cores_odd(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 4)

@patch("os.cpu_count", return_value=None)
def test_half_logical_cores_none(self, mock_cpu_count):
self.assertEqual(get_half_logical_cores(), 0)
5 changes: 3 additions & 2 deletions voicevox_engine/core/core_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional

from ..tts_pipeline.tts_engine import CoreAdapter
from ..utility.core_utility import get_half_logical_cores
from ..utility.path_utility import engine_root, get_save_dir
from .core_wrapper import CoreWrapper, load_runtime_lib

Expand Down Expand Up @@ -44,10 +45,10 @@ def initialize_cores(
if cpu_num_threads == 0 or cpu_num_threads is None:
sigprogramming marked this conversation as resolved.
Show resolved Hide resolved
print(
"Warning: cpu_num_threads is set to 0. "
+ "( The library leaves the decision to the synthesis runtime )",
+ "Setting it to half of the logical cores.",
file=sys.stderr,
)
cpu_num_threads = 0
cpu_num_threads = get_half_logical_cores()

# ディレクトリを設定する
# 引数による指定を反映する
Expand Down
8 changes: 8 additions & 0 deletions voicevox_engine/utility/core_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os


def get_half_logical_cores() -> int:
logical_cores = os.cpu_count()
if logical_cores is None:
return 0
return logical_cores // 2
Loading