Class WorkerFactory
Factory to create worker that executes specified model on a particular device (GPU, CPU, etc) using particular backend.
See IWorker for usage of the worker itself.
Inherited Members
Namespace: Unity.Barracuda
Assembly: Unity.Barracuda.dll
Syntax
public class WorkerFactory
Methods
CreateComputeWorker(Model, bool)
Create a worker using the precompiled GPU backend for the given model.
Declaration
public static IWorker CreateComputeWorker(Model model, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreatePixelShaderWorker(Model, bool)
Create a worker using the reference GPU backend for the given model.
Declaration
public static IWorker CreatePixelShaderWorker(Model model, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateReferenceCPUWorker(Model, bool)
Create a worker using the reference CPU backend for the given model.
Declaration
public static IWorker CreateReferenceCPUWorker(Model model, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateReferenceComputeWorker(Model, bool)
Create a worker using the reference GPU backend for the given model.
Declaration
public static IWorker CreateReferenceComputeWorker(Model model, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, bool)
Create a worker that will execute model using the best backend that is available for a given device type.
Declaration
public static IWorker CreateWorker(Model model, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, string[], string[], Device, bool)
Create a worker that will execute model using the best backend that is available for a given device type.
Declaration
public static IWorker CreateWorker(Model model, string[] additionalOutputs, string[] trimOutputs, WorkerFactory.Device device = Device.Auto, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| string[] | trimOutputs | by specifying this list of outputs, all other non-specified outputs will be discarded |
| WorkerFactory.Device | device | the device type to run worker on. For example |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, string[], Device, bool)
Create a worker that will execute model using the best backend that is available for a given device type.
Declaration
public static IWorker CreateWorker(Model model, string[] additionalOutputs, WorkerFactory.Device device = Device.Auto, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| WorkerFactory.Device | device | the device type to run worker on. For example |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, Device, bool)
Create a worker that will execute model using the best backend that is available for a given device type.
Declaration
public static IWorker CreateWorker(Model model, WorkerFactory.Device device, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | the associated model. See ModelLoader.cs |
| WorkerFactory.Device | device | the preferred device for execution. For example |
| bool | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, bool)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, bool verbose)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, bool, Type, LogLevel)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, bool verbose, WorkerFactory.Type compareAgainstType, CompareOpsUtils.LogLevel differenceLogLevel = LogLevel.Warning)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| bool | verbose | will log scheduling of layers execution to the console |
| WorkerFactory.Type | compareAgainstType | if different than |
| CompareOpsUtils.LogLevel | differenceLogLevel | if |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, string[], bool)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, string[], string[], bool)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs = null, string[] trimOutputs = null, bool verbose = false)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| string[] | trimOutputs | by specifying this list of outputs, all other non-specified outputs will be discarded |
| bool | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, string[], string[], bool, Type, LogLevel)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs, string[] trimOutputs, bool verbose, WorkerFactory.Type compareAgainstType, CompareOpsUtils.LogLevel differenceLogLevel = LogLevel.Warning)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| string[] | trimOutputs | by specifying this list of outputs, all other non-specified outputs will be discarded |
| bool | verbose | will log scheduling of layers execution to the console |
| WorkerFactory.Type | compareAgainstType | if different than |
| CompareOpsUtils.LogLevel | differenceLogLevel | if |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, string[], string[], WorkerConfiguration, IModelExecutionsReporter)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs, string[] trimOutputs, WorkerFactory.WorkerConfiguration workerConfiguration, IModelExecutionsReporter modelExecutionsReporter = null)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| string[] | additionalOutputs | the additional outputs to track but not directly specified by the model |
| string[] | trimOutputs | by specifying this list of outputs, all other non-specified outputs will be discarded |
| WorkerFactory.WorkerConfiguration | workerConfiguration | define configurations such as logging and comparison backend, see WorkerConfiguration API docs |
| IModelExecutionsReporter | modelExecutionsReporter | execution reporter to use to track models executions |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Type, Model, WorkerConfiguration)
Create a worker with explicitly specified backend type to execute the given model.
Declaration
public static IWorker CreateWorker(WorkerFactory.Type type, Model model, WorkerFactory.WorkerConfiguration workerConfiguration)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| WorkerFactory.WorkerConfiguration | workerConfiguration | define configurations such as logging and comparison backend, see WorkerConfiguration API docs |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
GetBestTypeForDevice(Device)
Returns the best backend type that can run on a device given the model.
Declaration
public static WorkerFactory.Type GetBestTypeForDevice(WorkerFactory.Device device)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Device | device | device |
Returns
| Type | Description |
|---|---|
| WorkerFactory.Type | Best worker type for specified |
IsType(Type, Device)
Check if a backend is of a given type. For example: IsType(Type.CSharpRef, Device.GPU) == true
Declaration
public static bool IsType(WorkerFactory.Type type, WorkerFactory.Device device)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | type to check against |
| WorkerFactory.Device | device | device to check against |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | thrown if type is |
ValidateType(Type)
Validate if a backend of type is supported, otherwise return a fallback type.
Declaration
public static WorkerFactory.Type ValidateType(WorkerFactory.Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | type |
Returns
| Type | Description |
|---|---|
| WorkerFactory.Type | returns |