11
11
#include " core/providers/openvino/backend_utils.h"
12
12
#include " core/session/onnxruntime_session_options_config_keys.h"
13
13
#include " nlohmann/json.hpp"
14
+ #include " core/providers/openvino/openvino_parser_utils.h"
14
15
15
16
namespace onnxruntime {
16
17
namespace openvino_ep {
17
18
void ParseConfigOptions (ProviderInfo& pi ) {
18
- if (pi .config_options == NULL )
19
+ if (pi .config_options == NULL )
19
20
return ;
20
21
21
22
pi .so_disable_cpu_ep_fallback = pi .config_options ->GetConfigOrDefault (kOrtSessionOptionsDisableCPUEPFallback , " 0" ) == " 1" ;
@@ -29,7 +30,6 @@ void ParseConfigOptions(ProviderInfo& pi) {
29
30
map[" NPU_COMPILATION_MODE_PARAMS" ] = " enable-wd-blockarg-input=true compute-layers-with-higher-precision=Sqrt,Power,ReduceSum" ;
30
31
pi .load_config [" NPU" ] = std::move (map);
31
32
}
32
-
33
33
}
34
34
35
35
void * ParseUint64 (const ProviderOptions& provider_options, std::string option_name) {
@@ -115,58 +115,6 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio
115
115
}
116
116
}
117
117
118
- // Depends on ProviderOptions.
119
- std::string ParsePrecision (const ProviderOptions& provider_options, std::string& device_type, const std::string& option_name) {
120
- using DeviceName = std::string;
121
- using DefaultValue = std::string;
122
- using ValidValues = std::list<std::string>;
123
- using foo = std::pair<DefaultValue, ValidValues>;
124
- using ParserHelper = std::map<DeviceName, foo>;
125
- ParserHelper helper = {
126
- {" GPU" , {" FP16" , {" FP16" , " FP32" }}},
127
- {" NPU" , {" FP16" , {" FP16" }}},
128
- {" CPU" , {" FP32" , {" FP32" }}},
129
- };
130
-
131
- std::set<std::string> deprecated_device_types = {" CPU_FP32" , " GPU_FP32" ,
132
- " GPU.0_FP32" , " GPU.1_FP32" , " GPU_FP16" ,
133
- " GPU.0_FP16" , " GPU.1_FP16" };
134
-
135
- if (provider_options.contains (option_name)) {
136
- // Start by checking if the device_type is a normal valid one
137
- if (helper.contains (device_type)) {
138
- auto const & valid_values = helper[device_type].second ;
139
- const auto & precision = provider_options.at (option_name);
140
- if (precision == " ACCURACY" ) {
141
- return valid_values.back (); // Return highest supported precision
142
- } else {
143
- if (std::find (valid_values.begin (), valid_values.end (), precision) != valid_values.end ()) {
144
- return precision; // Return precision selected if valid
145
- } else {
146
- auto value_iter = valid_values.begin ();
147
- std::string valid_values_joined = *value_iter;
148
- // Append 2nd and up, if only one then ++value_iter is same as end()
149
- for (++value_iter; value_iter != valid_values.end (); ++value_iter) {
150
- valid_values_joined += " , " + *value_iter;
151
- }
152
-
153
- ORT_THROW (" [ERROR] [OpenVINO] Unsupported inference precision is selected. " , device_type, " only supports" , valid_values_joined, " .\n " );
154
- }
155
- }
156
- } else if (deprecated_device_types.contains (device_type)) {
157
- LOGS_DEFAULT (WARNING) << " [OpenVINO] Selected 'device_type' " + device_type + " is deprecated. \n "
158
- << " Update the 'device_type' to specified types 'CPU', 'GPU', 'GPU.0', "
159
- << " 'GPU.1', 'NPU' or from"
160
- << " HETERO/MULTI/AUTO options and set 'precision' separately. \n " ;
161
- auto delimit = device_type.find (" _" );
162
- device_type = device_type.substr (0 , delimit);
163
- return device_type.substr (delimit + 1 );
164
- }
165
- }
166
- // Return default
167
- return helper[device_type].first ;
168
- }
169
-
170
118
void ParseProviderOptions ([[maybe_unused]] ProviderInfo& result, [[maybe_unused]] const ProviderOptions& config_options) {}
171
119
172
120
struct OpenVINOProviderFactory : IExecutionProviderFactory {
@@ -204,7 +152,7 @@ struct OpenVINO_Provider : Provider {
204
152
const ProviderOptions* provider_options_ptr = reinterpret_cast <ProviderOptions*>(pointers_array[0 ]);
205
153
const ConfigOptions* config_options = reinterpret_cast <ConfigOptions*>(pointers_array[1 ]);
206
154
207
- if (provider_options_ptr == NULL ) {
155
+ if (provider_options_ptr == NULL ) {
208
156
LOGS_DEFAULT (ERROR) << " [OpenVINO EP] Passed NULL ProviderOptions to CreateExecutionProviderFactory()" ;
209
157
return nullptr ;
210
158
}
@@ -234,7 +182,7 @@ struct OpenVINO_Provider : Provider {
234
182
pi .cache_dir = provider_options.at (" cache_dir" );
235
183
}
236
184
237
- pi .precision = ParsePrecision (provider_options, pi .device_type , " precision" );
185
+ pi .precision = OpenVINOParserUtils:: ParsePrecision (provider_options, pi .device_type , " precision" );
238
186
239
187
if (provider_options.contains (" load_config" )) {
240
188
auto parse_config = [&](const std::string& config_str) -> std::map<std::string, ov::AnyMap> {
0 commit comments