File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed
Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ target_sources(visioncpp PRIVATE
88 ml.cpp
99 mobile-sam.cpp
1010 nn.cpp
11+ platform.cpp
1112 vision.cpp
1213)
1314target_compile_features (visioncpp PUBLIC cxx_std_20)
Original file line number Diff line number Diff line change 11#include " visp/ml.hpp"
2+ #include " visp/platform.hpp"
23#include " util/string.hpp"
34
45#include < algorithm>
@@ -27,6 +28,12 @@ bool load_ggml_backends() {
2728 return true ; // already loaded
2829 }
2930 ggml_backend_load_all ();
31+ if (ggml_backend_reg_count () == 0 ) {
32+ if (path dir = current_library_path (); !dir.empty ()) {
33+ auto str = dir.parent_path ().u8string ();
34+ ggml_backend_load_all_from_path ((char const *)str.c_str ());
35+ }
36+ }
3037 return true ;
3138 }();
3239 return loaded;
Original file line number Diff line number Diff line change 1+ #include " visp/platform.hpp"
2+
3+ #ifdef _WIN32
4+ # define WIN32_LEAN_AND_MEAN
5+ # include < windows.h>
6+ #else
7+ # include < dlfcn.h>
8+ #endif
9+
10+ namespace visp {
11+ using path = std::filesystem::path;
12+
13+ path current_library_path () {
14+
15+ #ifdef _WIN32
16+ HMODULE module = nullptr ;
17+ DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
18+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
19+ if (GetModuleHandleExW (flags, (LPCWSTR)¤t_library_path, &module )) {
20+ wchar_t buffer[MAX_PATH];
21+ if (GetModuleFileNameW (module , buffer, MAX_PATH) > 0 ) {
22+ return std::filesystem::path (buffer);
23+ }
24+ }
25+ #else
26+ Dl_info info;
27+ if (dladdr (reinterpret_cast <void *>(¤t_library_path), &info)) {
28+ return std::filesystem::path (info.dli_fname );
29+ }
30+ #endif
31+ return std::filesystem::path ();
32+ }
33+
34+ } // namespace visp
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < filesystem>
4+
5+ namespace visp {
6+ using path = std::filesystem::path;
7+
8+ path current_library_path ();
9+
10+ } // namespace visp
You can’t perform that action at this time.
0 commit comments