Skip to content

Commit

Permalink
Merge branch 'main' into cpp-library
Browse files Browse the repository at this point in the history
# Conflicts:
#	CMakeLists.txt
#	core/CMakeLists.txt
  • Loading branch information
y-chan committed Mar 23, 2022
2 parents 32d13af + b8651d8 commit 5041219
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 80 deletions.
95 changes: 83 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
device: gpu
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-win-x64-gpu-1.10.0.zip
artifact_name: windows-x64-gpu
artifact_name: windows-x64-cuda

- os: windows-2019
device: cpu-x64
Expand All @@ -52,6 +52,36 @@ jobs:
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm
artifact_name: windows-arm-cpu

- os: windows-2019
device: directml-x64
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/Microsoft.ML.OnnxRuntime.DirectML.1.10.0.zip
directml_url: https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.8.0
cmake_additional_options: -DDIRECTML=ON -DDIRECTML_DIR=download/directml
artifact_name: windows-x64-directml

- os: windows-2019
device: directml-x86
python_architecture: 'x86'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/Microsoft.ML.OnnxRuntime.DirectML.1.10.0.zip
directml_url: https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.8.0
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=Win32 -DDIRECTML=ON -DDIRECTML_DIR=download/directml
artifact_name: windows-x86-directml

- os: windows-2019
device: directml-arm64
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/Microsoft.ML.OnnxRuntime.DirectML.1.10.0.zip
directml_url: https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.8.0
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm64 -DDIRECTML=ON -DDIRECTML_DIR=download/directml
artifact_name: windows-arm64-directml

- os: windows-2019
device: directml-arm
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/Microsoft.ML.OnnxRuntime.DirectML.1.10.0.zip
directml_url: https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.8.0
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm -DDIRECTML=ON -DDIRECTML_DIR=download/directml
artifact_name: windows-arm-directml

- os: macos-10.15
device: cpu-x64
python_architecture: 'x64'
Expand Down Expand Up @@ -126,6 +156,19 @@ jobs:
key: onnxruntime-cache-v1-${{ hashFiles('download/onnxruntime_url.txt') }}
path: download/onnxruntime

- name: Export DirectML url to calc hash
if: endswith(matrix.artifact_name, '-directml')
shell: bash
run: echo "${{matrix.directml_url}}" >> download/directml_url.txt

- name: Cache DirectML
if: endswith(matrix.artifact_name, '-directml')
uses: actions/cache@v2
id: directml-cache
with:
key: directml-cache-v1-${{ hashFiles('download/directml_url.txt') }}
path: download/directml

