|
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 { |
@@ -114,58 +115,6 @@ std::string ParseDeviceType(std::shared_ptr<OVCore> ov_core, const ProviderOptio |
114 | 115 | } |
115 | 116 | } |
116 | 117 |
|
117 | | -// Depends on ProviderOptions. |
118 | | -std::string ParsePrecision(const ProviderOptions& provider_options, std::string& device_type, const std::string& option_name) { |
119 | | - using DeviceName = std::string; |
120 | | - using DefaultValue = std::string; |
121 | | - using ValidValues = std::list<std::string>; |
122 | | - using foo = std::pair<DefaultValue, ValidValues>; |
123 | | - using ParserHelper = std::map<DeviceName, foo>; |
124 | | - ParserHelper helper = { |
125 | | - {"GPU", {"FP16", {"FP16", "FP32"}}}, |
126 | | - {"NPU", {"FP16", {"FP16"}}}, |
127 | | - {"CPU", {"FP32", {"FP32"}}}, |
128 | | - }; |
129 | | - |
130 | | - std::set<std::string> deprecated_device_types = {"CPU_FP32", "GPU_FP32", |
131 | | - "GPU.0_FP32", "GPU.1_FP32", "GPU_FP16", |
132 | | - "GPU.0_FP16", "GPU.1_FP16"}; |
133 | | - |
134 | | - if (provider_options.contains(option_name)) { |
135 | | - // Start by checking if the device_type is a normal valid one |
136 | | - if (helper.contains(device_type)) { |
137 | | - auto const& valid_values = helper[device_type].second; |
138 | | - const auto& precision = provider_options.at(option_name); |
139 | | - if (precision == "ACCURACY") { |
140 | | - return valid_values.back(); // Return highest supported precision |
141 | | - } else { |
142 | | - if (std::find(valid_values.begin(), valid_values.end(), precision) != valid_values.end()) { |
143 | | - return precision; // Return precision selected if valid |
144 | | - } else { |
145 | | - auto value_iter = valid_values.begin(); |
146 | | - std::string valid_values_joined = *value_iter; |
147 | | - // Append 2nd and up, if only one then ++value_iter is same as end() |
148 | | - for (++value_iter; value_iter != valid_values.end(); ++value_iter) { |
149 | | - valid_values_joined += ", " + *value_iter; |
150 | | - } |
151 | | - |
152 | | - ORT_THROW("[ERROR] [OpenVINO] Unsupported inference precision is selected. ", device_type, " only supports", valid_values_joined, ".\n"); |
153 | | - } |
154 | | - } |
155 | | - } else if (deprecated_device_types.contains(device_type)) { |
156 | | - LOGS_DEFAULT(WARNING) << "[OpenVINO] Selected 'device_type' " + device_type + " is deprecated. \n" |
157 | | - << "Update the 'device_type' to specified types 'CPU', 'GPU', 'GPU.0', " |
158 | | - << "'GPU.1', 'NPU' or from" |
159 | | - << " HETERO/MULTI/AUTO options and set 'precision' separately. \n"; |
160 | | - auto delimit = device_type.find("_"); |
161 | | - device_type = device_type.substr(0, delimit); |
162 | | - return device_type.substr(delimit + 1); |
163 | | - } |
164 | | - } |
165 | | - // Return default |
166 | | - return helper[device_type].first; |
167 | | -} |
168 | | - |
169 | 118 | void ParseProviderOptions([[maybe_unused]] ProviderInfo& result, [[maybe_unused]] const ProviderOptions& config_options) {} |
170 | 119 |
|
171 | 120 | struct OpenVINOProviderFactory : IExecutionProviderFactory { |
@@ -227,7 +176,7 @@ struct OpenVINO_Provider : Provider { |
227 | 176 | pi.cache_dir = provider_options.at("cache_dir"); |
228 | 177 | } |
229 | 178 |
|
230 | | - pi.precision = ParsePrecision(provider_options, pi.device_type, "precision"); |
| 179 | + pi.precision = OpenVINOParserUtils::ParsePrecision(provider_options, pi.device_type, "precision"); |
231 | 180 |
|
232 | 181 | if (provider_options.contains("load_config")) { |
233 | 182 | auto parse_config = [&](const std::string& config_str) -> std::map<std::string, ov::AnyMap> { |
|
0 commit comments