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(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 |
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
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
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 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
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 |
Returns
Type | Description |
---|---|
TextureTensorData |
Reserve(Int32)
Reserves memory for count
elements.
Declaration
public void Reserve(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count |
Implements
ScheduleAsyncDownload()
Schedules asynchronous download of the internal data.
Declaration
public bool ScheduleAsyncDownload()
Returns
Type | Description |
---|---|
Boolean |
Implements
ToString()
Returns a string that represents the TextureTensorData
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
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 |