Skip to content

Commit

Permalink
Merge pull request #15 from occ-ai/roy.add_clblast_build
Browse files Browse the repository at this point in the history
Update build-project.yaml with architecture matrix and cublas options
  • Loading branch information
royshil authored May 1, 2024
2 parents cbfa4e9 + 6cbf4fe commit c5257f9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .github/scripts/Package-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ param(
[string] $Target = 'x64',
[ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
[string] $Configuration = 'RelWithDebInfo',
[ValidateSet('cpu', '12.2.0', '11.8.0')]
[ValidateSet('cpu', 'clblast', '12.2.0', '11.8.0')]
[string] $Cublas = 'cpu',
[switch] $BuildInstaller,
[switch] $SkipDeps
Expand Down Expand Up @@ -52,6 +52,8 @@ function Package {
# Check if $cublas is cpu or cuda
if ( $Cublas -eq 'cpu' ) {
$CudaName = 'cpu'
} elseif ( $Cublas -eq 'clblast' ) {
$CudaName = 'clblast'
} else {
$CudaName = "cuda${Cublas}"
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:
needs: check-event
strategy:
matrix:
cublas: [cpu, 12.2.0, 11.8.0]
cublas: [cpu, clblast, 12.2.0, 11.8.0]
defaults:
run:
shell: pwsh
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
'windows-x64-cpu;zip|exe'
'windows-x64-11.8.0;zip|exe'
'windows-x64-12.2.0;zip|exe'
'windows-x64-clblast;zip|exe'
'macos-arm64;tar.xz|pkg'
'macos-x86_64;tar.xz|pkg'
'ubuntu-22.04-x86_64;tar.xz|deb|ddeb'
Expand Down
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}
},
"name": "obs-cleanstream",
"version": "0.0.4",
"version": "0.0.5",
"author": "Roy Shilkrot",
"website": "https://github.com/occ-ai/obs-cleanstream/",
"email": "roy.shil@gmail.com",
Expand Down
31 changes: 18 additions & 13 deletions cmake/BuildWhispercpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ if(APPLE)
endif(NOT DEFINED ENV{MACOS_ARCH})

set(WHISPER_CPP_URL
"https://github.com/occ-ai/occ-ai-dep-whispercpp/releases/download/0.0.1/whispercpp-macos-$ENV{MACOS_ARCH}-0.0.1.tar.gz"
"https://github.com/occ-ai/occ-ai-dep-whispercpp/releases/download/0.0.2/whispercpp-macos-$ENV{MACOS_ARCH}-0.0.2.tar.gz"
)
if($ENV{MACOS_ARCH} STREQUAL "x86_64")
set(WHISPER_CPP_HASH "36F39F02F999AAF157EAD3460DD00C8BDAA3D6C4A769A9E4F64E327871B4B11F")
set(WHISPER_CPP_HASH "00C308AF0BFFF7619934403A8080CC9AFC4EDAA328D7587E617150A2C6A33313")
elseif($ENV{MACOS_ARCH} STREQUAL "arm64")
set(WHISPER_CPP_HASH "6AF7BB904B03B6208B4281D44465B727FB608A32CABD1394B727937C5F4828A1")
set(WHISPER_CPP_HASH "0478E2079E07FA81BEE77506101003F4A4C8F0DF9E23757BD7E1D25DCBD1DB30")
else()
message(
FATAL_ERROR
Expand All @@ -45,28 +45,34 @@ elseif(WIN32)
if(NOT DEFINED ENV{CPU_OR_CUDA})
message(
FATAL_ERROR
"The CPU_OR_CUDA environment variable is not set. Please set it to either `cpu` or `11.8.0` or `12.2.0`")
"The CPU_OR_CUDA environment variable is not set. Please set it to either `cpu`, `clblast`, `11.8.0` or `12.2.0`"
)
endif(NOT DEFINED ENV{CPU_OR_CUDA})

set(CUDA_PREFIX $ENV{CPU_OR_CUDA})
if(NOT $ENV{CPU_OR_CUDA} STREQUAL "cpu")
if(NOT $ENV{CPU_OR_CUDA} STREQUAL "cpu" AND NOT $ENV{CPU_OR_CUDA} STREQUAL "clblast")
set(CUDA_PREFIX "cuda$ENV{CPU_OR_CUDA}")
add_compile_definitions("LOCALVOCAL_WITH_CUDA")
elseif($ENV{CPU_OR_CUDA} STREQUAL "clblast")
set(CUDA_PREFIX "$ENV{CPU_OR_CUDA}")
add_compile_definitions("LOCALVOCAL_WITH_OPENCL")
endif()

set(WHISPER_CPP_URL
"https://github.com/occ-ai/occ-ai-dep-whispercpp/releases/download/0.0.1/whispercpp-windows-${CUDA_PREFIX}-0.0.1.zip"
"https://github.com/occ-ai/occ-ai-dep-whispercpp/releases/download/0.0.2/whispercpp-windows-${CUDA_PREFIX}-0.0.2.zip"
)
if($ENV{CPU_OR_CUDA} STREQUAL "cpu")
set(WHISPER_CPP_HASH "5261FCCD18BA52AE7ECD37617452F0514238FAB4B12713F1FCA491F4ABA170AA")
set(WHISPER_CPP_HASH "6DE628A51B9352624A1EC397231591FA3370E6BB42D9364F4F91F11DD18F77D2")
elseif($ENV{CPU_OR_CUDA} STREQUAL "clblast")
set(WHISPER_CPP_HASH "97BF58520F1818B7C9F4E996197F3097934E5E0BBA92B0B016C6B28BE9FF1642")
elseif($ENV{CPU_OR_CUDA} STREQUAL "12.2.0")
set(WHISPER_CPP_HASH "1966A6C7347FCB9529140F8097AED306F31C6DDE328836FD6498A980E20B8E6C")
set(WHISPER_CPP_HASH "48C059A3364E0AAD9FB0D4194BA554865928D22A27ECE5E3C116DC672D5D6EDE")
elseif($ENV{CPU_OR_CUDA} STREQUAL "11.8.0")
set(WHISPER_CPP_HASH "172F4021E888A89A694373AE0888C04DB99BC11F3A2633270248E03AF5AC762E")
set(WHISPER_CPP_HASH "29A5530E83896DE207F0199535CBBB24DF0D63B1373BA66139AD240BA67120EB")
else()
message(
FATAL_ERROR
"The CPU_OR_CUDA environment variable is not set to a valid value. Please set it to either `cpu` or `11.8.0` or `12.2.0`"
"The CPU_OR_CUDA environment variable is not set to a valid value. Please set it to either `cpu`, `clblast`, `11.8.0` or `12.2.0`"
)
endif()

Expand Down Expand Up @@ -100,10 +106,9 @@ elseif(WIN32)
install(FILES ${WHISPER_DLLS} DESTINATION "obs-plugins/64bit")

else()
set(Whispercpp_Build_GIT_TAG "f22d27a385d34b1e544031efe8aa2e3d73922791")
set(Whispercpp_Build_GIT_TAG "v1.5.5")
set(WHISPER_EXTRA_CXX_FLAGS "-fPIC")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF -DWHISPER_NO_AVX=ON
-DWHISPER_NO_AVX2=ON)
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF)

