Class GenericWorker
Generic IWorker implementation
Inherited Members
Namespace: Unity.Barracuda
Assembly: Unity.Barracuda.dll
Syntax
public class GenericWorker : IWorker, IDisposable
Constructors
GenericWorker(Model, IOps, IVars, bool, bool)
Create GenericWorker for specified model and ops
Declaration
public GenericWorker(Model model, IOps ops, IVars vars, bool verbose = false, bool takeoverWeights = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model |
|
| IOps | ops |
|
| IVars | vars |
|
| bool | verbose | verbose execution flag |
| bool | takeoverWeights | takeover weights execution flag |
Properties
scheduleProgress
Reports the fraction (from 0.0 to 1.0) of the model that was scheduled for the execution since the last call to StartManualSchedule.
This property will return 0.0 immediately after calling StartManualSchedule and will return 1.0 once the complete model was scheduled.
This property will monotonuosly increase with the every iteration of IEnumerator that was obtained by calling StartManualSchedule.
Declaration
public virtual float scheduleProgress { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Dispose()
Dispose all internal storage structures
Declaration
public virtual void Dispose()
Execute()
Non-blocking API that schedules network execution in one go.
Declaration
public virtual IWorker Execute()
Returns
| Type | Description |
|---|---|
| IWorker | IWorker instance |
Execute(IDictionary<string, Tensor>)
Non-blocking API that takes multiple input tensors and schedules network execution in one go.
Declaration
public virtual IWorker Execute(IDictionary<string, Tensor> inputs)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, Tensor> | inputs | input Tensor Dictionary: name -> Tensor |
Returns
| Type | Description |
|---|---|
| IWorker | IWorker instance |
Execute(Tensor)
Non-blocking API that takes single input tensor and schedules network execution in one go.
Useful when network have only one input as input name is not needed.
Declaration
public virtual IWorker Execute(Tensor input)
Parameters
| Type | Name | Description |
|---|---|---|
| Tensor | input | input Tensor |
Returns
| Type | Description |
|---|---|
| IWorker | IWorker instance |
~GenericWorker()
Finalizer
Declaration
protected ~GenericWorker()
FlushSchedule(bool)
Non-blocking API that starts immediate execution on the part of the network that was scheduled so far.
Optional blocking flag can force this function to block until execution is complete.
Declaration
public virtual void FlushSchedule(bool blocking)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | blocking | if blocking True, wait for completion |
PeekConstants(string)
Returns references to constants tensors for a layer. This reference might be valid only until the next Execute() or Dispose() method is called on the worker.
IMPORTANT: if you want tensor to outlive the worker, use CopyOutput() method or follow with TakeOwnership() call on the tensor, also worker Execute()
or PrepareForInput() should have been called at least once for the tensors to exist.
Declaration
public virtual Tensor[] PeekConstants(string layerName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | layerName | Layer name |
Returns
| Type | Description |
|---|---|
| Tensor[] | array of constant Tensors |
PeekOutput()
Non-blocking API that returns a reference to the main output tensor. This reference will be valid only until the next Execute() or Dispose() method is called on the worker.
Useful when network has only one output.
IMPORTANT: if you want tensor to outlive the worker, use CopyOutput() method or follow with TakeOwnership() call on the tensor.
Declaration
public virtual Tensor PeekOutput()
Returns
| Type | Description |
|---|---|
| Tensor | output Tensor |
PeekOutput(string)
Non-blocking API that returns a reference to output tensor by specified name. This reference will be valid only until the next Execute() or Dispose() method is called on the worker.
IMPORTANT: if you want tensor to outlive the worker, use CopyOutput() method or follow with TakeOwnership() call on the tensor.
Declaration
public virtual Tensor PeekOutput(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | output name |
Returns
| Type | Description |
|---|---|
| Tensor | output Tensor |
PrepareForInput(IDictionary<string, TensorShape>, DataType)
Optional API to prepare network execution for inputs of particular shapes.
Useful to initialize execution device ahead of the first call to Execute.
Declaration
public virtual void PrepareForInput(IDictionary<string, TensorShape> inputShapes, DataType dataType)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, TensorShape> | inputShapes | Dictionary of tensor name -> input shapes |
| DataType | dataType | expected type of the inputs |
SetInput(string, Tensor)
Assign tensor x to the named input of the network. String name specifies the name of the input.
Declaration
public virtual void SetInput(string name, Tensor x)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Tensor name |
| Tensor | x | Tensor |
SetInput(Tensor)
Specify single tensor x as the only input for the network.
Useful when network has only one input and caller does not need to specify input's name.
Declaration
public virtual void SetInput(Tensor x)
Parameters
| Type | Name | Description |
|---|---|---|
| Tensor | x | input Tensor |
StartManualSchedule()
Non-blocking API that allows manual scheduling of the model one layer at the time.
Call MoveNext on the IEnumerator obtained from calling this function to schedule next layer of the model.
Declaration
public virtual IEnumerator StartManualSchedule()
Returns
| Type | Description |
|---|---|
| IEnumerator | Manual schedule iterator |
StartManualSchedule(IDictionary<string, Tensor>)
Non-blocking API that takes mutliple input tensors and schedules network execution one layer at the time.
Call MoveNext on the IEnumerator obtained from calling this function to schedule next layer of the model.
Declaration
public virtual IEnumerator StartManualSchedule(IDictionary<string, Tensor> inputs)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, Tensor> | inputs | input Tensor Dictionary: name -> Tensor |
Returns
| Type | Description |
|---|---|
| IEnumerator | Manual schedule iterator |
StartManualSchedule(Tensor)
Non-blocking API that takes single input tensor and schedules network execution one layer at the time.
Call MoveNext on the IEnumerator obtained from calling this function to schedule next layer of the model.
Declaration
public virtual IEnumerator StartManualSchedule(Tensor input)
Parameters
| Type | Name | Description |
|---|---|---|
| Tensor | input | input Tensor |
Returns
| Type | Description |
|---|---|
| IEnumerator | Manual schedule iterator |
Summary()
Execution summary
Declaration
public virtual string Summary()
Returns
| Type | Description |
|---|---|
| string | execution summary |