Compare commits

..

3 Commits

Author SHA1 Message Date
c78f96dd57 Added vulkan backend 2024-08-28 20:02:35 +02:00
bb71986ce7 Changed backend-priority to be changeable 2024-08-28 20:02:29 +02:00
7fbbb70f90 Added vulkan nuget to backends-build 2024-08-28 20:01:42 +02:00
8 changed files with 38 additions and 7 deletions

View File

@ -363,6 +363,7 @@ jobs:
nuget pack ./Backends/StableDiffusion.NET.Backend.Cuda.nuspec -version ${{ github.event.inputs.version }}
nuget pack ./Backends/StableDiffusion.NET.Backend.Rocm.nuspec -version ${{ github.event.inputs.version }}
nuget pack ./Backends/StableDiffusion.NET.Backend.Sycl.nuspec -version ${{ github.event.inputs.version }}
nuget pack ./Backends/StableDiffusion.NET.Backend.Vulkan.nuspec -version ${{ github.event.inputs.version }}
- name: Upload artifacts
id: upload_artifacts

View File

@ -15,11 +15,12 @@ public static class Backends
public static CudaBackend CudaBackend { get; } = new();
public static RocmBackend RocmBackend { get; } = new();
public static SyclBackend SyclBackend { get; } = new();
public static VulkanBackend VulkanBackend { get; } = new();
private static readonly List<IBackend> CUSTOM_BACKENDS = [];
public static IReadOnlyList<IBackend> CustomBackends => CUSTOM_BACKENDS.AsReadOnly();
public static IEnumerable<IBackend> RegisteredBackends => [CpuBackend, CudaBackend, RocmBackend, SyclBackend, .. CUSTOM_BACKENDS];
public static IEnumerable<IBackend> RegisteredBackends => [CpuBackend, CudaBackend, RocmBackend, SyclBackend, VulkanBackend, .. CUSTOM_BACKENDS];
public static IEnumerable<IBackend> AvailableBackends => RegisteredBackends.Where(x => x.IsAvailable);
public static IEnumerable<IBackend> ActiveBackends => AvailableBackends.Where(x => x.IsEnabled);
@ -37,7 +38,7 @@ public static class Backends
public static bool RegisterBackend(IBackend backend)
{
if (backend is NET.CpuBackend or NET.CudaBackend or NET.RocmBackend or NET.SyclBackend)
if (backend is NET.CpuBackend or NET.CudaBackend or NET.RocmBackend or NET.SyclBackend or NET.VulkanBackend)
throw new ArgumentException("Default backends can't be registered again.");
if (CUSTOM_BACKENDS.Contains(backend))

View File

@ -13,7 +13,7 @@ public class CpuBackend : IBackend
public bool IsEnabled { get; set; } = true;
public int Priority => 0;
public int Priority { get; set; } = 0;
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux)

View File

@ -22,7 +22,7 @@ public partial class CudaBackend : IBackend
public bool IsEnabled { get; set; } = true;
public int Priority => 10;
public int Priority { get; set; } = 10;
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

View File

@ -6,7 +6,7 @@ namespace StableDiffusion.NET;
public interface IBackend
{
bool IsEnabled { get; set; }
public int Priority { get; }
public int Priority { get; set; }
bool IsAvailable { get; }
string PathPart { get; }
}

View File

@ -12,7 +12,7 @@ public partial class RocmBackend : IBackend
public bool IsEnabled { get; set; } = true;
public int Priority => 10;
public int Priority { get; set; } = 10;
public bool IsAvailable => ((RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& RocmVersion is 5)

View File

@ -11,7 +11,7 @@ public class SyclBackend : IBackend
//TODO DarthAffe 10.08.2024: tbh I'm not really sure how to detect a sycl-compatible system so for now it's disabled by default
public bool IsEnabled { get; set; } = false;
public int Priority => 5;
public int Priority { get; set; } = 5;
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

View File

@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
using JetBrains.Annotations;
namespace StableDiffusion.NET;
[PublicAPI]
public class VulkanBackend : IBackend
{
#region Properties & Fields
//TODO DarthAffe 28.08.2024: Find a way to detect vulkan compatibility
public bool IsEnabled { get; set; } = false;
public int Priority { get; set; } = 5;
public bool IsAvailable => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& (RuntimeInformation.OSArchitecture == Architecture.X64);
public string PathPart => "vulkan";
#endregion
#region Constructors
internal VulkanBackend()
{ }
#endregion
}