From 928cdb7f5e338dc22429879623ac80b92c946ad6 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Sun, 9 Jun 2024 20:45:30 +0200 Subject: [PATCH 1/6] Add scripts to build in a container for windows --- docker/Readme.md | 15 +++++++++++++++ docker/build-cuda.ps1 | 9 +++++++++ docker/build-rocm.ps1 | 17 +++++++++++++++++ docker/build.ps1 | 17 +++++++++++++++++ docker/win.Dockerfile | 24 ++++++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 docker/Readme.md create mode 100644 docker/build-cuda.ps1 create mode 100644 docker/build-rocm.ps1 create mode 100644 docker/build.ps1 create mode 100644 docker/win.Dockerfile diff --git a/docker/Readme.md b/docker/Readme.md new file mode 100644 index 000000000..1e7e7cb97 --- /dev/null +++ b/docker/Readme.md @@ -0,0 +1,15 @@ +# Building with a container +Builds in a container without installing requirements on the local system. +> Note: Windows only for now. + +### HIP SDK (rocm) +I did not find a way to download the HIP SDK installer automatically, because the download page requires to accept license conditions. Download the installer manually and place it in directory `docker`. Download page: https://www.amd.com/en/developer/resources/rocm-hub/hip-sdk.html#downloads. + +### Build +The script will first build the container image that contains build requirements. Then, stable-diffusion.cpp will be compiled in a container that mounts the local source code. + +Build with +```pwsh +./docker/build.ps1 -Acceleration [cuda|rocm] +``` +Binaries can be found in `docker/build`. diff --git a/docker/build-cuda.ps1 b/docker/build-cuda.ps1 new file mode 100644 index 000000000..8e0e43bb5 --- /dev/null +++ b/docker/build-cuda.ps1 @@ -0,0 +1,9 @@ +& 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 -HostArch amd64 + +cmake -S source -B build -G "Ninja" -D CMAKE_BUILD_TYPE=Release -D SD_CUBLAS=ON +cmake --build build --config Release --parallel + +$cudaDir = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3" +Copy-Item "$cudaDir\bin\cublas64_12.dll" ./build/bin +Copy-Item "$cudaDir\bin\cudart64_12.dll" ./build/bin +Copy-Item "$cudaDir\bin\cublasLt64_12.dll" ./build/bin \ No newline at end of file diff --git a/docker/build-rocm.ps1 b/docker/build-rocm.ps1 new file mode 100644 index 000000000..1279d82fb --- /dev/null +++ b/docker/build-rocm.ps1 @@ -0,0 +1,17 @@ +$rocMDir = "C:/Program Files/AMD/ROCm/5.7" + +$env:PATH += ";$rocMDir/bin" +$env:PATH += ";C:/Strawberry/perl/bin" + +cmake -S source -B build -G "Ninja" ` + -D CMAKE_BUILD_TYPE=Release ` + -D CMAKE_C_COMPILER=clang ` + -D CMAKE_CXX_COMPILER=clang++ ` + -D SD_HIPBLAS=ON ` + -D SD_FLASH_ATTN=ON ` + -D AMDGPU_TARGETS="gfx1100;gfx1102;gfx1030" +cmake --build build --config Release --parallel + +Copy-Item "$rocMDir/bin/hipblas.dll" ./build/bin +Copy-Item "$rocMDir/bin/rocblas.dll" ./build/bin +Copy-Item -Recurse "$rocMDir/bin/rocblas/library" ./build/bin \ No newline at end of file diff --git a/docker/build.ps1 b/docker/build.ps1 new file mode 100644 index 000000000..e2c06cd3f --- /dev/null +++ b/docker/build.ps1 @@ -0,0 +1,17 @@ +param ( + [Parameter(Mandatory = $true)] + [ValidateSet("rocm", "cuda")] + [string] + $Acceleration +) + +docker build -t sd-cpp -f $PSScriptRoot/win.Dockerfile $PSScriptRoot + +if (!(Test-Path $PSScriptRoot/build)) { + mkdir $PSScriptRoot/build +} + +docker run --rm ` + -v $PSScriptRoot/..:C:/sd_cpp/source ` + -v $PSScriptRoot/build:c:/sd_cpp/build sd-cpp ` + powershell -File source/docker/build-${Acceleration}.ps1 diff --git a/docker/win.Dockerfile b/docker/win.Dockerfile new file mode 100644 index 000000000..3d2cd061c --- /dev/null +++ b/docker/win.Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +SHELL [ "powershell", "-Command" ] + +RUN Set-ExecutionPolicy RemoteSigned -Scope Process -Force; \ + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +RUN choco install -y cmake --installargs "ADD_CMAKE_TO_PATH=System"; \ + choco install -y ninja; \ + choco install -y StrawberryPerl + +ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe +RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ + Remove-Item vs_buildtools.exe -Force + +COPY AMD-Software-PRO-Edition-23.Q4-WinSvr2022-For-HIP.exe ./hip_installer.exe +RUN Start-Process hip_installer.exe -NoNewWindow -Wait -ArgumentList '"-install -log hip_install_log.txt"'; \ + Remove-Item hip_installer.exe + +RUN choco install -y cuda + +WORKDIR C:/sd_cpp +CMD ["powershell"] \ No newline at end of file From c30132f2051fa88c80f37af674ffb6d86b6657e6 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Tue, 6 Aug 2024 22:34:57 +0200 Subject: [PATCH 2/6] Update HIP SDK (rocm) --- docker/build-rocm.ps1 | 2 +- docker/win.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/build-rocm.ps1 b/docker/build-rocm.ps1 index 1279d82fb..53ca0d703 100644 --- a/docker/build-rocm.ps1 +++ b/docker/build-rocm.ps1 @@ -1,4 +1,4 @@ -$rocMDir = "C:/Program Files/AMD/ROCm/5.7" +$rocMDir = "C:/Program Files/AMD/ROCm/6.1" $env:PATH += ";$rocMDir/bin" $env:PATH += ";C:/Strawberry/perl/bin" diff --git a/docker/win.Dockerfile b/docker/win.Dockerfile index 3d2cd061c..d3486157c 100644 --- a/docker/win.Dockerfile +++ b/docker/win.Dockerfile @@ -14,7 +14,7 @@ ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ Remove-Item vs_buildtools.exe -Force -COPY AMD-Software-PRO-Edition-23.Q4-WinSvr2022-For-HIP.exe ./hip_installer.exe +COPY AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe ./hip_installer.exe RUN Start-Process hip_installer.exe -NoNewWindow -Wait -ArgumentList '"-install -log hip_install_log.txt"'; \ Remove-Item hip_installer.exe From aaff83f0d752f1951d34b4ad6d7aef174271d626 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Thu, 17 Apr 2025 22:12:13 +0200 Subject: [PATCH 3/6] chore: update hip version --- docker/build-rocm.ps1 | 2 +- docker/win.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/build-rocm.ps1 b/docker/build-rocm.ps1 index 53ca0d703..7ab850300 100644 --- a/docker/build-rocm.ps1 +++ b/docker/build-rocm.ps1 @@ -1,4 +1,4 @@ -$rocMDir = "C:/Program Files/AMD/ROCm/6.1" +$rocMDir = "C:/Program Files/AMD/ROCm/6.2" $env:PATH += ";$rocMDir/bin" $env:PATH += ";C:/Strawberry/perl/bin" diff --git a/docker/win.Dockerfile b/docker/win.Dockerfile index d3486157c..da5b7ef03 100644 --- a/docker/win.Dockerfile +++ b/docker/win.Dockerfile @@ -14,7 +14,7 @@ ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ Remove-Item vs_buildtools.exe -Force -COPY AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe ./hip_installer.exe +COPY AMD-Software-PRO-Edition-24.Q4-WinSvr2022-For-HIP.exe ./hip_installer.exe RUN Start-Process hip_installer.exe -NoNewWindow -Wait -ArgumentList '"-install -log hip_install_log.txt"'; \ Remove-Item hip_installer.exe From 53a1c9a986984caa08e558f7ba5397b880097ea7 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Tue, 29 Apr 2025 22:13:24 +0200 Subject: [PATCH 4/6] chore: update cuda version and split dockerfile in one each for rocm and cuda --- docker/build-cuda.ps1 | 2 +- docker/build-rocm.ps1 | 1 - docker/build.ps1 | 5 +++-- docker/win-cuda.Dockerfile | 22 +++++++++++++++++++ .../{win.Dockerfile => win-rocm.Dockerfile} | 13 +++++------ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 docker/win-cuda.Dockerfile rename docker/{win.Dockerfile => win-rocm.Dockerfile} (92%) diff --git a/docker/build-cuda.ps1 b/docker/build-cuda.ps1 index 8e0e43bb5..3bd13a0b2 100644 --- a/docker/build-cuda.ps1 +++ b/docker/build-cuda.ps1 @@ -3,7 +3,7 @@ cmake -S source -B build -G "Ninja" -D CMAKE_BUILD_TYPE=Release -D SD_CUBLAS=ON cmake --build build --config Release --parallel -$cudaDir = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3" +$cudaDir = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8" Copy-Item "$cudaDir\bin\cublas64_12.dll" ./build/bin Copy-Item "$cudaDir\bin\cudart64_12.dll" ./build/bin Copy-Item "$cudaDir\bin\cublasLt64_12.dll" ./build/bin \ No newline at end of file diff --git a/docker/build-rocm.ps1 b/docker/build-rocm.ps1 index 7ab850300..fff2564c7 100644 --- a/docker/build-rocm.ps1 +++ b/docker/build-rocm.ps1 @@ -8,7 +8,6 @@ cmake -S source -B build -G "Ninja" ` -D CMAKE_C_COMPILER=clang ` -D CMAKE_CXX_COMPILER=clang++ ` -D SD_HIPBLAS=ON ` - -D SD_FLASH_ATTN=ON ` -D AMDGPU_TARGETS="gfx1100;gfx1102;gfx1030" cmake --build build --config Release --parallel diff --git a/docker/build.ps1 b/docker/build.ps1 index e2c06cd3f..a6545d2b0 100644 --- a/docker/build.ps1 +++ b/docker/build.ps1 @@ -5,13 +5,14 @@ param ( $Acceleration ) -docker build -t sd-cpp -f $PSScriptRoot/win.Dockerfile $PSScriptRoot +$dockerfile = "${PSScriptRoot}/win-${Acceleration}.Dockerfile" +docker build -t sd-cpp -f $dockerfile $PSScriptRoot if (!(Test-Path $PSScriptRoot/build)) { mkdir $PSScriptRoot/build } -docker run --rm ` +docker run --rm --isolation process ` -v $PSScriptRoot/..:C:/sd_cpp/source ` -v $PSScriptRoot/build:c:/sd_cpp/build sd-cpp ` powershell -File source/docker/build-${Acceleration}.ps1 diff --git a/docker/win-cuda.Dockerfile b/docker/win-cuda.Dockerfile new file mode 100644 index 000000000..a1a3409ac --- /dev/null +++ b/docker/win-cuda.Dockerfile @@ -0,0 +1,22 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +SHELL [ "powershell", "-Command" ] + +ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe +RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ + Remove-Item vs_buildtools.exe -Force + +RUN Set-ExecutionPolicy RemoteSigned -Scope Process -Force; \ + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +RUN choco install -y cmake --installargs "ADD_CMAKE_TO_PATH=System"; \ + choco install -y ninja; \ + choco install -y git + +ADD https://developer.download.nvidia.com/compute/cuda/12.8.1/network_installers/cuda_12.8.1_windows_network.exe cuda_installer.exe +RUN Start-Process cuda_installer.exe -NoNewWindow -Wait -ArgumentList '"-s -n cudart_12.8 cublas_12.8 nvcc_12.8"'; \ + Remove-Item cuda_installer.exe + +WORKDIR C:/sd_cpp +CMD ["powershell"] \ No newline at end of file diff --git a/docker/win.Dockerfile b/docker/win-rocm.Dockerfile similarity index 92% rename from docker/win.Dockerfile rename to docker/win-rocm.Dockerfile index da5b7ef03..6053a4542 100644 --- a/docker/win.Dockerfile +++ b/docker/win-rocm.Dockerfile @@ -2,23 +2,22 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2022 SHELL [ "powershell", "-Command" ] +ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe +RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ + Remove-Item vs_buildtools.exe -Force + RUN Set-ExecutionPolicy RemoteSigned -Scope Process -Force; \ [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \ Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) RUN choco install -y cmake --installargs "ADD_CMAKE_TO_PATH=System"; \ choco install -y ninja; \ - choco install -y StrawberryPerl - -ADD https://aka.ms/vs/17/release/vs_buildtools.exe vs_buildtools.exe -RUN ./vs_buildtools.exe --quiet --wait --norestart --nocache --add 'Microsoft.VisualStudio.Workload.VCTools;includeRecommended'; \ - Remove-Item vs_buildtools.exe -Force + choco install -y StrawberryPerl; \ + choco install -y git COPY AMD-Software-PRO-Edition-24.Q4-WinSvr2022-For-HIP.exe ./hip_installer.exe RUN Start-Process hip_installer.exe -NoNewWindow -Wait -ArgumentList '"-install -log hip_install_log.txt"'; \ Remove-Item hip_installer.exe -RUN choco install -y cuda - WORKDIR C:/sd_cpp CMD ["powershell"] \ No newline at end of file From b205ecdeece199fa7bd84a339e8fe21aa785f053 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Thu, 5 Jun 2025 21:38:05 +0200 Subject: [PATCH 5/6] fix: allow larger lora sizes --- lora.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lora.hpp b/lora.hpp index d38c7116f..9f690a397 100644 --- a/lora.hpp +++ b/lora.hpp @@ -3,7 +3,7 @@ #include "ggml_extend.hpp" -#define LORA_GRAPH_SIZE 10240 +#define LORA_GRAPH_SIZE 20480 struct LoraModel : public GGMLRunner { enum lora_t { From 1ec53481e56277cf16b06d807e0594a8ad3b9282 Mon Sep 17 00:00:00 2001 From: Marcus Schaber Date: Thu, 10 Jul 2025 16:37:31 +0200 Subject: [PATCH 6/6] Revert "fix: allow larger lora sizes" This reverts commit b205ecdeece199fa7bd84a339e8fe21aa785f053. --- lora.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lora.hpp b/lora.hpp index 9f690a397..d38c7116f 100644 --- a/lora.hpp +++ b/lora.hpp @@ -3,7 +3,7 @@ #include "ggml_extend.hpp" -#define LORA_GRAPH_SIZE 20480 +#define LORA_GRAPH_SIZE 10240 struct LoraModel : public GGMLRunner { enum lora_t {