|
@@ -4,11 +4,11 @@ Date: Sun, 16 Feb 2025 20:00:22 -0500
|
|
Subject: [PATCH] use std::filesystem::path instead of wstring
|
|
Subject: [PATCH] use std::filesystem::path instead of wstring
|
|
|
|
|
|
---
|
|
---
|
|
- ggml/src/ggml-backend-reg.cpp | 144 ++++++++++++++--------------------
|
|
|
|
- 1 file changed, 58 insertions(+), 86 deletions(-)
|
|
|
|
|
|
+ ggml/src/ggml-backend-reg.cpp | 199 +++++++++++++++-------------------
|
|
|
|
+ 1 file changed, 88 insertions(+), 111 deletions(-)
|
|
|
|
|
|
diff --git a/ggml/src/ggml-backend-reg.cpp b/ggml/src/ggml-backend-reg.cpp
|
|
diff --git a/ggml/src/ggml-backend-reg.cpp b/ggml/src/ggml-backend-reg.cpp
|
|
-index 1c19129a..c854e6bb 100644
|
|
|
|
|
|
+index 98d5e14d..799af5f3 100644
|
|
--- a/ggml/src/ggml-backend-reg.cpp
|
|
--- a/ggml/src/ggml-backend-reg.cpp
|
|
+++ b/ggml/src/ggml-backend-reg.cpp
|
|
+++ b/ggml/src/ggml-backend-reg.cpp
|
|
@@ -66,26 +66,6 @@
|
|
@@ -66,26 +66,6 @@
|
|
@@ -264,47 +264,55 @@ index 1c19129a..c854e6bb 100644
|
|
for (const auto & search_path : search_paths) {
|
|
for (const auto & search_path : search_paths) {
|
|
if (!fs::exists(search_path)) {
|
|
if (!fs::exists(search_path)) {
|
|
continue;
|
|
continue;
|
|
-@@ -514,31 +486,31 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
|
|
|
|
+@@ -513,29 +485,26 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
|
|
+ fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
|
|
for (const auto & entry : dir_it) {
|
|
for (const auto & entry : dir_it) {
|
|
- try {
|
|
|
|
- if (entry.is_regular_file()) {
|
|
|
|
-- std::wstring filename = entry.path().filename().wstring();
|
|
|
|
-- std::wstring ext = entry.path().extension().wstring();
|
|
|
|
-+ std::string filename = entry.path().filename().string();
|
|
|
|
-+ std::string ext = entry.path().extension().string();
|
|
|
|
- if (filename.find(file_prefix) == 0 && ext == backend_filename_suffix()) {
|
|
|
|
-- dl_handle_ptr handle { dl_load_library(entry.path().wstring()) };
|
|
|
|
-+ dl_handle_ptr handle { dl_load_library(entry.path()) };
|
|
|
|
- if (!handle) {
|
|
|
|
-- GGML_LOG_ERROR("%s: failed to load %s\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str());
|
|
|
|
-+ GGML_LOG_ERROR("%s: failed to load %s\n", __func__, path_to_string(entry.path()).c_str());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- auto score_fn = (ggml_backend_score_t) dl_get_sym(handle.get(), "ggml_backend_score");
|
|
|
|
- if (!score_fn) {
|
|
|
|
-- GGML_LOG_DEBUG("%s: failed to find ggml_backend_score in %s\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str());
|
|
|
|
-+ GGML_LOG_DEBUG("%s: failed to find ggml_backend_score in %s\n", __func__, path_to_string(entry.path()).c_str());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int s = score_fn();
|
|
|
|
-- GGML_LOG_DEBUG("%s: %s score: %d\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str(), s);
|
|
|
|
-+ GGML_LOG_DEBUG("%s: %s score: %d\n", __func__, path_to_string(entry.path()).c_str(), s);
|
|
|
|
- if (s > best_score) {
|
|
|
|
- best_score = s;
|
|
|
|
-- best_path = entry.path().wstring();
|
|
|
|
-+ best_path = entry.path();
|
|
|
|
- }
|
|
|
|
|
|
+ if (entry.is_regular_file()) {
|
|
|
|
+- std::wstring filename = entry.path().filename().wstring();
|
|
|
|
+- std::wstring ext = entry.path().extension().wstring();
|
|
|
|
++ std::string filename = entry.path().filename().string();
|
|
|
|
++ std::string ext = entry.path().extension().string();
|
|
|
|
+ if (filename.find(file_prefix) == 0 && ext == backend_filename_suffix()) {
|
|
|
|
+- dl_handle_ptr handle { dl_load_library(entry.path().wstring()) };
|
|
|
|
+- if (!handle && !silent) {
|
|
|
|
+- GGML_LOG_ERROR("%s: failed to load %s\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str());
|
|
|
|
++ dl_handle_ptr handle { dl_load_library(entry.path()) };
|
|
|
|
++ if (!handle) {
|
|
|
|
++ GGML_LOG_ERROR("%s: failed to load %s\n", __func__, path_to_string(entry.path()).c_str());
|
|
|
|
++ continue;
|
|
|
|
+ }
|
|
|
|
+- if (handle) {
|
|
|
|
+- auto score_fn = (ggml_backend_score_t) dl_get_sym(handle.get(), "ggml_backend_score");
|
|
|
|
+- if (score_fn) {
|
|
|
|
+- int s = score_fn();
|
|
|
|
+-#ifndef NDEBUG
|
|
|
|
+- GGML_LOG_DEBUG("%s: %s score: %d\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str(), s);
|
|
|
|
+-#endif
|
|
|
|
+- if (s > best_score) {
|
|
|
|
+- best_score = s;
|
|
|
|
+- best_path = entry.path().wstring();
|
|
|
|
+- }
|
|
|
|
+- } else {
|
|
|
|
+- if (!silent) {
|
|
|
|
+- GGML_LOG_INFO("%s: failed to find ggml_backend_score in %s\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str());
|
|
|
|
+- }
|
|
|
|
+- }
|
|
|
|
++
|
|
|
|
++ auto score_fn = (ggml_backend_score_t) dl_get_sym(handle.get(), "ggml_backend_score");
|
|
|
|
++ if (!score_fn) {
|
|
|
|
++ GGML_LOG_DEBUG("%s: failed to find ggml_backend_score in %s\n", __func__, path_to_string(entry.path()).c_str());
|
|
|
|
++ continue;
|
|
|
|
++ }
|
|
|
|
++
|
|
|
|
++ int s = score_fn();
|
|
|
|
++ GGML_LOG_DEBUG("%s: %s score: %d\n", __func__, path_to_string(entry.path()).c_str(), s);
|
|
|
|
++ if (s > best_score) {
|
|
|
|
++ best_score = s;
|
|
|
|
++ best_path = entry.path();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } catch (const std::exception & e) {
|
|
|
|
-- GGML_LOG_ERROR("%s: failed to load %s: %s\n", __func__, utf16_to_utf8(entry.path().wstring()).c_str(), e.what());
|
|
|
|
-+ GGML_LOG_ERROR("%s: failed to load %s: %s\n", __func__, path_to_string(entry.path()).c_str(), e.what());
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
-@@ -546,7 +518,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
|
|
|
|
+@@ -545,7 +514,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
if (best_score == 0) {
|
|
if (best_score == 0) {
|
|
// try to load the base backend
|
|
// try to load the base backend
|
|
for (const auto & search_path : search_paths) {
|
|
for (const auto & search_path : search_paths) {
|
|
@@ -313,3 +321,49 @@ index 1c19129a..c854e6bb 100644
|
|
if (fs::exists(path)) {
|
|
if (fs::exists(path)) {
|
|
return get_reg().load_backend(path, silent);
|
|
return get_reg().load_backend(path, silent);
|
|
}
|
|
}
|
|
|
|
+@@ -560,6 +529,14 @@ void ggml_backend_load_all() {
|
|
|
|
+ ggml_backend_load_all_from_path(nullptr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
++static void ggml_backend_try_load_best(const char * name, bool silent, const char * user_search_path) {
|
|
|
|
++ try {
|
|
|
|
++ ggml_backend_load_best(name, silent, user_search_path);
|
|
|
|
++ } catch (const std::exception & e) {
|
|
|
|
++ GGML_LOG_DEBUG("%s: failed to load %s: %s\n", __func__, name, e.what());
|
|
|
|
++ }
|
|
|
|
++}
|
|
|
|
++
|
|
|
|
+ void ggml_backend_load_all_from_path(const char * dir_path) {
|
|
|
|
+ #ifdef NDEBUG
|
|
|
|
+ bool silent = true;
|
|
|
|
+@@ -567,18 +544,18 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
|
|
|
|
+ bool silent = false;
|
|
|
|
+ #endif
|
|
|
|
+
|
|
|
|
+- ggml_backend_load_best("blas", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("cann", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("cuda", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("hip", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("kompute", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("metal", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("rpc", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("sycl", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("vulkan", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("opencl", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("musa", silent, dir_path);
|
|
|
|
+- ggml_backend_load_best("cpu", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("blas", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("cann", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("cuda", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("hip", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("kompute", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("metal", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("rpc", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("sycl", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("vulkan", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("opencl", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("musa", silent, dir_path);
|
|
|
|
++ ggml_backend_try_load_best("cpu", silent, 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) {
|