public FLSetup(string testName, string kernelPath, string performance = "performance", Type[] checkPipeline = null, bool useMultiThreading = false, int workSizeMultiplier = 2) : base(testName, performance) { KernelDatabase = new KernelDatabase(CLAPI.MainThread, kernelPath, DataVectorTypes.Uchar1); InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(KernelDatabase); BufferCreator = BufferCreator.CreateWithBuiltInTypes(); CheckBuilder = null; if (checkPipeline == null) { CheckBuilder = FLProgramCheckBuilder.CreateDefaultCheckBuilder(InstructionSet, BufferCreator); } else { CheckBuilder = new FLProgramCheckBuilder(InstructionSet, BufferCreator); foreach (Type useCheck in checkPipeline) { CheckBuilder.AddProgramCheck((FLProgramCheck)Activator.CreateInstance(useCheck)); } } Parser = new FLParser(InstructionSet, BufferCreator, new WorkItemRunnerSettings(useMultiThreading, workSizeMultiplier)); CheckBuilder.Attach(Parser, true); Directory.CreateDirectory(RunResultPath); Directory.CreateDirectory(DataOutputDirectory); }
public static FLInstructionSet CreateWithBuiltInTypes(CLAPI instance, string clKernelPath) { KernelDatabase db = new KernelDatabase(instance, clKernelPath, DataVectorTypes.Uchar1); return(CreateWithBuiltInTypes(db)); }
public FLScriptRunner( CLAPI instance, DataTypes dataTypes = DataTypes.Uchar1, string kernelFolder = "assets/kernel/") { Instance = instance; Db = new KernelDatabase(instance, kernelFolder, dataTypes); ProcessQueue = new Queue <FlScriptExecutionContext>(); }
public static string RunParserInitBenchmark(string testAdd, int iterations, string performanceFolder = "performance", bool useChecks = true, bool useMultiThreading = false, int workSizeMultiplier = 2) { //FLSetup setup = new FLSetup("FL_ParserProcess_Performance"+ testAdd, "resources/kernel", performanceFolder, // useChecks, useMultiThreading, workSizeMultiplier); StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n"); FLInstructionSet iset = null; BufferCreator bc = null; FLParser parser = null; FLProgramCheckBuilder checkBuilder = null; KernelDatabase db = new KernelDatabase(CLAPI.MainThread, "resources/kernel", DataVectorTypes.Uchar1); string key = "ParserInitPerformance"; Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1); PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations, null, (int its) => { iset = FLInstructionSet.CreateWithBuiltInTypes(db); bc = BufferCreator.CreateWithBuiltInTypes(); checkBuilder = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, bc); parser = new FLParser(iset, bc); }, null); logOut.AppendLine("\t" + result); Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1); return(logOut.ToString()); }
private static FLScriptData LoadScriptData(string file, CLBufferInfo inBuffer, int width, int height, int depth, int channelCount, KernelDatabase db, Dictionary <string, FLFunctionInfo> funcs) { Logger.Log("Loading Script Data for File: " + file, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 6); FLScriptData ret = new FLScriptData(LoadSource(file, channelCount)); ret.Defines.Add(InputBufferName, inBuffer); Logger.Log("Parsing Texture Defines for File: " + file, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 5); ParseDefines(DefineKey, DefineTexture, ret.Source, ret.Defines, width, height, depth, channelCount, db); Logger.Log("Parsing Script Defines for File: " + file, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 5); ParseDefines(ScriptDefineKey, DefineScript, ret.Source, ret.Defines, width, height, depth, channelCount, db); Logger.Log("Parsing JumpLocations for File: " + file, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 5); ret.JumpLocations = ParseJumpLocations(ret.Source); Logger.Log("Parsing Instruction Data for File: " + file, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 5); foreach (string line in ret.Source) { Logger.Log("Parsing Instruction Data for Line: " + line, DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 3); FLInstructionData data = GetInstructionData(line, ret.Defines, ret.JumpLocations, funcs, db); Logger.Log("Parsed Instruction Data: " + Enum.GetName(typeof(FLInstructionType), data.InstructionType), DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 2); ret.ParsedSource.Add(data); } return(ret); }
/// <summary> /// Resets the Interpreter to work with a new script /// </summary> /// <param name="file">The file containing the source</param> /// <param name="input">The input buffer</param> /// <param name="width">Width of the input buffer</param> /// <param name="height">Height of the input buffer</param> /// <param name="depth">Depth of the input buffer</param> /// <param name="channelCount">The Channel Count</param> /// <param name="kernelDB">The Kernel DB that will be used</param> /// <param name="ignoreDebug">a flag to ignore the brk statement</param> public void Reset(string file, MemoryBuffer input, int width, int height, int depth, int channelCount, KernelDatabase kernelDB, bool ignoreDebug) { //Clear old stuff ReleaseResources(); //Setting variables _currentBuffer = new CLBufferInfo(input, false); _currentBuffer.SetKey(InputBufferName); _ignoreDebug = ignoreDebug; _width = width; _height = height; _depth = depth; _channelCount = channelCount; _kernelDb = kernelDB; _activeChannels = new byte[_channelCount]; _currentArgStack = new Stack <object>(); for (int i = 0; i < _channelCount; i++) { _activeChannels[i] = 1; } _activeChannelBuffer = CLAPI.CreateBuffer(_activeChannels, MemoryFlag.ReadOnly | MemoryFlag.CopyHostPointer); //Parsing File _currentBuffer.SetKey(InputBufferName); Data = LoadScriptData(file, _currentBuffer, width, height, depth, channelCount, _kernelDb, _flFunctions); Reset(); }
public IncludedItem ProcessImport(string input) { string dir = input.Remove(0, 3); //Remove "CL " Log("Compiling CL Programs in directory {0}", dir); KernelDatabase dB = new KernelDatabase(CLAPI.MainThread, dir, DataVectorTypes.Uchar1); Log("Generating HL Wrapper for {0} Kernels in {1} Programs", dB.KernelCount, dB.ProgramCount); StringBuilder sb = new StringBuilder(); sb.AppendLine("public class CL\n{"); int count = 0; foreach (CLProgram clProgram in dB.Programs) { string progInitFunc = $"_CL_INIT_{count}"; sb.Append(EmbedProgramSource(clProgram, progInitFunc)); count++; foreach (KeyValuePair <string, CLKernel> clProgramContainedKernel in clProgram.ContainedKernels) { sb.Append(GenerateKernelWrapper(progInitFunc, clProgramContainedKernel.Value)); } } sb.AppendLine("\n}\n"); sb.AppendLine(GetStaticTypes()); string file = Path.Combine(m_DeviceDriverDirectory, "FL_CL_Integration.vhl"); File.WriteAllText(file, sb.ToString()); return(new IncludedItem(file, false)); }
private void Execute(object obj) { var observer = (IObserver <TModel>)obj; try { using (var sqlConnection = KernelDatabase.CreateSqlConnection()) { sqlConnection.Open(); using (var r = new SqlCommand(SqlBuilder(), sqlConnection).ExecuteReader()) { if (r.Read()) { var model = ModelBuilder(r); if (model != null) { observer.OnNext(model); } } } observer.OnCompleted(); return; } } catch (Exception ex) { observer.OnError(ex); } }
/// <summary> /// Resets the FLInterpreter to work with a new script /// </summary> /// <param name="file">The file containing the source</param> /// <param name="input">The input buffer</param> /// <param name="width">Width of the input buffer</param> /// <param name="height">Height of the input buffer</param> /// <param name="depth">Depth of the input buffer</param> /// <param name="channelCount">The Channel Count</param> /// <param name="kernelDb">The Kernel DB that will be used</param> /// <param name="ignoreDebug">a flag to ignore the brk statement</param> public void Reset(string file, MemoryBuffer input, int width, int height, int depth, int channelCount, KernelDatabase kernelDb, bool ignoreDebug) { //Clear old stuff ReleaseResources(); //Setting variables currentBuffer = new CLBufferInfo(input, false); currentBuffer.SetKey(INPUT_BUFFER_NAME); this.ignoreDebug = ignoreDebug; this.width = width; this.height = height; this.depth = depth; this.channelCount = channelCount; this.kernelDb = kernelDb; activeChannels = new byte[this.channelCount]; currentArgStack = new Stack <object>(); for (int i = 0; i < this.channelCount; i++) { activeChannels[i] = 1; } activeChannelBuffer = CLAPI.CreateBuffer(instance, activeChannels, MemoryFlag.ReadOnly | MemoryFlag.CopyHostPointer); //Parsing File currentBuffer.SetKey(INPUT_BUFFER_NAME); data = LoadScriptData(instance, file, currentBuffer, width, height, depth, channelCount, kernelDb, flFunctions); Reset(); }
public static FLInstructionSet CreateWithBuiltInTypes(KernelDatabase db) { FLInstructionSet iset = new FLInstructionSet(db); PluginManager.LoadPlugins(iset); return(iset); }
public FLRunner(CLAPI instance, KernelDatabase database) : this( instance, FLInstructionSet.CreateWithBuiltInTypes( database ), BufferCreator.CreateWithBuiltInTypes() ) { }
public void CompileTest() { CLAPI instance = CLAPI.GetInstance(); KernelDatabase db = new KernelDatabase(instance, "resources/kernel", DataVectorTypes.Uchar1); Assert.True(db.KernelNames.Count != 0); Assert.Pass("Kernels Loaded: " + db.KernelNames.Count); db.Dispose(); instance.Dispose(); }
public FLScriptRunner(CLAPI instance, DataVectorTypes dataVectorTypes = DataVectorTypes.Uchar1, string kernelFolder = "resources/kernel") { Db = new KernelDatabase(instance, kernelFolder, dataVectorTypes); InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(Db); BufferCreator = BufferCreator.CreateWithBuiltInTypes(); ProgramChecks = FLProgramCheckBuilder.CreateDefaultCheckBuilder(InstructionSet, BufferCreator); Parser = new FLParser(InstructionSet, BufferCreator); ProgramChecks.Attach(Parser, true); Instance = instance; ProcessQueue = new Queue <FlScriptExecutionContext>(); }
private static FLDataContainer InitializeCLKernels(string kernelPath) { { CLAPI instance = CLAPI.GetInstance(); Logger.Log(LogType.Log, "Discovering Files in Path: " + kernelPath, 1); string[] files = IOManager.DirectoryExists(kernelPath) ? IOManager.GetFiles(kernelPath, "*.cl") : new string[0]; if (files.Length == 0) { Logger.Log(LogType.Error, "Error: No Files found at path: " + kernelPath, 1); } KernelDatabase dataBase = new KernelDatabase(DataVectorTypes.Uchar1); List <CLProgramBuildResult> results = new List <CLProgramBuildResult>(); bool throwEx = false; int kernelCount = 0; int fileCount = 0; foreach (string file in files) { Logger.Log( LogType.Log, $"[{fileCount}/{files.Length}]Loading: {file} ({kernelCount})", 2 ); try { CLProgram prog = dataBase.AddProgram(instance, file, false, out CLProgramBuildResult res); kernelCount += prog.ContainedKernels.Count; throwEx |= !res; results.Add(res); } catch (Exception e) { Logger.Log(LogType.Error, "ERROR: " + e.Message, 2); } fileCount++; } Logger.Log(LogType.Log, "Kernels Loaded: " + kernelCount, 1); FLInstructionSet iset = FLInstructionSet.CreateWithBuiltInTypes(dataBase); BufferCreator creator = BufferCreator.CreateWithBuiltInTypes(); FLParser parser = new FLParser(iset, creator, new WorkItemRunnerSettings(true, 2)); return(new FLDataContainer(instance, iset, creator, parser)); } }
public FLScriptRunner(CLAPI instance, KernelDatabase dataBase, BufferCreator creator, FLInstructionSet instructionSet, FLProgramCheckBuilder checkBuilder, WorkItemRunnerSettings runnerSettings) { Db = dataBase; InstructionSet = instructionSet; BufferCreator = creator; Parser = new FLParser(InstructionSet, BufferCreator, runnerSettings); ProgramChecks = checkBuilder; checkBuilder.Attach(Parser, true); Instance = instance; ProcessQueue = new Queue <FlScriptExecutionContext>(); }
/// <summary> /// Finds, Parses and Loads all define statements /// </summary> private static void ParseDefines(string key, DefineHandler handler, List <string> source, Dictionary <string, CLBufferInfo> defines, int width, int height, int depth, int channelCount, KernelDatabase kernelDb) { for (int i = source.Count - 1; i >= 0; i--) { if (source[i].StartsWith(key)) { string[] kvp = source[i].Remove(0, key.Length).Split(FunctionNamePostfix); handler?.Invoke(kvp, defines, width, height, depth, channelCount, kernelDb); source.RemoveAt(i); } } }
public Fetch(DatabaseModel model) : base( (() => KernelDatabase.ReplaceSqlValue(@" USE [:P0:] SELECT CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible] FROM master.sys.databases AS dtb WHERE (dtb.name=[:P1:]) SELECT p.name AS [Name], CAST(p.value AS sql_variant) AS [Value] FROM sys.extended_properties AS p WHERE (p.major_id=0 AND p.minor_id=0 AND p.class=0)and(p.name=N'NeuroxContext')", new string[] { "iP0", "cP1" }, model.Name, model.Name)), ((r) => new Access(r)) ) { }
public Fetch(DatabaseModel databaseModel) : base( (() => KernelDatabase.ReplaceSqlValue(@" USE [:P0:] SELECT u.name AS [Name], 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Database[@Name=' + quotename(db_name(),'''') + ']' + '/User[@Name=' + quotename(u.name,'''') + ']' AS [Urn], u.principal_id AS [ID], CAST(CASE dp.state WHEN N'G' THEN 1 WHEN 'W' THEN 1 ELSE 0 END AS bit) AS [HasDBAccess], u.create_date AS [CreateDate] FROM sys.database_principals AS u LEFT OUTER JOIN sys.database_permissions AS dp ON dp.grantee_principal_id = u.principal_id and dp.type = N'CO' WHERE (u.type in ('U', 'S', 'G', 'C', 'K')) ORDER BY [Name] ASC", new string[] { "iP0" }, databaseModel.Name)), (r => new Ordinal(r)), ((ordinal, r) => new DatabaseSecurityLoginModel(ordinal, r)) ) { }
public Fetch(DatabaseModel databaseModel) : base( (() => KernelDatabase.ReplaceSqlValue(@" USE [:P0:] SELECT rl.name AS [Name], 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Database[@Name=' + quotename(db_name(),'''') + ']' + '/Role[@Name=' + quotename(rl.name,'''') + ']' AS [Urn], rl.principal_id AS [ID], CAST(CASE WHEN rl.principal_id > 16383 AND rl.principal_id < 16400 THEN 1 ELSE 0 END AS bit) AS [IsFixedRole], rl.create_date AS [CreateDate], ou.name AS [Owner] FROM sys.database_principals AS rl INNER JOIN sys.database_principals AS ou ON ou.principal_id = rl.owning_principal_id WHERE (rl.type = 'R') ORDER BY [Name] ASC", new string[] { "iP0" }, databaseModel.Name)), (r => new Ordinal(r)), ((ordinal, r) => new DatabaseSecurityRoleModel(ordinal, r)) ) { }
/// <summary> /// Finds, Parses and Loads all define statements /// </summary> private void ParseDefines(CLAPI instance, string key, DefineHandler handler, List <string> source, Dictionary <string, CLBufferInfo> defines, int width, int height, int depth, int channelCount, KernelDatabase kernelDb) { for (int i = source.Count - 1; i >= 0; i--) { if (source[i].StartsWith(key)) { string[] kvp = source[i].Remove(0, key.Length) .Split(new[] { FUNCTION_NAME_POSTFIX }, StringSplitOptions.None); handler?.Invoke(instance, kvp, defines, width, height, depth, channelCount, kernelDb); source.RemoveAt(i); } } }
public void SignatureParsing() { CLAPI instance = CLAPI.GetInstance(); KernelDatabase db = new KernelDatabase(DataVectorTypes.Uchar1); CLProgram program = db.AddProgram(instance, TEST_KERNEL, "./", true, out CLProgramBuildResult result); CLKernel kernel = program.ContainedKernels["set_value"]; Assert.True(CheckParameter(kernel.Parameter["arr"], "arr", true, 0, DataVectorTypes.Uchar1, MemoryScope.Global)); Assert.True(CheckParameter(kernel.Parameter["value"], "value", false, 1, DataVectorTypes.Uchar1, MemoryScope.None)); db.Dispose(); instance.Dispose(); }
private FLScriptData LoadScriptData(CLAPI instance, string file, CLBufferInfo inBuffer, int width, int height, int depth, int channelCount, KernelDatabase db, Dictionary <string, FLInterpreterFunctionInfo> funcs) { Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level6, "Loading Script Data for File: " + file); FLScriptData ret = new FLScriptData(LoadSource(file, channelCount)); ret.Defines.Add(INPUT_BUFFER_NAME, inBuffer); Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level5, "Parsing Texture Defines for File: " + file); ParseDefines(instance, DEFINE_KEY, DefineTexture, ret.Source, ret.Defines, width, height, depth, channelCount, db); Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level5, "Parsing Script Defines for File: " + file); ParseDefines(instance, SCRIPT_DEFINE_KEY, DefineScript, ret.Source, ret.Defines, width, height, depth, channelCount, db); Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level5, "Parsing JumpLocations for File: " + file); ret.JumpLocations = ParseJumpLocations(ret.Source); Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level5, "Parsing Instruction Data for File: " + file); foreach (string line in ret.Source) { Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level3, "Parsing Instruction Data for Line: " + line); FLInstructionData data = GetInstructionData(line, ret.Defines, ret.JumpLocations, funcs, db); Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level3, "Parsed Instruction Data: " + Enum.GetName(typeof(FLInstructionType), data.InstructionType)); ret.ParsedSource.Add(data); } return(ret); }
/// <summary> /// A public constructor /// </summary> /// <param name="file">The file containing the source</param> /// <param name="input">The input buffer</param> /// <param name="width">Width of the input buffer</param> /// <param name="height">Height of the input buffer</param> /// <param name="depth">Depth of the input buffer</param> /// <param name="channelCount">The Channel Count</param> /// <param name="kernelDB">The Kernel DB that will be used</param> /// <param name="ignoreDebug">a flag to ignore the brk statement</param> public Interpreter(string file, MemoryBuffer input, int width, int height, int depth, int channelCount, KernelDatabase kernelDB, bool ignoreDebug) { _flFunctions = new Dictionary <string, FLFunctionInfo> { { "setactive", new FLFunctionInfo(cmd_setactive, false) }, { "rnd", new FLFunctionInfo(cmd_writerandom, false) }, { "urnd", new FLFunctionInfo(cmd_writerandomu, false) }, { "jmp", new FLFunctionInfo(cmd_jump, true) }, { "brk", new FLFunctionInfo(cmd_break, false) } }; NumberParsingHelper.NumberFormat.NumberDecimalSeparator = ","; NumberParsingHelper.NumberFormat.NumberGroupSeparator = "."; Reset(file, input, width, height, depth, channelCount, kernelDB, ignoreDebug); }
/// <summary> /// Overridden Awake method for setting up the Interpreter and add the commands to the console /// </summary> protected override void Awake() { Tex = TextureLoader.ParameterToTexture(width, height); for (int i = 0; i < _previews.Count; i++) { _previews[i].Texture = Tex; } DebugConsoleComponent console = Owner.Scene.GetChildWithName("Console").GetComponent <DebugConsoleComponent>(); console?.AddCommand("runfl", cmd_RunFL); console?.AddCommand("dbgfl", cmd_RunFLStepped); console?.AddCommand("step", cmd_FLStep); console?.AddCommand("r", cmd_FLReset); console?.AddCommand("dbgstop", cmd_FLStop); _db = new KernelDatabase("kernel/", OpenCL.TypeEnums.DataTypes.UCHAR1); }
private void Execute(object obj) { var observer = (IObserver <TModel[]>)obj; try { using (var sqlConnection = KernelDatabase.CreateSqlConnection()) { sqlConnection.Open(); using (var r = new SqlCommand(SqlBuilder(), sqlConnection).ExecuteReader()) { var ordinal = OrdinalBuilder(r); var modelBuilder = ModelBuilder; int bufferIndex = 0; TModel[] buffer = new TModel[10]; while (r.Read()) { buffer[bufferIndex++] = modelBuilder(ordinal, r); if (bufferIndex < 10) { continue; } observer.OnNext(buffer); bufferIndex = 0; buffer = new TModel[10]; } if (bufferIndex > 0) { var partialBuffer = new TModel[bufferIndex]; Array.Copy(buffer, partialBuffer, bufferIndex); observer.OnNext(partialBuffer); } } observer.OnCompleted(); } } catch (Exception ex) { observer.OnError(ex); } }
/// <summary> /// A public constructor /// </summary> /// <param name="instance">CLAPI Instance for the current thread</param> /// <param name="file">The file containing the source</param> /// <param name="input">The input buffer</param> /// <param name="width">Width of the input buffer</param> /// <param name="height">Height of the input buffer</param> /// <param name="depth">Depth of the input buffer</param> /// <param name="channelCount">The Channel Count</param> /// <param name="kernelDb">The Kernel DB that will be used</param> /// <param name="ignoreDebug">a flag to ignore the brk statement</param> public FLInterpreter(CLAPI instance, string file, MemoryBuffer input, int width, int height, int depth, int channelCount, KernelDatabase kernelDb, bool ignoreDebug) { this.instance = instance; flFunctions = new Dictionary <string, FLInterpreterFunctionInfo> { { "setactive", new FLInterpreterFunctionInfo(CmdSetActive, false) }, { "rnd", new FLInterpreterFunctionInfo(CmdWriteRandom, false) }, { "urnd", new FLInterpreterFunctionInfo(CmdWriteRandomU, false) }, { "jmp", new FLInterpreterFunctionInfo(CmdJump, true) }, { "brk", new FLInterpreterFunctionInfo(CmdBreak, false) } }; NumberParsingHelper.NumberFormat.NumberDecimalSeparator = ","; NumberParsingHelper.NumberFormat.NumberGroupSeparator = "."; Reset(file, input, width, height, depth, channelCount, kernelDb, ignoreDebug); }
public void FLKernels() { DebugHelper.ThrowOnAllExceptions = true; DebugHelper.SeverityFilter = 10; string path = "resources/filter/tests"; string[] files = Directory.GetFiles(path, "*.fl"); KernelDatabase db = new KernelDatabase("resources/kernel", OpenCL.TypeEnums.DataTypes.UCHAR1); foreach (string file in files) { Interpreter P = new Interpreter(file, CLAPI.CreateEmpty <byte>(128 * 128 * 4, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite), 128, 128, 1, 4, db); //We need to Create a "fresh" database since xunit is making the cl context invalid when changing the test while (!P.Terminated) { P.Step(); } } }
public static FLInstructionSet CreateWithBuiltInTypes(KernelDatabase db) { FLInstructionSet iset = new FLInstructionSet(); iset.AddInstructionWithDefaultCreator <JumpFLInstruction>("jmp", "X"); iset.AddInstructionWithDefaultCreator <SetActiveFLInstruction>("setactive", "E|EV|EVV|EVVV|EVVVV|VVVV|VVV|VV|V"); iset.AddInstructionWithDefaultCreator <RandomFLInstruction>("rnd", "|B"); iset.AddInstructionWithDefaultCreator <URandomFLInstruction>("urnd", "|B"); iset.AddInstructionWithDefaultCreator <DefineVarFLInstruction>("def", "DV"); iset.AddInstructionWithDefaultCreator <DefineGlobalVarFLInstruction>("gdef", "DV"); iset.AddInstructionWithDefaultCreator <DecrementVarFLInstruction>("dec", "D|DV|DV"); iset.AddInstructionWithDefaultCreator <IncrementVarFLInstruction>("inc", "D|DV|DV"); iset.AddInstructionWithDefaultCreator <BranchLessOrEqualFLInstruction>("ble", "DVX|VVX|DDX"); iset.AddInstructionWithDefaultCreator <BranchGreaterOrEqualFLInstruction>("bge", "DVX|VVX|DDX"); iset.AddInstructionWithDefaultCreator <BranchLessThanFLInstruction>("blt", "DVX|VVX|DDX"); iset.AddInstructionWithDefaultCreator <BranchGreaterThanFLInstruction>("bgt", "DVX|VVX|DDX"); iset.AddInstructionWithDefaultCreator <PrintLineFLInstruction>("print", "A|AA|AAA|AAAA|AAAAA|AAAAAA|AAAAAAA|AAAAAAAA|AAAAAAAAA|AAAAAAAAAA|AAAAAAAAAAA|AAAAAAAAAAAA"); iset.AddInstruction(new KernelFLInstructionCreator(db)); return(iset); }
public void OpenFL_Kernels_Test() { string path = "resources/filter/tests"; string[] files = Directory.GetFiles(path, "*.fl"); KernelDatabase db = new KernelDatabase(CLAPI.MainThread, "resources/kernel", DataTypes.Uchar1); foreach (string file in files) { FLInterpreter p = new FLInterpreter(CLAPI.MainThread, file, CLAPI.CreateEmpty <byte>(CLAPI.MainThread, 64 * 64 * 4, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite), 64, 64, 1, 4, db); //We need to Create a "fresh" database since xunit is making the cl context invalid when changing the test while (!p.Terminated) { p.Step(); } } }
private void Run() { FLConsole.Settings.SetVerbosity(); BufferCreator creator = new BufferCreator(); FLConsole.Settings.BufferCreatorTypes.ForEach(x => creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x))); KernelDatabase db = new KernelDatabase(CLAPI.MainThread, FLConsole.Settings.KernelFolder, DataVectorTypes.Uchar1); FLInstructionSet iset = FLInstructionSet.CreateWithBuiltInTypes(db); FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator); FLConsole.Settings.ProgramCheckTypes.ForEach(x => programCheckBuilder.AddProgramCheck((FLProgramCheck)Activator.CreateInstance(x))); FLScriptRunner runner = new FLScriptRunner(CLAPI.MainThread, db, creator, iset, programCheckBuilder, new WorkItemRunnerSettings(FLConsole.Settings.MultiThread, FLConsole.Settings.WorkSizeMultiplier)); string[] inputFiles = SetInputFilesCommand.InputFiles; string[] outputFiles = SetOutputFilesCommand.OutputFiles; for (int i = 0; i < inputFiles.Length; i++) { string inp = inputFiles[i]; string outp = outputFiles.Length > i ? outputFiles[i] : $"./{Path.GetFileNameWithoutExtension(inp)}.out.png"; Bitmap bmp = new Bitmap(FLConsole.Settings.Resolution.X, FLConsole.Settings.Resolution.Y); runner.Enqueue(new FlScriptExecutionContext(inp, bmp, result => OnFinishCallback(result, outp))); } runner.Process(); }