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(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(TensorShape shape, int axis, bool clearOnInit = true)
    Parameters
    Type Name Description
    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

    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

    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 T[] Download<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    T[]
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Download<T>(Int32, Int32)

    Finalize()

    Finalizes the TextureTensorData.

    Declaration
    protected void Finalize()

    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 uploadCache = true)
    Parameters
    Type Name Description
    Tensor X
    Int32 blockAxis

    Which axis to block the tensor shape on.

    Boolean uploadCache

    Whether to also move the existing tensor data to the GPU. The default value is true.

    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)

    ScheduleAsyncDownload()

    Schedules asynchronous download of the internal data.

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

    ToString()

    Returns a string that represents the TextureTensorData.

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

    Upload<T>(T[], Int32, Int32)

    Uploads the tensor data to internal storage.

    Declaration
    public void Upload<T>(T[] data, int srcCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    T[] data
    Int32 srcCount
    Int32 srcOffset
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Upload<T>(T[], Int32, Int32)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • TextureTensorData(TensorShape, Int32, Boolean)
    • Properties
      • blockAxis
      • blockedShape
      • bufferAsTexture
      • deviceType
      • dimAxis
      • dimAxisDiv4
      • maxCapacity
      • shape
      • strideAxis
      • widthMask
      • widthShift
    • Methods
      • Dispose()
      • Download<T>(Int32, Int32)
      • Finalize()
      • Pin(Tensor, Int32, Boolean)
      • Reserve(Int32)
      • ScheduleAsyncDownload()
      • ToString()
      • Upload<T>(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