SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
Public Member Functions | Protected Attributes | Friends | List of all members
smaug::Tensor Class Reference

Tensor represents a single multi-dimensional array of data. More...

#include <tensor.h>

Inheritance diagram for smaug::Tensor:
smaug::TensorBase

Detailed Description

Tensor represents a single multi-dimensional array of data.

At construction time, the dataType of the Tensor is undetermined, and memory to store its data is not allocated. The dataType is set by a call to Tensor::allocateStorage() or Tensor::fillData<T>, where T is the type of the incoming data. Afterwards, the underlying data array can be accessed with Tensor::data<T> (which will check that T matches the expected data type and assert-fail if not) and indexed using TensorIndexIterator.

Definition at line 344 of file tensor.h.

Public Member Functions

 Tensor (const std::string &_name, const TensorShape &_shape)
 Construct a Tensor with the given name and shape.
 
 Tensor (const TensorProto &tensorProto, const TensorData &tensorData)
 Constructs a Tensor from serialized protobufs. More...
 
TensorIndexIterator startIndex () const
 Returns an iterator starting at the beginning of the Tensor.
 
virtual bool containsData () const
 
template<typename T >
void fillData (T *externalData, int size)
 Fills the Tensor with externalData. More...
 
template<typename T >
void fillData (std::initializer_list< T > externalData)
 Fills the Tensor byte-by-byte from the given initializer list.
 
template<typename T >
void fillData (const google::protobuf::RepeatedField< T > &externalData)
 Fills the Tensor byte-by-byte from a protobuf repeated field.
 
void fillHalfData (const google::protobuf::RepeatedField< int > &externalData)
 Fill the tensor with float16 data. More...
 
template<typename T >
T * allocateStorage ()
 Allocates memory to store Tensor data. More...
 
void allocateStorage (DataType _dataType)
 Allocates memory to store Tensor data. More...
 
TensorProto * asTensorProto ()
 Serializes this Tensor to a TensorProto.
 
template<typename T >
const T * data () const
 Returns a const pointer to the Tensor data.
 
template<typename T >
T * data ()
 Returns a non-const pointer to the Tensor data.
 
- Public Member Functions inherited from smaug::TensorBase
 TensorBase (const std::string &_name, const TensorShape &_shape)
 
 TensorBase (const TensorProto &tensorProto)
 
std::string getName () const
 
const TensorShapegetShape () const
 
int ndims () const
 
int dim (int index) const
 
int getTotalDim (int index) const
 
int getDataStorageFormat () const
 
DataType getDataType () const
 
int getDataTypeSize () const
 
bool isDead () const
 
void setDead (bool _dead=true)
 

Protected Attributes

std::shared_ptr< void > tensorData
 
- Protected Attributes inherited from smaug::TensorBase
std::string name
 Name of of the Tensor. More...
 
TensorShape shape
 Shape of the Tensor.
 
DataStorageFormat dataFormat
 Indicates the compression format of the data. More...
 
DataType dataType
 
bool dead
 If true, the tensor is dead, which means it is on an untaken control flow path. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Tensor &tensor)
 Prints the contents of the Tensor to the given ostream.
 

Constructor & Destructor Documentation

◆ Tensor()

smaug::Tensor::Tensor ( const TensorProto &  tensorProto,
const TensorData &  tensorData 
)
inline

Constructs a Tensor from serialized protobufs.

Parameters
tensorProtoBasic parameters of the Tensor.
tensorDataThe data contents of the Tensor.

Definition at line 359 of file tensor.h.

Member Function Documentation

◆ allocateStorage() [1/2]

template<typename T >
T* smaug::Tensor::allocateStorage ( )
inline

Allocates memory to store Tensor data.

Template Parameters
TThe type of data to store.

Definition at line 473 of file tensor.h.

◆ allocateStorage() [2/2]

void smaug::Tensor::allocateStorage ( DataType  _dataType)
inline

Allocates memory to store Tensor data.

Parameters
_dataTypeThe type of data to store.

Definition at line 489 of file tensor.h.

◆ fillData()

template<typename T >
void smaug::Tensor::fillData ( T *  externalData,
int  size 
)
inline

Fills the Tensor with externalData.

The contents of externalData are copied over byte by byte, without regard for padding zones.

Definition at line 400 of file tensor.h.

◆ fillHalfData()

void smaug::Tensor::fillHalfData ( const google::protobuf::RepeatedField< int > &  externalData)
inline

Fill the tensor with float16 data.

This special overload is required because the data stored in TensorProto packs two float16 into one int32.

Definition at line 452 of file tensor.h.


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