|
Mila
Deep Neural Network Library
|
Registry for compute device creation and management. More...
Public Types | |
| using | DeviceFactory = std::function< std::shared_ptr< ComputeDevice >()> |
| Type alias for device factory functions. | |
Public Member Functions | |
| std::shared_ptr< ComputeDevice > | createDevice (const std::string &device_name) const |
| Creates a device instance by name. | |
| bool | hasDevice (const std::string &name) const |
| std::vector< std::string > | listDevices () const |
| Lists all registered device types. | |
| void | registerDevice (const std::string &name, DeviceFactory factory) |
| Registers a compute device factory function with the registry. | |
Static Public Member Functions | |
| static DeviceRegistry & | instance () |
| Gets the singleton instance of the DeviceRegistry. | |
Private Member Functions | |
| DeviceRegistry ()=default | |
| Private constructor for singleton pattern. | |
Private Attributes | |
| std::unordered_map< std::string, DeviceFactory > | devices_ |
| Map of device names to their factory functions. | |
| std::mutex | mutex_ |
| Mutex for thread-safe access to the devices map. | |
Registry for compute device creation and management.
This singleton class provides functionality to register, create, and enumerate compute device types. It serves as a central registry for all available compute devices in the system and provides thread-safe access to them.
| using Mila::Dnn::Compute::DeviceRegistry::DeviceFactory = std::function<std::shared_ptr<ComputeDevice>()> |
Type alias for device factory functions.
Functions of this type are used to create instances of specific compute devices.
|
privatedefault |
Private constructor for singleton pattern.
|
inline |
Creates a device instance by name.
| device_name | The name of the device to create. |

|
inline |
|
inlinestatic |
Gets the singleton instance of the DeviceRegistry.

|
inline |
Lists all registered device types.
| std::runtime_error | If the registry is not initialized. |
|
inline |
Registers a compute device factory function with the registry.
| name | The name identifier for the device type. |
| factory | Factory function that creates instances of the device. |
| std::invalid_argument | If the name is empty or the factory is null. |

|
private |
Map of device names to their factory functions.
|
mutableprivate |
Mutex for thread-safe access to the devices map.