Skip to content

Commit

Permalink
fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline75489 committed Jul 26, 2024
1 parent 20743b8 commit 331acde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class path {
};

#ifdef _WIN32
path(const std::wstring& path) : wpath_(path) {};
path(const std::wstring& path) : wpath_(path){};
#endif

static constexpr char separator =
Expand Down
31 changes: 20 additions & 11 deletions src/models/onnxruntime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o
#define LOG_ERROR(...) Generators::Log(Generators::LOG_LABEL_ERROR, __VA_ARGS__)
#define LOG_FATAL(...) Generators::Log(Generators::LOG_LABEL_FATAL, __VA_ARGS__)


/** \brief Free functions and a few helpers are defined inside this namespace. Otherwise all types are the C API types
*
*/
Expand Down Expand Up @@ -188,16 +187,6 @@ inline void InitApi() {
std::string("libonnxruntime.so.1.19.0"),
std::string("libonnxruntime.so.1.20.0")};

Dl_info dl_info;
dladdr((void*)InitApi, &dl_info);
std::string module_name(dl_info.dli_fname);
std::string module_directory;

const size_t last_slash_idx = module_name.rfind('/');
if (std::string::npos != last_slash_idx) {
module_directory = module_name.substr(0, last_slash_idx);
}

for (const std::string& lib_path : target_libraries) {
const fs::path system_path{lib_path};
LOG_INFO("Attempting to dlopen %s", system_path.c_str());
Expand All @@ -206,6 +195,17 @@ inline void InitApi() {
break;
}

#if !defined(__ANDROID__)
Dl_info dl_info;
dladdr((void*)InitApi, &dl_info);
std::string module_name(dl_info.dli_fname);
std::string module_directory;

const size_t last_slash_idx = module_name.rfind('/');
if (std::string::npos != last_slash_idx) {
module_directory = module_name.substr(0, last_slash_idx);
}

const fs::path local_path{module_directory + "/" + lib_path};
LOG_INFO("Attempting to dlopen %s", local_path.c_str());
if (local_path.exists()) {
Expand All @@ -219,6 +219,7 @@ inline void InitApi() {
path = pip_path.string();
break;
}
#endif
}

if (path.empty()) {
Expand Down Expand Up @@ -267,6 +268,13 @@ inline void InitApi() {
break;
}

const fs::path local_path{module_directory + L"/" + lib_path};
LOG_INFO("Attempting to LoadLibrary %s", local_path.c_str());
if (local_path.exists()) {
path = local_path.wstring();
break;
}

const fs::path pip_path{module_directory + L"/../onnxruntime/capi/" + lib_path};
LOG_INFO_W(L"Attempting to LoadLibrary %s", pip_path.c_str());
if (pip_path.exists()) {
Expand All @@ -279,6 +287,7 @@ inline void InitApi() {
throw std::runtime_error("Failed to find onnxruntime. Please make sure you have onnxruntime installed");
}

AddDllDirectory(module_directory.c_str());
AddDllDirectory((module_directory + L"/../onnxruntime/capi/").c_str());

WCHAR cuda_path[PATH_MAX];
Expand Down

0 comments on commit 331acde

Please sign in to comment.