| 14 | { |
| 15 | |
| 16 | Expected<DeviceInfo> getDeviceInfo() |
| 17 | { |
| 18 | DeviceInfo res; |
| 19 | CUDA_RETURN_UNEXPECTED( cudaDriverGetVersion( &res.driverVersion ) ); |
| 20 | if ( res.driverVersion <= 0 ) |
| 21 | return MR::unexpected( "NVIDIA GPU error: no CUDA driver found" ); |
| 22 | |
| 23 | { |
| 24 | int n = 0; |
| 25 | auto code = cudaGetDeviceCount( &n ); |
| 26 | if ( code != cudaSuccess || n <= 0 ) |
| 27 | { |
| 28 | auto err = ( code != cudaSuccess ) ? MR::Cuda::getError( code ) : "NVIDIA GPU error: no capable device found"; |
| 29 | err += fmt::format( ", CUDA driver {}.{}", res.driverVersion / 1000, ( res.driverVersion % 1000 ) / 10 ); |
| 30 | return MR::unexpected( err ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | CUDA_RETURN_UNEXPECTED( cudaRuntimeGetVersion( &res.runtimeVersion ) ); |
| 35 | |
| 36 | cudaDeviceProp prop; |
| 37 | CUDA_RETURN_UNEXPECTED( cudaGetDeviceProperties( &prop, 0 ) ); |
| 38 | res.computeMajor = prop.major; |
| 39 | res.computeMinor = prop.minor; |
| 40 | res.totalGlobalMem = prop.totalGlobalMem; |
| 41 | res.name = prop.name; |
| 42 | |
| 43 | return res; |
| 44 | } |
| 45 | |
| 46 | bool DeviceInfo::fitForComputations() const |
| 47 | { |