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..3bd13a0b2 --- /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.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 new file mode 100644 index 000000000..fff2564c7 --- /dev/null +++ b/docker/build-rocm.ps1 @@ -0,0 +1,16 @@ +$rocMDir = "C:/Program Files/AMD/ROCm/6.2" + +$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 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..a6545d2b0 --- /dev/null +++ b/docker/build.ps1 @@ -0,0 +1,18 @@ +param ( + [Parameter(Mandatory = $true)] + [ValidateSet("rocm", "cuda")] + [string] + $Acceleration +) + +$dockerfile = "${PSScriptRoot}/win-${Acceleration}.Dockerfile" +docker build -t sd-cpp -f $dockerfile $PSScriptRoot + +if (!(Test-Path $PSScriptRoot/build)) { + mkdir $PSScriptRoot/build +} + +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-rocm.Dockerfile b/docker/win-rocm.Dockerfile new file mode 100644 index 000000000..6053a4542 --- /dev/null +++ b/docker/win-rocm.Dockerfile @@ -0,0 +1,23 @@ +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; \ + 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 + +WORKDIR C:/sd_cpp +CMD ["powershell"] \ No newline at end of file