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

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< ComputeDevicecreateDevice (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 DeviceRegistryinstance ()
 Gets the singleton instance of the DeviceRegistry.
 

Private Member Functions

 DeviceRegistry ()=default
 Private constructor for singleton pattern.
 

Private Attributes

std::unordered_map< std::string, DeviceFactorydevices_
 Map of device names to their factory functions.
 
std::mutex mutex_
 Mutex for thread-safe access to the devices map.
 

Detailed Description

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.

Member Typedef Documentation

◆ DeviceFactory

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.

Constructor & Destructor Documentation

◆ DeviceRegistry()

Mila::Dnn::Compute::DeviceRegistry::DeviceRegistry ( )
privatedefault

Private constructor for singleton pattern.

Member Function Documentation

◆ createDevice()

std::shared_ptr< ComputeDevice > Mila::Dnn::Compute::DeviceRegistry::createDevice ( const std::string &  device_name) const
inline

Creates a device instance by name.

Parameters
device_nameThe name of the device to create.
Returns
std::shared_ptr<ComputeDevice> The created device, or nullptr if the device name is invalid.
Here is the caller graph for this function:

◆ hasDevice()

bool Mila::Dnn::Compute::DeviceRegistry::hasDevice ( const std::string &  name) const
inline

◆ instance()

static DeviceRegistry & Mila::Dnn::Compute::DeviceRegistry::instance ( )
inlinestatic

Gets the singleton instance of the DeviceRegistry.

Returns
DeviceRegistry& Reference to the singleton instance.
Here is the caller graph for this function:

◆ listDevices()

std::vector< std::string > Mila::Dnn::Compute::DeviceRegistry::listDevices ( ) const
inline

Lists all registered device types.

Returns
std::vector<std::string> Vector of registered device type names.
Exceptions
std::runtime_errorIf the registry is not initialized.

◆ registerDevice()

void Mila::Dnn::Compute::DeviceRegistry::registerDevice ( const std::string &  name,
DeviceFactory  factory 
)
inline

Registers a compute device factory function with the registry.

Parameters
nameThe name identifier for the device type.
factoryFactory function that creates instances of the device.
Exceptions
std::invalid_argumentIf the name is empty or the factory is null.
Here is the caller graph for this function:

Member Data Documentation

◆ devices_

std::unordered_map<std::string, DeviceFactory> Mila::Dnn::Compute::DeviceRegistry::devices_
private

Map of device names to their factory functions.

◆ mutex_

std::mutex Mila::Dnn::Compute::DeviceRegistry::mutex_
mutableprivate

Mutex for thread-safe access to the devices map.


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