docs.unity3d.com
    Show / Hide Table of Contents

    Class Tensor

    Represents data in a multidimensional array-like structure.

    Inheritance
    Object
    Tensor
    TensorFloat
    TensorInt
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Sentis
    Syntax
    public abstract class Tensor : IDisposable

    Constructors

    Tensor(TensorShape, ITensorData, ITensorAllocator)

    Create a Tensor with the specified shape, an ITensorData data and an ITensorAllocator allocator.

    Declaration
    protected Tensor(TensorShape shape, ITensorData data = null, ITensorAllocator allocator = null)
    Parameters
    Type Name Description
    TensorShape shape
    ITensorData data
    ITensorAllocator allocator

    Fields

    m_CacheIsDirty

    Declaration
    protected bool m_CacheIsDirty
    Field Value
    Type Description
    Boolean

    m_Disposed

    Declaration
    protected bool m_Disposed
    Field Value
    Type Description
    Boolean

    m_Shape

    Declaration
    protected TensorShape m_Shape
    Field Value
    Type Description
    TensorShape

    m_TensorAllocator

    Declaration
    protected ITensorAllocator m_TensorAllocator
    Field Value
    Type Description
    ITensorAllocator

    m_TensorOnDevice

    Declaration
    protected ITensorData m_TensorOnDevice
    Field Value
    Type Description
    ITensorData

    Properties

    allocator

    The allocator for the tensor. Refer to ITensorAllocator.

    Declaration
    public ITensorAllocator allocator { get; }
    Property Value
    Type Description
    ITensorAllocator

    dataType

    The data type of the elements of the tensor.

    Declaration
    public abstract DataType dataType { get; }
    Property Value
    Type Description
    DataType

    isCacheNull

    Declaration
    protected abstract bool isCacheNull { get; }
    Property Value
    Type Description
    Boolean

    shape

    The shape of the tensor, as a TensorShape.

    Declaration
    public TensorShape shape { get; protected set; }
    Property Value
    Type Description
    TensorShape

    tensorOnDevice

    The device-specific internal representation of the tensor data.

    Declaration
    public ITensorData tensorOnDevice { get; protected set; }
    Property Value
    Type Description
    ITensorData

    Methods

    AllocateOnDevice(ITensorData)

    Upload tensor values to the device, by associating the tensor with the uninitialized block of data on the device.

    You should allocate destination on the device. UploadToDevice overwrites the current contents of destination.

    Sentis doesn't copy or initialize content from the tensor, regardless of the current cache or data on the device.

    Declaration
    public void AllocateOnDevice(ITensorData destination)
    Parameters
    Type Name Description
    ITensorData destination

    AttachToDevice(ITensorData)

    Associates a tensor with the block of data on a device. Sentis downloads from source on first access.

    Make sure source contains initialized and valid data that represents tensor values.

    Refer to PrepareCacheForAccess() if you need to schedule the download as soon as possible.

    Declaration
    public void AttachToDevice(ITensorData source)
    Parameters
    Type Name Description
    ITensorData source

    ClearCache()

    Declaration
    protected abstract void ClearCache()

    DeepCopy()

    Returns a deep copy of the current Tensor.

    Declaration
    public abstract Tensor DeepCopy()
    Returns
    Type Description
    Tensor

    DetachFromDevice(Boolean)

    Synchronizes the tensor cache with the data on the device, then remove the tensor from the device.

    Declaration
    public ITensorData DetachFromDevice(bool disposeDeviceData = true)
    Parameters
    Type Name Description
    Boolean disposeDeviceData
    Returns
    Type Description
    ITensorData

    Dispose()

    Disposes of the tensor and any associated memory.

    Declaration
    public virtual void Dispose()
    Implements
    IDisposable.Dispose()

    Finalize()

    Dispose of the tensor and any associated memory.

    Declaration
    protected void Finalize()

    FlushCache(Boolean)

    Upload the tensor cache to device memory and delete the tensor cache.

    Declaration
    public void FlushCache(bool uploadCache)
    Parameters
    Type Name Description
    Boolean uploadCache

    PrepareCacheForAccess(Boolean)

    Read data from the device and write it to the cache.

    The default value of blocking is true, which means this method is a blocking read.

    When the value of blocking is false, the read is non-blocking. You can keep calling the method to get the status of the asynchronous download. You can access the tensor data when the method returns true.

    Declaration
    public abstract bool PrepareCacheForAccess(bool blocking = true)
    Parameters
    Type Name Description
    Boolean blocking
    Returns
    Type Description
    Boolean

    ShallowCopy()

    Returns a shallow copy of the current Tensor. The copy shares data storage with original tensor.

    Declaration
    public Tensor ShallowCopy()
    Returns
    Type Description
    Tensor

    ShallowReshape(TensorShape)

    Returns a shallow copy of the Tensor with a new shape. The copy shares data storage with the original tensor.

    newShape.length must be equal to this.shape.length.

    Declaration
    public abstract Tensor ShallowReshape(TensorShape newShape)
    Parameters
    Type Name Description
    TensorShape newShape
    Returns
    Type Description
    Tensor

    TakeOwnership()

    Removes system references to the tensor. The caller assumes ownership.

    Declaration
    public void TakeOwnership()

    ToString()

    Returns a string that represents the Tensor.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    UploadIfDirty()

    Declaration
    protected abstract void UploadIfDirty()

    UploadToDevice(ITensorData, Boolean)

    Upload tensor values to the device, by associating the tensor with the uninitialized block of data on the device.

    You should allocate destination on the device. UploadToDevice overwrites the current contents of destination.

    By default Sentis discards the local cache after you call this method. Set invalidateCacheAfterUpload to false to keep the cache.

    Declaration
    public void UploadToDevice(ITensorData destination, bool invalidateCacheAfterUpload = true)
    Parameters
    Type Name Description
    ITensorData destination
    Boolean invalidateCacheAfterUpload

    Extension Methods

    TensorExtensions.PrintDataPart(Tensor, Int32, String)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023