Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            LConfig = new LoggerConfiguration()
                      .Enrich.FromLogContext()
                      .MinimumLevel.Debug()
                      .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss}<{ThreadId:d2}> [{Level:u3}] {Message}{NewLine}{Exception}")
                      .WriteTo.File("OpGen.log");
            L = Log.Logger = LConfig.CreateLogger();
            Parser p = new Parser();
            ParserResult <Options> result = p.ParseArguments <Options>(args);

            result.WithNotParsed((IEnumerable <Error> errors) =>
            {
                HelpText help            = GetAutoBuiltHelpText(result);
                help.MaximumDisplayWidth = Console.WindowWidth;
                help.Copyright           = string.Empty;
                help.Heading             = new HeadingInfo("Sylvester.tf OpGen CLI", Version.ToString(3));
                help.AddPreOptionsLine(string.Empty);
                if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
                {
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
                {
                    HelpVerbRequestedError error = (HelpVerbRequestedError)errors.First(e => e.Tag == ErrorType.HelpVerbRequestedError);
                    if (error.Type != null)
                    {
                        help.AddVerbs(error.Type);
                    }
                    else
                    {
                        help.AddVerbs(typeof(Options));
                    }
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpRequestedError))
                {
                    help.AddOptions(result);
                    L.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingRequiredOptionError))
                {
                    MissingRequiredOptionError error = (MissingRequiredOptionError)errors.First(e => e is MissingRequiredOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing: {error.NameInfo.NameText} The options and values for this benchmark category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingValueOptionError))
                {
                    MissingValueOptionError error = (MissingValueOptionError)errors.First(e => e.Tag == ErrorType.MissingValueOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing. The options and values for this category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.UnknownOptionError))
                {
                    UnknownOptionError error = (UnknownOptionError)errors.First(e => e.Tag == ErrorType.UnknownOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"Unknown option: {error.Token}.");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else
                {
                    help.AddPreOptionsLine($"An error occurred parsing the program options: {string.Join(" ", errors.Select(e => e.Tag.ToString()).ToArray())}");
                    help.AddVerbs(typeof(Options));
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
            })
            .WithParsed(o =>
            {
                Generator = new Generator(o.OutputFileName);
                var dirs  = !string.IsNullOrEmpty(o.Dirs) ? o.Dirs.Split(',') : Array.Empty <string>();
                if (dirs.Length == 1)
                {
                    L.Information("Using {0} TensorFlow op def directory.", 1);
                }
                else
                {
                    L.Information("Using {0} TensorFlow op def directories.", dirs.Length);
                }
                Generator.Run(dirs, o.Op);
                Exit(ExitResult.SUCCESS);
            });
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            LConfig = new LoggerConfiguration()
                      .Enrich.FromLogContext()
                      .MinimumLevel.Debug()
                      .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss}<{ThreadId:d2}> [{Level:u3}] {Message}{NewLine}{Exception}");
            L = Log.Logger = LConfig.CreateLogger();
            Type[]     BindOptionTypes      = Assembly.GetExecutingAssembly().GetTypes().Where(t => t == typeof(Options) || t.IsSubclassOf(typeof(Options))).ToArray();
            MethodInfo parseArgumentsMethod = typeof(ParserExtensions).GetMethods().Where(m => m.IsGenericMethod && m.Name == "ParseArguments" &&
                                                                                          m.GetGenericArguments().Count() == BindOptionTypes.Count()).First();
            Parser p = new Parser();
            ParserResult <object> result = (ParserResult <object>)parseArgumentsMethod.MakeGenericMethod(BindOptionTypes).Invoke(p, new object[] { p, args });

            result.WithNotParsed((IEnumerable <Error> errors) =>
            {
                HelpText help            = GetAutoBuiltHelpText(result);
                help.MaximumDisplayWidth = Console.WindowWidth;
                help.Copyright           = string.Empty;
                help.Heading             = new HeadingInfo("Sylvester Bindings CLI", Version.ToString(3));
                help.AddPreOptionsLine(string.Empty);
                if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
                {
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
                {
                    HelpVerbRequestedError error = (HelpVerbRequestedError)errors.First(e => e.Tag == ErrorType.HelpVerbRequestedError);
                    if (error.Type != null)
                    {
                        help.AddVerbs(error.Type);
                    }
                    else
                    {
                        help.AddVerbs(BindOptionTypes);
                    }
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpRequestedError))
                {
                    help.AddOptions(result);
                    L.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.NoVerbSelectedError))
                {
                    help.AddVerbs(BindOptionTypes);
                    help.AddPreOptionsLine("No library selected. Select a library or verb from the options below:");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingRequiredOptionError))
                {
                    MissingRequiredOptionError error = (MissingRequiredOptionError)errors.First(e => e is MissingRequiredOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing: {error.NameInfo.NameText} The options and values for this benchmark category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingValueOptionError))
                {
                    MissingValueOptionError error = (MissingValueOptionError)errors.First(e => e.Tag == ErrorType.MissingValueOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing. The options and values for this category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.UnknownOptionError))
                {
                    UnknownOptionError error = (UnknownOptionError)errors.First(e => e.Tag == ErrorType.UnknownOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"Unknown option: {error.Token}.");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else
                {
                    help.AddPreOptionsLine($"An error occurred parsing the program options: {string.Join(" ", errors.Select(e => e.Tag.ToString()).ToArray())}");
                    help.AddVerbs(BindOptionTypes);
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
            })
            .WithParsed <Options>(o =>
            {
                if (string.IsNullOrEmpty(o.ModuleName))
                {
                    Log.Error($"You must select a module to create bindings for. Use the --help option to get the list of available modules.");
                    Exit(ExitResult.INVALID_OPTIONS);
                }

                if (!string.IsNullOrEmpty(o.Root) && !Directory.Exists(o.Root))
                {
                    Log.Error($"The library root directory specified {o.Root} does not exist.");
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (!string.IsNullOrEmpty(o.Root))
                {
                    ProgramOptions.Add("RootDirectory", new DirectoryInfo(o.Root));
                }
                foreach (PropertyInfo prop in o.GetType().GetProperties())
                {
                    ProgramOptions.Add(prop.Name, prop.GetValue(o));
                }
            })
            .WithParsed <PlaidMLOptions>(o =>
            {
                if (!File.Exists(Path.Combine(AssemblyDirectory.FullName, "plaidml", "base.h")))
                {
                    L.Error($"The PlaidML header file {Path.Combine(AssemblyDirectory.FullName, "plaidml", "base.h")} was not found.");
                    Exit(ExitResult.FILE_MISSING);
                }
                else if (!File.Exists(Path.Combine(AssemblyDirectory.FullName, "plaidml", "plaidml.h")))
                {
                    L.Error($"The PlaidML header file {Path.Combine(AssemblyDirectory.FullName, "plaidml", "plaidml.h")} was not found.");
                    Exit(ExitResult.FILE_MISSING);
                }
                ProgramLibrary = new PlaidML(ProgramOptions);
                ConsoleDriver.Run(ProgramLibrary);
                if (ProgramLibrary.CleanAndFixup())
                {
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    Exit(ExitResult.ERROR_DURING_CLEANUP);
                }
            })
            .WithParsed <TensorFlowOptions>(o =>
            {
                if (!File.Exists(Path.Combine(AssemblyDirectory.FullName, "tf", "c_api.h")))
                {
                    L.Error($"The TensorFlow header file {Path.Combine(AssemblyDirectory.FullName, "tf", "c_api.h")} was not found.");
                    Exit(ExitResult.FILE_MISSING);
                }
                ProgramLibrary = new TensorFlow(ProgramOptions);
                ConsoleDriver.Run(ProgramLibrary);
                if (ProgramLibrary.CleanAndFixup())
                {
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    Exit(ExitResult.ERROR_DURING_CLEANUP);
                }
            });
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            LConfig = new LoggerConfiguration()
                      .Enrich.FromLogContext()
                      .Enrich.WithThreadId()
                      .Enrich.WithProcessId()
                      .MinimumLevel.Debug()
                      .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss}<{ThreadId:d2}> [{Level:u3}] {Message}{NewLine}{Exception}");
            L = Log.Logger = LConfig.CreateLogger();
            Type[] BenchmarkOptionTypes  = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(Options))).ToArray();
            ParserResult <object> result = new Parser().ParseArguments <Options, MallocBenchmarkOptions, NativeArrayBenchmarkOptions, HugeNativeArrayBenchmarkOptions>(args);

            result.WithNotParsed((IEnumerable <Error> errors) =>
            {
                HelpText help            = GetAutoBuiltHelpText(result);
                help.MaximumDisplayWidth = Console.WindowWidth;
                help.Copyright           = string.Empty;
                help.Heading             = new HeadingInfo("jemalloc.NET", Version.ToString(3));
                help.AddPreOptionsLine(string.Empty);
                if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
                {
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
                {
                    HelpVerbRequestedError error = (HelpVerbRequestedError)errors.First(e => e.Tag == ErrorType.HelpVerbRequestedError);
                    if (error.Type != null)
                    {
                        help.AddVerbs(error.Type);
                    }
                    Log.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.HelpRequestedError))
                {
                    help.AddVerbs(BenchmarkOptionTypes);
                    L.Information(help);
                    Exit(ExitResult.SUCCESS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.NoVerbSelectedError))
                {
                    help.AddVerbs(BenchmarkOptionTypes);
                    help.AddPreOptionsLine("No category selected. Select a category from the options below:");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingRequiredOptionError))
                {
                    MissingRequiredOptionError error = (MissingRequiredOptionError)errors.First(e => e is MissingRequiredOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing. The options and values for this benchmark category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.MissingValueOptionError))
                {
                    MissingValueOptionError error = (MissingValueOptionError)errors.First(e => e.Tag == ErrorType.MissingValueOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"A required option or value is missing. The options and values for this benchmark category are: ");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else if (errors.Any(e => e.Tag == ErrorType.UnknownOptionError))
                {
                    UnknownOptionError error = (UnknownOptionError)errors.First(e => e.Tag == ErrorType.UnknownOptionError);
                    help.AddOptions(result);
                    help.AddPreOptionsLine($"Unknown option: {error.Token}.");
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
                else
                {
                    help.AddPreOptionsLine($"An error occurred parsing the program options: {string.Join(' ', errors.Select(e => e.Tag.ToString()).ToArray())}");
                    help.AddVerbs(BenchmarkOptionTypes);
                    L.Information(help);
                    Exit(ExitResult.INVALID_OPTIONS);
                }
            })
            .WithParsed((Options o) =>
            {
                foreach (PropertyInfo prop in o.GetType().GetProperties())
                {
                    BenchmarkOptions.Add(prop.Name, prop.GetValue(o));
                }
                if (o.ColdStart)
                {
                    JemBenchmarkJobAttribute.ColdStartOverride = true;
                }
                if (o.TargetCount > 0)
                {
                    JemBenchmarkJobAttribute.TargetCountOverride = o.TargetCount;
                }
            })
            .WithParsed <MallocBenchmarkOptions>(o =>
            {
                BenchmarkOptions.Add("Category", Category.MALLOC);
                if (o.Create)
                {
                    BenchmarkOptions.Add("Operation", Operation.CREATE);
                }
                else if (o.Fill)
                {
                    BenchmarkOptions.Add("Operation", Operation.FILL);
                }

                if (!BenchmarkOptions.ContainsKey("Operation"))
                {
                    Log.Error("You must select an operation to benchmark with --fill.");
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    Benchmark(o);
                }
            })

            .WithParsed <NativeArrayBenchmarkOptions>(o =>
            {
                BenchmarkOptions.Add("Category", Category.NARRAY);
                if (o.Create)
                {
                    BenchmarkOptions.Add("Operation", Operation.CREATE);
                }
                else if (o.Fill)
                {
                    BenchmarkOptions.Add("Operation", Operation.FILL);
                }
                else if (o.Math)
                {
                    BenchmarkOptions.Add("Operation", Operation.MATH);
                }

                if (!BenchmarkOptions.ContainsKey("Operation"))
                {
                    Log.Error("You must select an operation to benchmark with --create or --fill.");
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    Benchmark(o);
                }
            })

            .WithParsed <HugeNativeArrayBenchmarkOptions>(o =>
            {
                BenchmarkOptions.Add("Category", Category.HUGEARRAY);
                if (o.Create)
                {
                    BenchmarkOptions.Add("Operation", Operation.CREATE);
                }
                else if (o.Fill)
                {
                    BenchmarkOptions.Add("Operation", Operation.FILL);
                }
                else if (o.Math)
                {
                    BenchmarkOptions.Add("Operation", Operation.MATH);
                }

                if (!BenchmarkOptions.ContainsKey("Operation"))
                {
                    Log.Error("You must select an operation to benchmark with --create or --fill or --math.");
                    Exit(ExitResult.SUCCESS);
                }
                else
                {
                    Benchmark(o);
                }
            });
        }
