diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a245d67..447c8b93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,8 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES else() message(STATUS "x86 detected") if (MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2 /D_CRT_SECURE_NO_WARNINGS=1") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /arch:AVX2") else() if (EMSCRIPTEN) # we require support for WASM SIMD 128-bit @@ -148,7 +149,11 @@ target_include_directories(${TARGET} PUBLIC . ) -target_link_libraries(${TARGET} PRIVATE m ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT}) +if (MSVC) + target_link_libraries(${TARGET} PRIVATE ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT}) +else() + target_link_libraries(${TARGET} PRIVATE m ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT}) +endif() if (BUILD_SHARED_LIBS) target_link_libraries(${TARGET} PUBLIC @@ -158,6 +163,10 @@ if (BUILD_SHARED_LIBS) target_compile_definitions(${TARGET} PUBLIC WHISPER_SHARED ) + + if (MSVC) + target_compile_definitions(${TARGET} PUBLIC __AVX2__ _CRT_SECURE_NO_WARNINGS) + endif() endif() target_compile_definitions(${TARGET} PUBLIC diff --git a/examples/bench/bench.cpp b/examples/bench/bench.cpp index a9fdc819..d87bf37a 100644 --- a/examples/bench/bench.cpp +++ b/examples/bench/bench.cpp @@ -75,7 +75,7 @@ int main(int argc, char ** argv) { whisper_free(ctx); fprintf(stderr, "\n"); - fprintf(stderr, "system_info: n_threads = %d | %s\n", params.n_threads, whisper_print_system_info()); + fprintf(stderr, "system_info: n_threads = %d / %d | %s\n", params.n_threads, std::thread::hardware_concurrency(), whisper_print_system_info()); fprintf(stderr, "\n"); fprintf(stderr, "If you wish, you can submit these results here:\n"); diff --git a/examples/main/main.cpp b/examples/main/main.cpp index abbdee4b..0fe8efcf 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -412,5 +412,8 @@ int main(int argc, char ** argv) { whisper_print_timings(ctx); whisper_free(ctx); + fprintf(stderr, "\n"); + fprintf(stderr, "system_info: n_threads = %d / %d | %s\n", params.n_threads, std::thread::hardware_concurrency(), whisper_print_system_info()); + return 0; } diff --git a/extra/bench-all.sh b/extra/bench-all.sh new file mode 100755 index 00000000..5a5e6028 --- /dev/null +++ b/extra/bench-all.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Helper script to run the bench tool on all models and print the results in share-able format + +printf "Usage: ./bench.sh [n_threads]\n" + +if [ -z "$1" ]; then + n_threads=4 +else + n_threads=$1 +fi + +models=( "tiny" "base" "small" "medium" "large" ) + +printf "\n" +printf "Running benchmark for all models\n" +printf "This can take a while!\n" +printf "\n" + +printf "| CPU | OS | Config | Model | Threads | Load [ms] | Encode [ms] |\n" +printf "| --- | -- | ------ | ----- | ------- | --------- | ----------- |\n" + +for model in "${models[@]}"; do + # run once to heat-up the cache + ./bench -m ./models/ggml-$model.bin -t $n_threads 2>/dev/null 1>/dev/null + + # actual run + # store stderr output in a variable in order to parse it later + output=$(./bench -m ./models/ggml-$model.bin -t $n_threads 2>&1) + + # parse the output: + load_time=$(echo "$output" | grep "load time" | awk '{print $5}') + encode_time=$(echo "$output" | grep "encode time" | awk '{print $5}') + system_info=$(echo "$output" | grep "system_info") + n_threads=$(echo "$output" | grep "system_info" | awk '{print $4}') + + config="" + + if [[ $system_info == *"AVX2 = 1"* ]]; then + config="$config AVX2" + fi + + if [[ $system_info == *"NEON = 1"* ]]; then + config="$config NEON" + fi + + if [[ $system_info == *"BLAS = 1"* ]]; then + config="$config BLAS" + fi + + printf "| | | $config | $model | $n_threads | $load_time | $encode_time |\n" +done +