Skip to content

Commit ecac81d

Browse files
committed
Added sycl backend
1 parent 5c31ce7 commit ecac81d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

StableDiffusion.NET/Backends/Backends.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public static class Backends
1414
public static CpuBackend CpuBackend { get; } = new();
1515
public static CudaBackend CudaBackend { get; } = new();
1616
public static RocmBackend RocmBackend { get; } = new();
17+
public static SyclBackend SyclBackend { get; } = new();
1718

1819
private static readonly List<IBackend> CUSTOM_BACKENDS = [];
1920
public static IReadOnlyList<IBackend> CustomBackends => CUSTOM_BACKENDS.AsReadOnly();
2021

21-
public static IEnumerable<IBackend> RegisteredBackends => [CpuBackend, CudaBackend, RocmBackend, .. CUSTOM_BACKENDS];
22+
public static IEnumerable<IBackend> RegisteredBackends => [CpuBackend, CudaBackend, RocmBackend, SyclBackend, .. CUSTOM_BACKENDS];
2223
public static IEnumerable<IBackend> AvailableBackends => RegisteredBackends.Where(x => x.IsAvailable);
2324
public static IEnumerable<IBackend> ActiveBackends => AvailableBackends.Where(x => x.IsEnabled);
2425

@@ -36,7 +37,7 @@ public static class Backends
3637

3738
public static bool RegisterBackend(IBackend backend)
3839
{
39-
if (backend is NET.CpuBackend or NET.CudaBackend or NET.RocmBackend)
40+
if (backend is NET.CpuBackend or NET.CudaBackend or NET.RocmBackend or NET.SyclBackend)
4041
throw new ArgumentException("Default backends can't be registered again.");
4142

4243
if (CUSTOM_BACKENDS.Contains(backend))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Runtime.InteropServices;
2+
using JetBrains.Annotations;
3+
4+
namespace StableDiffusion.NET;
5+
6+
[PublicAPI]
7+
public class SyclBackend : IBackend
8+
{
9+
#region Properties & Fields
10+
11+
//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
12+
public bool IsEnabled { get; set; } = false;
13+
14+
public int Priority => 5;
15+
16+
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
17+
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
18+
&& (RuntimeInformation.OSArchitecture == Architecture.X64);
19+
20+
public string PathPart => "sycl";
21+
22+
#endregion
23+
24+
#region Constructors
25+
26+
internal SyclBackend()
27+
{ }
28+
29+
#endregion
30+
}

0 commit comments

Comments
 (0)