Exemplo n.º 4
0
        public static string GetHelpForInvalidOptions(ParserResult <object> result, IEnumerable <Error> errors)
        {
            Type[]   stageTypes = GetSubTypes <Stage>(ExplicitAssemblyName);
            HelpText help       = HelpText.AutoBuild(result, h =>
            {
                h.AddOptions(result);
                return(h);
            },
                                                     e =>
            {
                return(e);
            },
                                                     true);

            help.MaximumDisplayWidth = Console.WindowWidth;
            help.Copyright           = string.Empty;
            help.Heading             = new HeadingInfo("ClassifyBot", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));
            help.AddPreOptionsLine(string.Empty);

            if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
            {
                help.Heading = string.Empty;
                return("{2}{0}v{1}".F(FiggleFonts.Chunky.Render("ClassifyBot"), Assembly.GetExecutingAssembly().GetName().Version.ToString(4), Environment.NewLine));
            }
            else if (errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
            {
                HelpVerbRequestedError error = (HelpVerbRequestedError)errors.First(e => e.Tag == ErrorType.HelpVerbRequestedError);
                if (error.Type != null)
                {
                    help.AddVerbs(error.Type);
                }
                else
                {
                    help.AddVerbs(stageTypes);
                }

                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.HelpRequestedError))
            {
                HelpRequestedError error = (HelpRequestedError)errors.First(e => e.Tag == ErrorType.HelpRequestedError);
                help.AddOptions(result);
                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.NoVerbSelectedError))
            {
                help.AddVerbs(stageTypes);
                help.AddPreOptionsLine("No stage selected. Select a stage or verb from the ones listed below:");
                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.BadVerbSelectedError))
            {
                BadVerbSelectedError error = (BadVerbSelectedError)errors.First(e => e.Tag == ErrorType.BadVerbSelectedError);
                help.AddVerbs(stageTypes);
                help.AddPreOptionsLine($"Unknown stage: {error.Token}. Valid stages and verbs are:");
                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.MissingRequiredOptionError))
            {
                MissingRequiredOptionError error = (MissingRequiredOptionError)errors.First(e => e is MissingRequiredOptionError);
                help.AddOptions(result);
                help.AddPreOptionsLine($"A required option or value is missing. The options and values for this stage are: ");
                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.MissingValueOptionError))
            {
                MissingValueOptionError error = (MissingValueOptionError)errors.First(e => e.Tag == ErrorType.MissingValueOptionError);
                help.AddOptions(result);
                help.AddPreOptionsLine($"A required option or value is missing. The options and values for this stage are: ");
                return(help);
            }
            else if (errors.Any(e => e.Tag == ErrorType.UnknownOptionError))
            {
                UnknownOptionError error = (UnknownOptionError)errors.First(e => e.Tag == ErrorType.UnknownOptionError);
                help.AddOptions(result);
                help.AddPreOptionsLine($"Unknown option: {error.Token}.");
                return(help);
            }
            else
            {
                help.AddPreOptionsLine($"An error occurred parsing the program options: {string.Join(" ", errors.Select(e => e.Tag.ToString()).ToArray())}");
                help.AddVerbs(stageTypes);
                return(help);
            }
        }