1414
1515namespace onnxruntime {
1616namespace openvino_ep {
17- void ParseConfigOptions (ProviderInfo& pi, const ConfigOptions& config_options) {
18- pi.so_disable_cpu_ep_fallback = config_options.GetConfigOrDefault (kOrtSessionOptionsDisableCPUEPFallback , " 0" ) == " 1" ;
19- pi.so_context_enable = config_options.GetConfigOrDefault (kOrtSessionOptionEpContextEnable , " 0" ) == " 1" ;
20- pi.so_context_embed_mode = config_options.GetConfigOrDefault (kOrtSessionOptionEpContextEmbedMode , " 0" ) == " 1" ;
21- pi.so_share_ep_contexts = config_options.GetConfigOrDefault (kOrtSessionOptionShareEpContexts , " 0" ) == " 1" ;
22- pi.so_context_file_path = config_options.GetConfigOrDefault (kOrtSessionOptionEpContextFilePath , " " );
17+ void ParseConfigOptions (ProviderInfo& pi) {
18+ if (pi.config_options ==NULL )
19+ return ;
20+
21+ pi.so_disable_cpu_ep_fallback = pi.config_options ->GetConfigOrDefault (kOrtSessionOptionsDisableCPUEPFallback , " 0" ) == " 1" ;
22+ pi.so_context_enable = pi.config_options ->GetConfigOrDefault (kOrtSessionOptionEpContextEnable , " 0" ) == " 1" ;
23+ pi.so_context_embed_mode = pi.config_options ->GetConfigOrDefault (kOrtSessionOptionEpContextEmbedMode , " 0" ) == " 1" ;
24+ pi.so_share_ep_contexts = pi.config_options ->GetConfigOrDefault (kOrtSessionOptionShareEpContexts , " 0" ) == " 1" ;
25+ pi.so_context_file_path = pi.config_options ->GetConfigOrDefault (kOrtSessionOptionEpContextFilePath , " " );
26+
27+ if (pi.so_share_ep_contexts ) {
28+ ov::AnyMap map;
29+ map[" NPU_COMPILATION_MODE_PARAMS" ] = " enable-wd-blockarg-input=true compute-layers-with-higher-precision=Sqrt,Power,ReduceSum" ;
30+ pi.load_config [" NPU" ] = std::move (map);
31+ }
32+
2333}
2434
2535void * ParseUint64 (const ProviderOptions& provider_options, std::string option_name) {
@@ -166,6 +176,7 @@ struct OpenVINOProviderFactory : IExecutionProviderFactory {
166176 ~OpenVINOProviderFactory () override {}
167177
168178 std::unique_ptr<IExecutionProvider> CreateProvider () override {
179+ ParseConfigOptions (provider_info_);
169180 return std::make_unique<OpenVINOExecutionProvider>(provider_info_, shared_context_);
170181 }
171182
@@ -184,13 +195,23 @@ struct OpenVINO_Provider : Provider {
184195 void * GetInfo () override { return &info_; }
185196
186197 std::shared_ptr<IExecutionProviderFactory> CreateExecutionProviderFactory (const void * void_params) override {
187- // Extract the void_params into ProviderOptions and ConfigOptions
188- using ConfigBuffer = std::pair<const ProviderOptions*, const ConfigOptions&>;
189- const ConfigBuffer* buffer = reinterpret_cast <const ConfigBuffer*>(void_params);
190- const auto & provider_options = *buffer->first ;
191- const auto & config_options = buffer->second ;
198+ if (void_params == nullptr ) {
199+ LOGS_DEFAULT (ERROR) << " [OpenVINO EP] Passed NULL options to CreateExecutionProviderFactory()" ;
200+ return nullptr ;
201+ }
202+
203+ std::array<void *, 2 > pointers_array = *reinterpret_cast <const std::array<void *, 2 >*>(void_params);
204+ const ProviderOptions* provider_options_ptr = reinterpret_cast <ProviderOptions*>(pointers_array[0 ]);
205+ const ConfigOptions* config_options = reinterpret_cast <ConfigOptions*>(pointers_array[1 ]);
206+
207+ if (provider_options_ptr == NULL ) {
208+ LOGS_DEFAULT (ERROR) << " [OpenVINO EP] Passed NULL ProviderOptions to CreateExecutionProviderFactory()" ;
209+ return nullptr ;
210+ }
211+ const ProviderOptions provider_options = *provider_options_ptr;
192212
193213 ProviderInfo pi;
214+ pi.config_options = config_options;
194215
195216 std::string bool_flag = " " ;
196217
@@ -326,20 +347,11 @@ struct OpenVINO_Provider : Provider {
326347
327348 pi.disable_dynamic_shapes = ParseBooleanOption (provider_options, " disable_dynamic_shapes" );
328349
329- ParseConfigOptions (pi, config_options);
330-
331350 // Always true for NPU plugin or when passed .
332351 if (pi.device_type .find (" NPU" ) != std::string::npos) {
333352 pi.disable_dynamic_shapes = true ;
334353 }
335354
336- // Append values to config to support weight-as-inputs conversion for shared contexts
337- if (pi.so_share_ep_contexts ) {
338- ov::AnyMap map;
339- map[" NPU_COMPILATION_MODE_PARAMS" ] = " enable-wd-blockarg-input=true compute-layers-with-higher-precision=Sqrt,Power,ReduceSum" ;
340- pi.load_config [" NPU" ] = std::move (map);
341- }
342-
343355 return std::make_shared<OpenVINOProviderFactory>(pi, SharedContext::Get ());
344356 }
345357
0 commit comments