Skip to content

Vulkan backend #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/backends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ on:
jobs:
windows:
runs-on: windows-latest


env:
VULKAN_VERSION: 1.3.261.1

strategy:
matrix:
include:
Expand All @@ -33,6 +36,8 @@ jobs:
defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON'
- build: 'rocm5'
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'
- build: 'vulkan'
defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON"

steps:
- name: Checkout
Expand Down Expand Up @@ -79,6 +84,15 @@ jobs:
with:
version: 1.11.1

- name: Install Vulkan SDK
id: get_vulkan
if: ${{ matrix.build == 'vulkan' }}
run: |
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"
& "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"

- name: Build
id: cmake_build
run: |
Expand Down Expand Up @@ -349,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
Expand Down
28 changes: 28 additions & 0 deletions Backends/StableDiffusion.NET.Backend.Vulkan.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>StableDiffusion.NET.Backend.Vulkan</id>
<version>$version$</version>
<title>StableDiffusion.NET.Backend.Vulkan</title>
<authors>Darth Affe &amp; stable-diffusion.cpp Authors</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<icon>sd_net_vulkan.png</icon>
<projectUrl>https://github.com/DarthAffe/StableDiffusion.NET</projectUrl>
<description>Vulkan-Backend for StableDiffusion.NET.</description>
<releaseNotes></releaseNotes>
<copyright>Copyright © Darth Affe 2024</copyright>
<readme>readme.md</readme>
</metadata>

<files>
<file src="StableDiffusion.NET.Backend.props" target="build/net8.0/StableDiffusion.NET.Backend.Vulkan.props" />

<file src="windows-vulkan/stable-diffusion.dll" target="runtimes\win-x64\native\vulkan\stable-diffusion.dll" />

<file src="sd_net_vulkan.png" target="sd_net_vulkan.png" />
<file src="readme.md" target="readme.md" />
<file src="ggml.txt" target="ggml.txt" />
<file src="stable-diffusion.cpp.txt" target="stable-diffusion.cpp.txt" />
</files>
</package>
Binary file added Backends/sd_net_vulkan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Resources/sd_net_icon.xcf
Binary file not shown.
5 changes: 3 additions & 2 deletions StableDiffusion.NET/Backends/Backends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion StableDiffusion.NET/Backends/CpuBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion StableDiffusion.NET/Backends/CudaBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion StableDiffusion.NET/Backends/IBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
2 changes: 1 addition & 1 deletion StableDiffusion.NET/Backends/RocmBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion StableDiffusion.NET/Backends/SyclBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions StableDiffusion.NET/Backends/VulkanBackend.cs
Original file line number Diff line number Diff line change
@@ -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
}