Hide certain settings based on conditions, auto-pick DAIN tile size based on VRAM

This commit is contained in:
N00MKRAD
2024-11-21 01:22:31 +01:00
parent 8a578daac0
commit 7aab7158fa
13 changed files with 1077 additions and 513 deletions

View File

@@ -14,7 +14,7 @@ namespace Flowframes
{
public class Cli
{
public static bool ShowConsole = false;
public static bool Debug = false;
public static bool DisablePython = true;
public static bool ShowMdlDownloader = false;
public static bool CloseMdlDownloaderWhenDone = false;
@@ -43,6 +43,10 @@ namespace Flowframes
var optsSet = new OptionSet
{
{
"d|debug", "Enable debug/developer features and experimental or deprecated options",
v => Debug = v != null
},
{
"np|no_python", "Disable Python implementations",
v => DisablePython = v != null

View File

@@ -437,5 +437,29 @@ namespace Flowframes
{
return Math.Abs(a - b) < tolerance;
}
public static float GetVramGb(this NvAPIWrapper.GPU.PhysicalGPU gpu)
{
try
{
return gpu.MemoryInformation.AvailableDedicatedVideoMemoryInkB / 1024f / 1000f;
}
catch
{
return 0f;
}
}
public static float GetFreeVramGb(this NvAPIWrapper.GPU.PhysicalGPU gpu)
{
try
{
return gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB / 1024f / 1000f;
}
catch
{
return 0f;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,9 +2,11 @@
using Flowframes.IO;
using Flowframes.Media;
using Flowframes.MiscUtils;
using Flowframes.Os;
using Flowframes.Ui;
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -169,6 +171,28 @@ namespace Flowframes.Forms
ConfigParser.LoadGuiElement(ffEncArgs);
}
private void SetVisibility ()
{
// Dev options
List<Control> devOptions = new List<Control> { panKeepTempFolder, };
devOptions.ForEach(c => c.SetVisible(Program.Debug));
// Legacy/deprecated/untested options
List<Control> legacyUntestedOptions = new List<Control> { panProcessingStyle, panEnableAlpha, panHqJpegImport };
legacyUntestedOptions.ForEach(c => c.SetVisible(Program.Debug));
// AutoEnc options
bool autoEncEnabled = autoEncMode.SelectedIndex != 0;
List<Control> autoEncOptions = new List<Control> { panAutoEncBackups, panAutoEncLowSpaceMode };
autoEncOptions.ForEach(c => c.SetVisible(autoEncEnabled));
panAutoEncInSbsMode.SetVisible(autoEncEnabled && panProcessingStyle.Visible);
var availAis = Implementations.NetworksAvailable;
panTorchGpus.SetVisible(NvApi.NvGpus.Count > 0 && Python.IsPytorchReady());
panNcnnGpus.SetVisible(VulkanUtils.VkDevices.Count > 0);
panRifeCudaHalfPrec.SetVisible(NvApi.NvGpus.Count > 0 && availAis.Contains(Implementations.rifeCuda));
}
private void tempFolderLoc_SelectedIndexChanged(object sender, EventArgs e)
{
tempDirBrowseBtn.Visible = tempFolderLoc.SelectedIndex == 4;
@@ -229,7 +253,7 @@ namespace Flowframes.Forms
private void autoEncMode_SelectedIndexChanged(object sender, EventArgs e)
{
autoEncBlockPanel.Visible = autoEncMode.SelectedIndex == 0;
SetVisibility();
}
private async void resetBtn_Click(object sender, EventArgs e)
@@ -253,6 +277,8 @@ namespace Flowframes.Forms
private void settingsTabList_SelectedIndexChanged(object sender, EventArgs e)
{
SetVisibility();
if (!_sizeFixApplied)
{
Size = new Size(Width + 1, Height + 1);

View File

@@ -120,6 +120,9 @@
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="info1.ToolTip" xml:space="preserve">
<value>Set the filename patterns using placeholders:
[NAME] for the input filename

View File

@@ -1,4 +1,5 @@
using Flowframes.Forms;
using Flowframes.Utilities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -157,7 +158,7 @@ namespace Flowframes.IO
public static bool GetBool(Key key, bool defaultVal = false)
{
WriteIfDoesntExist(key.ToString(), (defaultVal ? "True" : "False"));
WriteIfDoesntExist(key.ToString(), (defaultVal ? true : false).ToString());
return Get(key, Type.Bool).GetBool();
}
@@ -168,7 +169,7 @@ namespace Flowframes.IO
public static bool GetBool(string key, bool defaultVal)
{
WriteIfDoesntExist(key.ToString(), (defaultVal ? "True" : "False"));
WriteIfDoesntExist(key.ToString(), (defaultVal ? true : false).ToString());
return bool.Parse(Get(key, Type.Bool));
}
@@ -258,22 +259,22 @@ namespace Flowframes.IO
return WriteDefault(keyStr, "");
}
if (key == Key.disablePreview) return WriteDefault(key, "True");
if (key == Key.disablePreview) return WriteDefault(key, true);
if (key == Key.maxVidHeight) return WriteDefault(key, "2160");
if (key == Key.clearLogOnInput) return WriteDefault(key, "True");
if (key == Key.clearLogOnInput) return WriteDefault(key, true);
if (key == Key.tempDirCustom) return WriteDefault(key, "D:/");
if (key == Key.exportNamePattern) return WriteDefault(key, "[NAME]-[FACTOR]x-[MODEL]-[FPS]fps");
if (key == Key.exportNamePatternLoop) return WriteDefault(key, "-Loop[LOOPS]");
// Interpolation
if (key == Key.dedupThresh) return WriteDefault(key, "2");
if (key == Key.keepAudio) return WriteDefault(key, "True");
if (key == Key.keepSubs) return WriteDefault(key, "True");
if (key == Key.keepMeta) return WriteDefault(key, "True");
if (key == Key.scnDetect) return WriteDefault(key, "True");
if (key == Key.keepAudio) return WriteDefault(key, true);
if (key == Key.keepSubs) return WriteDefault(key, true);
if (key == Key.keepMeta) return WriteDefault(key, true);
if (key == Key.scnDetect) return WriteDefault(key, true);
if (key == Key.scnDetectValue) return WriteDefault(key, "0.2");
if (key == Key.sceneChangeFillMode) return WriteDefault(key, "0");
if (key == Key.autoEncMode) return WriteDefault(key, "2");
if (key == Key.jpegFrames) return WriteDefault(key, "True");
if (key == Key.jpegFrames) return WriteDefault(key, true);
// Video Export
if (key == Key.minOutVidLength) return WriteDefault(key, "5");
if (key == Key.gifDitherType) return WriteDefault(key, "bayer");
@@ -283,15 +284,21 @@ namespace Flowframes.IO
if (key == Key.torchGpus) return WriteDefault(key, "0");
if (key == Key.ncnnGpus) return WriteDefault(key, "0");
if (key == Key.ncnnThreads) return WriteDefault(key, "0");
if (key == Key.dainNcnnTilesize) return WriteDefault(key, "768");
if (key == Key.dainNcnnTilesize) return WriteDefault(key, NcnnUtils.GetDainNcnnTileSizeBasedOnVram(768).ToString());
// Debug / Other / Experimental
if (key == Key.ffEncPreset) return WriteDefault(key, "fast");
if (key == Key.sbsRunPreviousStepIfNeeded) return WriteDefault(key, "True");
if (key == Key.sbsRunPreviousStepIfNeeded) return WriteDefault(key, true);
if (type == Type.Int || type == Type.Float) return WriteDefault(key, "0"); // Write default int/float (0)
if (type == Type.Bool) return WriteDefault(key, "False"); // Write default bool (False)
if (type == Type.Bool) return WriteDefault(key, false); // Write default bool (False)
return WriteDefault(key, "");
}
private static string WriteDefault(Key key, object def)
{
Set(key, def.ToString());
return def.ToString();
}
private static string WriteDefault(Key key, string def)
{
Set(key, def);

View File

@@ -161,7 +161,7 @@ namespace Flowframes.Main
}
}
public static bool CheckAiAvailable(AiInfo ai, ModelCollection.ModelInfo model)
public static bool CheckAiAvailable(AiInfo ai, ModelCollection.ModelInfo model, bool allowNullModel = false)
{
if (IoUtils.GetAmountOfFiles(Path.Combine(Paths.GetPkgPath(), ai.PkgDir), true) < 1)
{
@@ -170,14 +170,14 @@ namespace Flowframes.Main
return false;
}
if (model == null || model.Dir.Trim() == "")
if (!allowNullModel && (model == null || model.Dir.Trim() == ""))
{
UiUtils.ShowMessageBox("No valid AI model has been selected!", UiUtils.MessageType.Error);
I.Cancel("No valid model selected.", true);
return false;
}
if (I.currentSettings.ai.NameInternal.Upper().Contains("CUDA") && NvApi.gpuList.Count < 1)
if (I.currentSettings.ai.NameInternal.Upper().Contains("CUDA") && NvApi.NvGpus.Count < 1)
{
UiUtils.ShowMessageBox("Warning: No Nvidia GPU was detected. CUDA might fall back to CPU!\n\nTry an NCNN implementation instead if you don't have an Nvidia GPU.", UiUtils.MessageType.Error);

View File

@@ -4,14 +4,15 @@ using NvAPIWrapper.GPU;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Flowframes.Os
{
class NvApi
{
public enum Architecture { Undetected, Fermi, Kepler, Maxwell, Pascal, Turing, Ampere };
public static List<PhysicalGPU> gpuList = new List<PhysicalGPU>();
public enum Architecture { Undetected, Fermi, Kepler, Maxwell, Pascal, Turing, Ampere, Ada, Blackwell };
public static List<PhysicalGPU> NvGpus = new List<PhysicalGPU>();
public static PhysicalGPU GpuWithMostVram = null;
public static int GpuWithMostVramId => NvGpus.IndexOf(GpuWithMostVram);
public static void Init()
{
@@ -24,16 +25,22 @@ namespace Flowframes.Os
if (gpus.Length == 0)
return;
gpuList = gpus.ToList();
List<string> gpuNames = new List<string>();
NvGpus = gpus.ToList();
float mostVram = -1f;
foreach (PhysicalGPU gpu in gpus)
gpuNames.Add(gpu.FullName);
{
float vramGb = gpu.GetVramGb();
Logger.Log($"Nvidia GPU: {gpu.FullName} ({vramGb.ToString("0.")} GB) {GetArch(gpu)} Architecture", true);
string gpuNamesList = string.Join(", ", gpuNames);
if (vramGb > mostVram)
{
mostVram = vramGb;
GpuWithMostVram = gpu;
}
}
Logger.Log($"Initialized Nvidia API in {sw.ElapsedMs} ms. GPU{(gpus.Length > 1 ? "s" : "")}: {gpuNamesList}", true);
Logger.Log($"Initialized Nvidia API in {sw.ElapsedMs} ms. GPU{(gpus.Length > 1 ? "s" : "")}: {string.Join(", ", gpus.Select(g => g.FullName))}. Most VRAM: {GpuWithMostVram.FullName} ({mostVram} GB)", true);
}
catch (Exception e)
{
@@ -46,7 +53,7 @@ namespace Flowframes.Os
{
try
{
return (gpuList[gpu].MemoryInformation.AvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
return (NvGpus[gpu].MemoryInformation.AvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
}
catch
{
@@ -58,7 +65,7 @@ namespace Flowframes.Os
{
try
{
return (gpuList[gpu].MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
return (NvGpus[gpu].MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
}
catch
{
@@ -85,7 +92,7 @@ namespace Flowframes.Os
public static bool HasAmpereOrNewer()
{
foreach (PhysicalGPU gpu in gpuList)
foreach (PhysicalGPU gpu in NvGpus)
{
Architecture arch = GetArch(gpu);
@@ -98,14 +105,16 @@ namespace Flowframes.Os
public static Architecture GetArch(PhysicalGPU gpu)
{
string gpuCode = gpu.ArchitectInformation.ShortName;
string arch = gpu.ArchitectInformation.ShortName.Trim();
if (gpuCode.Trim().StartsWith("GF")) return Architecture.Fermi;
if (gpuCode.Trim().StartsWith("GK")) return Architecture.Kepler;
if (gpuCode.Trim().StartsWith("GM")) return Architecture.Maxwell;
if (gpuCode.Trim().StartsWith("GP")) return Architecture.Pascal;
if (gpuCode.Trim().StartsWith("TU")) return Architecture.Turing;
if (gpuCode.Trim().StartsWith("GA")) return Architecture.Ampere;
if (arch.StartsWith("GF")) return Architecture.Fermi;
if (arch.StartsWith("GK")) return Architecture.Kepler;
if (arch.StartsWith("GM")) return Architecture.Maxwell;
if (arch.StartsWith("GP")) return Architecture.Pascal;
if (arch.StartsWith("TU")) return Architecture.Turing;
if (arch.StartsWith("GA")) return Architecture.Ampere;
if (arch.StartsWith("AD")) return Architecture.Ada;
if (arch.StartsWith("GB")) return Architecture.Blackwell;
return Architecture.Undetected;
}
@@ -114,14 +123,14 @@ namespace Flowframes.Os
{
try
{
if (gpuList == null)
if (NvGpus == null)
Init();
if (gpuList == null)
if (NvGpus == null)
return false;
Architecture arch = GetArch(gpuList[gpu]);
return arch == Architecture.Turing || arch == Architecture.Ampere;
Architecture arch = GetArch(NvGpus[gpu]);
return arch >= Architecture.Turing;
}
catch (Exception e)
{

View File

@@ -291,9 +291,9 @@ namespace Flowframes.Os
gpusVk.AddRange(VulkanUtils.VkDevices.Select(d => $"{d.Name.Remove("NVIDIA ").Remove("GeForce ").Remove("AMD ").Remove("Intel ").Remove("(TM)")} ({d.Id})"));
}
if (NvApi.gpuList != null && NvApi.gpuList.Any())
if (NvApi.NvGpus != null && NvApi.NvGpus.Any())
{
gpusNv.AddRange(NvApi.gpuList.Select(d => $"{d.FullName.Remove("NVIDIA ").Remove("GeForce ")} ({NvApi.gpuList.IndexOf(d)})"));
gpusNv.AddRange(NvApi.NvGpus.Select(d => $"{d.FullName.Remove("NVIDIA ").Remove("GeForce ")} ({NvApi.NvGpus.IndexOf(d)})"));
}
if (!gpusVk.Any() && !gpusNv.Any())

View File

@@ -19,6 +19,7 @@ namespace Flowframes
{
static class Program
{
public static bool Debug = false;
public static string[] args = new string[0];
public static bool initialRun = true;
public static Form1 mainForm;
@@ -40,6 +41,7 @@ namespace Flowframes
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Cli.HandleCli();
Debug = Cli.Debug || System.Diagnostics.Debugger.IsAttached;
CmdMode = Paths.GetExe().EndsWith("Cmd.exe");
// Show splash screen

View File

@@ -30,5 +30,36 @@ namespace Flowframes.Ui
controls.ForEach(c => list.AddRange(c.GetControls()));
return list;
}
public static void SetEnabled(this Control control, bool enabled, bool includeChildren = false)
{
// Set Enabled property of the control only if it's different from the desired value to avoid event firing etc.
if (enabled && !control.Enabled)
{
control.Enabled = true;
}
else if (!enabled && control.Enabled)
{
control.Enabled = false;
}
if (includeChildren)
{
control.GetControls().ForEach(c => c.SetEnabled(enabled, includeChildren));
}
}
public static void SetVisible(this Control control, bool visible)
{
// Set Visible property of the control only if it's different from the desired value to avoid event firing etc.
if (visible && !control.Visible)
{
control.Visible = true;
}
else if (!visible && control.Visible)
{
control.Visible = false;
}
}
}
}

View File

@@ -70,7 +70,7 @@ namespace Flowframes.Ui
static void SelectNcnnIfNoCudaAvail(ComboBox combox)
{
if (NvApi.gpuList.Count < 1)
if (NvApi.NvGpus.Count < 1)
{
for (int i = 0; i < combox.Items.Count; i++)
{
@@ -86,7 +86,7 @@ namespace Flowframes.Ui
{
Logger.Log($"MessageBox: {text} ({type}){(BatchProcessing.busy ? "[Batch Mode - Will not display messagebox]" : "")}", true);
if(Cli.ShowConsole)
if(Program.CmdMode)
return DialogResult.OK;
if (BatchProcessing.busy)

View File

@@ -64,7 +64,7 @@ namespace Flowframes.Utilities
{
try
{
files.ForEach(x => x.Delete());
files.ForEach(x => IoUtils.DeleteIfExists(x.FullName));
break;
}
catch (Exception ex)
@@ -83,5 +83,24 @@ namespace Flowframes.Utilities
}
}
}
public static int GetDainNcnnTileSizeBasedOnVram(int defaultTileSize = 512)
{
if(NvApi.NvGpus.Count < 1)
return defaultTileSize;
float vram = NvApi.GpuWithMostVram.GetVramGb();
int tileSize = defaultTileSize;
if (vram > 5.5f) tileSize = 640; // 6 GB VRAM default
else if (vram > 7.5f) tileSize = 768; // 8 GB VRAM default
else if (vram > 11.5f) tileSize = 1024; // 12 GB VRAM default
else if (vram > 15.5f) tileSize = 1536; // 16 GB VRAM default
else if (vram > 19.5f) tileSize = 2048; // 20+ GB VRAM default
Logger.Log($"Using DAIN NCNN tile size {tileSize} for {vram.ToString("0.")} GB GPU", true);
return tileSize;
}
}
}