# On Linux and MacOS build a static Whisper library
ExternalProject_Add(
Expand Down
19 changes: 14 additions & 5 deletions src/whisper-utils/whisper-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ struct whisper_context *init_whisper_context(const std::string &model_path_)
struct whisper_context_params cparams;
#ifdef LOCALVOCAL_WITH_CUDA
cparams.use_gpu = true;
#elif defined(LOCALVOCAL_WITH_OPENCL)
cparams.use_gpu = true;
#else
cparams.use_gpu = false;
#endif
Expand Down Expand Up @@ -168,14 +170,21 @@ struct whisper_context *init_whisper_context(const std::string &model_path_)
std::vector<char> modelBuffer(modelFileSize);
modelFile.read(modelBuffer.data(), modelFileSize);
modelFile.close();
#endif // _WIN32

// Initialize whisper
struct whisper_context *ctx =
whisper_init_from_buffer_with_params(modelBuffer.data(), modelFileSize, cparams);
struct whisper_context *ctx = nullptr;
try {
#ifdef _WIN32
ctx = whisper_init_from_buffer_with_params(modelBuffer.data(), modelFileSize,
cparams);
#else
struct whisper_context *ctx =
whisper_init_from_file_with_params(model_path.c_str(), cparams);
ctx = whisper_init_from_file_with_params(model_path.c_str(), cparams);
#endif
} catch (const std::exception &e) {
obs_log(LOG_ERROR, "Whisper exception: %s", e.what());
}

// Initialize whisper
if (ctx == nullptr) {
obs_log(LOG_ERROR, "Failed to load whisper model");
return nullptr;
Expand Down

0 comments on commit c5257f9

Please sign in to comment.