Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Compute::DeviceRegistry Class Referenceexport

Registry of discovered compute devices with lazy instantiation. More...

Public Types

using DeviceFactory = std::function<std::shared_ptr<Device>( DeviceConstructionKey )>

Public Member Functions

 DeviceRegistry (const DeviceRegistry &)=delete
std::shared_ptr< DevicegetDevice (DeviceId id) const
 Retrieve or create a device by ID.
std::size_t getDeviceCount (DeviceType device_type) const noexcept
 Return number of registered devices for the given DeviceType.
bool hasDevice (DeviceId id) const noexcept
 Non-throwing check whether a specific DeviceId has been registered.
bool hasDeviceType (DeviceType type) const
 Check whether a specific DeviceType has been registered.
std::vector< DeviceIdlistDeviceIds () const
 List registered DeviceId values.
std::vector< DeviceTypelistDeviceTypes () const
 List registered device types (unique).
DeviceRegistry & operator= (const DeviceRegistry &)=delete
void registerDevice (DeviceId id, DeviceFactory factory)
 Register a discovered DeviceId with factory callback.

Static Public Member Functions

static DeviceRegistry & instance ()

Detailed Description

Registry of discovered compute devices with lazy instantiation.

Thread-safe singleton that stores registered DeviceId values and creates concrete Device instances on-demand. Device registrars register lightweight DeviceId values during initialization; Device objects are created lazily when first requested and then cached for subsequent calls.

Member Function Documentation

◆ getDevice()

std::shared_ptr< Device > Mila::Dnn::Compute::DeviceRegistry::getDevice ( DeviceId id) const
inline

Retrieve or create a device by ID.

Validates that the DeviceId is registered, then returns a cached Device instance. If this is the first request, invokes the factory callback to create the device and caches it.

Parameters
idDevice identifier (e.g., Device::Cuda(0), Device::Cpu())
Returns
std::shared_ptr<Device> Cached device instance with properties
Exceptions
std::runtime_errorIf DeviceId is not registered or creation fails

◆ getDeviceCount()

std::size_t Mila::Dnn::Compute::DeviceRegistry::getDeviceCount ( DeviceType device_type) const
inlinenoexcept

Return number of registered devices for the given DeviceType.

Parameters
device_typeDevice type to count
Returns
std::size_t Number of registered devices of this type (0 on error)

◆ hasDevice()

bool Mila::Dnn::Compute::DeviceRegistry::hasDevice ( DeviceId id) const
inlinenoexcept

Non-throwing check whether a specific DeviceId has been registered.

Parameters
idDevice identifier to check
Returns
bool True if device is registered, false otherwise (or on error)

◆ hasDeviceType()

bool Mila::Dnn::Compute::DeviceRegistry::hasDeviceType ( DeviceType type) const
inline

Check whether a specific DeviceType has been registered.

Parameters
typeDevice type to check (Cpu, Cuda, Metal, Rocm)
Returns
bool True if at least one device of this type is registered

◆ listDeviceIds()

std::vector< DeviceId > Mila::Dnn::Compute::DeviceRegistry::listDeviceIds ( ) const
inline

List registered DeviceId values.

Returns
std::vector<DeviceId> Vector of registered device identifiers

◆ listDeviceTypes()

std::vector< DeviceType > Mila::Dnn::Compute::DeviceRegistry::listDeviceTypes ( ) const
inline

List registered device types (unique).

Returns
std::vector<DeviceType> Vector of unique device types

◆ registerDevice()

void Mila::Dnn::Compute::DeviceRegistry::registerDevice ( DeviceId id,
DeviceFactory factory )
inline

Register a discovered DeviceId with factory callback.

Parameters
idDevice identifier to register
factoryFactory function to create the device instance
Exceptions
std::runtime_errorIf DeviceId is already registered

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