@@ -30,6 +30,10 @@ struct OpenVINOProviderFactory : IExecutionProviderFactory {
30
30
so_epctx_embed_mode_(so_epctx_embed_mode) {
31
31
device_type_ = (device_type == nullptr ) ? " " : device_type;
32
32
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
+ }
33
37
}
34
38
35
39
~OpenVINOProviderFactory () override {
@@ -90,7 +94,7 @@ struct OpenVINO_Provider : Provider {
90
94
// speeds up the model's compilation to NPU device specific format.
91
95
int num_of_threads = 0 ; // [num_of_threads]: Overrides the accelerator default value of number of
92
96
// 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
94
98
// dump and load the blobs for the model caching/kernel caching (GPU)
95
99
// feature. If blob files are already present, it will be directly loaded.
96
100
const char * model_priority = " DEFAULT" ; // High-level OpenVINO model priority hint
@@ -305,17 +309,22 @@ struct OpenVINO_Provider : Provider {
305
309
auto ep_context_file_path_ = provider_options_map.at (" so_epctx_path" );
306
310
auto file_path = std::filesystem::path (ep_context_file_path_);
307
311
// 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 " );
315
327
}
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 " );
319
328
}
320
329
}
321
330
}
0 commit comments