diff --git a/.github/workflows/backends.yml b/.github/workflows/backends.yml index 53851d0..cfbe27b 100644 --- a/.github/workflows/backends.yml +++ b/.github/workflows/backends.yml @@ -30,8 +30,6 @@ jobs: defines: '-DGGML_AVX2=ON -DSD_BUILD_SHARED_LIBS=ON' - build: 'avx512' defines: '-DGGML_AVX512=ON -DSD_BUILD_SHARED_LIBS=ON' - - build: 'cuda11' - defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_FLAGS="-allow-unsupported-compiler"' - build: 'cuda12' defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON' - build: 'rocm5' @@ -48,17 +46,6 @@ jobs: ref: '${{ github.event.inputs.commit }}' submodules: recursive - - name: Install cuda-toolkit - id: cuda-toolkit-11 - if: ${{ matrix.build == 'cuda11' }} - uses: Jimver/cuda-toolkit@v0.2.14 - with: - cuda: '11.8.0' - method: network - sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' - use-github-cache: false - use-local-cache: false - - name: Install cuda-toolkit id: cuda-toolkit-12 if: ${{ matrix.build == 'cuda12' }} @@ -116,6 +103,51 @@ jobs: with: name: windows-${{ matrix.build }} path: .\build\bin\stable-diffusion.dll + + windows-2019: + runs-on: windows-2019 + + strategy: + matrix: + include: + - build: 'cuda11' + defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_FLAGS="-allow-unsupported-compiler"' + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4.1.2 + with: + repository: 'leejet/stable-diffusion.cpp' + ref: '${{ github.event.inputs.commit }}' + submodules: recursive + + - name: Install cuda-toolkit + id: cuda-toolkit-11 + if: ${{ matrix.build == 'cuda11' }} + uses: Jimver/cuda-toolkit@v0.2.16 + with: + cuda: '11.8.0' + method: network + sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' + use-github-cache: false + use-local-cache: false + + - name: Build + id: cmake_build + run: | + mkdir build + cd build + cmake .. ${{ matrix.defines }} + cmake --build . --config Release + + - name: Upload artifact + id: upload_artifact + if: ${{ matrix.build != 'rocm5' }} + uses: actions/upload-artifact@v4.3.1 + with: + name: windows-${{ matrix.build }} + path: .\build\bin\Release\stable-diffusion.dll windows-sycl: runs-on: windows-latest diff --git a/StableDiffusion.NET/Helper/ImageHelper.cs b/StableDiffusion.NET/Helper/ImageHelper.cs index dbccb15..1c38a31 100644 --- a/StableDiffusion.NET/Helper/ImageHelper.cs +++ b/StableDiffusion.NET/Helper/ImageHelper.cs @@ -8,21 +8,29 @@ internal static class ImageHelper { public static unsafe Image ToImage(Native.sd_image_t* sdImage) { - int width = (int)sdImage->width; - int height = (int)sdImage->height; - int bpp = (int)sdImage->channel; + Image image = ToImage(*sdImage); - Image image = Image.Create(new ReadOnlySpan(sdImage->data, width * height * bpp), width, height, width * bpp); + Marshal.FreeHGlobal((nint)sdImage); + + return image; + } + + public static unsafe Image ToImage(Native.sd_image_t sdImage) + { + int width = (int)sdImage.width; + int height = (int)sdImage.height; + int bpp = (int)sdImage.channel; + + Image image = Image.Create(new ReadOnlySpan(sdImage.data, width * height * bpp), width, height, width * bpp); Dispose(sdImage); return image; } - public static unsafe void Dispose(Native.sd_image_t* image) + public static unsafe void Dispose(Native.sd_image_t image) { - Marshal.FreeHGlobal((nint)image->data); - Marshal.FreeHGlobal((nint)image); + Marshal.FreeHGlobal((nint)image.data); } public static unsafe Native.sd_image_t ToSdImage(this IImage image, byte* pinnedReference) diff --git a/StableDiffusion.NET/Models/UpscaleModel.cs b/StableDiffusion.NET/Models/UpscaleModel.cs index eb7e610..600f5b3 100644 --- a/StableDiffusion.NET/Models/UpscaleModel.cs +++ b/StableDiffusion.NET/Models/UpscaleModel.cs @@ -58,14 +58,14 @@ public IImage Upscale(IImage image, int upscaleFactor) fixed (byte* imagePtr = sourceImage.AsRefImage()) { Native.sd_image_t result = Native.upscale(_ctx, sourceImage.ToSdImage(imagePtr), upscaleFactor); - return ImageHelper.ToImage(&result); + return ImageHelper.ToImage(result); } } private IImage Upscale(Native.sd_image_t image, int upscaleFactor) { Native.sd_image_t result = Native.upscale(_ctx, image, upscaleFactor); - return ImageHelper.ToImage(&result); + return ImageHelper.ToImage(result); } public void Dispose()