Skip to main content

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::kCPU

At 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() const

The 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
) const

Move a tensor to the active device.

Returns the tensor unchanged if it is already on the correct device.

function DeviceManager

DeviceManager(
    DeviceManager const & 
) =delete

function operator=

DeviceManager & operator=(
    DeviceManager const & 
) =delete

function DeviceManager

DeviceManager(
    DeviceManager && 
) =delete

function operator=

DeviceManager & operator=(
    DeviceManager && 
) =delete

Updated on 2026-11-13 at 20:25:42 +0000