Skip to content
fn

device_name

→std::string_view
int device_name(Device d)

Returns the canonical lower-case name for a device tag.

The string form is what the engine's error messages print, so it is the public device name: metal, as tensor.device says, not the enum's.

Parameters

dDevice
Device tag to convert.

Returns

std::string_view

"cpu" for Device::CPU, "metal" for Device::GPU. The returned view points into a static string literal — safe to store beyond the call site.

Raises

:logic_error
The enum was extended without updating this switch. Indicates a missing recompile of all translation units.

Examples

::
    const auto name = device_name(Device::GPU);   // "metal"