Skip to content

Commit 7bd8fe7

Browse files
authored
Merge pull request #26 from DarthAffe/vulkan_backend
Vulkan backend
2 parents 74af9cb + c78f96d commit 7bd8fe7

File tree

11 files changed

+81
-8
lines changed

11 files changed

+81
-8
lines changed

.github/workflows/backends.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ on:
1515
jobs:
1616
windows:
1717
runs-on: windows-latest
18-
18+
19+
env:
20+
VULKAN_VERSION: 1.3.261.1
21+
1922
strategy:
2023
matrix:
2124
include:
@@ -33,6 +36,8 @@ jobs:
3336
defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON'
3437
- build: 'rocm5'
3538
defines: '-G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DSD_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release -DAMDGPU_TARGETS="gfx1100;gfx1102;gfx1030" -DSD_BUILD_SHARED_LIBS=ON'
39+
- build: 'vulkan'
40+
defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON"
3641

3742
steps:
3843
- name: Checkout
@@ -79,6 +84,15 @@ jobs:
7984
with:
8085
version: 1.11.1
8186

87+
- name: Install Vulkan SDK
88+
id: get_vulkan
89+
if: ${{ matrix.build == 'vulkan' }}
90+
run: |
91+
curl.exe -o $env:RUNNER_TEMP/VulkanSDK-Installer.exe -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/VulkanSDK-${env:VULKAN_VERSION}-Installer.exe"
92+
& "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install
93+
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
94+
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"
95+
8296
- name: Build
8397
id: cmake_build
8498
run: |
@@ -349,6 +363,7 @@ jobs:
349363
nuget pack ./Backends/StableDiffusion.NET.Backend.Cuda.nuspec -version ${{ github.event.inputs.version }}
350364
nuget pack ./Backends/StableDiffusion.NET.Backend.Rocm.nuspec -version ${{ github.event.inputs.version }}
351365
nuget pack ./Backends/StableDiffusion.NET.Backend.Sycl.nuspec -version ${{ github.event.inputs.version }}
366+
nuget pack ./Backends/StableDiffusion.NET.Backend.Vulkan.nuspec -version ${{ github.event.inputs.version }}
352367
353368
- name: Upload artifacts
354369
id: upload_artifacts
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>StableDiffusion.NET.Backend.Vulkan</id>
5+
<version>$version$</version>
6+
<title>StableDiffusion.NET.Backend.Vulkan</title>
7+
<authors>Darth Affe &amp; stable-diffusion.cpp Authors</authors>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<license type="expression">MIT</license>
10+
<icon>sd_net_vulkan.png</icon>
11+
<projectUrl>https://github.com/DarthAffe/StableDiffusion.NET</projectUrl>
12+
<description>Vulkan-Backend for StableDiffusion.NET.</description>
13+
<releaseNotes></releaseNotes>
14+
<copyright>Copyright © Darth Affe 2024</copyright>
15+
<readme>readme.md</readme>
16+
</metadata>
17+
18+
<files>
19+
<file src="StableDiffusion.NET.Backend.props" target="build/net8.0/StableDiffusion.NET.Backend.Vulkan.props" />
20+
21+
<file src="windows-vulkan/stable-diffusion.dll" target="runtimes\win-x64\native\vulkan\stable-diffusion.dll" />
22+
23+
<file src="sd_net_vulkan.png" target="sd_net_vulkan.png" />
24+
<file src="readme.md" target="readme.md" />
25+
<file src="ggml.txt" target="ggml.txt" />
26+
<file src="stable-diffusion.cpp.txt" target="stable-diffusion.cpp.txt" />
27+
</files>
28+
</package>

Backends/sd_net_vulkan.png

432 KB
Loading

Resources/sd_net_icon.xcf

75.5 KB
Binary file not shown.

StableDiffusion.NET/Backends/Backends.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ public static class Backends
1515
public static CudaBackend CudaBackend { get; } = new();
1616
public static RocmBackend RocmBackend { get; } = new();
1717
public static SyclBackend SyclBackend { get; } = new();
18+
public static VulkanBackend VulkanBackend { get; } = new();
1819

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

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

@@ -37,7 +38,7 @@ public static class Backends
3738

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

4344
if (CUSTOM_BACKENDS.Contains(backend))

StableDiffusion.NET/Backends/CpuBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CpuBackend : IBackend
1313

1414
public bool IsEnabled { get; set; } = true;
1515

16-
public int Priority => 0;
16+
public int Priority { get; set; } = 0;
1717

1818
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1919
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux)

StableDiffusion.NET/Backends/CudaBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class CudaBackend : IBackend
2222

2323
public bool IsEnabled { get; set; } = true;
2424

25-
public int Priority => 10;
25+
public int Priority { get; set; } = 10;
2626

2727
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
2828
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

StableDiffusion.NET/Backends/IBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace StableDiffusion.NET;
66
public interface IBackend
77
{
88
bool IsEnabled { get; set; }
9-
public int Priority { get; }
9+
public int Priority { get; set; }
1010
bool IsAvailable { get; }
1111
string PathPart { get; }
1212
}

StableDiffusion.NET/Backends/RocmBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class RocmBackend : IBackend
1212

1313
public bool IsEnabled { get; set; } = true;
1414

15-
public int Priority => 10;
15+
public int Priority { get; set; } = 10;
1616

1717
public bool IsAvailable => ((RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1818
&& RocmVersion is 5)

StableDiffusion.NET/Backends/SyclBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class SyclBackend : IBackend
1111
//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
1212
public bool IsEnabled { get; set; } = false;
1313

14-
public int Priority => 5;
14+
public int Priority { get; set; } = 5;
1515

1616
public bool IsAvailable => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1717
|| RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Runtime.InteropServices;
2+
using JetBrains.Annotations;
3+
4+
namespace StableDiffusion.NET;
5+
6+
[PublicAPI]
7+
public class VulkanBackend : IBackend
8+
{
9+
#region Properties & Fields
10+
11+
//TODO DarthAffe 28.08.2024: Find a way to detect vulkan compatibility
12+
public bool IsEnabled { get; set; } = false;
13+
14+
public int Priority { get; set; } = 5;
15+
16+
public bool IsAvailable => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
17+
&& (RuntimeInformation.OSArchitecture == Architecture.X64);
18+
19+
public string PathPart => "vulkan";
20+
21+
#endregion
22+
23+
#region Constructors
24+
25+
internal VulkanBackend()
26+
{ }
27+
28+
#endregion
29+
}

0 commit comments

Comments
 (0)