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.
Inherited Members
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 |
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
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
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
Clone()
Returns a deep copy of the internal storage.
Declaration
public ITensorData Clone()
Returns
Type | Description |
---|---|
ITensorData |
Implements
CompleteAllPendingOperations()
Blocking call to make sure that internal data is correctly written to and available for CPU read back.
Declaration
public void CompleteAllPendingOperations()
Implements
Dispose()
Disposes of the TextureTensorData
and any associated memory.
Declaration
public void Dispose()
Implements
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
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
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
ToString()
Returns a string that represents the TextureTensorData
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
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 |