Table of Contents

Class CudaDevice

Namespace
DotCompute.Backends.CUDA
Assembly
DotCompute.Backends.CUDA.dll

Represents a CUDA-capable GPU device with enhanced device detection capabilities. Provides detailed hardware information and capabilities for RTX 2000 Ada Generation and other CUDA devices. Requires CUDA 13.0+ and compute capability 7.5 or higher (Turing architecture minimum).

public sealed class CudaDevice : IDisposable
Inheritance
CudaDevice
Implements
Inherited Members
Extension Methods

Constructors

CudaDevice(int, ILogger?)

Initializes a new instance of the CudaDevice class.

public CudaDevice(int deviceId, ILogger? logger = null)

Parameters

deviceId int

The CUDA device ID.

logger ILogger

Optional logger instance.

Exceptions

ArgumentOutOfRangeException

Thrown when deviceId is negative.

InvalidOperationException

Thrown when device properties cannot be retrieved or device doesn't meet CUDA 13.0 requirements.

Properties

ArchitectureGeneration

Gets the device architecture generation (e.g., "Ada Lovelace", "Ampere", etc.).

public string ArchitectureGeneration { get; }

Property Value

string

Capabilities

Gets device-specific capabilities.

public IReadOnlyDictionary<string, object> Capabilities { get; }

Property Value

IReadOnlyDictionary<string, object>

ClockRate

Gets the core clock rate in kHz.

public int ClockRate { get; }

Property Value

int

ComputeCapability

Gets the compute capability as a version object.

public Version ComputeCapability { get; }

Property Value

Version

ComputeCapabilityMajor

Gets the compute capability major version.

public int ComputeCapabilityMajor { get; }

Property Value

int

ComputeCapabilityMinor

Gets the compute capability minor version.

public int ComputeCapabilityMinor { get; }

Property Value

int

ConcurrentManagedAccess

Gets whether the device supports concurrent managed access.

public bool ConcurrentManagedAccess { get; }

Property Value

bool

ConstantMemorySize

Gets the constant memory size in bytes.

public ulong ConstantMemorySize { get; }

Property Value

ulong

DeviceId

Gets the device ID.

public int DeviceId { get; }

Property Value

int

EstimatedCudaCores

Gets the estimated CUDA cores count for this device. Note: This is an approximation based on architecture and SM count.

public int EstimatedCudaCores { get; }

Property Value

int

Estimated number of CUDA cores.

GlobalMemorySize

Gets the total global memory in bytes.

public ulong GlobalMemorySize { get; }

Property Value

ulong

Info

Gets device information for compatibility with test/benchmark code.

public CudaDeviceInfo Info { get; }

Property Value

CudaDeviceInfo

IsECCEnabled

Gets whether ECC (Error-Correcting Code) is enabled.

public bool IsECCEnabled { get; }

Property Value

bool

IsRTX2000Ada

Gets whether this is an RTX 2000 Ada Generation GPU.

public bool IsRTX2000Ada { get; }

Property Value

bool

L2CacheSize

Gets the L2 cache size in bytes.

public int L2CacheSize { get; }

Property Value

int

MaxThreadsPerBlock

Gets the maximum threads per block.

public int MaxThreadsPerBlock { get; }

Property Value

int

MaxThreadsPerMultiprocessor

Gets the maximum threads per multiprocessor.

public int MaxThreadsPerMultiprocessor { get; }

Property Value

int

Memory

Gets the memory manager for this device.

public CudaMemoryManager? Memory { get; set; }

Property Value

CudaMemoryManager

Remarks

Memory manager must be set externally to avoid circular dependencies.

MemoryBandwidthGBps

Gets the estimated memory bandwidth in GB/s.

public double MemoryBandwidthGBps { get; }

Property Value

double

MemoryBusWidth

Gets the memory bus width in bits.

public int MemoryBusWidth { get; }

Property Value

int

MemoryClockRate

Gets the memory clock rate in kHz.

public int MemoryClockRate { get; }

Property Value

int

Name

Gets the device name.

public string Name { get; }

Property Value

string

PageableMemoryAccess

Gets whether the device supports pageable memory access.

public bool PageableMemoryAccess { get; }

Property Value

bool

PciBusId

Gets the PCI bus ID.

