Singleton class to manage GPU device context and initialization.
More...
#include <device.h>
Singleton class to manage GPU device context and initialization.
This class provides a centralized way to:
- Initialize GPU device binding (only once)
- Query GPU device state (device_id, device_count, etc.)
- Ensure thread-safe initialization
Usage: // Initialize (call once after MPI init and after determining device=gpu) DeviceContext::instance().init(MPI_COMM_WORLD);
// Query device info int dev_id = DeviceContext::instance().get_device_id();
◆ DeviceContext() [1/2]
| base_device::DeviceContext::DeviceContext |
( |
const DeviceContext & |
| ) |
|
|
delete |
◆ DeviceContext() [2/2]
| base_device::DeviceContext::DeviceContext |
( |
| ) |
|
|
privatedefault |
◆ ~DeviceContext()
| base_device::DeviceContext::~DeviceContext |
( |
| ) |
|
|
privatedefault |
◆ get_device_count()
| int base_device::DeviceContext::get_device_count |
( |
| ) |
const |
|
inline |
Get the total number of GPU devices on this node.
- Returns
- Number of GPU devices, or 0 if not initialized
◆ get_device_id()
| int base_device::DeviceContext::get_device_id |
( |
| ) |
const |
|
inline |
Get the bound GPU device ID.
- Returns
- Device ID (0-based), or -1 if not initialized
◆ get_local_rank()
| int base_device::DeviceContext::get_local_rank |
( |
| ) |
const |
|
inline |
Get the local MPI rank within the node.
- Returns
- Local rank, or 0 if not initialized
◆ init()
| void base_device::DeviceContext::init |
( |
| ) |
|
Initialize GPU device binding.
This function:
- Gets the local rank within the node using MPI_COMM_TYPE_SHARED (MPI_COMM_WORLD)
- Queries the number of available GPU devices
- Binds the current process to a GPU device (local_rank % device_count)
- Note
- This function should only be called once. Subsequent calls are no-ops.
-
This function should only be called when device=gpu is confirmed.
-
In MPI builds, uses MPI_COMM_WORLD internally.
◆ instance()
Get the singleton instance of DeviceContext.
- Returns
- Reference to the singleton instance
◆ operator=()
◆ device_count_
| int base_device::DeviceContext::device_count_ = 0 |
|
private |
◆ device_id_
| int base_device::DeviceContext::device_id_ = -1 |
|
private |
◆ gpu_enabled_
| bool base_device::DeviceContext::gpu_enabled_ = false |
|
private |
◆ init_mutex_
| std::mutex base_device::DeviceContext::init_mutex_ |
|
private |
◆ initialized_
| bool base_device::DeviceContext::initialized_ = false |
|
private |
◆ local_rank_
| int base_device::DeviceContext::local_rank_ = 0 |
|
private |
The documentation for this class was generated from the following files:
- /home/runner/work/abacus-develop/abacus-develop/source/source_base/module_device/device.h
- /home/runner/work/abacus-develop/abacus-develop/source/source_base/module_device/device.cpp