rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rexlib::device_manager Class Referencefinal

Centralize multiple device_backend sessions and route device queries to the appropriate one. More...

#include <rexlib/core/hardware/device_manager.hpp>

Inheritance diagram for rexlib::device_manager:
rexlib::service_manager

Public Member Functions

 device_manager (const device_manager &other)=delete
 
 device_manager (device_manager &&other) noexcept=delete
 
device_manager & operator= (const device_manager &other)=delete
 
device_manager & operator= (device_manager &&other)=delete
 
void register_builtin_backends () override
 Register backends bundled with the core library.
 
void enumerate_backends (std::vector< std::string > &names) const
 Enumerate the names of all registered backends.
 
device_backend * get_backend (const std::string &name) const
 Get a backend contained in this manager by its name.
 
bool register_backend (std::unique_ptr< device_backend > backend)
 Register a new backend.
 
void enumerate_devices (std::vector< device_index > &indices) const
 Enumerate devices across all registered backends.
 
bool get_device_properties (const device_index &index, device_properties &properties) const
 Query the properties of a device.
 
std::shared_ptr< device_session > create_device_session (const device_index &index) const
 Create a device session.
 
- Public Member Functions inherited from rexlib::service_manager
 service_manager (const service_manager &other)=delete
 
 service_manager (service_manager &&other)=delete
 
service_manager & operator= (const service_manager &other)=delete
 
service_manager & operator= (service_manager &&other)=delete
 

Detailed Description

Centralize multiple device_backend sessions and route device queries to the appropriate one.

The manager owns the registered backends and exposes a unified view of all devices known to the framework, identified across backends by device_index. Backends are typically contributed by plugins at load time via register_backend, with register_builtin_backends adding those that are statically linked.

Member Function Documentation

◆ create_device_session()

std::shared_ptr< device_session > rexlib::device_manager::create_device_session ( const device_index &  index) const

Create a device session.

Resolves the backend named by index, delegates the actual device instantiation to device_backend::create_device and queries its device_properties, then bundles both into a device_session (which also selects the default allocators for the device).

Instances are not cached: each call returns a freshly created device_session.

Parameters
[in]indexIndex identifying the target device.
Returns
std::shared_ptr<device_session> A non-null session.
Exceptions
std::invalid_argumentIf no backend is registered under the name carried by index, or if the backend does not recognize the device id. The backend may additionally throw if the device id is invalid.

◆ enumerate_backends()

void rexlib::device_manager::enumerate_backends ( std::vector< std::string > &  names) const

Enumerate the names of all registered backends.

Parameters
[out]namesOutput parameter with the names of the contained backends. Cleared before being populated.

◆ enumerate_devices()

void rexlib::device_manager::enumerate_devices ( std::vector< device_index > &  indices) const

Enumerate devices across all registered backends.

Asks every registered backend to enumerate its devices and aggregates the results into indices. The relative order of backends in the output is implementation defined; within a single backend the order matches whatever device_backend::enumerate_devices reports.

Parameters
[out]indicesOutput list of device indices. Cleared before being populated, so existing contents are discarded.

◆ get_backend()

device_backend * rexlib::device_manager::get_backend ( const std::string &  name) const

Get a backend contained in this manager by its name.

Parameters
nameThe name of the backend.
Returns
device_backend* The retrieved backend. nullptr if none is found.

◆ get_device_properties()

bool rexlib::device_manager::get_device_properties ( const device_index &  index,
device_properties &  properties 
) const

Query the properties of a device.

Looks up the backend named by index and forwards the query to device_backend::get_device_properties. Fails if the backend is not registered or if the backend itself does not recognize the device id.

Parameters
[in]indexIndex identifying the target device.
[out]propertiesOutput device properties. Only modified when the call succeeds.
Returns
true The device exists and properties has been written.
false The backend or device referenced by index does not exist; properties is left untouched.

◆ register_backend()

bool rexlib::device_manager::register_backend ( std::unique_ptr< device_backend >  backend)

Register a new backend.

Takes ownership of backend and keeps it alive for the rest of the manager's lifetime, indexed by the name it reports through device_backend::get_name. Registration fails if another backend with the same name is already registered or if backend is null; on failure, ownership of backend remains with the caller (the unique_ptr is not consumed) and the manager state is unchanged.

Parameters
[in]backendThe backend to be registered. Must be non-null for registration to succeed.
Returns
true The backend was successfully registered and is now owned by the manager.
false A name collision occurred or backend was null; the manager is left unchanged.

◆ register_builtin_backends()

void rexlib::device_manager::register_builtin_backends ( )
overridevirtual

Register backends bundled with the core library.

This usually loads fallback implementations that are always available although they may not be the most efficient or performant. The loaded backend(s) depend on the implementation of the specific interface.

Reimplemented from rexlib::service_manager.


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