public override void Process() { FLBuffer input = Root.ActiveBuffer; FLProgram externalFunction = ExternalFunctionBlueprint.Initialize(InstructionSet); input.SetRoot(externalFunction); externalFunction.ActiveChannels = Root.ActiveChannels; externalFunction.SetCLVariables(Root.Instance, input, false); //Not making it internal to the subscript because that would dispose the buffer later in the method FLProgram.Debugger?.SubProgramStarted(Root, this, externalFunction); externalFunction.EntryPoint.Process(); FLProgram.Debugger?.SubProgramEnded(Root, externalFunction); FLBuffer buf = externalFunction.ActiveBuffer; buf.SetRoot(Root); input.SetRoot(Root); externalFunction.RemoveFromSystem(buf); externalFunction.RemoveFromSystem(input); Root.ActiveChannels = externalFunction.ActiveChannels; Root.ActiveBuffer = buf; externalFunction.FreeResources(); }
public void CorrectUnderlyingBuffer_For_IN_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/bug_checks/set_temp_to_in_bug.fl"; FLSetup s = new FLSetup(nameof(CorrectUnderlyingBuffer_For_IN_Test), "resources/kernel"); SerializableFLProgram p = s.Parser.Process(new FLParserInput(file)); FLProgram pp = p.Initialize(s.InstructionSet); FLBuffer b = new FLBuffer(CLAPI.MainThread, 128, 128, "TestInput"); pp.Run(CLAPI.MainThread, b, true); FLBuffer i = pp.GetActiveBuffer(false); byte[] c = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, i.Buffer, (int)i.Size); for (int j = 0; j < c.Length; j++) { if (c[j] != 255) { Assert.Fail("Output does not match expected"); } } pp.FreeResources(); }
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()); }
public void Process() { FLBuffer input = Root.ActiveBuffer; FLProgram externalFunction = ExternalFunctionBlueprint.Initialize(Root.Instance, InstructionSet); input.SetRoot(externalFunction); externalFunction.ActiveChannels = Root.ActiveChannels; externalFunction.SetCLVariables(input, false); //Not making it internal to the subscript because that would dispose the buffer later in the method //FLProgram.Debugger?.SubProgramStarted(Root, this, externalFunction); FLDebuggerHelper.OnSubProgramStart( Root, new FLDebuggerEvents.SubProgramStartEventArgs( externalFunction, this, externalFunction .EntryPoint, false ) ); //FLDebuggerHelper.OnProgramStart(externalFunction, new FLDebuggerEvents.ProgramStartEventArgs(externalFunction, externalFunction.EntryPoint, false, false)); externalFunction.EntryPoint.Process(); //FLProgram.Debugger?.SubProgramEnded(Root, externalFunction); FLDebuggerHelper.OnSubProgramExit( Root, new FLDebuggerEvents.SubProgramExitEventArgs(externalFunction, this) ); //FLDebuggerHelper.OnProgramExit(externalFunction, new FLDebuggerEvents.ProgramExitEventArgs(externalFunction, false)); //Fire On Program Exit as External Function as well FLBuffer buf = externalFunction.ActiveBuffer; buf.SetRoot(Root); input.SetRoot(Root); externalFunction.RemoveFromSystem(buf); externalFunction.RemoveFromSystem(input); Root.ActiveChannels = externalFunction.ActiveChannels; Root.ActiveBuffer = buf; externalFunction.FreeResources(); }
public static string RunProgramInitBenchmark(string testAdd, List <string> files, int iterations, string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false, int workSizeMultiplier = 2) { FLSetup setup = new FLSetup("FL_ProgramInit_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++) { //Untimed SerializableFLProgram pr = setup.Parser.Process(new FLParserInput(files[i])); FLProgram program = null; string key = "ProgramInitPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." + i; Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1); PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations, null, (int its) => { program = pr.Initialize(setup.InstructionSet); }, (int its) => program.FreeResources()); 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()); }
public FLProgram Initialize(SerializableFLProgram file) { return(file.Initialize(InstructionSet)); }
public FLProgram Run(SerializableFLProgram file, int width, int height) { return(Run(file.Initialize(InstructionSet), width, height)); }
public override void Process(FLRunEndpointWorkItem item) { if (NextRateClear < DateTime.Now) { NextRateClear = DateTime.Now + TimeSpan.FromSeconds(Settings.RateLimitIntervalSeconds); RateLimits.Clear(); } if (!RateLimits.ContainsKey(item.Request.RemoteEndPoint.ToString())) { RateLimits[item.Request.RemoteEndPoint.ToString()] = Settings.RateLimit; } if (RateLimits[item.Request.RemoteEndPoint.ToString()] > 0) { RateLimits[item.Request.RemoteEndPoint.ToString()]--; try { SerializableFLProgram prog = Container.Parser.Process( new FLParserInput( "./memfile.fl", item.Source.Split('\n') .Select(x => x.Trim()).ToArray(), true ) ); FLBuffer inBuffer = Container.CreateBuffer( int.Parse(item.Width), int.Parse(item.Height), 1, "input_buffer" ); FLProgram program = prog.Initialize(Container); program.Run(inBuffer, true); Bitmap bmp = program.GetActiveBitmap(); MemoryStream ms = new MemoryStream(); bmp.Save(ms, ImageFormat.Png); bmp.Dispose(); byte[] result = ms.GetBuffer(); StatisticCollector.OnProgramBuilt(item.Source, out string outFilePath); File.WriteAllBytes(outFilePath, result); RunResponseObject rr = new RunResponseObject { OutputData64 = Convert.ToBase64String(result) }; item.Serve(rr); } catch (Exception e) { StatisticCollector.OnProgramFailed(item.Source, e); item.Serve(new ExceptionResponseObject(e)); } } else { item.Serve( new ErrorResponseObject( 429, $"Rate limit exceeded. Try again in: {Math.Round((NextRateClear - DateTime.Now).TotalSeconds)} seconds" ) ); } }