From adb2ede905d9f5c67f19f1ddaca592c6e1eaca04 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 11 Sep 2023 00:48:49 -0400 Subject: [PATCH 1/6] add openblas --- cmake/BuildWhispercpp.cmake | 58 ++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index f559b7f..afc7ced 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -13,6 +13,25 @@ if(UNIX AND NOT APPLE) set(WHISPER_EXTRA_CXX_FLAGS "-fPIC") endif() +# if on Windows - download OpenBLAS prebuilt binaries +if(WIN32) + set(OpenBLAS_URL + "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") + set(OpenBLAS_SHA256 + "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132" + ) + ExternalProject_Add( + OpenBLAS + URL ${OpenBLAS_URL} + URL_HASH SHA256=${OpenBLAS_SHA256} + DOWNLOAD_NO_PROGRESS true + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) + ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) + set(OpenBLAS_DIR ${INSTALL_DIR}) +endif(WIN32) + ExternalProject_Add( Whispercpp_Build DOWNLOAD_EXTRACT_TIMESTAMP true @@ -20,31 +39,56 @@ ExternalProject_Add( GIT_TAG 7b374c9ac9b9861bb737eec060e4dfa29d229259 BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} + /bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} + /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} - INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib + CONFIGURE_COMMAND + ${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} + ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} + -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} - -DBUILD_SHARED_LIBS=OFF + -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF - -DWHISPER_OPENBLAS=ON) + -DWHISPER_BLAS=ON) + +if(WIN32) + add_dependencies(Whispercpp_Build OpenBLAS) +endif(WIN32) ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR) -add_library(Whispercpp::Whisper STATIC IMPORTED) +add_library(Whispercpp::Whisper SHARED IMPORTED) set_target_properties( Whispercpp::Whisper PROPERTIES IMPORTED_LOCATION - ${INSTALL_DIR}/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}) + ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX}) +set_target_properties( + Whispercpp::Whisper + PROPERTIES IMPORTED_IMPLIB + ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}) + +install(FILES ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION "obs-plugins/64bit") + +# add openblas to the link line +if(WIN32) + add_library(Whispercpp::OpenBLAS STATIC IMPORTED) + set_target_properties( + Whispercpp::OpenBLAS + PROPERTIES IMPORTED_LOCATION + ${OpenBLAS_DIR}/lib/libopenblas.dll.a) + install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") +endif(WIN32) add_library(Whispercpp INTERFACE) add_dependencies(Whispercpp Whispercpp_Build) -target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper) +target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper Whispercpp::OpenBLAS) set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) if(APPLE) target_link_libraries(Whispercpp INTERFACE "-framework Accelerate") From a0713f4bce11da00c172600c8ee18ea521b3190e Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 11 Sep 2023 01:14:44 -0400 Subject: [PATCH 2/6] fix osx linux --- cmake/BuildWhispercpp.cmake | 142 ++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 63 deletions(-) diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index afc7ced..c8da670 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -15,80 +15,96 @@ endif() # if on Windows - download OpenBLAS prebuilt binaries if(WIN32) - set(OpenBLAS_URL - "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") - set(OpenBLAS_SHA256 - "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132" - ) - ExternalProject_Add( - OpenBLAS - URL ${OpenBLAS_URL} - URL_HASH SHA256=${OpenBLAS_SHA256} - DOWNLOAD_NO_PROGRESS true - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) - ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) - set(OpenBLAS_DIR ${INSTALL_DIR}) -endif(WIN32) + set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") + set(OpenBLAS_SHA256 "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132") + ExternalProject_Add( + OpenBLAS + URL ${OpenBLAS_URL} + URL_HASH SHA256=${OpenBLAS_SHA256} + DOWNLOAD_NO_PROGRESS true + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) + ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) + set(OpenBLAS_DIR ${INSTALL_DIR}) -ExternalProject_Add( - Whispercpp_Build - DOWNLOAD_EXTRACT_TIMESTAMP true - GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git - GIT_TAG 7b374c9ac9b9861bb737eec060e4dfa29d229259 - BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} - BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} - /bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} - /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} - CMAKE_GENERATOR ${CMAKE_GENERATOR} - INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib - CONFIGURE_COMMAND - ${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} - ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} - -DCMAKE_INSTALL_PREFIX= - -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} - -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} - -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 - -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} - -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} - -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} - -DBUILD_SHARED_LIBS=ON - -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF - -DWHISPER_BLAS=ON) + # On Windows add the `-DWHISPER_BLAS=ON` flag to the cmake command as well as building a shared Whisper library + ExternalProject_Add( + Whispercpp_Build + DOWNLOAD_EXTRACT_TIMESTAMP true + GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git + GIT_TAG 7b374c9ac9b9861bb737eec060e4dfa29d229259 + BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} + BUILD_BYPRODUCTS + /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} + /bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} + /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} + CMAKE_GENERATOR ${CMAKE_GENERATOR} + INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E + copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib + CONFIGURE_COMMAND + ${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} ${CMAKE_COMMAND} -B -G + ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} + -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF + -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BLAS=ON) -if(WIN32) - add_dependencies(Whispercpp_Build OpenBLAS) + add_dependencies(Whispercpp_Build OpenBLAS) +else() + # On Linux and MacOS build a static Whisper library + ExternalProject_Add( + Whispercpp_Build + DOWNLOAD_EXTRACT_TIMESTAMP true + GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git + GIT_TAG 7b374c9ac9b9861bb737eec060e4dfa29d229259 + BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} + BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} + CMAKE_GENERATOR ${CMAKE_GENERATOR} + INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} + CONFIGURE_COMMAND + ${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} ${CMAKE_COMMAND} -B -G + ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} + -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF + -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BLAS=OFF) endif(WIN32) ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR) -add_library(Whispercpp::Whisper SHARED IMPORTED) -set_target_properties( - Whispercpp::Whisper - PROPERTIES IMPORTED_LOCATION - ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX}) -set_target_properties( - Whispercpp::Whisper - PROPERTIES IMPORTED_IMPLIB - ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}) - -install(FILES ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION "obs-plugins/64bit") - -# add openblas to the link line +# add the Whisper library to the link line if(WIN32) - add_library(Whispercpp::OpenBLAS STATIC IMPORTED) - set_target_properties( - Whispercpp::OpenBLAS - PROPERTIES IMPORTED_LOCATION - ${OpenBLAS_DIR}/lib/libopenblas.dll.a) - install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") + add_library(Whispercpp::Whisper SHARED IMPORTED) + set_target_properties( + Whispercpp::Whisper + PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX}) + set_target_properties( + Whispercpp::Whisper + PROPERTIES IMPORTED_IMPLIB ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}) + + install(FILES ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} + DESTINATION "obs-plugins/64bit") + + # add openblas to the link line + add_library(Whispercpp::OpenBLAS STATIC IMPORTED) + set_target_properties(Whispercpp::OpenBLAS PROPERTIES IMPORTED_LOCATION ${OpenBLAS_DIR}/lib/libopenblas.dll.a) + install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") +else() + # on Linux and MacOS add the static Whisper library to the link line + add_library(Whispercpp::Whisper STATIC IMPORTED) + set_target_properties( + Whispercpp::Whisper + PROPERTIES IMPORTED_LOCATION + ${INSTALL_DIR}/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}) endif(WIN32) add_library(Whispercpp INTERFACE) add_dependencies(Whispercpp Whispercpp_Build) -target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper Whispercpp::OpenBLAS) +target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper) +if(WIN32) + target_link_libraries(Whispercpp INTERFACE Whispercpp::OpenBLAS) +endif(WIN32) set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) if(APPLE) target_link_libraries(Whispercpp INTERFACE "-framework Accelerate") From b60451f9e338bb93835d58e69b1e50473bd43b86 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 11 Sep 2023 23:21:48 -0400 Subject: [PATCH 3/6] lean libcurl build --- cmake/BuildMyCurl.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/BuildMyCurl.cmake b/cmake/BuildMyCurl.cmake index 26b26bd..54eec54 100644 --- a/cmake/BuildMyCurl.cmake +++ b/cmake/BuildMyCurl.cmake @@ -18,8 +18,18 @@ elseif(OS_LINUX) endif() set(BUILD_CURL_EXE OFF) set(BUILD_SHARED_LIBS OFF) -set(HTTP_ONLY OFF) +set(HTTP_ONLY ON) set(CURL_USE_LIBSSH2 OFF) +set(CURL_DISABLE_FTP ON) +set(CURL_DISABLE_LDAP ON) +set(CURL_DISABLE_LDAPS ON) +set(CURL_DISABLE_TELNET ON) +set(CURL_DISABLE_MQTT ON) +set(CURL_DISABLE_POP3 ON) +set(CURL_DISABLE_RTMP ON) +set(CURL_DISABLE_SMTP ON) +set(CURL_DISABLE_GOPHER ON) + add_subdirectory(${LIBCURL_SOURCE_DIR} EXCLUDE_FROM_ALL) if(OS_MACOS) target_compile_options( From b92bf4d36ccdcf037d3d3bfcbcd82c34d2d8b0af Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 12 Sep 2023 01:03:05 -0400 Subject: [PATCH 4/6] add cuda build options --- .github/scripts/Build-Windows.ps1 | 6 ++- CMakeLists.txt | 2 + cmake/BuildWhispercpp.cmake | 62 ++++++++++++++++++++----------- src/whisper-processing.cpp | 1 + 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/.github/scripts/Build-Windows.ps1 b/.github/scripts/Build-Windows.ps1 index 5f32296..458b60e 100644 --- a/.github/scripts/Build-Windows.ps1 +++ b/.github/scripts/Build-Windows.ps1 @@ -6,7 +6,8 @@ param( [string] $Configuration = 'RelWithDebInfo', [switch] $SkipAll, [switch] $SkipBuild, - [switch] $SkipDeps + [switch] $SkipDeps, + [string] $ExtraCmakeArgs ) $ErrorActionPreference = 'Stop' @@ -56,7 +57,8 @@ function Build { if ( ! ( ( $SkipAll ) -or ( $SkipBuild ) ) ) { Ensure-Location $ProjectRoot - $CmakeArgs = @() + # take cmake args from $ExtraCmakeArgs + $CmakeArgs = @($ExtraCmakeArgs) $CmakeBuildArgs = @() $CmakeInstallArgs = @() diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a5c8a1..9d0539b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ project(${_name} VERSION ${_version}) option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" ON) option(ENABLE_QT "Use Qt functionality" ON) +option(LOCALVOCAL_WITH_CUDA "Build with CUDA support. (Windows, CUDA toolkit required)" OFF) + include(compilerconfig) include(defaults) include(helpers) diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index c8da670..5e0d664 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -15,20 +15,34 @@ endif() # if on Windows - download OpenBLAS prebuilt binaries if(WIN32) - set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") - set(OpenBLAS_SHA256 "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132") - ExternalProject_Add( - OpenBLAS - URL ${OpenBLAS_URL} - URL_HASH SHA256=${OpenBLAS_SHA256} - DOWNLOAD_NO_PROGRESS true - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) - ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) - set(OpenBLAS_DIR ${INSTALL_DIR}) + if(LOCALVOCAL_WITH_CUDA) + ## Build with CUDA + # Check that CUDA_TOOLKIT_ROOT_DIR is set + if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) + message(FATAL_ERROR "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " + "installation.") + endif(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) + + set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_CUBLAS=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) + else(LOCALVOCAL_WITH_CUDA) + ## Build with OpenBLAS + set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") + set(OpenBLAS_SHA256 "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132") + ExternalProject_Add( + OpenBLAS + URL ${OpenBLAS_URL} + URL_HASH SHA256=${OpenBLAS_SHA256} + DOWNLOAD_NO_PROGRESS true + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) + ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) + set(OpenBLAS_DIR ${INSTALL_DIR}) + set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${OpenBLAS_DIR}") + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_CUBLAS=OFF) + endif(LOCALVOCAL_WITH_CUDA) - # On Windows add the `-DWHISPER_BLAS=ON` flag to the cmake command as well as building a shared Whisper library ExternalProject_Add( Whispercpp_Build DOWNLOAD_EXTRACT_TIMESTAMP true @@ -43,14 +57,16 @@ if(WIN32) INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib CONFIGURE_COMMAND - ${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} ${CMAKE_COMMAND} -B -G + ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BLAS=ON) + -DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) - add_dependencies(Whispercpp_Build OpenBLAS) + if(NOT LOCALVOCAL_WITH_CUDA) + add_dependencies(Whispercpp_Build OpenBLAS) + endif(NOT LOCALVOCAL_WITH_CUDA) else() # On Linux and MacOS build a static Whisper library ExternalProject_Add( @@ -86,10 +102,12 @@ if(WIN32) install(FILES ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION "obs-plugins/64bit") - # add openblas to the link line - add_library(Whispercpp::OpenBLAS STATIC IMPORTED) - set_target_properties(Whispercpp::OpenBLAS PROPERTIES IMPORTED_LOCATION ${OpenBLAS_DIR}/lib/libopenblas.dll.a) - install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") + if(NOT LOCALVOCAL_WITH_CUDA) + # add openblas to the link line + add_library(Whispercpp::OpenBLAS STATIC IMPORTED) + set_target_properties(Whispercpp::OpenBLAS PROPERTIES IMPORTED_LOCATION ${OpenBLAS_DIR}/lib/libopenblas.dll.a) + install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") + endif(NOT LOCALVOCAL_WITH_CUDA) else() # on Linux and MacOS add the static Whisper library to the link line add_library(Whispercpp::Whisper STATIC IMPORTED) @@ -102,9 +120,9 @@ endif(WIN32) add_library(Whispercpp INTERFACE) add_dependencies(Whispercpp Whispercpp_Build) target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper) -if(WIN32) +if(WIN32 AND NOT LOCALVOCAL_WITH_CUDA) target_link_libraries(Whispercpp INTERFACE Whispercpp::OpenBLAS) -endif(WIN32) +endif() set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) if(APPLE) target_link_libraries(Whispercpp INTERFACE "-framework Accelerate") diff --git a/src/whisper-processing.cpp b/src/whisper-processing.cpp index c05525e..cf7ba7b 100644 --- a/src/whisper-processing.cpp +++ b/src/whisper-processing.cpp @@ -78,6 +78,7 @@ struct whisper_context *init_whisper_context(const std::string &model_path) obs_log(LOG_ERROR, "Failed to load whisper model"); return nullptr; } + obs_log(LOG_INFO, "Whisper model loaded: %s", whisper_print_system_info()); return ctx; } From 06675eb0bb4dbe983c8968dba9e0021f2fa503ff Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 12 Sep 2023 01:03:32 -0400 Subject: [PATCH 5/6] lint --- cmake/BuildWhispercpp.cmake | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index 5e0d664..21aa74a 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -16,8 +16,7 @@ endif() # if on Windows - download OpenBLAS prebuilt binaries if(WIN32) if(LOCALVOCAL_WITH_CUDA) - ## Build with CUDA - # Check that CUDA_TOOLKIT_ROOT_DIR is set + # Build with CUDA Check that CUDA_TOOLKIT_ROOT_DIR is set if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) message(FATAL_ERROR "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " "installation.") @@ -26,17 +25,17 @@ if(WIN32) set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_CUBLAS=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) else(LOCALVOCAL_WITH_CUDA) - ## Build with OpenBLAS + # Build with OpenBLAS set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") set(OpenBLAS_SHA256 "8E777E406BA7030D21ADB18683D6175E4FA5ADACFBC09982C01E81245B348132") ExternalProject_Add( - OpenBLAS - URL ${OpenBLAS_URL} - URL_HASH SHA256=${OpenBLAS_SHA256} - DOWNLOAD_NO_PROGRESS true - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) + OpenBLAS + URL ${OpenBLAS_URL} + URL_HASH SHA256=${OpenBLAS_SHA256} + DOWNLOAD_NO_PROGRESS true + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) set(OpenBLAS_DIR ${INSTALL_DIR}) set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${OpenBLAS_DIR}") From 91b259e643a170cafdddf5da47c7ee64598b5b2d Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 12 Sep 2023 01:14:02 -0400 Subject: [PATCH 6/6] readme --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 303fa59..16b3703 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,22 @@ Use the CI scripts again, for example: ``` The build should exist in the `./release` folder off the root. You can manually install the files in the OBS directory. + +#### Building with CUDA support on Windows + +To build with CUDA support on Windows, you need to install the CUDA toolkit from NVIDIA. The CUDA toolkit is available for download from [here](https://developer.nvidia.com/cuda-downloads). + +After installing the CUDA toolkit, you need to set variables to point CMake to the CUDA toolkit installation directory. For example, if you have installed the CUDA toolkit in `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4`, you need to set `CUDA_TOOLKIT_ROOT_DIR` to `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4` and `LOCALVOCAL_WITH_CUDA` to `ON` when running `.github/scripts/Build-Windows.ps1`. + +For example +```powershell +> .github/scripts/Build-Windows.ps1 -Target x64 -ExtraCmakeFlags "-D LOCALVOCAL_WITH_CUDA=ON -D CUDA_TOOLKIT_ROOT_DIR='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4'" +``` + +You will need to copy a few CUDA .dll files to the location of the plugin .dll for it to run. The required .dll files from CUDA (which are located in the `bin` folder of the CUDA toolkit installation directory) are: + +- `cudart64_NN.dll` +- `cublas64_NN.dll` +- `cublasLt64_NN.dll` + +where `NN` is the CUDA version number. For example, if you have installed CUDA 11.4 then `NN` is likely `11`.