# download/onnxruntime/lib/onnxruntime.dll
- name: Download ONNX Runtime (zip)
if: steps.onnxruntime-cache.outputs.cache-hit != 'true' && endsWith(matrix.onnxruntime_url, '.zip')
Expand All @@ -137,7 +180,13 @@ jobs:
# strip-components
TEMPDIR=$(mktemp -d)
unzip download/onnxruntime.zip -d "${TEMPDIR}"
mv "${TEMPDIR}"/*/* download/onnxruntime/
if [[ ${{ matrix.artifact_name }} != *-directml ]]; then
mv "${TEMPDIR}"/*/* download/onnxruntime/
else
mv "${TEMPDIR}"/* download/onnxruntime/
fi
rm -rf "${TEMPDIR}"
rm download/onnxruntime.zip
Expand All @@ -153,6 +202,24 @@ jobs:
tar xf download/onnxruntime.tgz -C download/onnxruntime --strip-components 1
rm download/onnxruntime.tgz
# download directml
- name: Download DirectML
if: steps.directml-cache.outputs.cache-hit != 'true' && endswith(matrix.artifact_name, '-directml')
shell: bash
run: |
curl -L "${{matrix.directml_url}}" -o download/directml.zip
mkdir -p download/directml
# strip-components
TEMPDIR=$(mktemp -d)
unzip download/directml.zip -d "${TEMPDIR}"
mv "${TEMPDIR}"/* download/directml/.
rm -rf "${TEMPDIR}"
rm download/directml.zip
ls download/directml
# Build
- if: startsWith(matrix.os, 'windows')
uses: ilammy/msvc-dev-cmd@v1
Expand Down Expand Up @@ -259,16 +326,20 @@ jobs:
mkdir release
readarray -t MAPPINGS <<EOF
windows-x64-gpu core.dll core_gpu_x64_nvidia.dll
windows-x64-cpu core.dll core_cpu_x64.dll
windows-x86-cpu core.dll core_cpu_x86.dll
windows-arm64-cpu core.dll core_cpu_arm64.dll
windows-arm-cpu core.dll core_cpu_arm.dll
osx-universal2-cpu libcore.dylib libcore_cpu_universal2.dylib
linux-x64-gpu libcore.so libcore_gpu_x64_nvidia.so
linux-x64-cpu libcore.so libcore_cpu_x64.so
linux-armhf-cpu libcore.so libcore_cpu_armhf.so
linux-arm64-cpu libcore.so libcore_cpu_arm64.so
windows-x64-cuda core.dll core_gpu_x64_nvidia.dll
windows-x64-directml core.dll core_gpu_x64_directml.dll
windows-x86-directml core.dll core_gpu_x86_directml.dll
windows-arm64-directml core.dll core_gpu_arm64_directml.dll
windows-arm-directml core.dll core_gpu_arm_directml.dll
windows-x64-cpu core.dll core_cpu_x64.dll
windows-x86-cpu core.dll core_cpu_x86.dll
windows-arm64-cpu core.dll core_cpu_arm64.dll
windows-arm-cpu core.dll core_cpu_arm.dll
osx-universal2-cpu libcore.dylib libcore_cpu_universal2.dylib
linux-x64-gpu libcore.so libcore_gpu_x64_nvidia.so
linux-x64-cpu libcore.so libcore_cpu_x64.so
linux-armhf-cpu libcore.so libcore_cpu_armhf.so
linux-arm64-cpu libcore.so libcore_cpu_arm64.so
EOF
for line in "${MAPPINGS[@]}"; do
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# ONNX
onnxruntime*/

# DirectML
directml*/

