Dynamically set RIFE NCNN VS GPU threads to reduce VRAM/RAM usage with high resolutions

This commit is contained in:
n00mkrad
2022-07-20 18:29:36 +02:00
parent d96513ed4b
commit 48c8893da7
2 changed files with 14 additions and 2 deletions

View File

@@ -338,7 +338,7 @@ namespace Flowframes.Os
try try
{ {
Size scaledSize = await InterpolateUtils.GetOutputResolution(Interpolate.currentSettings.inPath, false); Size scaledSize = await InterpolateUtils.GetOutputResolution(Interpolate.currentSettings.inPath, false, false);
Logger.Log($"Running RIFE (NCNN-VS){(InterpolateUtils.UseUhd(scaledSize) ? " (UHD Mode)" : "")}...", false); Logger.Log($"Running RIFE (NCNN-VS){(InterpolateUtils.UseUhd(scaledSize) ? " (UHD Mode)" : "")}...", false);
await RunRifeNcnnVsProcess(framesPath, factor, outPath, mdl, scaledSize, rt); await RunRifeNcnnVsProcess(framesPath, factor, outPath, mdl, scaledSize, rt);
@@ -384,9 +384,10 @@ namespace Flowframes.Os
InterpSettings = Interpolate.currentSettings, InterpSettings = Interpolate.currentSettings,
ModelDir = mdl, ModelDir = mdl,
Factor = factor, Factor = factor,
Res = InterpolateUtils.GetOutputResolution(Interpolate.currentSettings.InputResolution, true, true), Res = res,
Uhd = InterpolateUtils.UseUhd(res), Uhd = InterpolateUtils.UseUhd(res),
GpuId = Config.Get(Config.Key.ncnnGpus).Split(',')[0].GetInt(), GpuId = Config.Get(Config.Key.ncnnGpus).Split(',')[0].GetInt(),
GpuThreads = GetRifeNcnnVsGpuThreads(res),
SceneDetectSensitivity = Config.GetBool(Config.Key.scnDetect) ? Config.GetFloat(Config.Key.scnDetectValue) * 0.7f : 0f, SceneDetectSensitivity = Config.GetBool(Config.Key.scnDetect) ? Config.GetFloat(Config.Key.scnDetectValue) * 0.7f : 0f,
Loop = Config.GetBool(Config.Key.enableLoop), Loop = Config.GetBool(Config.Key.enableLoop),
MatchDuration = Config.GetBool(Config.Key.fixOutputDuration), MatchDuration = Config.GetBool(Config.Key.fixOutputDuration),
@@ -648,6 +649,14 @@ namespace Flowframes.Os
InterpolationProgress.UpdateLastFrameFromInterpOutput(line); InterpolationProgress.UpdateLastFrameFromInterpOutput(line);
} }
static int GetRifeNcnnVsGpuThreads (Size res)
{
int threads = 3;
if(res.Width * res.Height > 2560 * 1440) threads = 2;
if(res.Width * res.Height > 3840 * 2160) threads = 1;
return threads;
}
static string GetNcnnPattern() static string GetNcnnPattern()
{ {
return $"%0{Padding.interpFrames}d{Interpolate.currentSettings.interpExt}"; return $"%0{Padding.interpFrames}d{Interpolate.currentSettings.interpExt}";

View File

@@ -34,6 +34,9 @@ namespace Flowframes.Os
public static string CreateScript(VsSettings s) public static string CreateScript(VsSettings s)
{ {
Logger.Log($"Creating RIFE VS script. Model: {s.ModelDir}, Factor: {s.Factor}, Res: {s.Res.Width}x{s.Res.Height}, UHD: {s.Uhd}, SC Sens: {s.SceneDetectSensitivity}, " +
$"GPU ID: {s.GpuId}, GPU Threads: {s.GpuThreads}, TTA: {s.Tta}, Loop: {s.Loop}, Match Duration: {s.MatchDuration}, Dedupe: {s.Dedupe}, RT: {s.Realtime}{(s.Osd ? $", OSD: {s.Osd}" : "")}", true);
string inputPath = s.InterpSettings.inPath; string inputPath = s.InterpSettings.inPath;
string mdlPath = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir, s.ModelDir).Replace(@"\", "/").Wrap(); string mdlPath = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir, s.ModelDir).Replace(@"\", "/").Wrap();