!32064 Refine error log when get device count fail

Merge pull request !32064 from zyli2020/master
This commit is contained in:
i-robot 2022-03-28 06:34:13 +00:00 committed by Gitee
commit 95e5475f58
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 8 additions and 2 deletions

View File

@ -230,10 +230,16 @@ bool CudaDriver::ElapsedTime(float *cost_time, const CudaDeviceEvent &start, con
}
int CudaDriver::device_count() {
int dev_count;
auto last_error = cudaGetLastError();
if (last_error != cudaSuccess) {
MS_LOG(EXCEPTION) << "There is a cuda error, errorno[" << static_cast<int>(last_error) << "], "
<< cudaGetErrorString(last_error);
}
int dev_count = 0;
auto ret = cudaGetDeviceCount(&dev_count);
if (ret != cudaSuccess) {
MS_LOG(ERROR) << "cudaGetDeviceCount failed, ret[" << static_cast<int>(ret) << "], " << cudaGetErrorString(ret);
MS_LOG(EXCEPTION) << "cudaGetDeviceCount failed, ret[" << static_cast<int>(ret) << "], " << cudaGetErrorString(ret);
}
return dev_count;
}