# Build artifacts
build/
lib/
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@ project(VoiceVoxCore)
set(ONNXRUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime" CACHE PATH "Path to ONNX Runtime")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_subdirectory(open_jtalk/src)
option(DIRECTML "Enables building for DirectML" OFF)
set(DIRECTML_DIR "${CMAKE_CURRENT_SOURCE_DIR}/directml" CACHE PATH "Path to ONNX Runtime")
if(DIRECTML)
# DirectML読み込み用にCPUのアーキテクチャを求める
set(DML_ARCH)
include(${CMAKE_CURRENT_SOURCE_DIR}/DetermineTargetArchitecture.cmake)
determine_target_architecture(DML_ARCH)
endif()

add_subdirectory(core)
add_subdirectory(open_jtalk/src)
62 changes: 62 additions & 0 deletions DetermineTargetArchitecture.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# https://github.com/civetweb/civetweb/blob/master/cmake/DetermineTargetArchitecture.cmake
#
# Copyright (c) 2013-2021 The CivetWeb developers (https://github.com/civetweb/civetweb/blob/master/CREDITS.md)
# Copyright (c) 2004-2013 Sergey Lyubka
# Copyright (c) 2013 No Face Press, LLC (Thomas Davis)
# Copyright (c) 2013 F-Secure Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# - Determines the target architecture of the compilation
#
# This function checks the architecture that will be built by the compiler
# and sets a variable to the architecture
#
# determine_target_architecture(<OUTPUT_VAR>)
#
# - Example
#
# include(DetermineTargetArchitecture)
# determine_target_architecture(PROJECT_NAME_ARCHITECTURE)

if(__determine_target_architecture)
return()
endif()
set(__determine_target_architecture INCLUDED)

function(determine_target_architecture FLAG)
if (MSVC)
if("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86")
set(ARCH "x86")
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64")
set(ARCH "x64")
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM64")
set(ARCH "arm64")
elseif("${MSVC_C_ARCHITECTURE_ID}" MATCHES "ARM*")
set(ARCH "arm")
else()
message(FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}")
endif()
else()
execute_process(
COMMAND ${CMAKE_C_COMPILER} -dumpmachine
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE ARCH
ERROR_QUIET
)
if (RESULT)
message(FATAL_ERROR "Failed to determine target architecture triplet: ${RESULT}")
endif()
string(REGEX MATCH "([^-]+).*" ARCH_MATCH ${ARCH})
if (NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH)
message(FATAL_ERROR "Failed to match the target architecture triplet: ${ARCH}")
endif()
set(ARCH ${CMAKE_MATCH_1})
endif()
message(STATUS "Target architecture - ${ARCH}")
set(${FLAG} ${ARCH} PARENT_SCOPE)
endfunction()
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ pip install .
- ONNX Runtime v1.9.0/v1.9.1

#### GPUを使用する場合
##### CUDA
Windows, Linux上でnvidia製GPUを使用してCUDAを用いた合成を行う場合、[CUDA 11.1](https://developer.nvidia.com/cuda-11.1.0-download-archive),[CUDNN](https://developer.nvidia.com/cudnn)のインストールに加えてGPU に対応した [ONNXRUNTIME](https://github.com/microsoft/onnxruntime) のダウンロードが必要です。

Windows, Linux上でnvidia製GPUを使用する場合、CUDA11.1,CUDNNのインストールに加えてGPU に対応した [ONNXRUNTIME](https://github.com/microsoft/onnxruntime) のダウンロードが必要です。
##### DirectML
Windows上でDirectX12に対応したGPUを使用してDirectMLを用いた合成を行う場合、[DirectML](https://www.nuget.org/packages/Microsoft.AI.DirectML)及びDirectMLに対応した[ONNXRUNTIME](https://github.com/microsoft/onnxruntime) のダウンロードが必要です。

DirectMLは.nupkgファイルで提供されますが、拡張子を.zipに変更した上で、リポジトリに`directml`というディレクトリ名で展開してください。


#### Raspberry Pi (armhf)の場合
Expand Down Expand Up @@ -61,10 +66,19 @@ pip install .
### 注意
#### GPUの使用について

##### CUDA
nvidia製GPUを搭載したWindows, Linux PCではCUDAを用いた合成が可能です。
CUDAを使用する場合、[CUDA 11.1](https://developer.nvidia.com/cuda-11.1.0-download-archive)[CUDNN](https://developer.nvidia.com/cudnn) をインストールした上で、環境構築時、上記例の代わりに
```bash
python configure.py --use_gpu
python configure.py --use_cuda
```
を実行する必要があります

##### DirectML
DirectX12に対応したGPUを搭載したWindows PCではDirectMLを用いた合成が可能です
DirectMLを使用する場合、環境構築時、上記例の代わりに
```bash
python configure.py --use_directml
```
を実行する必要があります

Expand Down Expand Up @@ -116,14 +130,18 @@ python run.py \
## コアライブラリのビルド

[Releases](https://github.com/Hiroshiba/voicevox_core/releases) にあるビルド済みのコアライブラリを利用せず、自分で一からビルドする場合こちらを参照してください。ビルドにはONNXRUNTIMEに加えてCMake 3.16以上が必要です。

modelフォルダにあるonnxモデルはダミーのため、ノイズの混じった音声が出力されます

```bash
# C++モジュールのビルド
mkdir build
cd build
# もしダウンロードしたonnx runtimeが別のところにあるなら、以下のコマンドを
# cmake .. -DONNXRUNTIME_DIR=(ダウンロードしたonnx runtimeのパス) に変更する。

# cmake .. 時のオプション
# -DONNXRUNTIME_DIR=(パス) ダウンロードしたonnxruntimeが別フォルダにある時指定
# -DDIRECTML=ON DirectMLを使用する場合指定
# -DDIRECTML_DIR=(パス) ダウンロードしたDirectMLが別フォルダにある時指定
cmake ..
cmake --build . --config Release
cmake --install .
Expand Down
Loading

0 comments on commit 5041219

Please sign in to comment.