Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions | Static Public Member Functions | Friends
c10::UndefinedTensorImpl Struct Referencefinal
Inheritance diagram for c10::UndefinedTensorImpl:
c10::TensorImpl c10::intrusive_ptr_target

Public Member Functions

IntArrayRef sizes () const override
 Return a reference to the sizes of this tensor. More...
 
IntArrayRef strides () const override
 Return a reference to the strides of this tensor. More...
 
int64_t size (int64_t d) const override
 Return the size of a tensor at some dimension.
 
int64_t stride (int64_t d) const override
 Return the stride of a tensor at some dimension.
 
int64_t dim () const override
 Return the number of dimensions of this tensor. More...
 
bool has_storage () const override
 True if this tensor has storage. More...
 
const Storagestorage () const override
 Return the underlying storage of a Tensor. More...
 
int64_t storage_offset () const override
 Return the offset in number of elements into the storage that this tensor points to. More...
 
- Public Member Functions inherited from c10::TensorImpl
 TensorImpl (TensorTypeId type_id, const caffe2::TypeMeta &data_type, Allocator *allocator, bool is_variable)
 Construct a 1-dim 0-size tensor with the given settings. More...
 
 TensorImpl (Storage &&storage, TensorTypeId type_id, bool is_variable)
 Construct a 1-dim 0-size tensor backed by the given storage.
 
 TensorImpl (const TensorImpl &)=delete
 
TensorImploperator= (const TensorImpl &)=delete
 
 TensorImpl (TensorImpl &&)=default
 
TensorImploperator= (TensorImpl &&)=default
 
virtual void release_resources () override
 Release (decref) storage, and any other external allocations. More...
 
TensorTypeId type_id () const
 Return the TensorTypeId corresponding to this Tensor. More...
 
virtual int64_t numel () const
 The number of elements in a tensor. More...
 
virtual bool is_contiguous () const
 Whether or not a tensor is laid out in contiguous memory. More...
 
bool is_sparse () const
 
bool is_cuda () const
 
bool is_hip () const
 
int64_t get_device () const
 
Device device () const
 
Layout layout () const
 
virtual TensorImplmaybe_zero_dim (bool condition_when_zero_dim)
 If condition_when_zero_dim is true, and the tensor is a 1-dim, 1-size tensor, reshape the tensor into a 0-dim tensor (scalar). More...
 
bool is_wrapped_number () const
 True if a tensor was auto-wrapped from a C++ or Python number. More...
 
void set_wrapped_number (bool value)
 Set whether or not a tensor was auto-wrapped from a C++ or Python number. More...
 
void set_requires_grad (bool requires_grad)
 Set whether or not a tensor requires gradient. More...
 
bool requires_grad () const
 True if a tensor requires gradient. More...
 
at::Tensorgrad ()
 Return a mutable reference to the gradient. More...
 
const at::Tensorgrad () const
 Return the accumulated gradient of a tensor. More...
 
template<typename T >
Tdata () const
 Return a typed data pointer to the actual data which this tensor refers to. More...
 
void * data () const
 Return a void* data pointer to the actual data which this tensor refers to. More...
 
virtual void * slow_data () const
 This is just like data(), except it works with Variables. More...
 
template<typename T >
Tunsafe_data () const
 Like data<T>(), but performs no checks. More...
 
const caffe2::TypeMetadtype () const
 Returns the TypeMeta of a tensor, which describes what data type it is (e.g., int, float, ...)
 
size_t itemsize () const
 Return the size of a single element of this tensor in bytes.
 
bool is_empty () const
 True if a tensor has no elements (e.g., numel() == 0).
 
virtual void resize_dim (int64_t ndim)
 Change the dimensionality of a tensor. More...
 
virtual void set_size (int64_t dim, int64_t new_size)
 Change the size at some dimension. More...
 
virtual void set_stride (int64_t dim, int64_t new_stride)
 Change the stride at some dimension. More...
 
virtual void set_storage_offset (int64_t storage_offset)
 Set the offset into the storage of this tensor. More...
 
void set_sizes_contiguous (IntArrayRef new_size)
 Like set_sizes_and_strides but assumes contiguous strides. More...
 
void set_sizes_and_strides (IntArrayRef new_size, IntArrayRef new_stride)
 Set the sizes and strides of a tensor. More...
 
bool is_variable () const
 True if a tensor is a variable. More...
 
