device_ref#

class device_ref#

A non-owning representation of a CUDA device.

Public Functions

inline constexpr device_ref(int __id) noexcept#

Create a device_ref object from a native device ordinal.

inline constexpr int get() const noexcept#

Retrieve the native ordinal of the device_ref

Returns:

int The native device ordinal held by the device_ref object

template<typename _Attr>
inline auto attribute(_Attr __attr) const#

Retrieve the specified attribute for the device.

See also

device::attrs

Parameters:

__attr – The attribute to query. See device::attrs for the available attributes.

Throws:

cuda_error – if the attribute query fails

template<::cudaDeviceAttr _Attr>
inline auto attribute() const#

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline operator memory_location() const noexcept#

Retrieve the memory location of this device.

Returns:

The memory location of this device

inline void init() const#

Initializes the primary context of the device.

inline ::cuda::std::string_view name() const#

Retrieve the name of this device.

Returns:

String view containing the name of this device.

inline bool has_peer_access_to(device_ref __other_dev) const#

Queries if its possible for this device to directly access specified device’s memory.

If this function returns true, device supplied to this call can be passed into enable_peer_access on memory resource or pool that manages memory on this device. It will make allocations from that pool accessible by this device.

Parameters:

__other_dev – Device to query the peer access

Returns:

true if its possible for this device to access the specified device’s memory

inline ::cuda::std::span<const device_ref> peers() const#

Retrieve device_refs that are peers of this device.

The device on which this API is called is not included in the vector.

Throws:

cuda_error – if any peer access query fails

Friends

inline friend constexpr bool operator==(
device_ref __lhs,
device_ref __rhs,
) noexcept#

Compares two device_refs for equality.

Note

Allows comparison with int due to implicit conversion to device_ref.

Parameters:
Returns:

true if lhs and rhs refer to the same device ordinal