PyTorch
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
c10::Device Struct Referencefinal

Represents a a compute device on which a tensor is located. More...

#include <Device.h>

Public Types

using Type = DeviceType
 

Public Member Functions

 Device (DeviceType type, DeviceIndex index=-1)
 Constructs a new Device from a DeviceType and an optional device index. More...
 
 Device (const std::string &device_string)
 Constructs a Device from a string description, for convenience. More...
 
bool operator== (const Device &other) const noexcept
 Returns true if the type and index of this Device matches that of other. More...
 
bool operator!= (const Device &other) const noexcept
 Returns true if the type or index of this Device differs from that of other. More...
 
void set_index (DeviceIndex index)
 Sets the device index. More...
 
DeviceType type () const noexcept
 Returns the type of device this is. More...
 
DeviceIndex index () const noexcept
 Returns the optional index. More...
 
bool has_index () const noexcept
 Returns true if the device has a non-default index. More...
 
bool is_cuda () const noexcept
 Return true if the device is of CUDA type. More...
 
bool is_mps () const noexcept
 Return true if the device is of MPS type. More...
 
bool is_hip () const noexcept
 Return true if the device is of HIP type. More...
 
bool is_ve () const noexcept
 Return true if the device is of VE type. More...
 
bool is_xpu () const noexcept
 Return true if the device is of XPU type. More...
 
bool is_ipu () const noexcept
 Return true if the device is of IPU type. More...
 
bool is_xla () const noexcept
 Return true if the device is of XLA type. More...
 
bool is_hpu () const noexcept
 Return true if the device is of HPU type. More...
 
bool is_lazy () const noexcept
 Return true if the device is of Lazy type. More...
 
bool is_vulkan () const noexcept
 Return true if the device is of Vulkan type. More...
 
bool is_metal () const noexcept
 Return true if the device is of Metal type. More...
 
bool is_ort () const noexcept
 Return true if the device is of ORT type. More...
 
bool is_meta () const noexcept
 Return true if the device is of META type. More...
 
bool is_cpu () const noexcept
 Return true if the device is of CPU type. More...
 
bool supports_as_strided () const noexcept
 Return true if the device supports arbirtary strides. More...
 
std::string str () const
 Same string as returned from operator<<. More...
 

Detailed Description

Represents a a compute device on which a tensor is located.

A device is uniquely identified by a type, which specifies the type of machine it is (e.g. CPU or CUDA GPU), and a device index or ordinal, which identifies the specific compute device when there is more than one of a certain type. The device index is optional, and in its defaulted state represents (abstractly) "the current device". Further, there are two constraints on the value of the device index, if one is explicitly stored:

  1. A negative index represents the current device, a non-negative index represents a specific, concrete device,
  2. When the device type is CPU, the device index must be zero.

Member Typedef Documentation

◆ Type

Constructor & Destructor Documentation

◆ Device() [1/2]

c10::Device::Device ( DeviceType  type,
DeviceIndex  index = -1 
)
inline

Constructs a new Device from a DeviceType and an optional device index.

◆ Device() [2/2]

c10::Device::Device ( const std::string &  device_string)

Constructs a Device from a string description, for convenience.

The string supplied must follow the following schema: (cpu|cuda)[:<device-index>] where cpu or cuda specifies the device type, and :<device-index> optionally specifies a device index.

Member Function Documentation

◆ has_index()

bool c10::Device::has_index ( ) const
inlinenoexcept

Returns true if the device has a non-default index.

◆ index()

DeviceIndex c10::Device::index ( ) const
inlinenoexcept

Returns the optional index.

◆ is_cpu()

bool c10::Device::is_cpu ( ) const
inlinenoexcept

Return true if the device is of CPU type.

◆ is_cuda()

bool c10::Device::is_cuda ( ) const
inlinenoexcept

Return true if the device is of CUDA type.

◆ is_hip()

bool c10::Device::is_hip ( ) const
inlinenoexcept

Return true if the device is of HIP type.

◆ is_hpu()

bool c10::Device::is_hpu ( ) const
inlinenoexcept

Return true if the device is of HPU type.

◆ is_ipu()

bool c10::Device::is_ipu ( ) const
inlinenoexcept

Return true if the device is of IPU type.

◆ is_lazy()

bool c10::Device::is_lazy ( ) const
inlinenoexcept

Return true if the device is of Lazy type.

◆ is_meta()

bool c10::Device::is_meta ( ) const
inlinenoexcept

Return true if the device is of META type.

◆ is_metal()

bool c10::Device::is_metal ( ) const
inlinenoexcept

Return true if the device is of Metal type.

◆ is_mps()

bool c10::Device::is_mps ( ) const
inlinenoexcept

Return true if the device is of MPS type.

◆ is_ort()

bool c10::Device::is_ort ( ) const
inlinenoexcept

Return true if the device is of ORT type.

◆ is_ve()

bool c10::Device::is_ve ( ) const
inlinenoexcept

Return true if the device is of VE type.

◆ is_vulkan()

bool c10::Device::is_vulkan ( ) const
inlinenoexcept

Return true if the device is of Vulkan type.

◆ is_xla()

bool c10::Device::is_xla ( ) const
inlinenoexcept

Return true if the device is of XLA type.

◆ is_xpu()

bool c10::Device::is_xpu ( ) const
inlinenoexcept

Return true if the device is of XPU type.

◆ operator!=()

bool c10::Device::operator!= ( const Device other) const
inlinenoexcept

Returns true if the type or index of this Device differs from that of other.

◆ operator==()

bool c10::Device::operator== ( const Device other) const
inlinenoexcept

Returns true if the type and index of this Device matches that of other.

◆ set_index()

void c10::Device::set_index ( DeviceIndex  index)
inline

Sets the device index.

◆ str()

std::string c10::Device::str ( ) const

Same string as returned from operator<<.

◆ supports_as_strided()

bool c10::Device::supports_as_strided ( ) const
inlinenoexcept

Return true if the device supports arbirtary strides.

◆ type()

DeviceType c10::Device::type ( ) const
inlinenoexcept

Returns the type of device this is.


The documentation for this struct was generated from the following file: