@@ -214,107 +214,29 @@ void BasicBackend::PopulateConfigValue(ov::AnyMap& device_config) {
214
214
if (!session_context_.load_config .empty ()) {
215
215
const std::map<std::string, ov::AnyMap>& target_config = session_context_.load_config ;
216
216
217
- if ((session_context_.device_type .find (" NPU" ) != std::string::npos) && session_context_.enable_causallm ) {
218
- if (target_config.find (" NPU" ) != target_config.end ()) {
219
- auto npu_genai_config = target_config.at (" NPU" );
220
- CausalLMConfig ().ApplyConfig (npu_genai_config, device_config);
221
- } else {
222
- LOGS_DEFAULT (WARNING) << " ORT GenAI CausalLMConfig Configuration not found." ;
223
- }
224
- }
225
-
226
- if (session_context_.device_type .find (" NPU" ) != std::string::npos) {
227
- auto npuw_config = target_config.at (" NPU" );
228
-
229
- // Check if "NPU_USE_NPUW" exists and is set to "YES"
230
- auto npu_use_npuw_it = npuw_config.find (" NPU_USE_NPUW" );
231
- if (npu_use_npuw_it != npuw_config.end () &&
232
- npu_use_npuw_it->second .is <std::string>() &&
233
- npu_use_npuw_it->second .as <std::string>() == " YES" ) {
234
- // Only add NPUW-related keys if NPU_USE_NPUW is "YES"
235
- for (const auto & [key, value] : npuw_config) {
236
- if (key.find (" NPUW" ) != std::string::npos) {
237
- if (!value.is <std::string>()) {
238
- LOGS_DEFAULT (ERROR) << " Invalid value type for key: " << key;
239
- continue ;
240
- }
241
- device_config[key] = value;
242
- }
243
- }
244
- } else {
245
- // Check if there are any "NPUW" keys and log a warning
246
- if (std::any_of (npuw_config.begin (), npuw_config.end (),
247
- [&](const auto & pair) { return pair.first .find (" NPUW" ) != std::string::npos; })) {
248
- LOGS_DEFAULT (WARNING) << " Skipping NPUW-related configurations as NPU_USE_NPUW is not set to 'YES'." ;
249
- }
250
- }
251
- }
252
- auto find_device_type_mode = [&](const std::string& device_type) -> std::string {
253
- std::string device_mode = " " ;
254
- auto delimiter_pos = device_type.find (' :' );
255
- if (delimiter_pos != std::string::npos) {
256
- std::stringstream str_stream (device_type.substr (0 , delimiter_pos));
257
- std::getline (str_stream, device_mode, ' ,' );
258
- }
259
- return device_mode;
260
- };
217
+ // Extract device names from device string and apply their configs
218
+ // Examples: "GPU" -> ["GPU"], "AUTO:GPU.0,CPU" -> ["AUTO", "GPU", "CPU"]
219
+ auto apply_device_config = [&](std::string_view device) {
220
+ if (device.empty ()) return ;
261
221
262
- // Parse device types like "AUTO:CPU,GPU" and extract individual devices
263
- auto parse_individual_devices = [&](const std::string& device_type) -> std::vector<std::string> {
264
- std::vector<std::string> devices;
265
- auto delimiter_pos = device_type.find (' :' );
266
- if (delimiter_pos != std::string::npos) {
267
- std::stringstream str_stream (device_type.substr (delimiter_pos + 1 ));
268
- std::string device;
269
- while (std::getline (str_stream, device, ' ,' )) {
270
- devices.emplace_back (device);
271
- }
272
- } else {
273
- devices.emplace_back (device_type);
274
- }
275
- return devices;
276
- };
222
+ // Remove device index: "GPU.0" -> "GPU"
223
+ auto base_device = device.substr (0 , device.find (' .' ));
277
224
278
- // Set properties, Validation will be handled by OpenVINO Core
279
- auto set_target_properties = [&](const std::string& device, const ov::AnyMap& config_options) {
280
- for (const auto & [key, value] : config_options) {
281
- // Update the device_config map from the target_config to avoid load_config being overridden
282
- // by the device_config set by the OpenVINO EP.
283
- auto it = device_config.find (key);
284
- if (it != device_config.end ()) {
285
- it->second = value;
286
- }
287
- if ((key.find (" NPUW" ) != std::string::npos) ||
288
- ((it != device_config.end ()) && session_context_.enable_causallm )) {
289
- continue ;
225
+ if (auto config_it = target_config.find (std::string (base_device)); config_it != target_config.end ()) {
226
+ for (const auto & [key, value] : config_it->second ) {
227
+ device_config[key] = value;
290
228
}
291
- OVCore::Get ()->core .set_property (device, ov::AnyMap{{key, value}});
292
229
}
293
230
};
294
231
295
- // Check if the device type is AUTO, HETERO, or MULTI
296
- if (session_context_.device_type .find (" AUTO" ) == 0 ||
297
- session_context_.device_type .find (" HETERO" ) == 0 ||
298
- session_context_.device_type .find (" MULTI" ) == 0 ) {
299
- // // Parse to get the device mode (e.g., "AUTO:CPU,GPU" -> "AUTO")
300
- std::unordered_set<std::string> supported_mode = {" AUTO" , " HETERO" , " MULTI" };
301
- auto device_mode = find_device_type_mode (session_context_.device_type );
302
- ORT_ENFORCE (supported_mode.find (device_mode) != supported_mode.end (), " Invalid device mode is passed : " , session_context_.device_type );
303
- // Parse individual devices (e.g., "AUTO:CPU,GPU" -> ["CPU", "GPU"])
304
- auto individual_devices = parse_individual_devices (session_context_.device_type );
305
- if (!device_mode.empty ()) individual_devices.emplace_back (device_mode);
306
-
307
- // Set properties only for individual devices (e.g., "CPU", "GPU")
308
- for (const std::string& device : individual_devices) {
309
- if (target_config.count (device)) {
310
- // Set properties for the device
311
- set_target_properties (device, target_config.at (device));
232
+ // Parse device string by splitting on ':' and ',' delimiters
233
+ const auto & device_str = session_context_.device_type ;
234
+ for (size_t start = 0 , pos = 0 ; pos <= device_str.size (); ++pos) {
235
+ if (pos == device_str.size () || device_str[pos] == ' :' || device_str[pos] == ' ,' ) {
236
+ if (pos > start) {
237
+ apply_device_config (std::string_view (device_str).substr (start, pos - start));
312
238
}
313
- }
314
- } else {
315
- if (target_config.count (session_context_.device_type )) {
316
- set_target_properties (session_context_.device_type ,
317
- target_config.at (session_context_.device_type ));
239
+ start = pos + 1 ;
318
240
}
319
241
}
320
242
}
0 commit comments