Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
c10::impl::DeviceGuardImplInterface Struct Referenceabstract

DeviceGuardImplInterface represents the virtual interface which provides functionality to provide an RAII class for device and stream switching, via DeviceGuard. More...

#include <DeviceGuardImplInterface.h>

Inheritance diagram for c10::impl::DeviceGuardImplInterface:
at::detail::CPUGuardImpl c10::cuda::impl::CUDAGuardImpl c10::hip::HIPGuardImplMasqueradingAsCUDA c10::impl::FakeGuardImpl< T > c10::impl::VirtualGuardImpl MSNPUGuardImpl

Public Member Functions

virtual DeviceType type () const =0
 Return the type of device managed by this guard implementation.
 
virtual Device exchangeDevice (Device) const =0
 Set the current device to Device, and return the previous Device.
 
virtual Device getDevice () const =0
 Get the current device.
 
virtual void setDevice (Device) const =0
 Set the current device to Device.
 
virtual void uncheckedSetDevice (Device) const noexcept=0
 Set the current device to Device, without checking for errors (so, e.g., this can be called from a destructor).
 
virtual Stream getStream (Device) const noexcept=0
 Get the current stream for a given device.
 
virtual Stream exchangeStream (Stream) const noexcept=0
 Set a stream to be the thread local current stream for its device. More...
 
virtual DeviceIndex deviceCount () const =0
 Get the number of devices.
 
virtual ~DeviceGuardImplInterface ()=default
 Intended use of this class is to leak the DeviceGuardImpl at program end. More...
 

Detailed Description

DeviceGuardImplInterface represents the virtual interface which provides functionality to provide an RAII class for device and stream switching, via DeviceGuard.

Every distinct device type, e.g., CUDA and HIP, is expected to implement and register an implementation of this interface. All classes which inherit from DeviceGuardImplInterface should be declared 'final'.

This class exists because we provide a unified interface for performing device guards via DeviceGuard, but we cannot assume that we have actually compiled against the, e.g., CUDA library, which actually implements this guard functionality. In this case, a dynamic dispatch is required to cross the library boundary.

If possible, you should directly use implementations of this interface; those uses will be devirtualized.

Definition at line 32 of file DeviceGuardImplInterface.h.

Constructor & Destructor Documentation

virtual c10::impl::DeviceGuardImplInterface::~DeviceGuardImplInterface ( )
virtualdefault

Intended use of this class is to leak the DeviceGuardImpl at program end.

So you better not call the destructor, buster!

Member Function Documentation

virtual Stream c10::impl::DeviceGuardImplInterface::exchangeStream ( Stream  ) const
pure virtualnoexcept

Set a stream to be the thread local current stream for its device.

Return the previous stream for that device. You are NOT required to set the current device to match the device of this stream.

Implemented in c10::hip::HIPGuardImplMasqueradingAsCUDA, c10::impl::FakeGuardImpl< T >, c10::cuda::impl::CUDAGuardImpl, c10::impl::VirtualGuardImpl, and at::detail::CPUGuardImpl.


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