Skip to content

MRCuda: add getRuntimeInfo() returning Expected<RuntimeInfo>; deprecate isCudaAvailable()#6307

Merged
Fedr merged 5 commits into
masterfrom
fix/cuda-info
Jun 23, 2026
Merged

MRCuda: add getRuntimeInfo() returning Expected<RuntimeInfo>; deprecate isCudaAvailable()#6307
Fedr merged 5 commits into
masterfrom
fix/cuda-info

Conversation

@Fedr

@Fedr Fedr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces Cuda::getRuntimeInfo() as the primary way to query CUDA availability and device capabilities, and re-expresses the existing isCudaAvailable() on top of it (now deprecated).

The old isCudaAvailable() packed several concerns into one bool return plus four optional out-parameters: it queried the driver/runtime versions and the compute capability, and decided whether the device was suitable for computations — while discarding the underlying CUDA error on failure.

New API:

struct RuntimeInfo
{
    int driverVersion = 0;   ///< maximum driver supported version
    int runtimeVersion = 0;  ///< current runtime version
    int computeMajor = 0;    ///< compute capability major version
    int computeMinor = 0;    ///< compute capability minor version

    /// 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();

getRuntimeInfo() returns the four versions on success, or a descriptive error string when no CUDA device is present or a CUDA call fails. The compute-capability-vs-runtime-version suitability logic now lives in RuntimeInfo::fitForComputations(), separate from the query.

Changes

  • MRCudaBasic.h / .cpp — add RuntimeInfo + getRuntimeInfo(); propagate CUDA errors as Expected via the CUDA_RETURN_UNEXPECTED macro instead of returning a bare false.
  • isCudaAvailable() — kept for backward compatibility (existing callers, the Python/C bindings and downstream code keep working unchanged), now marked [[deprecated( "Use getRuntimeInfo" )]] and reimplemented as a thin wrapper: it fills the optional out-parameters from getRuntimeInfo() and returns RuntimeInfo::fitForComputations().
  • getCudaAvailableMemory() — no longer routes through the availability check; it tries cudaSetDevice( 0 ) directly and now also checks the result of cudaMemGetInfo (previously ignored), returning 0 on failure.
  • Doc comments converted to /// Doxygen style.
  • MRTestCuda — updated to the new API; logs the actual CUDA error message on failure and checks fitForComputations() explicitly.

Notes

  • Backward compatible — isCudaAvailable() keeps its old signature and semantics (out-parameters + the fit-for-computations result), so no binding regeneration or downstream changes are required.

@Fedr Fedr requested a review from Grantim June 23, 2026 13:35
@Fedr Fedr changed the title refactor CUDA initialization MRCuda: replace isCudaAvailable() with getRuntimeInfo() returning Expected<RuntimeInfo> Jun 23, 2026
- test_cuda_smoke: getRuntimeInfo() raises when no device, returns info
  with fitForComputations() when available
- test_cuda_module_exists: check getRuntimeInfo symbol exists
- cuda_placeholder.h: mirror new RuntimeInfo/getRuntimeInfo stub API
@Fedr Fedr changed the title MRCuda: replace isCudaAvailable() with getRuntimeInfo() returning Expected<RuntimeInfo> MRCuda: add getRuntimeInfo() returning Expected<RuntimeInfo>; deprecate isCudaAvailable() Jun 23, 2026
@Fedr Fedr merged commit f32289b into master Jun 23, 2026
40 checks passed
@Fedr Fedr deleted the fix/cuda-info branch June 23, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants