diff --git a/StableDiffusion.NET/Backends/RocmBackend.cs b/StableDiffusion.NET/Backends/RocmBackend.cs index acce69f..87a7730 100644 --- a/StableDiffusion.NET/Backends/RocmBackend.cs +++ b/StableDiffusion.NET/Backends/RocmBackend.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Text.RegularExpressions; +using StableDiffusion.NET.Helper; namespace StableDiffusion.NET; @@ -12,14 +13,16 @@ public partial class RocmBackend : IBackend public int Priority => 10; - public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - /*|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux)*/) - && (RuntimeInformation.OSArchitecture == Architecture.X64) - && RocmVersion is 5; + public bool IsAvailable => ((RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + && RocmVersion is 5) + || (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + && RocmVersion is 6)) + && (RuntimeInformation.OSArchitecture == Architecture.X64); public string PathPart => RocmVersion switch { 5 => "rocm5", + 6 => "rocm6", _ => string.Empty }; @@ -46,7 +49,6 @@ public partial class RocmBackend : IBackend if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string? rocmPath = Environment.GetEnvironmentVariable("HIP_PATH"); - if (rocmPath == null) return -1; Match match = GetWindowsVersionRegex().Match(rocmPath); @@ -55,7 +57,12 @@ public partial class RocmBackend : IBackend } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - //TODO DarthAffe 23.03.2024: Get some info where it's located on linux + string? hipconfig = ProcessHelper.RunCommand("hipconfig"); + if (hipconfig == null) return -1; + + Match match = GetLinuxVersionRegex().Match(hipconfig); + if (match.Success) + version = match.Groups["version"].Value; } if (string.IsNullOrEmpty(version)) @@ -73,5 +80,8 @@ public partial class RocmBackend : IBackend [GeneratedRegex(@".*?\\(?\d+.\d*)\\")] private static partial Regex GetWindowsVersionRegex(); + [GeneratedRegex(@"HIP_PATH\s*:\s*[\w\/]+-(?[\d.]+)$")] + private static partial Regex GetLinuxVersionRegex(); + #endregion } \ No newline at end of file diff --git a/StableDiffusion.NET/Helper/ProcessHelper.cs b/StableDiffusion.NET/Helper/ProcessHelper.cs new file mode 100644 index 0000000..938aa73 --- /dev/null +++ b/StableDiffusion.NET/Helper/ProcessHelper.cs @@ -0,0 +1,27 @@ +using System.Diagnostics; + +namespace StableDiffusion.NET.Helper; + +internal static class ProcessHelper +{ + public static string? RunCommand(string command) + { + try + { + using Process process = new(); + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.FileName = command; + process.Start(); + + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + return output; + } + catch + { + return null; + } + } +} \ No newline at end of file