Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Compute::DeviceId Struct Referenceexport

Lightweight identifier for a compute device. More...

Public Member Functions

constexpr DeviceId () noexcept
 Construct a default DeviceId.
constexpr DeviceId (DeviceType type, int index=0) noexcept
 Construct a DeviceId from components.
constexpr auto operator<=> (const DeviceId &) const noexcept=default
 Three-way comparison for DeviceId.
std::string toString () const
 Convert to human-readable string.

Static Public Member Functions

static DeviceId parse (std::string_view device_name)
 Parse a textual device identifier.

Public Attributes

int index = -1
 Zero-based device index for the given type.
DeviceType type
 The device type (e.g., Cuda, Cpu, Metal, Rocm).

Detailed Description

Lightweight identifier for a compute device.

Pairs a DeviceType with a zero-based index. Used throughout the API as a value type for device identification, function parameters, and class members.

Construction:

  • Preferred: Use Device factory methods (Device::Cuda(0), Device::Cpu())
  • Direct: DeviceId(DeviceType::Cuda, 0) for low-level code
  • Parsing: DeviceId::parse("cuda:0") for configuration files

Equality- and order-comparable. Suitable as key in associative containers.

Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Components/Normalization/Softmax.ixx.

Constructor & Destructor Documentation

◆ DeviceId() [1/2]

Mila::Dnn::Compute::DeviceId::DeviceId ( )
inlineconstexprnoexcept

Construct a default DeviceId.

Default constructs to Cuda device 0.

Here is the caller graph for this function:

◆ DeviceId() [2/2]

Mila::Dnn::Compute::DeviceId::DeviceId ( DeviceType type,
int index = 0 )
inlineconstexprnoexcept

Construct a DeviceId from components.

Parameters
typeDeviceType enum value.
indexZero-based device index (default 0).

Member Function Documentation

◆ operator<=>()

auto Mila::Dnn::Compute::DeviceId::operator<=> ( const DeviceId & ) const
constexprdefaultnoexcept

Three-way comparison for DeviceId.

Provides total ordering and equality. Comparison is performed by first comparing type, then index.

Here is the call graph for this function:

◆ parse()

DeviceId Mila::Dnn::Compute::DeviceId::parse ( std::string_view device_name)
inlinestatic

Parse a textual device identifier.

Accepted forms:

  • "<type>" -> interpreted as "<type>:0"
  • "<type>:<index>" -> explicit zero-based index

Examples: "cuda:0", "cpu", "metal:1", "rocm:2"

Parameters
device_nameText to parse (case-insensitive for type).
Returns
DeviceId Parsed device identifier.
Exceptions
std::invalid_argumentIf format is invalid or type is unknown.
Here is the call graph for this function:

◆ toString()

std::string Mila::Dnn::Compute::DeviceId::toString ( ) const
inline

Convert to human-readable string.

Produces "<type>:<index>" using deviceTypeToString() for the type component (e.g., "Cuda:0", "CPU:0", "Metal:1").

Useful for logging, diagnostics, and configuration serialization.

Returns
std::string Device name in "<type>:<index>" format.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ index

int Mila::Dnn::Compute::DeviceId::index = -1

Zero-based device index for the given type.

◆ type

DeviceType Mila::Dnn::Compute::DeviceId::type

The device type (e.g., Cuda, Cpu, Metal, Rocm).


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