internal static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs, string[] trimOutputs, WorkerFactory.WorkerConfiguration workerConfiguration, IModelExecutionsReporter modelExecutionsReporter = null)
        {
            type = ResolveAutoType(type);
            var compareAgainstType = ResolveAutoType(workerConfiguration.compareAgainstType);

            Assert.AreNotEqual(type, WorkerFactory.Type.Auto);
            Assert.AreNotEqual(compareAgainstType, WorkerFactory.Type.Auto);

            bool compare = type != compareAgainstType;

            if (WorkerFactory.IsType(type, WorkerFactory.Device.GPU) && !SystemInfo.supportsComputeShaders && !Application.isEditor)
            {
                D.LogWarning("Compute shaders are not supported on current platform. Falling back to CSharpFast.");
                type = WorkerFactory.Type.CSharpBurst;
            }

            IVars vars;

            if (WorkerFactory.IsType(type, WorkerFactory.Device.GPU) || WorkerFactory.IsType(compareAgainstType, WorkerFactory.Device.GPU))
            {
                vars = new ComputeVarsWithSharedModel();
            }
            else
            {
                vars = new DefaultVars();
            }

            ITensorAllocator allocator = vars.GetAllocator();

            if (workerConfiguration.verbose)
            {
                D.Log($"Storage type: {vars.GetType()}. Allocator type: {allocator.GetType()}.");
            }

            IOps ops = CreateOps(type, allocator, workerConfiguration.verbose);

            if (compare)
            {
                ops = new CompareOps(ops,
                                     CreateOps(compareAgainstType, allocator, workerConfiguration.verbose), workerConfiguration.compareLogLevel, workerConfiguration.compareEpsilon);
            }

            if (workerConfiguration.verbose || modelExecutionsReporter != null)
            {
                ops = new VerboseOps(ops, workerConfiguration.verbose);
            }

            if (Application.isEditor || modelExecutionsReporter != null)
            {
                ops = new StatsOps(ops);
            }

            model = ValidateModel(
                PatchModel(model, additionalOutputs, trimOutputs));

            ops.SetModelExecutionsReporter(modelExecutionsReporter);
            return(new GenericWorker(model, ops, vars, workerConfiguration.verbose));
        }
Exemplo n.º 2
0
        internal static IWorker CreateWorker(WorkerFactory.Type type, Model model, string[] additionalOutputs, string[] trimOutputs, WorkerFactory.WorkerConfiguration workerConfiguration, IModelExecutionsReporter modelExecutionsReporter = null)
        {
            type = ResolveAutoType(type);
            var compareAgainstType = ResolveAutoType(workerConfiguration.compareAgainstType);

            Assert.AreNotEqual(type, WorkerFactory.Type.Auto);
            Assert.AreNotEqual(compareAgainstType, WorkerFactory.Type.Auto);

            bool compare = type != compareAgainstType;

            if (WorkerFactory.IsType(type, WorkerFactory.Device.GPU) && !SystemInfo.supportsComputeShaders && !Application.isEditor)
            {
                type = WorkerFactory.Type.PixelShader;
            }

            IVars vars;

            // PixelShader worker uses Blit/Textures, cannot re-use vars unless the dispatch mechanism allows rendering to sub part of the texture
            if ((type == WorkerFactory.Type.PixelShader) || (compareAgainstType == WorkerFactory.Type.PixelShader))
            {
                vars = new GenericVarsWithReuse();
            }
            else
            {
                if (WorkerFactory.IsType(type, WorkerFactory.Device.GPU) || WorkerFactory.IsType(compareAgainstType, WorkerFactory.Device.GPU))
                {
                    vars = new ComputeVarsWithSharedModel();
                }
                else
                {
                    vars = new DefaultVars();
                }
            }

            ITensorAllocator allocator = vars.GetAllocator();

            if ((type == WorkerFactory.Type.PixelShader) || (compareAgainstType == WorkerFactory.Type.PixelShader))
            {
                allocator = new TensorCachingByShapeAllocator();
            }

            if (workerConfiguration.verbose)
            {
                D.Log($"Storage type: {vars.GetType()}. Allocator type: {allocator.GetType()}.");
            }

            IOps ops = CreateOps(type, allocator, workerConfiguration.verbose);

            if (compare)
            {
                ops = new CompareOps(ops,
                                     CreateOps(compareAgainstType, allocator, workerConfiguration.verbose), workerConfiguration.compareLogLevel, workerConfiguration.compareEpsilon);
            }

            if (workerConfiguration.verbose || modelExecutionsReporter != null)
            {
                ops = new VerboseOps(ops, workerConfiguration.verbose);
            }

            if (Application.isEditor || modelExecutionsReporter != null)
            {
                ops = new StatsOps(ops);
            }

            model = ValidateModel(
                PatchModel(model, additionalOutputs, trimOutputs));

            ops.SetModelExecutionsReporter(modelExecutionsReporter);
            return(new GenericWorker(model, ops, vars, workerConfiguration.verbose, workerConfiguration.takeoverWeights));
        }