Skip to content

Commit 0368dd4

Browse files
Ovep 1.19 bug fix 2 (microsoft#21829)
### Description Handles bug fix for EPCtx file path assertions. --------- Co-authored-by: jatinwadhwa921 <110383850+jatinwadhwa921@users.noreply.github.com> Co-authored-by: jatinwadhwa921 <jatin.wadhwa@intel.com>
1 parent 37a7dd7 commit 0368dd4

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

onnxruntime/core/providers/openvino/openvino_provider_factory.cc

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ struct OpenVINOProviderFactory : IExecutionProviderFactory {
3030
so_epctx_embed_mode_(so_epctx_embed_mode) {
3131
device_type_ = (device_type == nullptr) ? "" : device_type;
3232
cache_dir_ = (cache_dir == nullptr) ? "" : cache_dir;
33+
if (cache_dir != nullptr) {
34+
free(const_cast<void*>(static_cast<const void*>(cache_dir)));
35+
cache_dir = nullptr;
36+
}
3337
}
3438

3539
~OpenVINOProviderFactory() override {
@@ -90,7 +94,7 @@ struct OpenVINO_Provider : Provider {
9094
// speeds up the model's compilation to NPU device specific format.
9195
int num_of_threads = 0; // [num_of_threads]: Overrides the accelerator default value of number of
9296
// threads with this value at runtime.
93-
const char* cache_dir = ""; // [cache_dir]: specify the path to
97+
const char* cache_dir = nullptr; // [cache_dir]: specify the path to
9498
// dump and load the blobs for the model caching/kernel caching (GPU)
9599
// feature. If blob files are already present, it will be directly loaded.
96100
const char* model_priority = "DEFAULT"; // High-level OpenVINO model priority hint
@@ -305,17 +309,22 @@ struct OpenVINO_Provider : Provider {
305309
auto ep_context_file_path_ = provider_options_map.at("so_epctx_path");
306310
auto file_path = std::filesystem::path(ep_context_file_path_);
307311
// ep_context_file_path_ file extension must be .onnx
308-
if (!ep_context_file_path_.empty() &&
309-
file_path.extension().generic_string() == ".onnx") {
310-
// ep_context_file_path_ must be provided as a directory, create it if doesn't exist
311-
auto parent_path = file_path.parent_path();
312-
if (!std::filesystem::is_directory(parent_path) &&
313-
!std::filesystem::create_directory(parent_path)) {
314-
ORT_THROW("[ERROR] [OpenVINO] Failed to create directory : " + file_path.parent_path().generic_string() + " \n");
312+
if (!ep_context_file_path_.empty()) {
313+
if (file_path.extension().generic_string() == ".onnx") {
314+
// ep_context_file_path_ must be provided as a directory, create it if doesn't exist
315+
auto parent_path = file_path.parent_path();
316+
if (!parent_path.empty() && !std::filesystem::is_directory(parent_path) &&
317+
!std::filesystem::create_directory(parent_path)) {
318+
ORT_THROW("[ERROR] [OpenVINO] Failed to create directory : " + file_path.parent_path().generic_string() + " \n");
319+
}
320+
#ifdef _WIN32
321+
cache_dir = _strdup(ep_context_file_path_.c_str());
322+
#else
323+
cache_dir = strdup(ep_context_file_path_.c_str());
324+
#endif
325+
} else {
326+
ORT_THROW("[ERROR] [OpenVINO] Invalid ep_ctx_file_path" + ep_context_file_path_ + " \n");
315327
}
316-
cache_dir = ep_context_file_path_.c_str();
317-
} else {
318-
ORT_THROW("[ERROR] [OpenVINO] Invalid ep_ctx_file_path" + ep_context_file_path_ + " \n");
319328
}
320329
}
321330
}

0 commit comments

Comments
 (0)