Skip to content

Commit 4fe18df

Browse files
committed
fix: Address multi-GPU issue in engine deserialize
- Fix issue where GPU ID of device compiled on was taking precedence over GPU ID of device in context
1 parent c1f130a commit 4fe18df

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

core/runtime/runtime.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace runtime {
1010
c10::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 (device.id == current_device.id && best_match.id != current_device.id) {
29+
best_match = device;
30+
break;
31+
} // Second priority is selecting a candidate which agrees with the compiled device ID
32+
else if (device.id == target_device.id && best_match.id != target_device.id) {
33+
best_match = device;
34+
break;
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

Comments
 (0)