NvApi UX improvements

This commit is contained in:
N00MKRAD
2021-02-24 14:56:47 +01:00
parent 35c3938217
commit 8dd1d4ee4c
4 changed files with 28 additions and 20 deletions

View File

@@ -35,7 +35,7 @@ namespace Flowframes
CheckForIllegalCrossThreadCalls = false;
AutoScaleMode = AutoScaleMode.None;
if(!File.Exists(Paths.GetVerPath()) && Paths.GetExeDir().ToLower().Contains("temp"))
if (!File.Exists(Paths.GetVerPath()) && Paths.GetExeDir().ToLower().Contains("temp"))
{
MessageBox.Show("You seem to be running Flowframes out of an archive.\nPlease extract the whole archive first!", "Error");
IOUtils.TryDeleteIfExists(Paths.GetDataPath());
@@ -54,6 +54,7 @@ namespace Flowframes
Program.mainForm = this;
Logger.textbox = logBox;
NvApi.Init();
InitAis();
InterpolateUtils.preview = previewPicturebox;

View File

@@ -2,53 +2,60 @@
using NvAPIWrapper.GPU;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flowframes.OS
{
class NvApi
{
static PhysicalGPU gpu;
static List<PhysicalGPU> gpuList = new List<PhysicalGPU>();
public static async void Init()
public static void Init()
{
try
{
NVIDIA.Initialize();
PhysicalGPU[] gpus = PhysicalGPU.GetPhysicalGPUs();
if (gpus.Length == 0)
return;
gpu = gpus[0];
Logger.Log($"Initialized NvApi. GPU: {gpu.FullName} - Tensor Cores: {HasTensorCores()}");
gpuList = gpus.ToList();
List<string> gpuNames = new List<string>();
foreach (PhysicalGPU gpu in gpus)
gpuNames.Add(gpu.FullName);
string gpuNamesList = string.Join(", ", gpuNames);
Logger.Log($"Initialized Nvidia API. GPU{(gpus.Length > 1 ? "s" : "")}: {gpuNamesList}");
}
catch (Exception e)
{
Logger.Log($"Failed to initialize NvApi: {e.Message}\nIgnore this if you don't have an Nvidia GPU.");
Logger.Log("No Nvidia GPU(s) detected. You will not be able to use CUDA implementations.");
Logger.Log($"Failed to initialize NvApi: {e.Message}\nIgnore this if you don't have an Nvidia GPU.", true);
}
}
public static float GetVramGb ()
public static float GetVramGb (int gpu = 0)
{
try
{
return (gpu.MemoryInformation.AvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
return (gpuList[gpu].MemoryInformation.AvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
}
catch (Exception e)
catch
{
return 0f;
}
}
public static float GetFreeVramGb()
public static float GetFreeVramGb(int gpu = 0)
{
try
{
return (gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
return (gpuList[gpu].MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB / 1000f / 1024f);
}
catch
{
@@ -73,15 +80,15 @@ namespace Flowframes.OS
}
}
public static bool HasTensorCores ()
public static bool HasTensorCores (int gpu = 0)
{
if (gpu == null)
if (gpuList == null)
Init();
if (gpu == null)
if (gpuList == null)
return false;
string gpuName = gpu.FullName;
string gpuName = gpuList[gpu].FullName;
return (gpuName.Contains("RTX ") || gpuName.Contains("Tesla V") || gpuName.Contains("Tesla T"));
}

View File

@@ -26,7 +26,8 @@ namespace Flowframes.OS
}
catch (Exception e)
{
Logger.Log("Error getting installed version: " + e.Message);
Logger.Log("Error getting installed version!");
Logger.Log(e.Message, true);
return new Version(0, 0, 0);
}
}

View File

@@ -30,7 +30,6 @@ namespace Flowframes
IOUtils.DeleteContentsOfDir(Paths.GetLogPath()); // Clear out older logs from previous session
Networks.Init();
NvApi.Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);