public static AifFile GetAifFile(out string name)
        {
            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Provide a path to a AIF file. Enter nothing to exit.");

                Console.ForegroundColor = ConsoleColor.White;
                var path = Console.ReadLine();

                if (string.IsNullOrEmpty(path))
                {
                    name = null;
                    return(null);
                }

                if (!File.Exists(path))
                {
                    throw new FileNotFoundException(path);
                }

                var returnValue = new AifFile(path);

                Log.Info(returnValue);

                name = Path.GetFileNameWithoutExtension(path);

                return(returnValue);
            }
            catch (Exception error)
            {
                Log.Error(error);
                return(GetAifFile(out name));
            }
        }
        public static int?GetLatency(AifFile file)
        {
            try
            {
                var minLatency = file.MinCycles.Values.Max();

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"Enter a latency constraint greater then or equal to {minLatency} (enter nothing to exit):");

                Console.ForegroundColor = ConsoleColor.White;
                var line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    return(null);
                }

                var returnValue = Convert.ToInt32(line);
                if (returnValue < minLatency)
                {
                    throw new ArgumentException($"The latency must be greater then or equal to {minLatency}.");
                }

                Log.Info("Latency Constraint: " + returnValue);

                return(returnValue);
            }
            catch (Exception error)
            {
                Log.Error(error);
                return(GetLatency(file));
            }
        }
        public static SchedulerBase GetSchedule(AifFile file)
        {
            try
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Select a scheduler algorithm:");
                Console.WriteLine("\tA) List Scheduler (resource constraints required)");
                Console.WriteLine("\tB) Integer Linear Programing Scheduler (time constraint required)");
                Console.WriteLine("\tC) Exit");

                Console.ForegroundColor = ConsoleColor.White;
                var selection = Console.ReadLine()?.Trim().ToUpper().Substring(0, 1) ?? "C";

                SchedulerBase schedule;
                switch (selection)
                {
                case "A":
                    var resources = GetResources(file);
                    schedule = resources == null ? null : new ListScheduler(file, resources);
                    break;

                case "B":
                    var latency = GetLatency(file);
                    schedule = latency == null ? null : new IlpScheduler(file, latency.Value);
                    break;

                case "C":
                    schedule = null;
                    break;

                default:
                    throw new ArgumentException("Unable to parse answer: " + selection);
                }

                schedule?.BuildSchedule();

                return(schedule);
            }
            catch (Exception error)
            {
                Log.Error(error);
                return(GetSchedule(file));
            }
        }
示例#4
0
        public IlpScheduler(AifFile file, int latency = -1)
            : base(file)
        {
            Log.Info("Generating schedule with integer linear programming.");

            buildOperationCycleRanges(latency);

            Log.Info("Setting up model for ILP.");
            Context = SolverContext.GetContext();
            Context.ClearModel();
            ProblemModel = Context.CreateModel();

            buildLinearModel();

            var solution = Context.Solve(new MixedIntegerProgrammingDirective
            {
                Arithmetic = Arithmetic.Exact
            });

            if (solution.Quality != SolverQuality.Optimal)
            {
                throw new ArgumentException("Unable to find an optimal solution.");
            }

            var cycleCount = OperationCycleRanges.Max(item => item.MaxCycle) + 1;

            Log.Info($"{"Cycle",-10} = " + string.Join(", ", Enumerable.Range(1, cycleCount)
                                                       .Select(cycle => $"{cycle, 2}")));
            foreach (var op in OperationCycleRanges.OrderBy(op => op.Operation.Id))
            {
                Log.Info($"{op.Operation.Name,-10} = " + string.Join(", ", Enumerable.Range(1, cycleCount)
                                                                     .Select(cycle => $"{(op.Variables.ContainsKey(cycle) ? op.Variables[cycle].ToDouble() : 0), 2}")));
            }

            var report = solution.GetReport();

            Log.Trace(report.ToString());
        }
        public static Dictionary <string, int> GetResources(AifFile file)
        {
            try
            {
                var returnValue = new Dictionary <string, int>();
                foreach (var op in file.OperationTypes)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"Enter a resource constraint for {op} that is greater then or equal to 1 (enter nothing to exit):");

                    Console.ForegroundColor = ConsoleColor.White;
                    var line = Console.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        return(null);
                    }

                    var value = Convert.ToInt32(line);
                    if (value < 1)
                    {
                        throw new ArgumentException($"The resource constraint for {op} must be greater then or equal to 1.");
                    }

                    returnValue[op] = value;
                }

                Log.Info("Resource Constraint: " + string.Join(", ", returnValue.Select(pair => $"{pair.Key} = {pair.Value}")));

                return(returnValue);
            }
            catch (Exception error)
            {
                Log.Error(error);
                return(GetResources(file));
            }
        }
 protected SchedulerBase(AifFile file)
 {
     AifFile = file;
 }
示例#7
0
 public ListScheduler(AifFile file, Dictionary <string, int> resources)
     : base(file)
 {
     Resources = resources;
 }
示例#8
0
        public void SaveTestBench(StreamWriter stream, Dictionary <string, string>[] inputAndOutputs)
        {
            writeTestBenchComments(stream);

            stream.WriteLine();
            stream.WriteLine("library IEEE;");
            stream.WriteLine("use IEEE.std_logic_1164.all;");

            stream.WriteLine();
            stream.WriteLine("entity test_me_tb is");
            stream.WriteLine("end test_me_tb;");

            stream.WriteLine();
            stream.WriteLine("architecture test_me of test_me_tb is");

            var registers = writeTestBenchComponents(stream);

            writeTestBenchWires(stream, registers);

            stream.WriteLine();
            stream.WriteLine("begin");

            writeTestBenchTestUnit(stream, registers);

            stream.WriteLine();
            stream.WriteLine("\tprocess");
            stream.WriteLine("\t\tbegin");
            stream.WriteLine("\t\t\twait for 1 ns;");

            foreach (var testCase in inputAndOutputs)
            {
                var values = testCase.ToDictionary(pair => pair.Key, pair => Convert.ToInt64(pair.Value, 2));

                stream.WriteLine();
                foreach (var expression in AifFile.AsExpressions)
                {
                    stream.WriteLine("\t\t\t-- " + expression);
                }
                foreach (var reg in registers.OfType <InputRegister>())
                {
                    stream.WriteLine($"\t\t\t{reg.Name} <= \"{testCase[reg.Name]}\"; -- {values[reg.Name]}");
                }
                stream.WriteLine("\t\t\ts_tart <= '1';");
                stream.WriteLine("\t\t\tclock <= '1'; wait for 1 ns;");
                stream.WriteLine("\t\t\tclock <= '0'; wait for 1 ns;");
                for (var cycle = 1; cycle < Scheduler.Cycles.Length; cycle++)
                {
                    stream.WriteLine("\t\t\tclock <= '1'; wait for 1 ns;");
                    stream.WriteLine("\t\t\tclock <= '0'; wait for 1 ns;");
                }
                foreach (var output in registers.OfType <OutputRegister>())
                {
                    stream.WriteLine($"\t\t\tassert {output.Name} = \"{testCase[output.Name]}\" report \"{AifFile.GetExpression(output, values)}\" severity failure;");
                }
            }

            stream.WriteLine();
            stream.WriteLine("\t\t\twait;");
            stream.WriteLine("\tend process;");
            stream.WriteLine("end test_me;");
        }