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
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
Capabilities
Gets device-specific capabilities.
public IReadOnlyDictionary<string, object> Capabilities { get; }
Property Value
ClockRate
Gets the core clock rate in kHz.
public int ClockRate { get; }
Property Value
ComputeCapability
Gets the compute capability as a version object.
public Version ComputeCapability { get; }
Property Value
ComputeCapabilityMajor
Gets the compute capability major version.
public int ComputeCapabilityMajor { get; }
Property Value
ComputeCapabilityMinor
Gets the compute capability minor version.
public int ComputeCapabilityMinor { get; }
Property Value
ConcurrentManagedAccess
Gets whether the device supports concurrent managed access.
public bool ConcurrentManagedAccess { get; }
Property Value
ConstantMemorySize
Gets the constant memory size in bytes.
public ulong ConstantMemorySize { get; }
Property Value
DeviceId
Gets the device ID.
public int DeviceId { get; }
Property Value
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
Info
Gets device information for compatibility with test/benchmark code.
public CudaDeviceInfo Info { get; }
Property Value
IsECCEnabled
Gets whether ECC (Error-Correcting Code) is enabled.
public bool IsECCEnabled { get; }
Property Value
IsRTX2000Ada
Gets whether this is an RTX 2000 Ada Generation GPU.
public bool IsRTX2000Ada { get; }
Property Value
L2CacheSize
Gets the L2 cache size in bytes.
public int L2CacheSize { get; }
Property Value
MaxThreadsPerBlock
Gets the maximum threads per block.
public int MaxThreadsPerBlock { get; }
Property Value
MaxThreadsPerMultiprocessor
Gets the maximum threads per multiprocessor.
public int MaxThreadsPerMultiprocessor { get; }
Property Value
Memory
Gets the memory manager for this device.
public CudaMemoryManager? Memory { get; set; }
Property Value
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
MemoryBusWidth
Gets the memory bus width in bits.
public int MemoryBusWidth { get; }
Property Value
MemoryClockRate
Gets the memory clock rate in kHz.
public int MemoryClockRate { get; }
Property Value
Name
Gets the device name.
public string Name { get; }
Property Value
PageableMemoryAccess
Gets whether the device supports pageable memory access.
public bool PageableMemoryAccess { get; }
Property Value
PciBusId
Gets the PCI bus ID.
public int PciBusId { get; }
Property Value
PciDeviceId
Gets the PCI device ID.
public int PciDeviceId { get; }
Property Value
PciDomainId
Gets the PCI domain ID.
public int PciDomainId { get; }
Property Value
Properties
Gets the device properties structure.
public CudaDeviceProperties Properties { get; }
Property Value
SharedMemoryPerBlock
Gets the shared memory per block in bytes.
public ulong SharedMemoryPerBlock { get; }
Property Value
StreamingMultiprocessorCount
Gets the number of streaming multiprocessors (SMs).
public int StreamingMultiprocessorCount { get; }
Property Value
SupportsConcurrentKernels
Gets whether the device supports concurrent kernels.
public bool SupportsConcurrentKernels { get; }
Property Value
SupportsManagedMemory
Gets whether the device supports managed memory. Uses the corrected detection logic that handles known device issues.
public bool SupportsManagedMemory { get; }
Property Value
SupportsUnifiedAddressing
Gets whether the device supports unified addressing.
public bool SupportsUnifiedAddressing { get; }
Property Value
WarpSize
Gets the warp size.
public int WarpSize { get; }
Property Value
Methods
AllocateAsync(ulong)
Allocates memory on this device asynchronously.
public Task<IUnifiedMemoryBuffer> AllocateAsync(ulong sizeInBytes)
Parameters
sizeInBytesulong
Returns
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
hostPtrnintdeviceBufferIUnifiedMemoryBuffersizeInBytesulongcancellationTokenCancellationToken
Returns
CreateContext()
Creates a CUDA context for this device.
public CudaContext CreateContext()
Returns
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
deviceIdintThe device ID to detect.
loggerILogger<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
loggerILoggerOptional 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
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
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
cancellationTokenCancellationToken
Returns
ToAcceleratorInfo()
Creates an AcceleratorInfo instance from this device.
public AcceleratorInfo ToAcceleratorInfo()
Returns
- AcceleratorInfo
An AcceleratorInfo instance representing this device.