Ejemplo n.º 1
0
        protected FLProgram Process(FlScriptExecutionContext context)
        {
            FLBuffer input = new FLBuffer(
                Instance,
                context.Input,
                context.Width,
                context.Height,
                context.Depth,
                context.Filename
                );

            FLProgram program;

            if (context.IsCompiled)
            {
                Stream s = IOManager.GetStream(context.Filename);
                program = FLSerializer.LoadProgram(s, InstructionSet).Initialize(Instance, InstructionSet);
                s.Close();
            }
            else
            {
                program = Parser.Process(new FLParserInput(context.Filename)).Initialize(Instance, InstructionSet);
            }

            program.Run(input, true);

            return(program);
        }
Ejemplo n.º 2
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = FLSerializer.LoadProgram(stream, runner.InstructionSet);

            progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);
            FLProgram p = runner.Run(prog, 512, 512, 1);

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath.Remove(filePath.Length - 3, 3) + "png";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Bitmap bmp = new Bitmap(512, 512);

            CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
            bmp.Save(filePath);
            stream.Close();
            p.FreeResources();
            progressIndicator?.Dispose();
        }
Ejemplo n.º 3
0
 protected SerializableFLProgram Load(string input)
 {
     using (Stream s = File.OpenRead(input))
     {
         return(FLSerializer.LoadProgram(s, FLData.Container.InstructionSet));
     }
 }
Ejemplo n.º 4
0
        public static string RunDeserializedFLExecutionBenchmark(string testAdd, List <string> files, int iterations,
                                                                 string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false,
                                                                 int workSizeMultiplier   = 2)
        {
            FLSetup setup = new FLSetup("FL_DeserializedExecution_Performance" + testAdd, "resources/kernel", performanceFolder,
                                        checkPipeline, useMultiThreading, workSizeMultiplier);
            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");

            for (int i = 0; i < files.Count; i++)
            {
                Bitmap   bmp = null;
                FLBuffer buf = null;
                SerializableFLProgram parsedProgram = null;
                MemoryStream          ms            = new MemoryStream();
                FLProgram             program       = null;
                string key = "FLDeserializedExecutionPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." +
                             i;

                Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);

                parsedProgram = setup.Parser.Process(new FLParserInput(files[i]));
                FLSerializer.SaveProgram(ms, parsedProgram, setup.InstructionSet, new string[0]);

                ms.Position   = 0;
                parsedProgram = FLSerializer.LoadProgram(ms, setup.InstructionSet);

                ms.Dispose();
                PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations,
                                                                                              (int its) => //BeforeTest
                {
                    bmp     = new Bitmap(BITMAP_RESOLUTION, BITMAP_RESOLUTION);
                    buf     = new FLBuffer(CLAPI.MainThread, bmp, files[i]);
                    program = parsedProgram.Initialize(setup.InstructionSet);
                },
                                                                                              (int its) => program.Run(CLAPI.MainThread, buf, true),
                                                                                              (int its) => //After Test
                {
                    if (its == iterations - 1)
                    {
                        SaveOutput("deserialized-output", bmp, program, setup, files[i]);
                    }

                    program.FreeResources();
                    bmp.Dispose();
                    buf.Dispose();
                });
                logOut.AppendLine("\t" + result);

                Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
                setup.WriteResult(result);
            }

            logOut.AppendLine();
            setup.WriteLog(logOut.ToString());
            setup.Dispose();
            return(logOut.ToString());
        }
Ejemplo n.º 5
0
        public override object Deserialize(PrimitiveValueWrapper s)
        {
            string name = s.ReadString();
            FLExecutableElementModifiers emod = new FLExecutableElementModifiers(name, s.ReadArray <string>());

            byte[] payload = s.ReadBytes();

            MemoryStream ms = new MemoryStream(payload);

            return(new SerializableExternalFLFunction(
                       name,
                       FLSerializer.LoadProgram(ms, instructionSet),
                       emod
                       ));
        }
Ejemplo n.º 6
0
        private void ExportViewer_Load(object sender, EventArgs e)
        {
            StyleManager.RegisterControls(this);


            Stream s = File.OpenRead(file);


            FLProgram p     = FLSerializer.LoadProgram(s, FLContainer.InstructionSet).Initialize(FLContainer);
            FLBuffer  input = FLContainer.CreateBuffer(512, 512, 1, "Input");

            p.Run(input, true);

            Bitmap bmp = p.GetActiveBitmap();

            pbExportView.Image = bmp;
        }
Ejemplo n.º 7
0
        public static string RunProgramDeserializationBenchmark(string testAdd, List <string> files, int iterations,
                                                                string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false,
                                                                int workSizeMultiplier   = 2)
        {
            FLSetup setup = new FLSetup("FL_DeserializationProcess_Performance" + testAdd, "resources/kernel", performanceFolder,
                                        checkPipeline, useMultiThreading, workSizeMultiplier);


            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");

            MemoryStream dst = new MemoryStream();

            for (int i = 0; i < files.Count; i++)
            {
                SerializableFLProgram pr = setup.Parser.Process(new FLParserInput(files[i]));
                string key = "ProgramDeserializationPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." +
                             i;
                FLSerializer.SaveProgram(dst, pr, setup.InstructionSet, new string[] { });
                Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);

                PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations,
                                                                                              (int its) => dst.Position = 0,
                                                                                              (int its) => FLSerializer.LoadProgram(dst, setup.InstructionSet),
                                                                                              null);
                logOut.AppendLine("\t" + result);
                Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
                setup.WriteResult(result);
            }

            dst.Dispose();
            logOut.AppendLine();
            setup.WriteLog(logOut.ToString());
            setup.Dispose();
            return(logOut.ToString());
        }