From 48c8893da7480e5b76a640c94bd1c28cb3446003 Mon Sep 17 00:00:00 2001 From: n00mkrad Date: Wed, 20 Jul 2022 18:29:36 +0200 Subject: [PATCH] Dynamically set RIFE NCNN VS GPU threads to reduce VRAM/RAM usage with high resolutions --- Code/Os/AiProcess.cs | 13 +++++++++++-- Code/Os/VapourSynthUtils.cs | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Code/Os/AiProcess.cs b/Code/Os/AiProcess.cs index ba1f7c2..5cdfc6b 100644 --- a/Code/Os/AiProcess.cs +++ b/Code/Os/AiProcess.cs @@ -338,7 +338,7 @@ namespace Flowframes.Os 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); await RunRifeNcnnVsProcess(framesPath, factor, outPath, mdl, scaledSize, rt); @@ -384,9 +384,10 @@ namespace Flowframes.Os InterpSettings = Interpolate.currentSettings, ModelDir = mdl, Factor = factor, - Res = InterpolateUtils.GetOutputResolution(Interpolate.currentSettings.InputResolution, true, true), + Res = res, Uhd = InterpolateUtils.UseUhd(res), 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, Loop = Config.GetBool(Config.Key.enableLoop), MatchDuration = Config.GetBool(Config.Key.fixOutputDuration), @@ -648,6 +649,14 @@ namespace Flowframes.Os 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() { return $"%0{Padding.interpFrames}d{Interpolate.currentSettings.interpExt}"; diff --git a/Code/Os/VapourSynthUtils.cs b/Code/Os/VapourSynthUtils.cs index 5202636..93c6d3e 100644 --- a/Code/Os/VapourSynthUtils.cs +++ b/Code/Os/VapourSynthUtils.cs @@ -34,6 +34,9 @@ namespace Flowframes.Os 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 mdlPath = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir, s.ModelDir).Replace(@"\", "/").Wrap();