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 RGBA float4 texture.
Sentis chooses a single tensor dimension as the blocked axis, across which data is chunked in float4 blocks.
Tensor dimensions don't map directly to texture dimensions. Sentis creates the texture with dimensions large enough to fit all the data and pixel shaders index the data based on both the tensor and texture dimensions (see example below).
Inherited Members
Namespace: Unity.Sentis
Assembly: Unity.Sentis.dll
Syntax
public class TextureTensorData : ITensorData, IDisposable
Constructors
TextureTensorData(DataType, TensorShape, int, bool)
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 = false)
Parameters
Type | Name | Description |
---|---|---|
DataType | dataType | The data type of the tensor. |
TensorShape | shape | The (unblocked) shape of the tensor. |
int | axis | The axis on which to block the shape. |
bool | clearOnInit | Whether to zero the data on allocation. The default value is |
Properties
backendType
On what backend are the data elements stored.
Declaration
public BackendType backendType { get; }
Property Value
Type | Description |
---|---|
BackendType |
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 |
---|---|
int |
blockedAxisDiv4RemainderMask
A 4 int mask with 1 or 0 in each component to indicate whether the last blocked slice along the blocked axis has a valid entry or not. eg. if dimAxis % 4 = ceil(dimAxis/4)*4 - dimAxis = 3, blockedAxisDiv4RemainderMask = {1, 1, 1, 0};
Declaration
public int[] blockedAxisDiv4RemainderMask { get; }
Property Value
Type | Description |
---|---|
int[] |
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 |
dimAxis
The size of the blocked axis in the original tensor shape (when not blocked).
Declaration
public int dimAxis { get; }
Property Value
Type | Description |
---|---|
int |
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 |
---|---|
int |
maxCapacity
The maximum count of the stored data elements.
Declaration
public int maxCapacity { get; }
Property Value
Type | Description |
---|---|
int |
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 |
---|---|
int |
widthMask
Returns the width of the texture - 1 for efficient masking in shaders.
Declaration
public int widthMask { get; }
Property Value
Type | Description |
---|---|
int |
widthShift
Returns the power in the power of two width of the backing texture.
Declaration
public int widthShift { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Clone()
Returns a deep copy of the internal storage.
Declaration
public ITensorData Clone()
Returns
Type | Description |
---|---|
ITensorData | Cloned internal storage. |
CompleteAllPendingOperations()
Blocking call to make sure that internal data is correctly written to and available for CPU read back.
Declaration
public void CompleteAllPendingOperations()
Dispose()
Disposes of the TextureTensorData
and any associated memory.
Declaration
public void Dispose()
Download<T>(int, int)
Returns a contiguous block of data from internal storage.
Declaration
public NativeArray<T> Download<T>(int dstCount, int srcOffset = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | dstCount | The number of elements to download. |
int | srcOffset | The index of the first element in storage to download. |
Returns
Type | Description |
---|---|
NativeArray<T> | A native array of downloaded elements. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |
~TextureTensorData()
Finalizes the TextureTensorData
.
Declaration
protected ~TextureTensorData()
IsReadbackRequestDone()
Checks if asynchronous readback request is done.
Declaration
public bool IsReadbackRequestDone()
Returns
Type | Description |
---|---|
bool | Whether async readback is successful. |
Pin(Tensor, int, bool)
Moves the tensor into GPU memory on the GPUPixel
back end device.
Declaration
public static TextureTensorData Pin(Tensor X, int blockAxis, bool clearOnInit = false)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | The tensor to move to the compute backend. |
int | blockAxis | Which axis to block the tensor shape on. |
bool | clearOnInit | Whether to zero the data on pinning. The default value is |
Returns
Type | Description |
---|---|
TextureTensorData | The pinned |
ReadbackRequest(Action<bool>)
Schedules asynchronous readback of the internal data.
Declaration
public void ReadbackRequest(Action<bool> task = null)
Parameters
Type | Name | Description |
---|---|---|
Action<bool> | task |
ReadbackRequestAsync()
Schedules awaitable asynchronous readback of the internal data.
See AsyncReadbackRequest for more info
Declaration
public Task<bool> ReadbackRequestAsync()
Returns
Type | Description |
---|---|
Task<bool> | Whether awaitable task for when readback is successful. |
ToString()
Returns a string that represents the TextureTensorData
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The summary string of the |
Overrides
Upload<T>(NativeArray<T>, int, int)
Uploads a contiguous block of tensor data to internal storage.
Declaration
public void Upload<T>(NativeArray<T> data, int srcCount, int srcOffset = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | data | The data to upload. |
int | srcCount | The number of elements to upload. |
int | srcOffset | The index of the first data element to upload. |
Type Parameters
Name | Description |
---|---|
T | The type of data to upload. |