virtual void set_allow_tensor_metadata_change (bool value)
 Set whether a tensor allows changes to its metadata (e.g. More...
 
virtual bool allow_tensor_metadata_change () const
 True if a tensor allows changes to its metadata (e.g. More...
 
void set_autograd_meta (std::unique_ptr< c10::AutogradMetaInterface > autograd_meta)
 Set the pointer to autograd metadata.
 
c10::AutogradMetaInterfaceautograd_meta () const
 Return the pointer to autograd metadata.
 
std::unique_ptr< c10::AutogradMetaInterfacedetach_autograd_meta ()
 Detach the autograd metadata unique_ptr from this tensor, and return it.
 
virtual c10::intrusive_ptr< TensorImplshallow_copy_and_detach () const
 
DeviceType device_type () const
 The device type of a Tensor, e.g., DeviceType::CPU or DeviceType::CUDA.
 
Device GetDevice () const
 The device of a Tensor; e.g., Device(kCUDA, 1) (the 1-index CUDA device).
 
void Extend (int64_t num, float growthPct)
 Extends the outer-most dimension of this tensor by num elements, preserving the existing data. More...
 
template<class T >
void ReserveSpace (const T &outer_dim)
 Reserve space for the underlying tensor. More...
 
template<typename... Ts>
void Resize (Ts...dim_source)
 Resizes a tensor. More...
 
void Reshape (const std::vector< int64_t > &dims)
 Resizes the tensor without touching underlying storage. More...
 
void FreeMemory ()
 Release whatever memory the tensor was holding but keep size and type information. More...
 
void ShareData (const TensorImpl &src)
 Shares the data with another tensor. More...
 
void ShareExternalPointer (DataPtr &&data_ptr, const caffe2::TypeMeta &data_type, size_t capacity)
 
void * raw_mutable_data (const caffe2::TypeMeta &meta)
 Returns a mutable raw pointer of the underlying storage. More...
 
template<typename T >
Tmutable_data ()
 Returns a typed pointer of the underlying storage. More...
 
bool storage_initialized () const noexcept
 True if a tensor is storage initialized. More...
 
bool dtype_initialized () const noexcept
 True if a tensor is dtype initialized. More...
 
void set_storage (at::Storage storage)
 

Static Public Member Functions

static constexpr TensorImplsingleton ()
 

Friends

struct UndefinedType
 

Additional Inherited Members

- Protected Member Functions inherited from c10::TensorImpl
void refresh_numel ()
 Recompute the cached numel of a tensor. More...
 
void refresh_contiguous ()
 Recompute the cached contiguity of a tensor. More...
 
- Protected Member Functions inherited from c10::intrusive_ptr_target
 intrusive_ptr_target (intrusive_ptr_target &&other) noexcept
 
intrusive_ptr_targetoperator= (intrusive_ptr_target &&other) noexcept
 
 intrusive_ptr_target (const intrusive_ptr_target &other) noexcept
 
intrusive_ptr_targetoperator= (const intrusive_ptr_target &other) noexcept
 
- Protected Attributes inherited from c10::TensorImpl
Storage storage_
 
std::unique_ptr< c10::AutogradMetaInterfaceautograd_meta_ = nullptr
 
SmallVector< int64_t, 5 > sizes_
 
SmallVector< int64_t, 5 > strides_
 
int64_t storage_offset_ = 0
 
int64_t numel_ = 1
 
caffe2::TypeMeta data_type_
 
TensorTypeId type_id_
 
bool is_contiguous_ = true
 
bool is_variable_ = false
 
bool is_wrapped_number_ = false
 
bool allow_tensor_metadata_change_ = true
 
bool reserved_ = false
 

Detailed Description

Definition at line 7 of file UndefinedTensorImpl.h.

Member Function Documentation

int64_t c10::UndefinedTensorImpl::dim ( ) const
overridevirtual

Return the number of dimensions of this tensor.

Note that 0-dimension represents a Tensor that is a Scalar, e.g., one that has a single element.

Reimplemented from c10::TensorImpl.

Definition at line 23 of file UndefinedTensorImpl.cpp.

bool c10::UndefinedTensorImpl::has_storage ( ) const
overridevirtual

True if this tensor has storage.

See storage() for details.

Reimplemented from c10::TensorImpl.

Definition at line 27 of file UndefinedTensorImpl.cpp.

IntArrayRef c10::UndefinedTensorImpl::sizes ( ) const
overridevirtual

Return a reference to the sizes of this tensor.

This reference remains valid as long as the tensor is live and not resized.

Reimplemented from c10::TensorImpl.

Definition at line 11 of file UndefinedTensorImpl.cpp.

const Storage & c10::UndefinedTensorImpl::storage ( ) const
overridevirtual

Return the underlying storage of a Tensor.

Multiple tensors may share a single storage. A Storage is an impoverished, Tensor-like class which supports far less operations than Tensor.

Avoid using this method if possible; try to use only Tensor APIs to perform operations.

Reimplemented from c10::TensorImpl.

Definition at line 31 of file UndefinedTensorImpl.cpp.

int64_t c10::UndefinedTensorImpl::storage_offset ( ) const
overridevirtual

Return the offset in number of elements into the storage that this tensor points to.

Most tensors have storage_offset() == 0, but, for example, an index into a tensor will have a non-zero storage_offset().

WARNING: This is NOT computed in bytes.

XXX: The only thing stopping this function from being virtual is Variable.

Reimplemented from c10::TensorImpl.

Definition at line 35 of file UndefinedTensorImpl.cpp.

IntArrayRef c10::UndefinedTensorImpl::strides ( ) const
overridevirtual

Return a reference to the strides of this tensor.

This reference remains valid as long as the tensor is live and not restrided.

Reimplemented from c10::TensorImpl.

Definition at line 39 of file UndefinedTensorImpl.cpp.


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