Exemple #1
0
        public void Stop()
        {
            if (calculatorGraph == null)
            {
                return;
            }

            // TODO: not to call CloseAllPacketSources if calculatorGraph has not started.
            using (var status = calculatorGraph.CloseAllPacketSources()) {
                if (!status.ok)
                {
                    Logger.LogError(TAG, status.ToString());
                }
            }

            using (var status = calculatorGraph.WaitUntilDone()) {
                if (!status.ok)
                {
                    Logger.LogError(TAG, status.ToString());
                }
            }

            nameTable.Remove(calculatorGraph.mpPtr);
            calculatorGraph.Dispose();
            calculatorGraph = null;

            if (stopwatch != null && stopwatch.IsRunning)
            {
                stopwatch.Stop();
            }

            OnOutput.RemoveAllListeners();
        }
    public override void Initialize()
    {
        PrepareDependentAssets();
        Debug.Log("Loaded dependent assets");

        var config = GetConfig();

        if (config == null)
        {
            throw new InvalidOperationException("config is missing");
        }

        var calculatorGraphConfig = CalculatorGraphConfig.Parser.ParseFromTextFormat(config.text);

        if (IsGpuEnabled())
        {
            var sinkNode = calculatorGraphConfig.Node.Last((node) => node.Calculator == "GlScalerCalculator");
            destinationBufferName = Tool.GetUnusedSidePacketName(calculatorGraphConfig, "destination_buffer");

  #if !UNITY_EDITOR
            sinkNode.InputSidePacket.Add($"DESTINATION:{destinationBufferName}");
  #endif
        }

        graph     = new CalculatorGraph(calculatorGraphConfig);
        stopwatch = new Stopwatch();
    }
Exemple #3
0
        public void Initialize_ShouldReturnInternalError_When_CalledWithConfig_And_ConfigIsSet()
        {
            var graph  = new CalculatorGraph(validConfigText);
            var status = graph.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText));

            Assert.AreEqual(status.code, Status.StatusCode.Internal);
        }
Exemple #4
0
 public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
 {
     using (var graph = new CalculatorGraph())
     {
         Assert.False(graph.isDisposed);
     }
 }
Exemple #5
0
        public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithConfigText()
        {
            var graph  = new CalculatorGraph(validConfigText);
            var config = graph.config;

            Assert.Greater(config.byteSizeLong, 0);
        }
Exemple #6
0
        public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithConfigText()
        {
            var graph  = new CalculatorGraph(validConfigText);
            var config = graph.Config();

            Assert.AreEqual(config.InputStream[0], "in");
            Assert.AreEqual(config.OutputStream[0], "out");
        }
Exemple #7
0
        public void Cancel_ShouldCancelGraph()
        {
            var graph = new CalculatorGraph(validConfigText);

            Assert.True(graph.StartRun().ok);
            graph.Cancel();
            Assert.AreEqual(graph.WaitUntilDone().code, Status.StatusCode.Cancelled);
        }
Exemple #8
0
 public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithNoArguments()
 {
     Assert.DoesNotThrow(() =>
     {
         var graph = new CalculatorGraph();
         graph.Dispose();
     });
 }
Exemple #9
0
        public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
        {
            var graph = new CalculatorGraph();

            graph.Dispose();

            Assert.True(graph.isDisposed);
        }
Exemple #10
0
        public void Initialize()
        {
            calculatorGraph = new CalculatorGraph(configText);

            nameTable.Add(calculatorGraph.mpPtr, GetInstanceID());
            stopwatch = new Stopwatch();
            stopwatch.Start();
        }
Exemple #11
0
        public void Initialize_ShouldReturnOk_When_CalledWithConfig_And_ConfigIsNotSet()
        {
            var graph  = new CalculatorGraph();
            var config = CalculatorGraphConfig.ParseFromString(validConfigText);
            var status = graph.Initialize(config);

            Assert.True(status.ok);
            Assert.Greater(graph.config.byteSizeLong, 0);
        }
Exemple #12
0
    public void Initialize()
    {
        if (config == null)
        {
            throw new InvalidOperationException("config is missing");
        }

        graph = new CalculatorGraph(config.text);
    }
Exemple #13
0
 public void Cancel_ShouldCancelGraph()
 {
     using (var graph = new CalculatorGraph(_ValidConfigText))
     {
         Assert.True(graph.StartRun().Ok());
         graph.Cancel();
         Assert.AreEqual(Status.StatusCode.Cancelled, graph.WaitUntilDone().Code());
     }
 }
Exemple #14
0
 public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithConfigText()
 {
     using (var graph = new CalculatorGraph(_ValidConfigText))
     {
         var config = graph.Config();
         Assert.AreEqual("in", config.InputStream[0]);
         Assert.AreEqual("out", config.OutputStream[0]);
     }
 }
Exemple #15
0
    public virtual void Initialize()
    {
        if (config == null)
        {
            throw new InvalidOperationException("config is missing");
        }

        graph          = new CalculatorGraph(config.text);
        timestampValue = System.Environment.TickCount & System.Int32.MaxValue;
    }
