Skip to content

Commit

Permalink
Improve version handling, logging, and UI adjustments
Browse files Browse the repository at this point in the history
Fixed Config Loading Issue
Added extra details and checks for requirementsmanager.

Updated error messages to reflect more general version ranges for TensorRT and CUDA/CUDNN. Made `AutoTrigger` method static. Upgraded `Microsoft.ML.OnnxRuntime.Gpu` package to 1.20.0. Added "CPU" execution provider dropdown item and commented out "DirectML". Modified `ReceiveNewConfig` method to include additional parameters and logging. Adjusted execution provider dropdown logic to include "CPU" and default to "CUDA". Improved `IsCUDAInstalled`, `IsCUDNNInstalled`, and `IsTensorRTInstalled` methods for more general version checks and added detailed logging. Removed redundant code and added comments for clarity. Fixed minor formatting issues and enhanced error handling and logging in various methods. Updated `LoadConfig` and `LoadModelsIntoListBox` methods with additional checks and logging. Enhanced `RequirementsManager` for more general version checks and added detailed logging.
  • Loading branch information
TaylorIsBlue committed Nov 25, 2024
1 parent 9b667f9 commit 3fbb69d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 52 deletions.
8 changes: 4 additions & 4 deletions Aimmy2/AILogic/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ private Task LoadModelAsync(SessionOptions sessionOptions, string modelPath, boo
(ex.Message.Contains("LoadLibrary failed with error 126") && ex.Message.Contains("onnxruntime_providers_tensorrt.dll")))
{
if (RequirementsManager.IsTensorRTInstalled())
{
{ // TensorRT should be preinstalled in all aimmy cuda versions, so this should be rare unless user has personally deleted the files.
message = "TensorRT has been found by Aimmy, but not by ONNX. Please check your configuration.\nHint: Check CUDNN and your CUDA, and install dependencies to PATH correctly.";
title = "Configuration Error";
}
else
{
message = "TensorRT execution provider has not been found on your build. Please check your configuration.\nHint: Download TensorRT 10.3.0 and install the LIB folder to path.";
message = "TensorRT execution provider has not been found on your build. Please check your configuration.\nHint: Download TensorRT 10.3.x and install the LIB folder to path.";
title = "TensorRT Error";
}
}
Expand All @@ -279,7 +279,7 @@ private Task LoadModelAsync(SessionOptions sessionOptions, string modelPath, boo
}
else
{
message = "CUDA execution provider has not been found on your build. Please check your configuration.\nHint: Download CUDA 12.6. Then install CUDNN 9.3 to your PATH";
message = "CUDA execution provider has not been found on your build. Please check your configuration.\nHint: Download CUDA 12.x. Then install CUDNN 9.x to your PATH (or install the DLL included aimmy)";
title = "CUDA Error";
}
}
Expand Down Expand Up @@ -406,7 +406,7 @@ private async void AiLoop()
#endregion
#region AI Loop Functions
#region misc
private async Task AutoTrigger()
private static async Task AutoTrigger()
{
if (Dictionary.toggleState["Auto Trigger"] &&
(InputBindingManager.IsHoldingBinding("Aim Keybind") ||
Expand Down
2 changes: 1 addition & 1 deletion Aimmy2/Aimmy2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.19.2" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.20.0" />
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Supercluster.KDTree" Version="1.0.4" />
Expand Down
10 changes: 8 additions & 2 deletions Aimmy2/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ public MainWindow()

uiManager.DDI_TensorRT.Selected += OnExecutionProviderSelected;

Check warning on line 111 in Aimmy2/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

Dereference of a possibly null reference.
uiManager.DDI_CUDA.Selected += OnExecutionProviderSelected;

Check warning on line 112 in Aimmy2/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

Dereference of a possibly null reference.
//uiManager.DDI_DirectML.Selected += OnExecutionProviderSelected;
uiManager.DDI_CPU.Selected += OnExecutionProviderSelected;

Check failure on line 114 in Aimmy2/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'UI' does not contain a definition for 'DDI_CPU' and no accessible extension method 'DDI_CPU' accepting a first argument of type 'UI' could be found (are you missing a using directive or an assembly reference?)

LoadMenuMinimizers();
VisibilityXY();

ActualFOV = Dictionary.sliderSettings["FOV Size"];
PropertyChanger.ReceiveNewConfig = (configPath, load) => FileManager.LoadConfig(uiManager);
PropertyChanger.ReceiveNewConfig = (configPath, load) => FileManager.LoadConfig(uiManager, configPath, true);

PropertyChanger.PostNewFOVSize(Dictionary.sliderSettings["FOV Size"]);
PropertyChanger.PostColor((Color)ColorConverter.ConvertFromString(Dictionary.colorState["FOV Color"]));
Expand Down Expand Up @@ -287,9 +289,11 @@ private void LoadDropdownStates()
};
uiManager.D_ExecutionProvider!.DropdownBox.SelectedIndex = Dictionary.dropdownState["Execution Provider Type"] switch
{
//"DirectML" => 0,
"CUDA" => 0,
"TensorRT" => 1,
_ => 0 // Default case if none of the above matches
"CPU" => 2,
_ => 0 // Default to CUDA
};
}
static void OnExecutionProviderSelected(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -849,8 +853,10 @@ private void LoadSettingsMenu()
};

uiManager.D_ExecutionProvider = AddDropdown(SettingsConfig, "Execution Provider Type");
//uiManager.DDI_DirectML = AddDropdownItem(uiManager.D_ExecutionProvider, "DirectML");
uiManager.DDI_CUDA = AddDropdownItem(uiManager.D_ExecutionProvider, "CUDA");
uiManager.DDI_TensorRT = AddDropdownItem(uiManager.D_ExecutionProvider, "TensorRT");
uiManager.DDI_CPU = AddDropdownItem(uiManager.D_ExecutionProvider, "CPU");

Check failure on line 859 in Aimmy2/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'UI' does not contain a definition for 'DDI_CPU' and no accessible extension method 'DDI_CPU' accepting a first argument of type 'UI' could be found (are you missing a using directive or an assembly reference?)



Expand Down
21 changes: 14 additions & 7 deletions Aimmy2/Other/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void ConfigListBox_DragDrop(object sender, DragEventArgs e)
}
}
}
#endregion
#endregion
#region models
public static bool CurrentlyLoadingModel = false;

