Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions source/MRCuda/MRCudaBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ namespace MR
namespace Cuda
{

Expected<RuntimeInfo> getRuntimeInfo()
Expected<DeviceInfo> getDeviceInfo()
{
int n;
CUDA_RETURN_UNEXPECTED( cudaGetDeviceCount( &n ) );
if ( n <= 0 )
return MR::unexpected( "NVIDIA GPU error: no single device" );

RuntimeInfo res;
DeviceInfo res;
CUDA_RETURN_UNEXPECTED( cudaDriverGetVersion( &res.driverVersion ) );
CUDA_RETURN_UNEXPECTED( cudaRuntimeGetVersion( &res.runtimeVersion ) );
CUDA_RETURN_UNEXPECTED( cudaDeviceGetAttribute( &res.computeMajor, cudaDevAttrComputeCapabilityMajor, 0 ) );
CUDA_RETURN_UNEXPECTED( cudaDeviceGetAttribute( &res.computeMinor, cudaDevAttrComputeCapabilityMinor, 0 ) );

cudaDeviceProp prop;
CUDA_RETURN_UNEXPECTED( cudaGetDeviceProperties( &prop, 0 ) );
res.computeMajor = prop.major;
res.computeMinor = prop.minor;
res.totalGlobalMem = prop.totalGlobalMem;
res.name = prop.name;

return res;
}

bool RuntimeInfo::fitForComputations() const
bool DeviceInfo::fitForComputations() const
{
// according to https://en.wikipedia.org/wiki/CUDA Compute Capability (CUDA SDK support vs. Microarchitecture) table
if ( runtimeVersion / 1000 >= 12 && computeMajor < 5 )
Expand All @@ -41,7 +47,7 @@ bool RuntimeInfo::fitForComputations() const

bool isCudaAvailable( int* driverVersionOut, int* runtimeVersionOut, int* computeMajorOut, int* computeMinorOut )
{
auto info = MR::Cuda::getRuntimeInfo();
auto info = MR::Cuda::getDeviceInfo();
if ( !info )
return false;

Expand Down
14 changes: 10 additions & 4 deletions source/MRCuda/MRCudaBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace MR
namespace Cuda
{

struct RuntimeInfo
struct DeviceInfo
{
/// maximum driver supported version
/// maximum CUDA version supported by the driver
int driverVersion = 0;

/// current runtime version
/// application's CUDA version
int runtimeVersion = 0;

/// compute capability major version
Expand All @@ -25,12 +25,18 @@ struct RuntimeInfo
/// compute capability minor version
int computeMinor = 0;

/// global memory on device in bytes (not all is available for our process)
size_t totalGlobalMem = 0;

/// name of the device
std::string name;

/// returns true if all versions pass the checks
[[nodiscard]] MRCUDA_API bool fitForComputations() const;
};

/// Returns an error if CUDA is not available
MRCUDA_API Expected<RuntimeInfo> getRuntimeInfo();
MRCUDA_API Expected<DeviceInfo> getDeviceInfo();

/// Returns true if Cuda is present on this GPU
/// optional out maximum driver supported version
Expand Down
2 changes: 1 addition & 1 deletion source/MRTestCuda/MRTestCuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main( int argc, char** argv )
{
MR::setupLoggerByDefault();

auto info = MR::Cuda::getRuntimeInfo();
auto info = MR::Cuda::getDeviceInfo();
if ( !info )
{
spdlog::critical( "CUDA error: {}", info.error() );
Expand Down
Loading