Spaces:
Running
Running
谢乃闻
Diego Devesa
commited on
Commit
·
e1df33d
1
Parent(s):
ec98109
Fix crash caused by ggml_backend_load_all when launching on Android Activity (llama/10812)
Browse files* Fix crash caused by ggml_backend_load_all when launching on AndroidActivity.
Details:
Calling ggml_backend_load_all during initialization in the AndroidActivity project leads to a crash with the error:
terminating with uncaught exception of type std::__ndk1::__fs::filesystem::filesystem_error: filesystem error: in directory_iterator::directory_iterator(...): Permission denied [./].
This issue occurs because AndroidActivity restricts file access due to sandboxing.
Reproduction:
In the example folder, the LlamaAndroid project can reproduce the crash by calling ggml_backend_load_all first in Java_android_llama_cpp_LLamaAndroid_backend_1init.
* Update ggml/src/ggml-backend-reg.cpp
---------
Co-authored-by: Diego Devesa <slarengh@gmail.com>
ggml/src/ggml-backend-reg.cpp
CHANGED
|
@@ -473,7 +473,8 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
| 473 |
if (!fs::exists(search_path)) {
|
| 474 |
continue;
|
| 475 |
}
|
| 476 |
-
|
|
|
|
| 477 |
if (entry.is_regular_file()) {
|
| 478 |
std::string filename = entry.path().filename().string();
|
| 479 |
std::string ext = entry.path().extension().string();
|
|
|
|
| 473 |
if (!fs::exists(search_path)) {
|
| 474 |
continue;
|
| 475 |
}
|
| 476 |
+
fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
|
| 477 |
+
for (const auto & entry : dir_it) {
|
| 478 |
if (entry.is_regular_file()) {
|
| 479 |
std::string filename = entry.path().filename().string();
|
| 480 |
std::string ext = entry.path().extension().string();
|