Expand Down Expand Up @@ -223,7 +223,7 @@ private async void ModelListBox_SelectionChanged(object sender, SelectionChanged
LogError($"Model path doesn't exist: {modelPath}", true);
return;
}

// Check if the model is already selected or currently loading
if (Dictionary.lastLoadedModel == selectedModel.Name || CurrentlyLoadingModel) return;

Expand All @@ -235,7 +235,7 @@ private async void ModelListBox_SelectionChanged(object sender, SelectionChanged
var model_ = _modelItems.FirstOrDefault(m => m.Name == selectedModelName);
if (model_ != null)
{

model_.IsLoading = true;
}

Expand Down Expand Up @@ -364,11 +364,21 @@ public static async Task<HashSet<string>> RetrieveAndAddFiles(string repoLink, s
public static void LoadConfig(UI uiManager, string path = "bin\\configs\\Default.cfg", bool loading_from_configlist = false)
{
SaveDictionary.LoadJSON(Dictionary.sliderSettings, path);
//LogInfo(path);
//LogInfo(string.Join(", ", Dictionary.sliderSettings.Values));
try
{
if (loading_from_configlist)
{
if (Dictionary.sliderSettings["Suggested Model"] != "N/A" || Dictionary.sliderSettings["Suggested Model"] != "")
//LogInfo("Loading From Config List");

if (uiManager == null)
{
LogError("UI Manager is null");
return;
}

if (Dictionary.sliderSettings["Suggested Model"] != "N/A" && Dictionary.sliderSettings["Suggested Model"] != "")
{
MessageBox.Show(
"The creator of this model suggests you use this model:\n" +
Expand All @@ -395,13 +405,10 @@ public static void LoadConfig(UI uiManager, string path = "bin\\configs\\Default

uiManager.S_EMASmoothing!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "EMA Smoothening", 0.5);

uiManager.S_AutoTriggerDelay!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "Auto Trigger Delay", 0.1);

uiManager.S_DPOpacity!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "Opacity", 1);
uiManager.S_DPCornerRadius!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "Corner Radius", 0);
uiManager.S_DPBorderThickness!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "Border Thickness", 1);
uiManager.S_DPFontSize!.Slider.Value = Dictionary.GetValueOrDefault(Dictionary.sliderSettings, "AI Confidence Font Size", 20);

}
}

Expand Down
116 changes: 78 additions & 38 deletions Aimmy2/Other/RequirementsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public static bool CheckForRequirements()

if (!IsCUDAInstalled())
{
MessageBox.Show("You don't have 12.6 CUDA Installed (or its improper install), you may not be able to use Aimmy.", "Aimmy");
MessageBox.Show("You don't have 12.x CUDA Installed (or its improper install), you may not be able to use Aimmy.", "Aimmy");
}

if (!IsCUDNNInstalled())
{
MessageBox.Show("You don't have 9.3 CUDNN Installed (or its improper install), you may not be able to use Aimmy.", "Aimmy");
MessageBox.Show("You don't have 9.x CUDNN Installed (or its improper install), you may not be able to use Aimmy.", "Aimmy");
return false;
}

Expand All @@ -67,26 +67,48 @@ public static bool IsCUDAInstalled()
{
try
{
string directory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin";
string baseDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
string envCudaPath = Environment.GetEnvironmentVariable("CUDA_PATH") ?? "";

if (Directory.Exists(directory) || envCudaPath == directory)
if (Directory.Exists(baseDirectory))
{
FileManager.LogInfo("CUDA 12.6 is installed");
return true;
}
var cudaDirectories = Directory.GetDirectories(baseDirectory, "v12.*");

foreach (var directory in cudaDirectories)
{
if (Directory.Exists(Path.Combine(directory, "bin")))
{
FileManager.LogInfo($"CUDA 12.x found in directory: {directory}");
return true;
}
}
}

//maybe they installed it on a different harddrive, or what if they wanna be different and change their local drive from C to D
string keyPath = @"SOFTWARE\NVIDIA Corporation\GPU Computing Toolkit\CUDA\v12.6";
using var key = Registry.LocalMachine.OpenSubKey(keyPath);
if (!string.IsNullOrEmpty(envCudaPath) && envCudaPath.Contains("CUDA\\v12."))
{
FileManager.LogInfo("CUDA 12.x found via CUDA_PATH environment variable.");
return true;
}

object? installedValue = key?.GetValue("64BitInstalled");
string registryBasePath = @"SOFTWARE\NVIDIA Corporation\GPU Computing Toolkit\CUDA";
using var baseKey = Registry.LocalMachine.OpenSubKey(registryBasePath);

if (installedValue != null && (int)installedValue == 1)
if (baseKey != null)
{
FileManager.LogInfo("CUDA 12.6 is installed");
return true;
var versionKeys = baseKey.GetSubKeyNames()
.Where(name => name.StartsWith("v12."));
foreach (var versionKey in versionKeys)
{
using var key = baseKey.OpenSubKey(versionKey);
object? installedValue = key?.GetValue("64BitInstalled");

if (installedValue != null && (int)installedValue == 1)
{
FileManager.LogInfo($"CUDA {versionKey} is installed as per registry.");
return true;
}
}
}

string[] dlls =
Expand Down Expand Up @@ -129,37 +151,45 @@ public static bool IsCUDNNInstalled()
{
try
{
string directory = @"C:\Program Files\NVIDIA\CUDNN\v9.3\bin";
string cudnnDirectoryBase = @"C:\Program Files\NVIDIA\CUDNN";
string aimmyDirectory = AppDomain.CurrentDomain.BaseDirectory;

if (Directory.Exists(directory) ||
Directory.Exists(directory + "\\12.6"))
// Check if there's a folder starting with "v9." in the NVIDIA CUDNN directory
if (Directory.Exists(cudnnDirectoryBase))
{
FileManager.LogInfo("CUDNN 9.3 is installed");
return true;
var cudnnDirectories = Directory.GetDirectories(cudnnDirectoryBase, "v9.*");

foreach (var directory in cudnnDirectories)
{
if (Directory.Exists(Path.Combine(directory, "bin")))
{
FileManager.LogInfo($"cuDNN 9.x found in directory: {directory}");
return true;
}
}
}

if(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "cudnn64_9.dll"))) {
FileManager.LogInfo("CUDNN 9.3 was found in aimmy directory.");
if (File.Exists(Path.Combine(aimmyDirectory, "cudnn64_9.dll")))
{
FileManager.LogInfo("cuDNN 9.x was found in the Aimmy directory.");
return true;
}

// maybe they installed it on a different harddrive, or what if they wanna be different and change their local drive from C to D
string path = Environment.GetEnvironmentVariable("PATH") ?? "";

if (string.IsNullOrEmpty(path)) return false;

if (path.Contains("CUDNN\\v9.3"))
if (!string.IsNullOrEmpty(path) && path.Contains("CUDNN\\v9."))
{
FileManager.LogInfo("CUDNN 9.3 may be installed"); // could be in CUDNN/v9.3 or CUDNN/v9.3/12.6
return true; //maybe.
FileManager.LogInfo("cuDNN 9.x may be installed and referenced in PATH.");
return true;
}

FileManager.LogError("CUDNN 9.3 is not installed");
FileManager.LogError("CUDNN 9.x is not installed");
return false;
}
catch (Exception ex)
{
FileManager.LogError($"Error while checking for CUDNN 9.3: {ex}");
FileManager.LogError($"Error while checking for CUDNN: {ex}");
return false;
}
}
Expand All @@ -175,19 +205,29 @@ public static bool IsTensorRTInstalled()
"nvinfer_plugin_10.dll",
"nvonnxparser_10.dll",
];
string baseDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin";
string baseDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
string exeDirectory = AppDomain.CurrentDomain.BaseDirectory;

