From a39eb4cea738367ae295cdab74818a0126b450e0 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Wed, 20 Mar 2024 17:50:12 -0400 Subject: [PATCH 1/8] Add CUDA matrix strategy and CUDA toolkit setup --- .github/workflows/build-project.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index 556ec4f..7c38b8b 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -219,6 +219,9 @@ jobs: name: Build for Windows 🪟 runs-on: windows-2022 needs: check-event + strategy: + matrix: + cuda: [ 'cpu', '12.2.0', '11.8.0' ] defaults: run: shell: pwsh @@ -228,6 +231,14 @@ jobs: submodules: recursive fetch-depth: 0 + - uses: Jimver/cuda-toolkit@v0.2.14 + if: matrix.cuda != 'cpu' + id: cuda-toolkit + with: + cuda: ${{ matrix.cuda }} + sub-packages: '["nvcc", "libcublas"]' + method: 'network' + - name: Set Up Environment 🔧 id: setup run: | From b81f3470de5de02ca1e4cd7b8d3f266be9208ae5 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Wed, 20 Mar 2024 17:53:06 -0400 Subject: [PATCH 2/8] Update CUDA toolkit configuration --- .github/workflows/build-project.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index 7c38b8b..e7b2cfb 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -236,8 +236,9 @@ jobs: id: cuda-toolkit with: cuda: ${{ matrix.cuda }} - sub-packages: '["nvcc", "libcublas"]' - method: 'network' + sub-packages: '["nvcc"]' + non-cuda-sub-packages: '["libcublas"]' + method: 'local' - name: Set Up Environment 🔧 id: setup From e68d593d2db491fd37e64ceb3ab4436cb7d7c311 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 22 Mar 2024 17:31:15 -0400 Subject: [PATCH 3/8] Update build-project.yaml and BuildCTranslate2.cmake --- .github/workflows/build-project.yaml | 11 ++------ cmake/BuildCTranslate2.cmake | 38 +++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index e7b2cfb..9be2f11 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -231,15 +231,6 @@ jobs: submodules: recursive fetch-depth: 0 - - uses: Jimver/cuda-toolkit@v0.2.14 - if: matrix.cuda != 'cpu' - id: cuda-toolkit - with: - cuda: ${{ matrix.cuda }} - sub-packages: '["nvcc"]' - non-cuda-sub-packages: '["libcublas"]' - method: 'local' - - name: Set Up Environment 🔧 id: setup run: | @@ -260,6 +251,8 @@ jobs: with: target: x64 config: ${{ needs.check-event.outputs.config }} + env: + CPU_OR_CUDA: ${{ matrix.cuda }} - name: Package Plugin 📀 uses: ./.github/actions/package-plugin diff --git a/cmake/BuildCTranslate2.cmake b/cmake/BuildCTranslate2.cmake index 9ce13df..8e93d28 100644 --- a/cmake/BuildCTranslate2.cmake +++ b/cmake/BuildCTranslate2.cmake @@ -19,10 +19,35 @@ if(APPLE) elseif(WIN32) - FetchContent_Declare( - ctranslate2_fetch - URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.1.1/libctranslate2-windows-4.1.1-Release.zip - URL_HASH SHA256=aa87073e663e4dfbbc9b9360d83bed847212309bea433c3b1888a33a51cb0db0) + # check CPU_OR_CUDA environment variable + if(NOT DEFINED ENV{CPU_OR_CUDA}) + message(FATAL_ERROR "Please set the CPU_OR_CUDA environment variable to either CPU or CUDA") + endif() + + if($ENV{CPU_OR_CUDA} STREQUAL "cpu") + FetchContent_Declare( + ctranslate2_fetch + URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cpu.zip + URL_HASH SHA256=30ff8b2499b8d3b5a6c4d6f7f8ddbc89e745ff06e0050b645e3b7c9b369451a3 + ) + else() + if($ENV{CPU_OR_CUDA} STREQUAL "12.2.0") + FetchContent_Declare( + ctranslate2_fetch + URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda12.2.0.zip + URL_HASH SHA256=131724d510f9f2829970953a1bc9e4e8fb7b4cbc8218e32270dcfe6172a51558 + ) + elseif($ENV{CPU_OR_CUDA} STREQUAL "11.8.0") + FetchContent_Declare( + ctranslate2_fetch + URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda11.8.0.zip + URL_HASH SHA256=a120bee82f821df35a4646add30ac18b5c23e4e16b56fa7ba338eeae336e0d81 + ) + else() + message(FATAL_ERROR "Unsupported CUDA version: $ENV{CPU_OR_CUDA}") + endif() + endif() + FetchContent_MakeAvailable(ctranslate2_fetch) add_library(ct2 INTERFACE) @@ -30,9 +55,8 @@ elseif(WIN32) set_target_properties(ct2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ctranslate2_fetch_SOURCE_DIR}/include) target_compile_options(ct2 INTERFACE /wd4267 /wd4244 /wd4305 /wd4996 /wd4099) - install(FILES ${ctranslate2_fetch_SOURCE_DIR}/bin/ctranslate2.dll ${ctranslate2_fetch_SOURCE_DIR}/bin/libopenblas.dll - DESTINATION "obs-plugins/64bit") - + file(GLOB CT2_DLLS ${ctranslate2_fetch_SOURCE_DIR}/bin/*.dll) + install(FILES ${CT2_DLLS} DESTINATION "obs-plugins/64bit") else() set(CT2_VERSION "4.1.1") set(CT2_URL "https://github.com/OpenNMT/CTranslate2.git") From ff61a33c54cae76562b74192fdf92b8914baee40 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 25 Mar 2024 13:01:05 -0400 Subject: [PATCH 4/8] Add target-specific output name for Windows builds --- .github/scripts/Package-Windows.ps1 | 9 ++++++++- .github/workflows/build-project.yaml | 2 ++ .github/workflows/push.yaml | 4 +++- cmake/BuildCTranslate2.cmake | 4 ++++ src/translation-service/translation.cpp | 11 ++++++++++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/scripts/Package-Windows.ps1 b/.github/scripts/Package-Windows.ps1 index 52317be..39a6832 100644 --- a/.github/scripts/Package-Windows.ps1 +++ b/.github/scripts/Package-Windows.ps1 @@ -48,7 +48,14 @@ function Package { $ProductName = $BuildSpec.name $ProductVersion = $BuildSpec.version - $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}" + # check the CPU_OR_CUDA env variable to determine the target + if ( $Env:CPU_OR_CUDA -eq 'cpu' ) { + $cudaName = 'cpu' + } else { + $cudaName = "cuda${Env:CPU_OR_CUDA}" + } + + $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}-${cudaName}" if ( ! $SkipDeps ) { Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile" diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index 9be2f11..aaea09b 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -260,6 +260,8 @@ jobs: target: x64 config: ${{ needs.check-event.outputs.config }} package: ${{ fromJSON(needs.check-event.outputs.package) }} + env: + CPU_OR_CUDA: ${{ matrix.cuda }} - name: Upload Artifacts 📡 uses: actions/upload-artifact@v3 diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 9e76855..e01bb33 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -75,7 +75,9 @@ jobs: commit_hash="${GITHUB_SHA:0:9}" variants=( - 'windows-x64;zip|exe' + 'windows-x64-cpu;zip|exe' + 'windows-x64-cuda12.2.0;zip|exe' + 'windows-x64-cuda11.8.0;zip|exe' 'macos-universal;tar.xz|pkg' 'ubuntu-22.04-x86_64;tar.xz|deb|ddeb' 'sources;tar.xz' diff --git a/cmake/BuildCTranslate2.cmake b/cmake/BuildCTranslate2.cmake index 8e93d28..90d0669 100644 --- a/cmake/BuildCTranslate2.cmake +++ b/cmake/BuildCTranslate2.cmake @@ -31,6 +31,10 @@ elseif(WIN32) URL_HASH SHA256=30ff8b2499b8d3b5a6c4d6f7f8ddbc89e745ff06e0050b645e3b7c9b369451a3 ) else() + # add compile definitions for CUDA + add_compile_definitions(POLYGLOT_WITH_CUDA) + add_compile_definitions(POLYGLOT_CUDA_VERSION=$ENV{CPU_OR_CUDA}) + if($ENV{CPU_OR_CUDA} STREQUAL "12.2.0") FetchContent_Declare( ctranslate2_fetch diff --git a/src/translation-service/translation.cpp b/src/translation-service/translation.cpp index 3cd422c..a54c72d 100644 --- a/src/translation-service/translation.cpp +++ b/src/translation-service/translation.cpp @@ -38,8 +38,17 @@ int build_translation_context() obs_log(LOG_INFO, "Loading CT2 model from %s", global_config.local_model_path.c_str()); + +#ifdef POLYGLOT_WITH_CUDA + ctranslate2::Device device = ctranslate2::Device::CUDA; + obs_log(LOG_INFO, "Using CUDA"); +#else + ctranslate2::Device device = ctranslate2::Device::CPU; + obs_log(LOG_INFO, "Using CPU"); +#endif + global_context.translator = new ctranslate2::Translator( - global_config.local_model_path, ctranslate2::Device::CPU, + global_config.local_model_path, device, ctranslate2::ComputeType::AUTO); obs_log(LOG_INFO, "CT2 Model loaded"); From 8f7d176b516ddd106ae7b1d5d042587654ea8d7f Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 25 Mar 2024 13:06:08 -0400 Subject: [PATCH 5/8] Update CTranslate2 dependencies and fix CUDA support --- cmake/BuildCTranslate2.cmake | 9 +++------ src/translation-service/translation.cpp | 11 +++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cmake/BuildCTranslate2.cmake b/cmake/BuildCTranslate2.cmake index 90d0669..df48fdc 100644 --- a/cmake/BuildCTranslate2.cmake +++ b/cmake/BuildCTranslate2.cmake @@ -28,8 +28,7 @@ elseif(WIN32) FetchContent_Declare( ctranslate2_fetch URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cpu.zip - URL_HASH SHA256=30ff8b2499b8d3b5a6c4d6f7f8ddbc89e745ff06e0050b645e3b7c9b369451a3 - ) + URL_HASH SHA256=30ff8b2499b8d3b5a6c4d6f7f8ddbc89e745ff06e0050b645e3b7c9b369451a3) else() # add compile definitions for CUDA add_compile_definitions(POLYGLOT_WITH_CUDA) @@ -39,14 +38,12 @@ elseif(WIN32) FetchContent_Declare( ctranslate2_fetch URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda12.2.0.zip - URL_HASH SHA256=131724d510f9f2829970953a1bc9e4e8fb7b4cbc8218e32270dcfe6172a51558 - ) + URL_HASH SHA256=131724d510f9f2829970953a1bc9e4e8fb7b4cbc8218e32270dcfe6172a51558) elseif($ENV{CPU_OR_CUDA} STREQUAL "11.8.0") FetchContent_Declare( ctranslate2_fetch URL https://github.com/occ-ai/obs-ai-ctranslate2-dep/releases/download/1.2.0/libctranslate2-windows-4.1.1-Release-cuda11.8.0.zip - URL_HASH SHA256=a120bee82f821df35a4646add30ac18b5c23e4e16b56fa7ba338eeae336e0d81 - ) + URL_HASH SHA256=a120bee82f821df35a4646add30ac18b5c23e4e16b56fa7ba338eeae336e0d81) else() message(FATAL_ERROR "Unsupported CUDA version: $ENV{CPU_OR_CUDA}") endif() diff --git a/src/translation-service/translation.cpp b/src/translation-service/translation.cpp index a54c72d..d52775a 100644 --- a/src/translation-service/translation.cpp +++ b/src/translation-service/translation.cpp @@ -40,16 +40,15 @@ int build_translation_context() global_config.local_model_path.c_str()); #ifdef POLYGLOT_WITH_CUDA - ctranslate2::Device device = ctranslate2::Device::CUDA; - obs_log(LOG_INFO, "Using CUDA"); + ctranslate2::Device device = ctranslate2::Device::CUDA; + obs_log(LOG_INFO, "Using CUDA"); #else - ctranslate2::Device device = ctranslate2::Device::CPU; - obs_log(LOG_INFO, "Using CPU"); + ctranslate2::Device device = ctranslate2::Device::CPU; + obs_log(LOG_INFO, "Using CPU"); #endif global_context.translator = new ctranslate2::Translator( - global_config.local_model_path, device, - ctranslate2::ComputeType::AUTO); + global_config.local_model_path, device, ctranslate2::ComputeType::AUTO); obs_log(LOG_INFO, "CT2 Model loaded"); global_context.options = new ctranslate2::TranslationOptions; From dbfebd91e8fb017141aedd1af787584e08d89542 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 26 Mar 2024 09:51:58 -0400 Subject: [PATCH 6/8] Add pre-routing handler for HTTP server --- src/translation-service/httpserver.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/translation-service/httpserver.cpp b/src/translation-service/httpserver.cpp index 473243f..8fb5bac 100644 --- a/src/translation-service/httpserver.cpp +++ b/src/translation-service/httpserver.cpp @@ -21,6 +21,13 @@ void start_http_server() } global_context.svr = new httplib::Server(); + global_context.svr->set_pre_routing_handler([](const httplib::Request&, httplib::Response& res) { + res.set_header("Access-Control-Allow-Origin", "*"); + res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); + res.set_header("Access-Control-Allow-Headers", "Content-Type, Authorization"); + return httplib::Server::HandlerResponse::Unhandled; + }); + // set an echo handler global_context.svr->Post("/echo", [](const httplib::Request &req, httplib::Response &res, From 9fa7cc3087fd1e5baf20539c11185d00014daede Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 26 Mar 2024 09:59:38 -0400 Subject: [PATCH 7/8] Update pre-routing handler in httpserver.cpp --- src/translation-service/httpserver.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/translation-service/httpserver.cpp b/src/translation-service/httpserver.cpp index 8fb5bac..3e5039d 100644 --- a/src/translation-service/httpserver.cpp +++ b/src/translation-service/httpserver.cpp @@ -21,12 +21,14 @@ void start_http_server() } global_context.svr = new httplib::Server(); - global_context.svr->set_pre_routing_handler([](const httplib::Request&, httplib::Response& res) { - res.set_header("Access-Control-Allow-Origin", "*"); - res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); - res.set_header("Access-Control-Allow-Headers", "Content-Type, Authorization"); - return httplib::Server::HandlerResponse::Unhandled; - }); + global_context.svr->set_pre_routing_handler([](const httplib::Request &, + httplib::Response &res) { + res.set_header("Access-Control-Allow-Origin", "*"); + res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); + res.set_header("Access-Control-Allow-Headers", + "Content-Type, Authorization"); + return httplib::Server::HandlerResponse::Unhandled; + }); // set an echo handler global_context.svr->Post("/echo", [](const httplib::Request &req, From 5a47bc951967f9ed7b7f9a8a79b3962455c06fb9 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 26 Mar 2024 10:38:14 -0400 Subject: [PATCH 8/8] Update dependencies and version in buildspec.json --- buildspec.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/buildspec.json b/buildspec.json index 08d012c..4016785 100644 --- a/buildspec.json +++ b/buildspec.json @@ -1,33 +1,33 @@ { "dependencies": { "obs-studio": { - "version": "29.1.2", + "version": "29.1.3", "baseUrl": "https://github.com/obsproject/obs-studio/archive/refs/tags", "label": "OBS sources", "hashes": { - "macos": "215f1fa5772c5dd9f3d6e35b0cb573912b00320149666a77864f9d305525504b", - "windows-x64": "46d451f3f42b9d2c59339ec268165849c7b7904cdf1cc2a8d44c015815a9e37d" + "macos": "9D9CFBDBDD255F48A23FEEEFB60089769A65F52BBCA24FA31D74125F3BBB0E90", + "windows-x64": "965334470E447DC164801F8812D583260761521E6E3C5EBEE1DA7CD8F6EC4A95" } }, "prebuilt": { - "version": "2023-04-12", + "version": "2023-06-22", "baseUrl": "https://github.com/obsproject/obs-deps/releases/download", "label": "Pre-Built obs-deps", "hashes": { - "macos": "9535c6e1ad96f7d49960251e85a245774088d48da1d602bb82f734b10219125a", - "windows-x64": "c13a14a1acc4224b21304d97b63da4121de1ed6981297e50496fbc474abc0503" + "macos": "a0d2e03f0ea79681634c31627430a220d9b62113d6ff58174d0bdab6fafdd32b", + "windows-x64": "1b12e86e2d62a97a889866d66b95fe47ddc6f7fa9b13e88aedfab4ea9e298ea2" } }, "qt6": { - "version": "2023-04-12", + "version": "2023-06-22", "baseUrl": "https://github.com/obsproject/obs-deps/releases/download", "label": "Pre-Built Qt6", "hashes": { - "macos": "eb7614544ab4f3d2c6052c797635602280ca5b028a6b987523d8484222ce45d1", - "windows-x64": "4d39364b8a8dee5aa24fcebd8440d5c22bb4551c6b440ffeacce7d61f2ed1add" + "macos": "f890d258a1afa7ba409b79c8ee55d53155e5c72105b8b18a3f52047ee70fc0aa", + "windows-x64": "1907fbcbcef69527154b29316c425b0885afb77ad69a9a2af7a1471d79512195" }, "debugSymbols": { - "windows-x64": "f34ee5067be19ed370268b15c53684b7b8aaa867dc800b68931df905d679e31f" + "windows-x64": "b461a7ade0c099505baea857fa5b98c4f8e9b702681be019ea354735d062e065" } } }, @@ -45,7 +45,7 @@ } }, "name": "obs-polyglot", - "version": "0.0.2", + "version": "0.0.3", "author": "Roy Shilkrot", "website": "https://github.com/occ-ai/obs-polyglot", "email": "roy.shil@gmail.com",