Files
Valentin Pollet 2e011cb198 Bug 2043658 - Update llama.cpp to 74ade527 - Rebase patch 2 (std::filesystem) r=jbowser,padenot
Upstream split dynamic-library loading into the new ggml-backend-dl.{cpp,h},
which use std::filesystem. The patch grew to #if 0 out the fs::path-based
dl_load_library there and add the <memory>/<type_traits> includes it
otherwise pulled in transitively.

Differential Revision: https://phabricator.services.mozilla.com/D307358
2026-06-26 22:34:24 +00:00

157 lines
4.3 KiB
Diff

diff --git a/ggml/src/ggml-backend-dl.cpp b/ggml/src/ggml-backend-dl.cpp
index a65cf0090552..571a3469f7c7 100644
--- a/ggml/src/ggml-backend-dl.cpp
+++ b/ggml/src/ggml-backend-dl.cpp
@@ -2,6 +2,7 @@
#ifdef _WIN32
+#if 0
dl_handle * dl_load_library(const fs::path & path) {
// suppress error dialogs for missing DLLs
DWORD old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
@@ -13,6 +14,7 @@ dl_handle * dl_load_library(const fs::path & path) {
return handle;
}
+#endif
void * dl_get_sym(dl_handle * handle, const char * name) {
DWORD old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
@@ -31,10 +33,12 @@ const char * dl_error() {
#else
+#if 0
dl_handle * dl_load_library(const fs::path & path) {
dl_handle * handle = dlopen(path.string().c_str(), RTLD_NOW | RTLD_LOCAL);
return handle;
}
+#endif
void * dl_get_sym(dl_handle * handle, const char * name) {
return dlsym(handle, name);
diff --git a/ggml/src/ggml-backend-dl.h b/ggml/src/ggml-backend-dl.h
index f74b7c948946..307ac8b9e2a6 100644
--- a/ggml/src/ggml-backend-dl.h
+++ b/ggml/src/ggml-backend-dl.h
@@ -11,9 +11,14 @@
# include <dlfcn.h>
# include <unistd.h>
#endif
+#if 0
#include <filesystem>
namespace fs = std::filesystem;
+#endif
+
+#include <memory>
+#include <type_traits>
#ifdef _WIN32
@@ -39,7 +44,9 @@ struct dl_handle_deleter {
using dl_handle_ptr = std::unique_ptr<dl_handle, dl_handle_deleter>;
+#if 0
dl_handle * dl_load_library(const fs::path & path);
+#endif
void * dl_get_sym(dl_handle * handle, const char * name);
const char * dl_error();
diff --git a/ggml/src/ggml-backend-reg.cpp b/ggml/src/ggml-backend-reg.cpp
index 8165ae2c8bbe..115833115dc3 100644
--- a/ggml/src/ggml-backend-reg.cpp
+++ b/ggml/src/ggml-backend-reg.cpp
@@ -4,7 +4,7 @@
#include "ggml-impl.h"
#include <algorithm>
#include <cstring>
-#include <filesystem>
+// #include <filesystem>
#include <memory>
#include <string>
#include <type_traits>
@@ -86,8 +86,8 @@
#include "ggml-openvino.h"
#endif
-namespace fs = std::filesystem;
-
+// namespace fs = std::filesystem;
+#if 0
static std::string path_str(const fs::path & path) {
try {
#if defined(__cpp_lib_char8_t)
@@ -102,6 +102,7 @@ static std::string path_str(const fs::path & path) {
return std::string();
}
}
+#endif
struct ggml_backend_reg_entry {
ggml_backend_reg_t reg;
@@ -210,6 +211,7 @@ struct ggml_backend_registry {
devices.push_back(device);
}
+#if 0
ggml_backend_reg_t load_backend(const fs::path & path, bool silent) {
dl_handle_ptr handle { dl_load_library(path) };
if (!handle) {
@@ -255,6 +257,7 @@ struct ggml_backend_registry {
return reg;
}
+#endif
void unload_backend(ggml_backend_reg_t reg, bool silent) {
auto it = std::find_if(backends.begin(), backends.end(),
@@ -382,6 +385,7 @@ ggml_backend_t ggml_backend_init_best(void) {
return ggml_backend_dev_init(dev, nullptr);
}
+#if 0
// Dynamic loading
ggml_backend_reg_t ggml_backend_load(const char * path) {
return get_reg().load_backend(path, false);
@@ -453,7 +457,8 @@ static fs::path get_executable_path() {
return {};
#endif
}
-
+#endif
+#if 0
static fs::path backend_filename_prefix() {
#ifdef _WIN32
return fs::u8path("ggml-");
@@ -469,8 +474,10 @@ static fs::path backend_filename_extension() {
return fs::u8path(".so");
#endif
}
+#endif
static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent, const char * user_search_path) {
+ #if 0
// enumerate all the files that match [lib]ggml-name-*.[so|dll] in the search paths
const fs::path name_path = fs::u8path(name);
const fs::path file_prefix = backend_filename_prefix().native() + name_path.native() + fs::u8path("-").native();
@@ -550,6 +557,8 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
}
return get_reg().load_backend(best_path, silent);
+ #endif
+ return nullptr;
}
void ggml_backend_load_all() {
@@ -581,6 +590,6 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
// check the environment variable GGML_BACKEND_PATH to load an out-of-tree backend
const char * backend_path = std::getenv("GGML_BACKEND_PATH");
if (backend_path) {
- ggml_backend_load(backend_path);
+ // ggml_backend_load(backend_path);
}
}