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.
Namespace: Unity.Barracuda
Syntax
public class WorkerFactory : object
Methods
CreateComputeWorker(Model, Boolean)
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 |
| Boolean | verbose |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreatePixelShaderWorker(Model, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateReferenceComputeWorker(Model, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateReferenceCPUWorker(Model, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, String[], String[], WorkerFactory.Device, Boolean)
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 = default(WorkerFactory.Device), 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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, String[], WorkerFactory.Device, Boolean)
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 = default(WorkerFactory.Device), 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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(Model, WorkerFactory.Device, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(WorkerFactory.Type, Model, Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(WorkerFactory.Type, Model, Boolean, WorkerFactory.Type, CompareOpsUtils.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 = CompareOpsUtils.LogLevel.Warning)
Parameters
| Type | Name | Description |
|---|---|---|
| WorkerFactory.Type | type | backend type to use. For example |
| Model | model | the associated model. See ModelLoader.cs |
| Boolean | 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(WorkerFactory.Type, Model, String[], Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(WorkerFactory.Type, Model, String[], String[], Boolean)
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 |
| Boolean | verbose | will log scheduling of layers execution to the console (default == false) |
Returns
| Type | Description |
|---|---|
| IWorker | Worker instance |
CreateWorker(WorkerFactory.Type, Model, String[], String[], Boolean, WorkerFactory.Type, CompareOpsUtils.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 = CompareOpsUtils.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 |
| Boolean | 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(WorkerFactory.Type, Model, String[], String[], WorkerFactory.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(WorkerFactory.Type, Model, WorkerFactory.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(WorkerFactory.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(WorkerFactory.Type, WorkerFactory.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 |
|---|---|
| Boolean |
|
ValidateType(WorkerFactory.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 |