Skip to content

Commit

Permalink
Auto-set NCNN GPU threads default value based on hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Nov 14, 2024
1 parent 7e043f5 commit 8a578da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 2 additions & 7 deletions CodeLegacy/Forms/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CodeLegacy/IO/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static string WriteDefaultValIfExists(string keyStr, Type type)
if (key == Key.uhdThresh) return WriteDefault(key, "1600");
if (key == Key.torchGpus) return WriteDefault(key, "0");
if (key == Key.ncnnGpus) return WriteDefault(key, "0");
if (key == Key.ncnnThreads) return WriteDefault(key, "4");
if (key == Key.ncnnThreads) return WriteDefault(key, "0");
if (key == Key.dainNcnnTilesize) return WriteDefault(key, "768");
// Debug / Other / Experimental
if (key == Key.ffEncPreset) return WriteDefault(key, "fast");
Expand Down
5 changes: 5 additions & 0 deletions CodeLegacy/Utilities/NcnnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static int GetRifeNcnnGpuThreads(Size res, int gpuId, AiInfo ai)
int threads = Config.GetInt(Config.Key.ncnnThreads);
int maxThreads = VulkanUtils.GetMaxNcnnThreads(gpuId).Clamp(1, 64);

if(threads == 0)
{
threads = (maxThreads / 2f).RoundToInt().Clamp(1, maxThreads); // Default to half of max threads
}

threads = threads.Clamp(1, maxThreads); // To avoid exceeding the max queue count
Logger.Log($"Using {threads}/{maxThreads} GPU compute threads.", true, false, ai.LogFilename);

Expand Down

0 comments on commit 8a578da

Please sign in to comment.