Optionaly fail when gpu_id is set to invalid value (#6342)

This commit is contained in:
Honza Sterba
2020-11-28 08:14:12 +01:00
committed by GitHub
parent 956beead70
commit b0036b339b
4 changed files with 25 additions and 1 deletions

View File

@@ -222,6 +222,10 @@ void GenericParameter::ConfigureGpuId(bool require_gpu) {
LOG(WARNING) << "No visible GPU is found, setting `gpu_id` to -1";
}
this->UpdateAllowUnknown(Args{{"gpu_id", std::to_string(kCpuId)}});
} else if (fail_on_invalid_gpu_id) {
CHECK(gpu_id == kCpuId || gpu_id < n_gpus)
<< "Only " << n_gpus << " GPUs are visible, gpu_id "
<< gpu_id << " is invalid.";
} else if (gpu_id != kCpuId && gpu_id >= n_gpus) {
LOG(WARNING) << "Only " << n_gpus
<< " GPUs are visible, setting `gpu_id` to " << gpu_id % n_gpus;