Skip to content

Flat fix #3114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ebc8707
Add base of flat bindings - to expand
peardox Apr 23, 2025
2527199
Add and expose ggml_backend_try_load_best
peardox Apr 24, 2025
e5184ae
Add back previous closed PR code
peardox Apr 24, 2025
0510bb7
disable whisper_load_backends if GGML_BACKEND_DL - prevents the loadall
peardox Apr 25, 2025
1f438d0
Merge branch 'ggml-org:master' into bindings_flat
peardox Apr 25, 2025
1e7a15e
Add whisper_flat_get_preferred_backend
peardox Apr 25, 2025
f603b5a
Merge branch 'ggml-org:master' into bindings_flat
peardox Apr 25, 2025
7307aa7
Add whisper_get_backend_count and whisper_get_indexed_backend
peardox Apr 26, 2025
bdd8628
Merge branch 'bindings_flat' of https://github.com/WhisperBooks/whisp…
peardox Apr 26, 2025
8199e52
Merge branch 'ggml-org:master' into bindings_flat
peardox Apr 26, 2025
c37671c
OK, really finished - just enable examples via GGML_BACKEND_DL + BIND…
peardox Apr 27, 2025
c859e24
Change type to size_t
peardox Apr 27, 2025
a0ccffa
Mac needs can't use GGML_BACKEND_DL, modify as needed
peardox Apr 27, 2025
b1ecac4
Forgot a few demos
peardox Apr 27, 2025
fe9e7d1
Merge branch 'ggml-org:master' into bindings_flat
peardox Apr 28, 2025
7ddd2f3
Deployment tests
peardox Apr 28, 2025
65d7b74
fix cmakelists.txt
peardox Apr 28, 2025
53943bb
Fix nullptr
peardox Apr 28, 2025
2ce178b
Merge Timings into Activity
peardox Apr 29, 2025
0e1ebc0
Show ggml_backend_try_load_best in debug
peardox Apr 29, 2025
d381617
Show some var sizes
peardox Apr 29, 2025
6b51a3b
Remove sizez again
peardox Apr 29, 2025
660bee1
Enable BACKEND_FLAT in 6 demos
peardox Apr 30, 2025
94faab8
ggml_backend_try_load_best only in BINDINGS_FLAT
peardox Apr 30, 2025
5ec6ad5
Merge branch 'ggml-org:master' into flat
peardox Apr 30, 2025
5a3b467
Disable breaking MSVC Warning CMakeFiles.txt if GGML_CPU_ALL_VARIANTS
peardox Apr 30, 2025
f65e8b1
Fix library load - update readme
peardox Apr 30, 2025
d6c7a10
Oops - accidental commit - fixup
peardox Apr 30, 2025
dffd00b
Oops - accidental commit - fixup2
peardox Apr 30, 2025
24a8551
Mend broken ifdef (one of mine)
peardox May 1, 2025
696f86c
Commit resolution
peardox May 2, 2025
f85b51e
Commit resolution
peardox May 2, 2025
db59f98
Conflict resolution
peardox May 2, 2025
bb09c6f
Merge branch 'ggml-org:master' into flat-fix
peardox May 2, 2025
0cc4f5e
Enable BINGINGS_FLAT in some examples
peardox May 3, 2025
c9e59b1
Merge branch 'ggml-org:master' into flat-fix
peardox May 5, 2025
9a690c5
Remove 'MSVC AND NOT DEFINED GGML_CPU_ALL_VARIANTS' in ggml cmake
peardox May 5, 2025
420af26
Replace new MSVC_WARNING_FLAGS with if msvc
peardox May 5, 2025
c71ced4
Add BINDINGS_FLAT and GGML_BINDINGS_FLAT to Ruby install options
KitaitiMakoto May 5, 2025
f957031
Merge pull request #1 from KitaitiMakoto/ruby-options
peardox May 5, 2025
bdf03cf
Updates as requested
peardox May 7, 2025
85cf9cc
Remove .h.bak file
peardox May 7, 2025
c838670
re-introduce broken code for non WHISPER_BINDINGS_FLAT
peardox May 8, 2025
92bf1e1
Merge branch 'ggml-org:master' into flat-fix
peardox May 8, 2025
731324e
Merge branch 'ggml-org:master' into flat-fix
peardox May 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ option(WHISPER_ALL_WARNINGS_3RD_PARTY "whisper: enable all compiler warnings in
option(WHISPER_FATAL_WARNINGS "whisper: enable -Werror flag" OFF)
option(WHISPER_USE_SYSTEM_GGML "whisper: use system-installed GGML library" OFF)

# flat bindings
option(BINDINGS_FLAT "Add extra flat definitions to Whisper + GGML" OFF)
option(GGML_BINDINGS_FLAT "Add extra flat definitions to Examples" ${BINDINGS_FLAT})

# sanitizers
option(WHISPER_SANITIZE_THREAD "whisper: enable thread sanitizer" OFF)
option(WHISPER_SANITIZE_ADDRESS "whisper: enable address sanitizer" OFF)
Expand Down Expand Up @@ -245,4 +249,4 @@ if (MSVC)
disable_msvc_warnings(whisper-bench)
disable_msvc_warnings(quantize)
endif()
endif()
endif()
2 changes: 2 additions & 0 deletions bindings/ruby/ext/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def extra_options

def configure
filepath "ACCELERATE_FRAMEWORK"
ignored "BINDINGS_FLAT"
ignored "BUILD_SHARED_LIBS"
ignored "BUILD_TESTING"
ignored "CMAKE_BUILD_TYPE"
Expand All @@ -83,6 +84,7 @@ def configure
bool "GGML_AVX_VNNI"
ignored "GGML_BACKEND_DL"
ignored "GGML_BIN_INSTALL_DIR"
ignored "GGML_BINDINGS_FLAT"
bool "GGML_BLAS"
string "GGML_BLAS_VENDOR"
bool "GGML_BMI2"
Expand Down
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ target_include_directories(json_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

# examples

if(BINDINGS_FLAT)
message(STATUS "Adding FLAT binding to examples")
add_compile_options(-DBINDINGS_FLAT)
endif()


include_directories(${CMAKE_CURRENT_SOURCE_DIR})

if (EMSCRIPTEN)
Expand Down
13 changes: 13 additions & 0 deletions examples/bench/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#include "../ggml/src/ggml-flat.h"
#endif

#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -61,6 +65,15 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
static int whisper_bench_full(const whisper_params & params) {
// whisper init

#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
if(params.use_gpu) {
whisper_flat_backend_load_all();
} else {
ggml_backend_try_load_best("cpu", nullptr);
}
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
13 changes: 13 additions & 0 deletions examples/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "common-whisper.h"

#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#include "../ggml/src/ggml-flat.h"
#endif
#include "grammar-parser.h"

#include <cmath>
Expand Down Expand Up @@ -935,6 +939,15 @@ int main(int argc, char ** argv) {

// whisper init

#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
if(params.use_gpu) {
whisper_flat_backend_load_all();
} else {
ggml_backend_try_load_best("cpu", nullptr);
}
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
13 changes: 13 additions & 0 deletions examples/command/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "common-sdl.h"
#include "common.h"
#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#include "../ggml/src/ggml-flat.h"
#endif
#include "grammar-parser.h"

#include <algorithm>
Expand Down Expand Up @@ -692,6 +696,15 @@ int main(int argc, char ** argv) {

// whisper init

#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
if(params.use_gpu) {
whisper_flat_backend_load_all();
} else {
ggml_backend_try_load_best("cpu", nullptr);
}
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
8 changes: 8 additions & 0 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "common-whisper.h"

#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#endif
#include "httplib.h"
#include "json.hpp"

Expand Down Expand Up @@ -541,6 +544,11 @@ int main(int argc, char ** argv) {
check_ffmpeg_availibility();
}
// whisper init
#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
whisper_flat_backend_load_all();
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
13 changes: 13 additions & 0 deletions examples/stream/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "common.h"
#include "common-whisper.h"
#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#include "../ggml/src/ggml-flat.h"
#endif

#include <chrono>
#include <cstdio>
Expand Down Expand Up @@ -155,6 +159,15 @@ int main(int argc, char ** argv) {
exit(0);
}

#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
if(params.use_gpu) {
whisper_flat_backend_load_all();
} else {
ggml_backend_try_load_best("cpu", nullptr);
}
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
13 changes: 13 additions & 0 deletions examples/talk-llama/talk-llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "common.h"
#include "common-whisper.h"
#include "whisper.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#include "../ggml/src/ggml-flat.h"
#endif
#include "llama.h"

#include <chrono>
Expand Down Expand Up @@ -287,6 +291,15 @@ int main(int argc, char ** argv) {

// whisper init

#ifdef BINDINGS_FLAT
fprintf(stderr, "+++ BINDINGS_FLAT +++\n");
if(params.use_gpu) {
whisper_flat_backend_load_all();
} else {
ggml_backend_try_load_best("cpu", nullptr);
}
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
7 changes: 7 additions & 0 deletions examples/wchess/wchess.cmd/wchess.cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "WChess.h"
#include "common-sdl.h"
#ifdef BINDINGS_FLAT
#include "whisper-flat.h"
#endif
#include <iostream>

#include <memory>
Expand Down Expand Up @@ -182,6 +185,10 @@ int main(int argc, char ** argv) {

// whisper init

#ifdef BINDINGS_FLAT
whisper_flat_backend_load_all();
#endif

struct whisper_context_params cparams = whisper_context_default_params();

cparams.use_gpu = params.use_gpu;
Expand Down
2 changes: 1 addition & 1 deletion ggml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,4 @@ if (MSVC)
disable_msvc_warnings(ggml-cpu-skylakex)
disable_msvc_warnings(ggml-cpu-icelake)
disable_msvc_warnings(ggml-cpu-alderlake)
endif()
endif()
1 change: 1 addition & 0 deletions ggml/include/ggml-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ extern "C" {
// CPU buffer types are always available
GGML_API ggml_backend_buffer_t ggml_backend_cpu_buffer_from_ptr(void * ptr, size_t size);
GGML_API ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void);


#ifdef __cplusplus
}
Expand Down
16 changes: 15 additions & 1 deletion ggml/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,22 @@ if (GGML_BACKEND_DL)
target_compile_definitions(ggml-base PUBLIC GGML_BACKEND_DL)
endif()

set(GGML_LIBRARY_SOURCES
ggml-backend-reg.cpp)

if(BINDINGS_FLAT)
message(STATUS "Adding FLAT GGML binding extras")

set(FLAT_GGML_SOURCES
ggml-flat.cpp
)
list(APPEND GGML_LIBRARY_SOURCES ${FLAT_GGML_SOURCES})
add_compile_options(-DGGML_BINDINGS_FLAT)
endif()

add_library(ggml
ggml-backend-reg.cpp)
${GGML_LIBRARY_SOURCES}
)

target_link_libraries(ggml PUBLIC ggml-base)

Expand Down
12 changes: 12 additions & 0 deletions ggml/src/ggml-backend-reg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# include <unistd.h>
#endif

#ifdef GGML_BINDINGS_FLAT
#include "ggml-flat.h"
#endif

// Backend registry
#ifdef GGML_USE_CPU
#include "ggml-cpu.h"
Expand Down Expand Up @@ -584,3 +588,11 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
ggml_backend_load(backend_path);
}
}

#ifdef GGML_BINDINGS_FLAT
ggml_backend_reg_t ggml_backend_try_load_best(const char * name, const char * dir_path) {
bool silent = true;
fprintf(stderr, "%s: (%s)\n", __func__, name);
return ggml_backend_load_best(name, silent, dir_path);
}
#endif
38 changes: 38 additions & 0 deletions ggml/src/ggml-flat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
#endif

#include "ggml-backend.h"
#include "ggml-backend-impl.h"
#include "ggml-alloc.h"
#include "ggml-impl.h"

#include <assert.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>

#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

#include "ggml-flat.h"

#ifdef GGML_BINDINGS_FLAT
// ggml_backend_reg_t ggml_backend_try_load_best(const char * name, const char * dir_path);

#endif



31 changes: 31 additions & 0 deletions ggml/src/ggml-flat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#ifdef BINDINGS_FLAT
#define GGML_BINDINGS_FLAT
#endif

#ifdef GGML_SHARED
# if defined(_WIN32) && !defined(__MINGW32__)
# ifdef GGML_BUILD
# define GGML_FLAT_API __declspec(dllexport) extern
# else
# define GGML_FLAT_API __declspec(dllimport) extern
# endif
# else
# define GGML_FLAT_API __attribute__ ((visibility ("default"))) extern
# endif
#else
# define GGML_FLAT_API extern
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef GGML_BINDINGS_FLAT
GGML_FLAT_API ggml_backend_reg_t ggml_backend_try_load_best(const char * name, const char * dir_path);
#endif

#ifdef __cplusplus
}
#endif
8 changes: 5 additions & 3 deletions ggml/src/ggml-opencl/ggml-opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS

// suppress warnings in CL headers for GCC and Clang
#pragma GCC diagnostic ignored "-Woverlength-strings"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Woverlength-strings"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
#endif
#endif

#include "ggml-opencl.h"
Expand Down
Loading
Loading