docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    WorkerFactory
    BarracudaWorkerFactory
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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

    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 WorkerFactory.Device.GPU specifies the fast GPU path

    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 WorkerFactory.Device.GPU specifies the fast GPU path

    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 WorkerFactory.Device.GPU specifies the fast GPU path

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 type model will be run on those two backend and result of every layer will be compared, checking for divergence. Great for debugging, but very slow because of the sync needed

    CompareOpsUtils.LogLevel differenceLogLevel

    if compareAgainstType is used difference will be reported as error is this is true or warning otherwise

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 type model will be run on those two backend and result of every layer will be compared, checking for divergence. Great for debugging, but very slow because of the sync needed

    CompareOpsUtils.LogLevel differenceLogLevel

    if compareAgainstType is used difference will be reported as error is this is true or warning otherwise

    Returns
    Type Description
    IWorker

    Worker instance

    CreateWorker(Type, Model, string[], string[], WorkerConfiguration)

    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)
    Parameters
    Type Name Description
    WorkerFactory.Type type

    backend type to use. For example WorkerFactory.Type.Compute specifies the fast GPU path

    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

    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 WorkerFactory.Type.Compute specifies the fast GPU path

    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 device

    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

    true if backend is of specified type

    Exceptions
    Type Condition
    ArgumentException

    thrown if type is Type.Auto

    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 type if valid, otherwise returns fallback type

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)