Exemple #16
0
 public void Initialize_ShouldReturnInternalError_When_CalledWithConfig_And_ConfigIsSet()
 {
     using (var graph = new CalculatorGraph(_ValidConfigText))
     {
         using (var status = graph.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_ValidConfigText)))
         {
             Assert.AreEqual(Status.StatusCode.Internal, status.Code());
         }
     }
 }
Exemple #17
0
        public void Initialize_ShouldReturnInternalError_When_CalledWithConfigAndSidePacket_And_ConfigIsSet()
        {
            var graph      = new CalculatorGraph(validConfigText);
            var config     = CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText);
            var sidePacket = new SidePacket();

            sidePacket.Emplace("flag", new BoolPacket(true));
            var status = graph.Initialize(config, sidePacket);

            Assert.AreEqual(status.code, Status.StatusCode.Internal);
        }
    protected virtual void OnDestroy()
    {
        Stop();
        graph     = null;
        gpuHelper = null;

        if (stopwatch != null && stopwatch.IsRunning)
        {
            stopwatch.Stop();
        }
    }
Exemple #19
0
        public void Initialize_ShouldReturnOk_When_CalledWithConfigAndSidePacket_And_ConfigIsNotSet()
        {
            var graph      = new CalculatorGraph();
            var config     = CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText);
            var sidePacket = new SidePacket();

            sidePacket.Emplace("flag", new BoolPacket(true));
            var status = graph.Initialize(config, sidePacket);

            Assert.True(status.ok);
        }
Exemple #20
0
        public void Initialize_ShouldReturnOk_When_CalledWithConfig_And_ConfigIsNotSet()
        {
            var graph  = new CalculatorGraph();
            var status = graph.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText));

            Assert.True(status.ok);

            var config = graph.Config();

            Assert.AreEqual(config.InputStream[0], "in");
            Assert.AreEqual(config.OutputStream[0], "out");
        }
Exemple #21
0
        public void LifecycleMethods_ShouldControlGraphLifeCycle()
        {
            var graph = new CalculatorGraph(validConfigText);

            Assert.True(graph.StartRun().ok);
            Assert.False(graph.GraphInputStreamsClosed());

            Assert.True(graph.WaitUntilIdle().ok);
            Assert.True(graph.CloseAllPacketSources().ok);
            Assert.True(graph.GraphInputStreamsClosed());
            Assert.True(graph.WaitUntilDone().ok);
            Assert.False(graph.HasError());
        }
Exemple #22
0
    public virtual void Initialize()
    {
        stopwatch = new Stopwatch();
        var config = GetConfig();

        if (config == null)
        {
            Debug.LogError("config is missing");
            return;
        }

        graph = new CalculatorGraph(config.text);
    }
Exemple #23
0
        public void Initialize_ShouldReturnOk_When_CalledWithConfig_And_ConfigIsNotSet()
        {
            using (var graph = new CalculatorGraph())
            {
                using (var status = graph.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_ValidConfigText)))
                {
                    Assert.True(status.Ok());
                }

                var config = graph.Config();
                Assert.AreEqual("in", config.InputStream[0]);
                Assert.AreEqual("out", config.OutputStream[0]);
            }
        }
Exemple #24
0
 protected virtual void OnDestroy()
 {
     Stop();
     if (graph != null)
     {
         graph.Dispose();
         graph = null;
     }
     if (gpuHelper != null)
     {
         gpuHelper.Dispose();
         gpuHelper = null;
     }
 }
    public override void Initialize()
    {
        if (config == null)
        {
            throw new InvalidOperationException("config is missing");
        }

        var calculatorGraphConfig = CalculatorGraphConfig.Parser.ParseFromTextFormat(config.text);
        var sinkNode = calculatorGraphConfig.Node.Last();

        destinationBufferName = Tool.GetUnusedSidePacketName(calculatorGraphConfig, "destination_buffer");
        sinkNode.InputSidePacket.Add($"DESTINATION:{destinationBufferName}");

        graph = new CalculatorGraph(calculatorGraphConfig);
    }
Exemple #26
0
    public virtual void Initialize()
    {
        PrepareDependentAssets();
        Debug.Log("Loaded dependent assets");

        var config = GetConfig();

        if (config == null)
        {
            Debug.LogError("config is missing");
            return;
        }

        graph     = new CalculatorGraph(config.text);
        stopwatch = new Stopwatch();
    }
    /// <summary>
    ///   This method must be called (only) once before calling StartRun.
    ///   `graph` and `gpuHelper` (if useGPU is true) are initialized here.
    ///    If the config is invalid, it throws an error.
    /// </summary>
    public void Initialize()
    {
        if (config == null)
        {
            throw new InvalidOperationException("config is missing");
        }

        graph = new CalculatorGraph(config.text);

        if (shouldUseGPU())
        {
            var gpuResources = new StatusOrGpuResources().ConsumeValue();
            graph.SetGpuResources(gpuResources).AssertOk();

            gpuHelper = new GlCalculatorHelper();
            gpuHelper.InitializeForTest(graph.GetGpuResources());
        }
    }
Exemple #28
0
 public void Initialize()
 {
     graph = new CalculatorGraph(configText);
 }