Skip to content

Commit

Permalink
use binary mode for context ep
Browse files Browse the repository at this point in the history
  • Loading branch information
BoarQing committed Jul 24, 2024
1 parent 2580d93 commit d1e6d20
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void VitisAIExecutionProvider::FulfillEPContextEnablement(
auto& ep_ctx_graph = p_ep_ctx_model_->MainGraph();
if (!ep_ctx_embed_mode_) {
auto ep_ctx_cache_path_str = GetEPContextCacheFileLocation(ep_ctx_model_file_loc_, model_path_str_);
std::ofstream ep_ctx_cache_ofs(ep_ctx_cache_path_str.c_str(), std::ios::trunc);
std::ofstream ep_ctx_cache_ofs(ep_ctx_cache_path_str.c_str(), std::ios::trunc | std::ios::binary);
if (!ep_ctx_cache_ofs.is_open()) {
ORT_THROW("Failed to open a file to write EP context cache: ", ep_ctx_cache_path_str.c_str());
}
Expand Down Expand Up @@ -136,12 +136,14 @@ std::vector<std::unique_ptr<ComputeCapability>> VitisAIExecutionProvider::GetCap
info_["cacheDir"] = cache_dir;
info_["cacheKey"] = cache_key;
LOGS_DEFAULT(VERBOSE) << "Trying getting compilation cache from " << PathToUTF8String(ep_ctx_model_file_loc_);
auto ep_ctx_payload = RetrieveEPContextCache(graph_viewer.GetGraph(), ep_ctx_model_file_loc_, false);
auto ep_ctx_payload = RetrieveEPContextCache(graph_viewer.GetGraph(), ep_ctx_model_file_loc_, true);
restore_backend_compilation_cache(cache_dir, cache_key, ep_ctx_payload, graph_viewer.ModelPath().string());
} else {
if (fs::exists(ep_ctx_model_file_loc_) && fs::is_regular_file(ep_ctx_model_file_loc_) && ep_ctx_enabled_) {
ORT_THROW("The inference session was created with a normal ONNX model but a model file with EP context cache exists at ",
PathToUTF8String(ep_ctx_model_file_loc_), ". Please remove the EP context model manually if you want to re-generate it.");
if (1) {
ORT_THROW("The inference session was created with a normal ONNX model but a model file with EP context cache exists at ",

Check warning on line 144 in onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc:144: Lines should be <= 120 characters long [whitespace/line_length] [2]
PathToUTF8String(ep_ctx_model_file_loc_), ". Please remove the EP context model manually if you want to re-generate it.");

Check warning on line 145 in onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc:145: Lines should be <= 120 characters long [whitespace/line_length] [2]
}
// Disable the flexibility implemented below by throwing an exception.
// Now the code below is unreachable but DCE will take care of it.
// We might want to re-enable it in future, so we keep it as is.
Expand Down

0 comments on commit d1e6d20

Please sign in to comment.