Skip to content

Commit f7b7cd8

Browse files
authored
Merge pull request #23 from DarthAffe/SYCL
SYCL support
2 parents ac5c318 + 3badc9c commit f7b7cd8

File tree

9 files changed

+181
-4
lines changed

9 files changed

+181
-4
lines changed

.github/workflows/backends.yml

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,51 @@ jobs:
101101
uses: actions/[email protected]
102102
with:
103103
name: windows-${{ matrix.build }}
104+
path: .\build\bin\stable-diffusion.dll
105+
106+
windows-sycl:
107+
runs-on: windows-latest
108+
109+
defaults:
110+
run:
111+
shell: bash
112+
113+
env:
114+
WINDOWS_BASEKIT_URL: https://registrationcenter-download.intel.com/akdlm/IRC_NAS/7dff44ba-e3af-4448-841c-0d616c8da6e7/w_BaseKit_p_2024.1.0.595_offline.exe
115+
WINDOWS_DPCPP_MKL: intel.oneapi.win.cpp-dpcpp-common:intel.oneapi.win.mkl.devel
116+
117+
steps:
118+
- name: Checkout
119+
id: checkout
120+
uses: actions/[email protected]
121+
with:
122+
repository: 'leejet/stable-diffusion.cpp'
123+
ref: '${{ github.event.inputs.commit }}'
124+
submodules: recursive
125+
126+
- name: Checkout Install Script
127+
id: checkoutInstallScript
128+
uses: actions/[email protected]
129+
with:
130+
path: scripts
131+
sparse-checkout: |
132+
Backends/install-oneapi.bat
133+
Backends/win-build-sycl.bat
134+
sparse-checkout-cone-mode: false
135+
136+
- name: Install Sycl tools
137+
id: installSyclCompiler
138+
run: scripts/Backends/install-oneapi.bat $WINDOWS_BASEKIT_URL $WINDOWS_DPCPP_MKL
139+
140+
- name: Build
141+
id: cmake_build
142+
run: scripts/Backends/win-build-sycl.bat
143+
144+
- name: Upload artifact
145+
id: upload_artifact
146+
uses: actions/[email protected]
147+
with:
148+
name: windows-sycl
104149
path: .\build\bin\stable-diffusion.dll
105150

106151
linux:
@@ -119,7 +164,9 @@ jobs:
119164
- build: 'cuda11'
120165
defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON'
121166
- build: 'cuda12'
122-
defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON'
167+
defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON'
168+
- build: 'sycl'
169+
defines: '-DSD_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DSD_BUILD_SHARED_LIBS=ON'
123170

124171
steps:
125172
- name: Checkout
@@ -150,8 +197,32 @@ jobs:
150197
use-github-cache: false
151198
use-local-cache: false
152199

200+
- name: Install Sycl tools
201+
id: installSyclCompiler
202+
if: ${{ matrix.build == 'sycl' }}
203+
shell: bash
204+
run: |
205+
cd /tmp
206+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
207+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
208+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
209+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
210+
sudo apt update
211+
sudo apt install intel-oneapi-compiler-dpcpp-cpp intel-oneapi-mkl-devel
212+
213+
- name: Build
214+
id: cmake_build_sycl
215+
if: ${{ matrix.build == 'sycl' }}
216+
run: |
217+
source /opt/intel/oneapi/setvars.sh
218+
mkdir build
219+
cd build
220+
cmake .. ${{ matrix.defines }}
221+
cmake --build . --config Release
222+
153223
- name: Build
154224
id: cmake_build
225+
if: ${{ matrix.build != 'sycl' }}
155226
run: |
156227
mkdir build
157228
cd build
@@ -244,6 +315,7 @@ jobs:
244315

