Class Device#
Defined in File device_struct.h
Class Documentation#
-
class Device#
A stable version of c10::Device.
Minimum compatible version: PyTorch 2.9.
Public Functions
-
inline Device(DeviceType type, DeviceIndex index = -1)#
Constructs a Device from a DeviceType and optional device index.
Minimum compatible version: PyTorch 2.9.
- Parameters:
type – The type of device (e.g., DeviceType::CPU, DeviceType::CUDA).
index – The device index. Default is -1 (current device).
-
inline bool operator==(const Device &other) const noexcept#
Checks if two devices are equal.
Minimum compatible version: PyTorch 2.9.
- Parameters:
other – The device to compare with.
- Returns:
true if both type and index match, false otherwise.
-
inline bool operator!=(const Device &other) const noexcept#
Checks if two devices are not equal.
Minimum compatible version: PyTorch 2.9.
- Parameters:
other – The device to compare with.
- Returns:
true if type or index differ, false otherwise.
-
inline void set_index(DeviceIndex index)#
Sets the device index.
Minimum compatible version: PyTorch 2.9.
- Parameters:
index – The new device index.
-
inline DeviceType type() const noexcept#
Returns the device type.
Minimum compatible version: PyTorch 2.9.
- Returns:
The DeviceType of this device.
-
inline DeviceIndex index() const noexcept#
Returns the device index.
Minimum compatible version: PyTorch 2.9.
- Returns:
The device index, or -1 if no specific index is set.
-
inline bool has_index() const noexcept#
Checks if this device has a specific index.
Minimum compatible version: PyTorch 2.9.
- Returns:
true if index is not -1, false otherwise.
-
inline bool is_cuda() const noexcept#
Checks if this is a CUDA device.
Minimum compatible version: PyTorch 2.9.
- Returns:
true if the device type is CUDA, false otherwise.
-
inline bool is_cpu() const noexcept#
Checks if this is a CPU device.
Minimum compatible version: PyTorch 2.9.
- Returns:
true if the device type is CPU, false otherwise.
-
inline Device(DeviceType type, DeviceIndex index = -1)#