|
Mila 0.13.48
Deep Neural Network Library
|
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< Device > | getDevice (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< DeviceId > | listDeviceIds () const |
| List registered DeviceId values. | |
| std::vector< DeviceType > | listDeviceTypes () 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 () |
Private Member Functions | |
| DeviceRegistry ()=default | |
Private Attributes | |
| std::unordered_map< DeviceId, std::shared_ptr< Device > > | device_cache_ |
| std::unordered_map< DeviceId, DeviceFactory > | factories_ |
| std::mutex | mutex_ |
| std::vector< DeviceId > | registered_ids_ |
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.
| using Mila::Dnn::Compute::DeviceRegistry::DeviceFactory = std::function<std::shared_ptr<Device>( DeviceConstructionKey )> |
|
delete |


|
privatedefault |
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.
| id | Device identifier (e.g., Device::Cuda(0), Device::Cpu()) |
| std::runtime_error | If DeviceId is not registered or creation fails |

|
inlinenoexcept |
Return number of registered devices for the given DeviceType.
| device_type | Device type to count |
|
inlinenoexcept |
|
inline |
Check whether a specific DeviceType has been registered.
|
inlinestatic |


|
inline |
List registered DeviceId values.
|
inline |
List registered device types (unique).
|
delete |

|
inline |
|
mutableprivate |
|
private |
|
mutableprivate |
|
private |