Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backend search path #12330

Merged
merged 3 commits into from
Mar 11, 2025
Merged

Fix backend search path #12330

merged 3 commits into from
Mar 11, 2025

Conversation

jklincn
Copy link
Contributor

@jklincn jklincn commented Mar 11, 2025

std::filesystem::current_path() returns path without '/', leading to path error when trying to load the base backend.

I provide a simple example to demonstrate.

lin@amx:~/bs$ touch test.txt
lin@amx:~/bs$ cat error.cpp
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
 
int main()
{
    fs::path search_path = fs::current_path();
    fs::path filename = "test.txt";
    fs::path path = search_path.native() + filename.native();
    if (fs::exists(path)) {
        std::cout << "File exists." << std::endl;
    } else {
        std::cout << "File does not exist." << std::endl;
    }
}
lin@amx:~/bs$ g++ error.cpp --std=c++17
lin@amx:~/bs$ ./a.out 
File does not exist.
lin@amx:~/bs$ diff error.cpp correct.cpp 
7c7
<     fs::path search_path = fs::current_path();
---
>     fs::path search_path = fs::current_path() / "";
lin@amx:~/bs$ g++ correct.cpp --std=c++17
lin@amx:~/bs$ ./a.out 
File exists.

Refenence: https://en.cppreference.com/w/cpp/filesystem/current_path

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Mar 11, 2025
@slaren
Copy link
Member

slaren commented Mar 11, 2025

We should probably use the / operator to build the path instead:

fs::path path = search_path / filename;

@jklincn
Copy link
Contributor Author

jklincn commented Mar 11, 2025

Thank you! I have made the changes and also addressed a few other places where .native() was used.

@slaren slaren merged commit ba76543 into ggml-org:master Mar 11, 2025
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants