Class BurstTensorData
Represents Burst-specific internal data storage for a Tensor
.
Implements
Inherited Members
Namespace: Unity.Sentis
Assembly: Unity.Sentis.dll
Syntax
public class BurstTensorData : ITensorData, IDisposable, IDependableMemoryResource, IConvertibleToComputeTensorData, IReadableTensorData
Constructors
BurstTensorData(int, bool)
Initializes and returns an instance of BurstTensorData
, and allocates storage for a tensor with the shape of shape
.
Declaration
public BurstTensorData(int count, bool clearOnInit = false)
Parameters
Type | Name | Description |
---|---|---|
int | count | The number of elements. |
bool | clearOnInit | Whether to zero the data on allocation. The default value is |
BurstTensorData(NativeTensorArray)
Initializes and returns an instance of BurstTensorData
from a NativeTensorArray
.
Declaration
public BurstTensorData(NativeTensorArray data)
Parameters
Type | Name | Description |
---|---|---|
NativeTensorArray | data | The elements of the tensor data as a |
Properties
array
The NativeTensorArray
managed array containing the Tensor
data.
Declaration
public NativeTensorArray array { get; }
Property Value
Type | Description |
---|---|
NativeTensorArray |
backendType
On what backend are the data elements stored.
Declaration
public BackendType backendType { get; }
Property Value
Type | Description |
---|---|
BackendType |
fence
A read fence job handle. You can use fence
as a dependsOn
argument when you schedule a job that reads data. The job will start when the tensor data is ready for read access.
Declaration
public JobHandle fence { get; set; }
Property Value
Type | Description |
---|---|
JobHandle |
maxCapacity
The maximum count of the stored data elements.
Declaration
public int maxCapacity { get; }
Property Value
Type | Description |
---|---|
int |
rawPtr
The raw memory pointer for the resource.
Declaration
public void* rawPtr { get; }
Property Value
Type | Description |
---|---|
void* |
reuse
A write fence job handle. You can use reuse
as a dependsOn
argument when you schedule a job that reads data. The job will start when the tensor data is ready for write access.
Declaration
public JobHandle reuse { get; set; }
Property Value
Type | Description |
---|---|
JobHandle |
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()
ConvertToComputeTensorData(int)
Implement this method to convert to ComputeTensorData
.
Declaration
public ComputeTensorData ConvertToComputeTensorData(int count)
Parameters
Type | Name | Description |
---|---|---|
int | count |
Returns
Type | Description |
---|---|
ComputeTensorData | Converted |
Dispose()
Disposes of the BurstTensorData
and any associated memory.
Declaration
public void Dispose()
Download<T>(int, int)
Returns 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 the data. |
Returns
Type | Description |
---|---|
NativeArray<T> | The downloaded data as a native array. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |
~BurstTensorData()
Finalizes the BurstTensorData
.
Declaration
protected ~BurstTensorData()
GetReadOnlyNativeArrayHandle<T>(int, int)
Returns a ReadOnlyNativeArray handle on the linear memory data.
Declaration
public NativeArray<T>.ReadOnly GetReadOnlyNativeArrayHandle<T>(int dstCount, int srcOffset = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | dstCount | The number of elements in the array. |
int | srcOffset | The index of the first element in the data. |
Returns
Type | Description |
---|---|
NativeArray<T>.ReadOnly | NativeArray of elements. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |
Get<T>(int)
Returns a data element.
Declaration
public T Get<T>(int index) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the element. |
Returns
Type | Description |
---|---|
T | Data element. |
Type Parameters
Name | Description |
---|---|
T | The data type of the element. |
IsReadbackRequestDone()
Checks if asynchronous readback request is done.
Declaration
public bool IsReadbackRequestDone()
Returns
Type | Description |
---|---|
bool | Whether async readback is successful. |
Pin(Tensor, bool)
Moves a tensor into memory on the CPU backend device.
Declaration
public static BurstTensorData Pin(Tensor X, bool clearOnInit = false)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | The |
bool | clearOnInit | Whether to initialize the backend data. The default value is |
Returns
Type | Description |
---|---|
BurstTensorData | The pinned |
ReadbackRequest(Action<bool>)
Schedules asynchronous readback of the internal data.
Declaration
public void ReadbackRequest(Action<bool> callback = null)
Parameters
Type | Name | Description |
---|---|---|
Action<bool> | callback | Callback invoked when async readback is finished. Return value indicates if async readback is successful. |
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. |
Set<T>(int, T)
Sets value
data element at index
.
Declaration
public void Set<T>(int index, T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the element to set. |
T | value | The value to set for the element. |
Type Parameters
Name | Description |
---|---|
T | The data type of the element. |
ToArray<T>(int, int)
Returns an array that is a copy of the linear memory data.
Declaration
public T[] ToArray<T>(int dstCount, int srcOffset = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | dstCount | The number of elements in the array. |
int | srcOffset | The index of the first element in the data. |
Returns
Type | Description |
---|---|
T[] | Array of elements. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |
ToReadOnlySpan<T>(int, int)
Returns a ReadOnlySpan on the linear memory data.
Declaration
public ReadOnlySpan<T> ToReadOnlySpan<T>(int dstCount, int srcOffset = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
int | dstCount | The number of elements to span. |
int | srcOffset | The index of the first element in the data. |
Returns
Type | Description |
---|---|
ReadOnlySpan<T> | Span of elements. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |
ToString()
Returns a string that represents the BurstTensorData
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The string summary of the |
Overrides
Upload<T>(NativeArray<T>, int, int)
Uploads 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 as a native array. |
int | srcCount | The number of elements to upload. |
int | srcOffset | The index of the first element in the native array. |
Type Parameters
Name | Description |
---|---|
T | The data type of the elements. |