docs.unity3d.com
    Show / Hide Table of Contents

    Class TextureTensorData

    Represents the data storage for a Tensor as a render texture, for backends that use GPU pixel shaders.

    Sentis packs the tensor data into the pixels of an ARGB float4 texture.

    Sentis chooses a single tensor dimension as the blocked axis, across which data is chunked in float4 blocks.

    Texture dimensions don't map directly to tensor dimensions. Sentis creates the texture with dimensions large enough for the data, and pixel shaders index the data based on both the tensor and texture dimensions.

    Inheritance
    Object
    TextureTensorData
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Sentis
    Syntax
    public class TextureTensorData : ITensorData, IDisposable

    Constructors

    TextureTensorData(DataType, TensorShape, Int32, Boolean)

    Initializes and returns an instance of TextureTensorData with given shape and blocked axis. A RenderTexture is allocated to the correct size.

    Declaration
    public TextureTensorData(DataType dataType, TensorShape shape, int axis, bool clearOnInit = true)
    Parameters
    Type Name Description
    DataType dataType

    The data type of the tensor.

    TensorShape shape

    The (unblocked) shape of the tensor.

    Int32 axis

    The axis on which to block the shape.

    Boolean clearOnInit

    Whether to zero the data on allocation. The default value is true.

    Properties

    blockAxis

    Returns the axis of the tensor which is blocked.

    It is possible to block on negative axes by considering a tensor of shape (d0, d1 ... dn) as one of shape (1, 1, .... 1, d0, d1 ... dn).

    Thus negative axis values do not count from the back of the shape as elsewhere.

    Declaration
    public int blockAxis { get; }
    Property Value
    Type Description
    Int32

    blockedShape

    Returns the shape of the tensor with the blocked axis divided by 4.

    Declaration
    public TensorShape blockedShape { get; }
    Property Value
    Type Description
    TensorShape

    bufferAsTexture

    Returns the backing texture storing the tensor data.

    Declaration
    public RenderTexture bufferAsTexture { get; }
    Property Value
    Type Description
    RenderTexture

    dataType

    Returns the data type of the associated tensor.

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

    deviceType

    On what device backend are the data elements stored.

    Declaration
    public DeviceType deviceType { get; }
    Property Value
    Type Description
    DeviceType
    Implements
    ITensorData.deviceType

    dimAxis

    The size of the blocked axis in the original tensor shape (when not blocked).

    Declaration
    public int dimAxis { get; }
    Property Value
    Type Description
    Int32

    dimAxisDiv4

    The size of the blocked axis in the blocked tensor shape, i.e. dimAxisDiv4 = ceil(dimAxis / 4).

    Declaration
    public int dimAxisDiv4 { get; }
    Property Value
    Type Description
    Int32

    maxCapacity

    The maximum count of the stored data elements.

    Declaration
    public int maxCapacity { get; }
    Property Value
    Type Description
    Int32
    Implements
    ITensorData.maxCapacity

    shape

    Returns the shape of the associated tensor.

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

    strideAxis

    The size of the stride of the blocked axis.

    Declaration
    public int strideAxis { get; }
    Property Value
    Type Description
    Int32

    widthMask

    Returns the width of the texture - 1 for efficient masking in shaders.

    Declaration
    public int widthMask { get; }
    Property Value
    Type Description
    Int32

    widthShift

    Returns the power in the power of two width of the backing texture.

    Declaration
    public int widthShift { get; }
    Property Value
    Type Description
    Int32

    Methods

    AsyncReadbackRequest(Action<Boolean>)

    Schedules asynchronous readback of the internal data.

    Invokes callback when async readback is finished.

    Boolean indicates if async readback is successful.

    Declaration
    public void AsyncReadbackRequest(Action<bool> task = null)
    Parameters
    Type Name Description
    Action<Boolean> task
    Implements
    ITensorData.AsyncReadbackRequest(Action<Boolean>)

    Clone()

    Returns a deep copy of the internal storage.

    Declaration
    public ITensorData Clone()
    Returns
    Type Description
    ITensorData
    Implements
    ITensorData.Clone()

    CompleteAllPendingOperations()

    Blocking call to make sure that internal data is correctly written to and available for CPU read back.

    Declaration
    public void CompleteAllPendingOperations()
    Implements
    ITensorData.CompleteAllPendingOperations()

    Dispose()

    Disposes of the TextureTensorData and any associated memory.

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

    Download<T>(Int32, Int32)

    Returns data from internal storage.

    Declaration
    public NativeArray<T> Download<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    NativeArray<T>
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Download<T>(Int32, Int32)

    Finalize()

    Finalizes the TextureTensorData.

    Declaration
    protected void Finalize()

    IsAsyncReadbackRequestDone()

    Checks if asynchronous readback request it done.

    Returns true if async readback is successful.

    Declaration
    public bool IsAsyncReadbackRequestDone()
    Returns
    Type Description
    Boolean
    Implements
    ITensorData.IsAsyncReadbackRequestDone()

    Pin(Tensor, Int32, Boolean)

    Moves the tensor into GPU memory on the GPUPixel back end device.

    Declaration
    public static TextureTensorData Pin(Tensor X, int blockAxis, bool clearOnInit = true)
    Parameters
    Type Name Description
    Tensor X
    Int32 blockAxis

    Which axis to block the tensor shape on.

    Boolean clearOnInit
    Returns
    Type Description
    TextureTensorData

    Reserve(Int32)

    Reserves memory for count elements.

    Declaration
    public void Reserve(int count)
    Parameters
    Type Name Description
    Int32 count
    Implements
    ITensorData.Reserve(Int32)

    ToString()

    Returns a string that represents the TextureTensorData.

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

    Upload<T>(NativeArray<T>, Int32, Int32)

    Uploads the tensor data to internal storage.

    Declaration
    public void Upload<T>(NativeArray<T> data, int srcCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    NativeArray<T> data
    Int32 srcCount
    Int32 srcOffset
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Upload<T>(NativeArray<T>, Int32, Int32)
    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