Spaces:
Running
Running
Gilad S
Diego Devesa
commited on
Commit
·
c6de218
1
Parent(s):
461484c
ggml: load all backends from a user-provided search path (llama/10699)
Browse files* feat: load all backends from a user-provided search path
* fix: Windows search path
* refactor: rename `ggml_backend_load_all_in_search_path` to `ggml_backend_load_all_from_path`
* refactor: rename `search_path` to `dir_path`
* fix: change `NULL` to `nullptr`
Co-authored-by: Diego Devesa <[email protected]>
* fix: change `NULL` to `nullptr`
---------
Co-authored-by: Diego Devesa <[email protected]>
- ggml/include/ggml-backend.h +1 -0
- ggml/src/ggml-backend-reg.cpp +27 -13
ggml/include/ggml-backend.h
CHANGED
|
@@ -228,6 +228,7 @@ extern "C" {
|
|
| 228 |
GGML_API void ggml_backend_unload(ggml_backend_reg_t reg);
|
| 229 |
// Load all known backends from dynamic libraries
|
| 230 |
GGML_API void ggml_backend_load_all(void);
|
|
|
|
| 231 |
|
| 232 |
//
|
| 233 |
// Backend scheduler
|
|
|
|
| 228 |
GGML_API void ggml_backend_unload(ggml_backend_reg_t reg);
|
| 229 |
// Load all known backends from dynamic libraries
|
| 230 |
GGML_API void ggml_backend_load_all(void);
|
| 231 |
+
GGML_API void ggml_backend_load_all_from_path(const char * dir_path);
|
| 232 |
|
| 233 |
//
|
| 234 |
// Backend scheduler
|
ggml/src/ggml-backend-reg.cpp
CHANGED
|
@@ -449,11 +449,21 @@ static std::string backend_filename_suffix() {
|
|
| 449 |
#endif
|
| 450 |
}
|
| 451 |
|
| 452 |
-
static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent) {
|
| 453 |
// enumerate all the files that match [lib]ggml-name-*.[so|dll] in the search paths
|
| 454 |
// TODO: search system paths
|
| 455 |
-
std::vector<std::string> search_paths = { "./", get_executable_path() };
|
| 456 |
std::string file_prefix = backend_filename_prefix() + name + "-";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
int best_score = 0;
|
| 459 |
std::string best_path;
|
|
@@ -509,21 +519,25 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent)
|
|
| 509 |
}
|
| 510 |
|
| 511 |
void ggml_backend_load_all() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
#ifdef NDEBUG
|
| 513 |
bool silent = true;
|
| 514 |
#else
|
| 515 |
bool silent = false;
|
| 516 |
#endif
|
| 517 |
|
| 518 |
-
ggml_backend_load_best("blas", silent);
|
| 519 |
-
ggml_backend_load_best("cann", silent);
|
| 520 |
-
ggml_backend_load_best("cuda", silent);
|
| 521 |
-
ggml_backend_load_best("hip", silent);
|
| 522 |
-
ggml_backend_load_best("kompute", silent);
|
| 523 |
-
ggml_backend_load_best("metal", silent);
|
| 524 |
-
ggml_backend_load_best("rpc", silent);
|
| 525 |
-
ggml_backend_load_best("sycl", silent);
|
| 526 |
-
ggml_backend_load_best("vulkan", silent);
|
| 527 |
-
ggml_backend_load_best("musa", silent);
|
| 528 |
-
ggml_backend_load_best("cpu", silent);
|
| 529 |
}
|
|
|
|
| 449 |
#endif
|
| 450 |
}
|
| 451 |
|
| 452 |
+
static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent, const char * user_search_path) {
|
| 453 |
// enumerate all the files that match [lib]ggml-name-*.[so|dll] in the search paths
|
| 454 |
// TODO: search system paths
|
|
|
|
| 455 |
std::string file_prefix = backend_filename_prefix() + name + "-";
|
| 456 |
+
std::vector<std::string> search_paths;
|
| 457 |
+
if (user_search_path == nullptr) {
|
| 458 |
+
search_paths.push_back("./");
|
| 459 |
+
search_paths.push_back(get_executable_path());
|
| 460 |
+
} else {
|
| 461 |
+
#if defined(_WIN32)
|
| 462 |
+
search_paths.push_back(std::string(user_search_path) + "\\");
|
| 463 |
+
#else
|
| 464 |
+
search_paths.push_back(std::string(user_search_path) + "/");
|
| 465 |
+
#endif
|
| 466 |
+
}
|
| 467 |
|
| 468 |
int best_score = 0;
|
| 469 |
std::string best_path;
|
|
|
|
| 519 |
}
|
| 520 |
|
| 521 |
void ggml_backend_load_all() {
|
| 522 |
+
ggml_backend_load_all_from_path(nullptr);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
void ggml_backend_load_all_from_path(const char * dir_path) {
|
| 526 |
#ifdef NDEBUG
|
| 527 |
bool silent = true;
|
| 528 |
#else
|
| 529 |
bool silent = false;
|
| 530 |
#endif
|
| 531 |
|
| 532 |
+
ggml_backend_load_best("blas", silent, dir_path);
|
| 533 |
+
ggml_backend_load_best("cann", silent, dir_path);
|
| 534 |
+
ggml_backend_load_best("cuda", silent, dir_path);
|
| 535 |
+
ggml_backend_load_best("hip", silent, dir_path);
|
| 536 |
+
ggml_backend_load_best("kompute", silent, dir_path);
|
| 537 |
+
ggml_backend_load_best("metal", silent, dir_path);
|
| 538 |
+
ggml_backend_load_best("rpc", silent, dir_path);
|
| 539 |
+
ggml_backend_load_best("sycl", silent, dir_path);
|
| 540 |
+
ggml_backend_load_best("vulkan", silent, dir_path);
|
| 541 |
+
ggml_backend_load_best("musa", silent, dir_path);
|
| 542 |
+
ggml_backend_load_best("cpu", silent, dir_path);
|
| 543 |
}
|