Devices#
2026-10-23
1 min read time
This page documents cuda::device_ref, cuda::devices and cuda::device_attributes, which describe and query the
HIP devices available in the system.
cuda::device_ref#
cuda::device_ref is a lightweight, non-owning handle to a HIP device ordinal. It allows to query
information about a device and serves as an argument to other runtime APIs which are tied to a specific device.
It offers:
get(): native device ordinalname(): device nameinit(): initialize the device context (a no-op in libhipcxx, the HIP runtime initializes devices implicitly)peers(): list peers for which peer access can be enabledhas_peer_access_to(cuda::device_ref): query if peer access can be enabled to the given deviceattribute(attr)/attribute<::hipDeviceAttribute_t>(): attribute queries
Availability: libhipcxx 3.4
cuda::devices#
cuda::devices is a random-access view of all available HIP devices in the form of
cuda::device_ref objects. It
provides indexing, size, and iteration for use
in range-based loops.
Availability: libhipcxx 3.4
Example:
#include <cuda/devices>
#include <iostream>
void print_devices() {
for (auto& dev : cuda::devices) {
std::cout << "Device " << dev.get() << ": " << dev.name() << '\n';
}
}
Device attributes#
cuda::device_attributes provides strongly-typed attribute query objects usable with
cuda::device_ref::attribute(). The attributes map to the corresponding hipDeviceAttribute_t values
queried with hipDeviceGetAttribute. Selected examples:
multiprocessor_countconcurrent_managed_accessclock_rate
Availability: libhipcxx 3.4
Example:
#include <cuda/devices>
int get_max_blocks_on_device(cuda::device_ref dev) {
return cuda::device_attributes::multiprocessor_count(dev) * cuda::device_attributes::max_blocks_per_multiprocessor(dev);
}