public static string ToTextFile(IModelExecutionsReporter report, bool spreadsheetFormat, string filename = null)
        {
            string stringToSave = report.GenerateStringReport(spreadsheetFormat);
            string fullPath     = Application.temporaryCachePath;

            if (filename == null)
            {
                fullPath = Path.Combine(fullPath, "ModelExecutionReport");
                fullPath = Path.ChangeExtension(fullPath, "txt");
            }
            else
            {
                fullPath = Path.Combine(fullPath, filename);
            }
            File.WriteAllText(fullPath, stringToSave);
            return(fullPath);
        }
Beispiel #2
0
 /// <inheritdoc/>
 void IOps.SetModelExecutionsReporter(IModelExecutionsReporter executionsReporter)
 {
     m_Ops.SetModelExecutionsReporter(executionsReporter);
 }
 /// <summary>
 /// Create a worker with explicitly specified backend `type` to execute the given `model`.
 /// </summary>
 /// <param name="type">backend type to use. For example `WorkerFactory.Type.Compute` specifies the fast GPU path</param>
 /// <param name="model">the associated model. See ModelLoader.cs</param>
 /// <param name="additionalOutputs">the additional outputs to track but not directly specified by the model</param>
 /// <param name="trimOutputs">by specifying this list of outputs, all other non-specified outputs will be discarded</param>
 /// <param name="workerConfiguration">define configurations such as logging and comparison backend, see WorkerConfiguration API docs</param>
 /// <param name="modelExecutionsReporter">execution reporter to use to track models executions</param>
 /// <returns>Worker instance</returns>
 public static IWorker CreateWorker(Type type, Model model, string[] additionalOutputs, string[] trimOutputs, WorkerConfiguration workerConfiguration, IModelExecutionsReporter modelExecutionsReporter = null)
 {
     return(BarracudaBackendsFactory.CreateWorker(type, model, additionalOutputs, trimOutputs, workerConfiguration, modelExecutionsReporter));
 }
Beispiel #4
0
 /// <inheritdoc/>
 void IOps.SetModelExecutionsReporter(IModelExecutionsReporter executionsReporter)
 {
     m_Ops1.SetModelExecutionsReporter(executionsReporter);
     m_Ops2.SetModelExecutionsReporter(null);
 }
        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));
        }
Beispiel #6
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));
        }