245316
needs:
246317
- windows
318+
- windows-sycl
247319
- linux
248320
- linux-hip
249321
- osx
@@ -276,6 +348,7 @@ jobs:
276348
nuget pack ./Backends/StableDiffusion.NET.Backend.Cuda12.Linux.nuspec -version ${{ github.event.inputs.version }}
277349
nuget pack ./Backends/StableDiffusion.NET.Backend.Cuda.nuspec -version ${{ github.event.inputs.version }}
278350
nuget pack ./Backends/StableDiffusion.NET.Backend.Rocm.nuspec -version ${{ github.event.inputs.version }}
351+
nuget pack ./Backends/StableDiffusion.NET.Backend.Sycl.nuspec -version ${{ github.event.inputs.version }}
279352
280353
- name: Upload artifacts
281354
id: upload_artifacts
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>StableDiffusion.NET.Backend.Sycl</id>
5+
<version>$version$</version>
6+
<title>StableDiffusion.NET.Backend.Sycl</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_sycl.png</icon>
11+
<projectUrl>https://github.com/DarthAffe/StableDiffusion.NET</projectUrl>
12+
<description>SYCL-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.Sycl.props" />
20+
21+
<file src="windows-sycl/stable-diffusion.dll" target="runtimes\win-x64\native\sycl\stable-diffusion.dll" />
22+
23+
<file src="linux-sycl/libstable-diffusion.so" target="runtimes\linux-x64\native\sycl\libstable-diffusion.so" />
24+
25+
<file src="sd_net_sycl.png" target="sd_net_sycl.png" />
26+
<file src="readme.md" target="readme.md" />
27+
<file src="ggml.txt" target="ggml.txt" />
28+
<file src="stable-diffusion.cpp.txt" target="stable-diffusion.cpp.txt" />
29+
</files>
30+
</package>

Backends/install-oneapi.bat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:: MIT license
2+
:: Copyright (C) 2024 Intel Corporation
3+
:: SPDX-License-Identifier: MIT
4+
5+
6+
set URL=%1
7+
set COMPONENTS=%2
8+
9+
curl.exe --output %TEMP%\webimage.exe --url %URL% --retry 5 --retry-delay 5
10+
start /b /wait %TEMP%\webimage.exe -s -x -f webimage_extracted --log extract.log
11+
del %TEMP%\webimage.exe
12+
if "%COMPONENTS%"=="" (
13+
webimage_extracted\bootstrapper.exe -s --action install --eula=accept -p=NEED_VS2017_INTEGRATION=0 -p=NEED_VS2019_INTEGRATION=0 -p=NEED_VS2022_INTEGRATION=0 --log-dir=.
14+
) else (
15+
webimage_extracted\bootstrapper.exe -s --action install --components=%COMPONENTS% --eula=accept -p=NEED_VS2017_INTEGRATION=0 -p=NEED_VS2019_INTEGRATION=0 -p=NEED_VS2022_INTEGRATION=0 --log-dir=.
16+
)
17+
set installer_exit_code=%ERRORLEVEL%
18+
rd /s/q "webimage_extracted"
19+
exit /b %installer_exit_code%

Backends/sd_net_sycl.png

404 KB
Loading

Backends/win-build-sycl.bat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:: MIT license
2+
:: Copyright (C) 2024 Intel Corporation
3+
:: SPDX-License-Identifier: MIT
4+
5+
6+
IF not exist build (mkdir build)
7+
cd build
8+
if %errorlevel% neq 0 goto ERROR
9+
10+
@call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 --force
11+
if %errorlevel% neq 0 goto ERROR
12+
13+
cmake -G "Ninja" .. -DGGML_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DSD_BUILD_SHARED_LIBS=ON
14+
if %errorlevel% neq 0 goto ERROR
15+
16+
cmake --build . -j --config Release
17+
if %errorlevel% neq 0 goto ERROR
18+
19+
cd ..
20+
exit /B 0
21+
22+
:ERROR
23+
echo comomand error: %errorlevel%
24+
exit /B %errorlevel%

Examples/ImageCreationUI/MainWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public MainWindowViewModel()
175175
}
176176
catch (Exception ex)
177177
{
178-
LogLine($"Failed to load stable-diffussion.cpp libraries!{Environment.NewLine}{ex.Message}");
178+
LogLine($"Failed to load stable-diffusion.cpp libraries!{Environment.NewLine}{ex.Message}");
179179
}
180180
}
181181

Resources/sd_net_icon.xcf

98.3 KB
Binary file not shown.

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)