@@ -10,6 +10,8 @@ namespace runtime {
1010c10::optional<RTDevice> get_most_compatible_device (const RTDevice& target_device) {
1111 LOG_DEBUG (" Target Device: " << target_device);
1212 auto device_options = find_compatible_devices (target_device);
13+ auto current_device = get_current_device ();
14+
1315 if (device_options.size () == 0 ) {
1416 return {};
1517 } else if (device_options.size () == 1 ) {
@@ -21,10 +23,17 @@ c10::optional<RTDevice> get_most_compatible_device(const RTDevice& target_device
2123 dev_list << " [" << std::endl;
2224 for (auto device : device_options) {
2325 dev_list << " " << device << ' ,' << std::endl;
24- if (device.device_name == target_device.device_name && best_match.device_name != target_device.device_name ) {
25- best_match = device;
26- } else if (device.device_name == target_device.device_name && best_match.device_name == target_device.device_name ) {
27- if (device.id == target_device.id && best_match.id != target_device.id ) {
26+ if (device.device_name == target_device.device_name ) {
27+ // First priority is selecting a candidate which agrees with the current device ID
28+ // If such a device is found, we can select it and break out of the loop
29+ if (device.id == current_device.id && best_match.id != current_device.id ) {
30+ best_match = device;
31+ break ;
32+ } // Second priority is selecting a candidate which agrees with the compiled device ID
33+ else if (device.id == target_device.id && best_match.id != target_device.id ) {
34+ best_match = device;
35+ } // If no such GPU ID is found, select the first available candidate GPU
36+ else if (best_match.device_name != target_device.device_name ) {
2837 best_match = device;
2938 }
3039 }
0 commit comments