Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Compute::Device Class Referenceabstractexport

Abstract interface for compute device implementations. More...

Inheritance diagram for Mila::Dnn::Compute::Device:
Mila::Dnn::Compute::CpuDevice Mila::Dnn::Compute::CudaDevice

Public Member Functions

virtual DeviceId getDeviceId () const =0
 Gets the device identifier.
virtual std::string getDeviceName () const =0
 Gets the human-readable device name.
virtual constexpr DeviceType getDeviceType () const =0
 Gets the device type.
virtual DeviceMemoryInfo getMemoryInfo () const
 Current free and total device memory.

Static Public Member Functions

static constexpr DeviceId Cpu () noexcept
 Create CPU device identifier.
static constexpr DeviceId Cuda (int index) noexcept
 Create CUDA device identifier.
template<DeviceType TDeviceType>
static constexpr DeviceId getDeviceId (int index) noexcept
static constexpr DeviceId Metal (int index) noexcept
 Create Metal device identifier.
static constexpr DeviceId Rocm (int index) noexcept
 Create ROCm device identifier.

Detailed Description

Abstract interface for compute device implementations.

Defines the common interface for all compute device types (CPU, CUDA, Metal, ROCm, etc.). Concrete device implementations inherit from this class and are registered with DeviceRegistry for runtime discovery.

This class also serves as the primary factory for DeviceId values via static methods, providing a clean API: Device::Cuda(0), Device::Cpu().

Member Function Documentation

◆ Cpu()

constexpr DeviceId Mila::Dnn::Compute::Device::Cpu ( )
inlinestaticconstexprnoexcept

Create CPU device identifier.

Returns a DeviceId representing the CPU device. CPU is always index 0 (single logical CPU device).

Returns
DeviceId CPU device identifier.

◆ Cuda()

constexpr DeviceId Mila::Dnn::Compute::Device::Cuda ( int index)
inlinestaticconstexprnoexcept

Create CUDA device identifier.

Parameters
indexZero-based CUDA device index (0, 1, 2, ...).
Returns
DeviceId CUDA device identifier.

◆ getDeviceId()

virtual DeviceId Mila::Dnn::Compute::Device::getDeviceId ( ) const
pure virtual

Gets the device identifier.

Returns
DeviceId The identifier for this device (type + index).

Implemented in Mila::Dnn::Compute::CpuDevice, and Mila::Dnn::Compute::CudaDevice.

◆ getDeviceName()

virtual std::string Mila::Dnn::Compute::Device::getDeviceName ( ) const
pure virtual

Gets the human-readable device name.

Returns
std::string Device name (e.g., "CPU:0", "CUDA:0", "Metal:1").

Implemented in Mila::Dnn::Compute::CpuDevice, and Mila::Dnn::Compute::CudaDevice.

◆ getDeviceType()

virtual constexpr DeviceType Mila::Dnn::Compute::Device::getDeviceType ( ) const
constexprpure virtual

Gets the device type.

Returns
DeviceType The type of this device (Cpu, Cuda, Metal, Rocm).

Implemented in Mila::Dnn::Compute::CpuDevice, and Mila::Dnn::Compute::CudaDevice.

◆ getMemoryInfo()

virtual DeviceMemoryInfo Mila::Dnn::Compute::Device::getMemoryInfo ( ) const
inlinevirtual

Current free and total device memory.

Answers "will this model fit" together with a footprint from Model::getRequiredMemory. Zeroed by default for devices with no distinct memory pool to report; a caller seeing total_bytes == 0 should treat the figure as unavailable rather than as a device with no memory.

NOTE on Windows: WDDM oversubscribes into shared host memory rather than failing, so free_bytes running out does not produce an allocation error – it produces a model that runs pathologically slowly. Callers should warn rather than refuse.

Reimplemented in Mila::Dnn::Compute::CudaDevice.

◆ Metal()

constexpr DeviceId Mila::Dnn::Compute::Device::Metal ( int index)
inlinestaticconstexprnoexcept

Create Metal device identifier.

Parameters
indexZero-based Metal device index.
Returns
DeviceId Metal device identifier.

◆ Rocm()

constexpr DeviceId Mila::Dnn::Compute::Device::Rocm ( int index)
inlinestaticconstexprnoexcept

Create ROCm device identifier.

Parameters
indexZero-based ROCm device index.
Returns
DeviceId ROCm device identifier.

The documentation for this class was generated from the following file: