Skip to content

Commit

Permalink
chore: 没看出来ort哪里会crash(
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 1, 2024
1 parent 578dde0 commit db44903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions source/MaaFramework/Resource/ONNXResMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@

MAA_RES_NS_BEGIN

ONNXResMgr::~ONNXResMgr()
{
if (gpu_device_id_) {
LogWarn << "GPU is enabled, leaking resources";

// FIXME: intentionally leak ort objects to avoid crash (double free?)
// https://github.com/microsoft/onnxruntime/issues/15174
for (auto& session : classifiers_ | std::views::values) {
auto leak_session = new Ort::Session(nullptr);
*leak_session = std::move(*session);
}
for (auto& session : detectors_ | std::views::values) {
auto leak_session = new Ort::Session(nullptr);
*leak_session = std::move(*session);
}

auto leak_options = new Ort::SessionOptions(nullptr);
*leak_options = std::move(options_);
}
}
// ONNXResMgr::~ONNXResMgr()
//{
// if (gpu_device_id_) {
// LogWarn << "GPU is enabled, leaking resources";
//
// // FIXME: intentionally leak ort objects to avoid crash (double free?)
// // https://github.com/microsoft/onnxruntime/issues/15174
// for (auto& session : classifiers_ | std::views::values) {
// auto leak_session = new Ort::Session(nullptr);
// *leak_session = std::move(*session);
// }
// for (auto& session : detectors_ | std::views::values) {
// auto leak_session = new Ort::Session(nullptr);
// *leak_session = std::move(*session);
// }
//
// auto leak_options = new Ort::SessionOptions(nullptr);
// *leak_options = std::move(options_);
// }
// }

bool ONNXResMgr::use_cpu()
{
Expand All @@ -62,6 +62,7 @@ bool ONNXResMgr::use_gpu(int device_id)
return true;
}
options_ = {};
gpu_device_id_ = std::nullopt;

auto all_providers_vec = Ort::GetAvailableProviders();
std::unordered_set<std::string> all_providers(
Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Resource/ONNXResMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ONNXResMgr : public NonCopyable
inline static const std::filesystem::path kClassifierDir = "classify";
inline static const std::filesystem::path kDetectorDir = "detect";

~ONNXResMgr();
//~ONNXResMgr();

public:
bool use_cpu();
Expand Down

0 comments on commit db44903

Please sign in to comment.