libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
dl::Device Class Referenceabstract
Collaboration diagram for dl::Device:

Public Member Functions

virtual TensorPtr empty (Shape shape, bool requiresGrad=false) const noexcept=0
 Creates a new tensor of the specified shape without initializing the memory.
 
virtual TensorPtr zeros (Shape shape, bool requiresGrad=false) const noexcept=0
 Creates a new tensor of the specified shape. All entries are initialized to zero.
 
virtual TensorPtr ones (Shape shape, bool requiresGrad=false) const noexcept=0
 Creates a new tensor of the specified shape. All entries are initialized to one.
 
virtual TensorPtr rand (Shape shape, bool requiresGrad=false) const noexcept=0
 
virtual TensorPtr constant (int value, bool requiresGrad=false) const noexcept=0
 
virtual TensorPtr constant (float value, bool requiresGrad=false) const noexcept=0
 
virtual TensorPtr constant (double value, bool requiresGrad=false) const noexcept=0
 
virtual TensorPtr constant (InitializerTensor< float > &&value, bool requiresGrad=false) const noexcept=0
 
virtual TensorPtr fromBytesFP32 (const char *buffer, size_t bufsize, Shape shape) const noexcept=0
 
template<typename T >
void setDefaultFloatTensorType ()
 
template<>
void setDefaultFloatTensorType ()
 
template<>
void setDefaultFloatTensorType ()
 

Static Public Member Functions

static const DevicegetDefault () noexcept
 Returns the default device for this thread.
 
static auto changeDefaultDevice (Device &device)
 Temporarily modifies the default device.
 

Static Public Attributes

static Device const & cpu
 The CPU-device implementation.
 

Detailed Description

Definition at line 8 of file device.hpp.

Member Function Documentation

◆ changeDefaultDevice()

static auto dl::Device::changeDefaultDevice ( Device device)
inlinestatic

Temporarily modifies the default device.

Example call:

// mydevice is default.
}
// mydevice is not default anymore.
static auto changeDefaultDevice(Device &device)
Temporarily modifies the default device.
Definition device.hpp:93
Parameters
deviceThe device that should be default for the current scope.
Returns
A scopeguard for the default device.
See also
Device::getDefault()

Definition at line 93 of file device.hpp.

93 {
94 auto oldDefault = defaultDevice;
95 defaultDevice = &device;
96 return dl::utils::ScopeGuard([oldDefault] { Device::defaultDevice = oldDefault; });
97 }

◆ empty()

virtual TensorPtr dl::Device::empty ( Shape  shape,
bool  requiresGrad = false 
) const
pure virtualnoexcept

Creates a new tensor of the specified shape without initializing the memory.

Parameters
shapeThe shape of the tensor.
requiresGradTrue if a gradient should be calculate for the newly constructed tensor.
Returns
The newly created tensor.

◆ getDefault()

static const Device & dl::Device::getDefault ( )
inlinestaticnoexcept

Returns the default device for this thread.

The default device is thread local. That means that modifying the default device from another thread will not effect other threads.

Returns
The current default device.
See also
Device::changeDefaultDevice(Device&)

Definition at line 76 of file device.hpp.

76{ return *defaultDevice; }

◆ ones()

virtual TensorPtr dl::Device::ones ( Shape  shape,
bool  requiresGrad = false 
) const
pure virtualnoexcept

Creates a new tensor of the specified shape. All entries are initialized to one.

Parameters
shapeThe shape of the tensor.
requiresGradTrue if a gradient should be calculate for the newly constructed tensor.
Returns
The newly created tensor.

◆ zeros()

virtual TensorPtr dl::Device::zeros ( Shape  shape,
bool  requiresGrad = false 
) const
pure virtualnoexcept

Creates a new tensor of the specified shape. All entries are initialized to zero.

Parameters
shapeThe shape of the tensor.
requiresGradTrue if a gradient should be calculate for the newly constructed tensor.
Returns
The newly created tensor.

Member Data Documentation

◆ cpu

Device const& dl::Device::cpu
static

The CPU-device implementation.

Definition at line 32 of file device.hpp.


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