Skip to content

Commit

Permalink
Since Debug mode runs very slowly, only allow if user sets options fl…
Browse files Browse the repository at this point in the history
…ag, abort at startup if not found.
  • Loading branch information
dje-dev committed Jan 2, 2021
1 parent f6a297c commit 7d92a53
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/Ceres.Base/OperatingSystem/HardwareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using Ceres.Base.Misc;
using Ceres.Base.OperatingSystem.Windows;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -60,11 +61,7 @@ public static void VerifyHardwareSoftwareCompatability()

if (errorString != null)
{
ConsoleColor priorColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Fatal Error. {errorString}");
Console.WriteLine();
Console.ForegroundColor = priorColor;
ConsoleUtils.WriteLineColored(ConsoleColor.Red, $"Fatal Error. {errorString}");
System.Environment.Exit(-1);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/Ceres.Chess/UserSettings/CeresUserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public record CeresUserSettings
/// </summary>
public string URLLC0Networks { get; set; } = @"http://training.lczero.org/networks";

/// <summary>
/// Ceres will not run if compiled in Debug mode
/// (Release required) unless this setting is true
/// or alternately the OS environment variable CERES_DEBUG exists.
/// </summary>
public bool DebugAllowed { get; set; } = false;

#region Metrics and Logging

/// <summary>
Expand Down
34 changes: 30 additions & 4 deletions src/Ceres/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ static void Main(string[] args)

CeresEnvironment.MONITORING_METRICS = CeresUserSettingsManager.Settings.LaunchMonitor;

// if (CeresUserSettingsManager.Settings.DirLC0Networks != null)
// NNWeightsFilesLC0.RegisterDirectory(CeresUserSettingsManager.Settings.DirLC0Networks);
// if (CeresUserSettingsManager.Settings.DirLC0Networks != null)
// NNWeightsFilesLC0.RegisterDirectory(CeresUserSettingsManager.Settings.DirLC0Networks);

MCTSEngineInitialization.BaseInitialize();


#if DEBUG
CheckDebugAllowed();
#endif

if (args.Length > 0 && args[0].ToUpper() == "CUSTOM")
{
TournamentTest.Test(); return;
// SuiteTest.RunSuiteTest(); return;
// SuiteTest.RunSuiteTest(); return;
}

StringBuilder allArgs = new StringBuilder();
Expand All @@ -87,7 +92,28 @@ static void Main(string[] args)


// Win32.WriteCrashdumpFile(@"d:\temp\dump.dmp");
}
}


/// <summary>
/// Because Ceres runs much more slowly under Debug mode (at least 30%)
/// this check verifies a debug bulid will not run unless explicitly
/// requested in the options file or environment variables.
/// </summary>
private static void CheckDebugAllowed()
{
if (!CeresUserSettingsManager.Settings.DebugAllowed
&& Environment.GetEnvironmentVariable("CERES_DEBUG") == null)
{
const string MSG = "ERROR: Ceres was compiled in Debug mode and will only run\r\n"
+ "if the the DebugAllowed option is set to true\r\n"
+ "or the operating system environment variable CERES_DEBUG is defined.";
Console.WriteLine();
ConsoleUtils.WriteLineColored(ConsoleColor.Red, MSG);
System.Environment.Exit(-1);
}
}


const string BannerString =
@"
Expand Down

0 comments on commit 7d92a53

Please sign in to comment.