From ea6c218840579cc2050275fa9476af46d53c15ab Mon Sep 17 00:00:00 2001 From: lizhenyu Date: Mon, 28 Mar 2022 10:38:46 +0800 Subject: [PATCH] refine error log of get device count --- .../ccsrc/plugin/device/gpu/hal/device/cuda_driver.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/device/cuda_driver.cc b/mindspore/ccsrc/plugin/device/gpu/hal/device/cuda_driver.cc index 17f1885a52a..01cf9f9819e 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/device/cuda_driver.cc +++ b/mindspore/ccsrc/plugin/device/gpu/hal/device/cuda_driver.cc @@ -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(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(ret) << "], " << cudaGetErrorString(ret); + MS_LOG(EXCEPTION) << "cudaGetDeviceCount failed, ret[" << static_cast(ret) << "], " << cudaGetErrorString(ret); } return dev_count; }