Lightweight identifier for a compute device.
More...
|
| static DeviceId | parse (std::string_view device_name) |
| | Parse a textual device identifier.
|
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.
◆ DeviceId() [1/2]
| Mila::Dnn::Compute::DeviceId::DeviceId |
( |
| ) |
|
|
inlineconstexprnoexcept |
Construct a default DeviceId.
Default constructs to Cuda device 0.
◆ DeviceId() [2/2]
| Mila::Dnn::Compute::DeviceId::DeviceId |
( |
DeviceType | type, |
|
|
int | index = 0 ) |
|
inlineconstexprnoexcept |
Construct a DeviceId from components.
- Parameters
-
| type | DeviceType enum value. |
| index | Zero-based device index (default 0). |
◆ 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.
◆ 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_name | Text to parse (case-insensitive for type). |
- Returns
- DeviceId Parsed device identifier.
- Exceptions
-
| std::invalid_argument | If format is invalid or type is unknown. |
◆ 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.
◆ index
| int Mila::Dnn::Compute::DeviceId::index = -1 |
Zero-based device index for the given type.
◆ type
The device type (e.g., Cuda, Cpu, Metal, Rocm).
The documentation for this struct was generated from the following file: