is_available() should check the device index too (#3107)

This commit is contained in:
Ronan Collobert
2026-02-06 13:02:04 -08:00
committed by GitHub
parent 69fd3fa9b1
commit ef3fbc60a3
+2 -2
View File
@@ -36,9 +36,9 @@ bool operator!=(const Device& lhs, const Device& rhs) {
bool is_available(const Device& d) {
switch (d.type) {
case Device::cpu:
return cpu::is_available();
return cpu::is_available() && (d.index < cpu::device_count());
case Device::gpu:
return gpu::is_available();
return gpu::is_available() && (d.index < gpu::device_count());
}
// appease compiler
return false;