dl::DeviceManager
dl::DeviceManager
Centralized, lazily-initialized device context for all deep-learning model wrappers and inference code. More…
#include <DeviceManager.hpp>
Public Functions
| Name | |
|---|---|
| DeviceManager & | instance() Get the singleton instance (thread-safe via Meyers’ singleton). |
| bool | cudaAvailable() Whether CUDA is available on this system. |
| at::Device | device() const The active device. Determined once at first access. |
| void | setDevice(at::Device dev) Force a specific device (useful for testing or user preference). |
| at::Tensor | toDevice(at::Tensor tensor) const Move a tensor to the active device. |
| DeviceManager(DeviceManager const & ) =delete | |
| DeviceManager & | operator=(DeviceManager const & ) =delete |
| DeviceManager(DeviceManager && ) =delete | |
| DeviceManager & | operator=(DeviceManager && ) =delete |
Detailed Description
class dl::DeviceManager;Centralized, lazily-initialized device context for all deep-learning model wrappers and inference code.
Usage:
auto & dm = dl::DeviceManager::instance();
auto tensor_on_device = dm.toDevice(cpu_tensor);
auto dev = dm.device(); // torch::kCUDA or torch::kCPUAt first access, auto-detects CUDA availability and selects GPU if present. Call [setDevice()](/api_generated/Classes/classdl_1_1DeviceManager.md#function-setdevice) to override (e.g. for testing or user preference).
Public Functions Documentation
function instance
static DeviceManager & instance()Get the singleton instance (thread-safe via Meyers’ singleton).
function cudaAvailable
static bool cudaAvailable()Whether CUDA is available on this system.
function device
at::Device device() constThe active device. Determined once at first access.
CUDA if available, else CPU.
function setDevice
void setDevice(
at::Device dev
)Force a specific device (useful for testing or user preference).
function toDevice
at::Tensor toDevice(
at::Tensor tensor
) constMove a tensor to the active device.
Returns the tensor unchanged if it is already on the correct device.
function DeviceManager
DeviceManager(
DeviceManager const &
) =deletefunction operator=
DeviceManager & operator=(
DeviceManager const &
) =deletefunction DeviceManager
DeviceManager(
DeviceManager &&
) =deletefunction operator=
DeviceManager & operator=(
DeviceManager &&
) =deleteUpdated on 2026-11-13 at 20:25:42 +0000