bool dllExists = false;

foreach (string dll in dlls)
{
if (File.Exists(baseDirectory + "\\" + dll))
// Search through CUDA directories for any version containing the DLLs
if (Directory.Exists(baseDirectory))
{
FileManager.LogInfo($"Found TensorRT DLL {dll}");
dllExists = true;
var cudaDirectories = Directory.GetDirectories(baseDirectory, "v*");
foreach (var directory in cudaDirectories)
{
if (File.Exists(Path.Combine(directory, "bin", dll)))
{
FileManager.LogInfo($"Found TensorRT DLL {dll} in {directory}\\bin");
dllExists = true;
}
}
}
else if (File.Exists(Path.Combine(exeDirectory, dll)))

// Check if the DLL is in the application's executable directory
if (File.Exists(Path.Combine(exeDirectory, dll)))
{
FileManager.LogInfo($"Found TensorRT DLL {dll} in executable directory");
dllExists = true;
Expand All @@ -204,19 +244,19 @@ public static bool IsTensorRTInstalled()

string path = Environment.GetEnvironmentVariable("PATH") ?? "";

if (string.IsNullOrEmpty(path)) return false;

if (path.Contains("TensorRT-10.3.0.26") || path.Contains("TensorRT"))
if (!string.IsNullOrEmpty(path) && path.Contains("TensorRT"))
{
FileManager.LogInfo("TensorRT 10.3.0 may be installed", true, 1000);
return true; //maybe.
FileManager.LogInfo("TensorRT may be installed based on PATH environment variable.");
return true;
}


FileManager.LogError("TensorRT not found.");
return false;
}
catch (Exception ex)
{
FileManager.LogError($"Error while checking for TensorRT 10.3.0: {ex}");
FileManager.LogError($"Error while checking for TensorRT: {ex}");
return false;
}
}
Expand Down

0 comments on commit 3fbb69d

Please sign in to comment.