public int PciBusId { get; }

Property Value

int

PciDeviceId

Gets the PCI device ID.

public int PciDeviceId { get; }

Property Value

int

PciDomainId

Gets the PCI domain ID.

public int PciDomainId { get; }

Property Value

int

Properties

Gets the device properties structure.

public CudaDeviceProperties Properties { get; }

Property Value

CudaDeviceProperties

SharedMemoryPerBlock

Gets the shared memory per block in bytes.

public ulong SharedMemoryPerBlock { get; }

Property Value

ulong

StreamingMultiprocessorCount

Gets the number of streaming multiprocessors (SMs).

public int StreamingMultiprocessorCount { get; }

Property Value

int

SupportsConcurrentKernels

Gets whether the device supports concurrent kernels.

public bool SupportsConcurrentKernels { get; }

Property Value

bool

SupportsManagedMemory

Gets whether the device supports managed memory. Uses the corrected detection logic that handles known device issues.

public bool SupportsManagedMemory { get; }

Property Value

bool

SupportsUnifiedAddressing

Gets whether the device supports unified addressing.

public bool SupportsUnifiedAddressing { get; }

Property Value

bool

WarpSize

Gets the warp size.

public int WarpSize { get; }

Property Value

int

Methods

AllocateAsync(ulong)

Allocates memory on this device asynchronously.

public Task<IUnifiedMemoryBuffer> AllocateAsync(ulong sizeInBytes)

Parameters

sizeInBytes ulong

Returns

Task<IUnifiedMemoryBuffer>

CopyToDeviceAsync(nint, IUnifiedMemoryBuffer, ulong, CancellationToken)

Copies data from host to device asynchronously.

public static Task CopyToDeviceAsync(nint hostPtr, IUnifiedMemoryBuffer deviceBuffer, ulong sizeInBytes, CancellationToken cancellationToken = default)

Parameters

hostPtr nint
deviceBuffer IUnifiedMemoryBuffer
sizeInBytes ulong
cancellationToken CancellationToken

Returns

Task

CreateContext()

Creates a CUDA context for this device.

public CudaContext CreateContext()

Returns

CudaContext

Detect(int, ILogger<CudaDevice>?)

Creates a CudaDevice instance by detecting and validating the specified device.

public static CudaDevice? Detect(int deviceId, ILogger<CudaDevice>? logger = null)

Parameters

deviceId int

The device ID to detect.

logger ILogger<CudaDevice>

Optional logger instance.

Returns

CudaDevice

A new CudaDevice instance if successful, null otherwise.

DetectAll(ILogger?)

Detects all available CUDA devices on the system.

public static IEnumerable<CudaDevice> DetectAll(ILogger? logger = null)

Parameters

logger ILogger

Optional logger instance.

Returns

IEnumerable<CudaDevice>

An enumerable of detected CudaDevice instances.

Dispose()

Releases all resources used by the CudaDevice.

public void Dispose()

GetEstimatedCudaCores()

Gets the estimated number of CUDA cores on this device (API compatibility method).

public int GetEstimatedCudaCores()

Returns

int

GetMemoryInfo()

Gets the current memory usage information for this device.

public (ulong freeMemory, ulong totalMemory) GetMemoryInfo()

Returns

(ulong freeMemory, ulong totalMemory)

A tuple containing (free memory, total memory) in bytes.

Exceptions

InvalidOperationException

Thrown when memory info cannot be retrieved.

IsCuda13Compatible()

Checks if this device is compatible with CUDA 13.0 requirements.

public bool IsCuda13Compatible()

Returns

bool

True if the device meets CUDA 13.0 minimum requirements.

SupportsComputeCapability(int, int)

Checks if this device supports the specified compute capability.

public bool SupportsComputeCapability(int major, int minor)

Parameters

major int

Major compute capability version.

minor int

Minor compute capability version.

Returns

bool

True if the device supports the specified compute capability or higher.

SynchronizeAsync(CancellationToken)

Synchronizes all operations on this device asynchronously.

public static Task SynchronizeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

ToAcceleratorInfo()

Creates an AcceleratorInfo instance from this device.

public AcceleratorInfo ToAcceleratorInfo()

Returns

AcceleratorInfo

An AcceleratorInfo instance representing this device.