From 82d84270f7721f77645ed0883afe991cdbf139a7 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Fri, 19 Jan 2024 18:00:58 +0800 Subject: [PATCH 01/12] chore: improve ci --- .github/workflows/build.yml | 130 +++++++++++++++++++++++++++--------- CMakeLists.txt | 13 ++-- 2 files changed, 109 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 50e6a9227..ce2bbbd89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,26 +30,42 @@ jobs: with: submodules: recursive - - name: Dependencies id: depends run: | sudo apt-get update - sudo apt-get install build-essential + sudo apt-get install build-essential zip - name: Build id: cmake_build run: | mkdir build cd build - cmake .. + cmake .. -DGGML_AVX2=ON -DSD_BUILD_SHARED_LIBS=ON cmake --build . --config Release - #- name: Test - #id: cmake_test - #run: | - #cd build - #ctest --verbose --timeout 900 + - name: Get commit hash + id: commit + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + uses: pr-mpt/actions-commit-hash@v2 + + - name: Fetch system info + id: system-info + run: | + echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" + echo "OS_NAME=`lsb_release -s -i`" >> "$GITHUB_OUTPUT" + echo "OS_VERSION=`lsb_release -s -r`" >> "$GITHUB_OUTPUT" + echo "OS_TYPE=`uname -s`" >> "$GITHUB_OUTPUT" + + - name: Pack artifacts + id: pack_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + run: | + cp ggml/LICENSE ./build/bin/ggml.txt + cp LICENSE ./build/bin/stable-diffusion.cpp.txt + zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + + macOS-latest-cmake: runs-on: macos-latest @@ -63,9 +79,8 @@ jobs: - name: Dependencies id: depends - continue-on-error: true run: | - brew update + brew install zip - name: Build id: cmake_build @@ -73,14 +88,37 @@ jobs: sysctl -a mkdir build cd build - cmake .. + cmake .. -DGGML_AVX2=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DSD_BUILD_SHARED_LIBS=ON cmake --build . --config Release - #- name: Test - #id: cmake_test - #run: | - #cd build - #ctest --verbose --timeout 900 + - name: Get commit hash + id: commit + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + uses: pr-mpt/actions-commit-hash@v2 + + - name: Fetch system info + id: system-info + run: | + echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" + echo "OS_NAME=`sw_vers -productName`" >> "$GITHUB_OUTPUT" + echo "OS_VERSION=`sw_vers -productVersion`" >> "$GITHUB_OUTPUT" + echo "OS_TYPE=`uname -s`" >> "$GITHUB_OUTPUT" + + - name: Pack artifacts + id: pack_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + run: | + cp ggml/LICENSE ./build/bin/ggml.txt + cp LICENSE ./build/bin/stable-diffusion.cpp.txt + zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + + - name: Upload artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-artifact@v3 + with: + path: | + sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip + windows-latest-cmake: runs-on: windows-latest @@ -89,14 +127,17 @@ jobs: matrix: include: - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DSD_BUILD_SHARED_LIBS=ON' - build: 'avx2' - defines: '-DGGML_AVX2=ON' + defines: '-DGGML_AVX2=ON -DSD_BUILD_SHARED_LIBS=ON' - build: 'avx' - defines: '-DGGML_AVX2=OFF' + defines: '-DGGML_AVX2=OFF -DSD_BUILD_SHARED_LIBS=ON' - build: 'avx512' - defines: '-DGGML_AVX512=ON' - + defines: '-DGGML_AVX512=ON -DSD_BUILD_SHARED_LIBS=ON' + - build: 'cuda12' + defines: '-DSD_CUBLAS=ON -DSD_BUILD_SHARED_LIBS=ON' + - build: 'rocm5.5' + 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' steps: - name: Clone id: checkout @@ -104,6 +145,29 @@ jobs: with: submodules: recursive + - name: Install cuda-toolkit + id: cuda_toolkit + if: ${{ matrix.build == 'cuda12' }} + uses: Jimver/cuda-toolkit@v0.2.11 + with: + cuda: '12.2.0' + method: 'network' + sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' + + - name: Install rocm-toolkit + id: rocm-toolkit + if: ${{ matrix.build == 'rocm5.5' }} + uses: Cyberhan123/rocm-toolkit@v0.1.0 + with: + rocm: '5.5.0' + + - name: Install Ninja + id: install-ninja + if: ${{ matrix.build == 'rocm5.5' }} + uses: urkle/action-get-ninja@v1 + with: + version: 1.11.1 + - name: Build id: cmake_build run: | @@ -125,12 +189,6 @@ jobs: & $cl /O2 /GS- /kernel avx512f.c /link /nodefaultlib /entry:main .\avx512f.exe && echo "AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo "AVX512F: NO" - #- name: Test - #id: cmake_test - #run: | - #cd build - #ctest -C Release --verbose --timeout 900 - - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -140,9 +198,21 @@ jobs: id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | - Copy-Item ggml/LICENSE .\build\bin\Release\ggml.txt - Copy-Item LICENSE .\build\bin\Release\stable-diffusion.cpp.txt - 7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip .\build\bin\Release\* + $filePath = ".\build\bin\Release\*" + if (Test-Path $filePath) { + echo "Exists at path $filePath" + Copy-Item ggml/LICENSE .\build\bin\Release\ggml.txt + Copy-Item LICENSE .\build\bin\Release\stable-diffusion.cpp.txt + } elseif (Test-Path ".\build\bin\stable-diffusion.dll") { + $filePath = ".\build\bin\*" + echo "Exists at path $filePath" + Copy-Item ggml/LICENSE .\build\bin\ggml.txt + Copy-Item LICENSE .\build\bin\stable-diffusion.cpp.txt + } else { + ls .\build\bin + throw "Can't find stable-diffusion.dll" + } + 7z a rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index d7522d5a3..82540a1be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ option(SD_HIPBLAS "sd: rocm backend" OFF) option(SD_METAL "sd: metal backend" OFF) option(SD_FLASH_ATTN "sd: use flash attention for x4 less memory usage" OFF) option(SD_FAST_SOFTMAX "sd: x1.5 faster softmax, indeterministic (sometimes, same seed don't generate same image), cuda only" OFF) -option(BUILD_SHARED_LIBS "sd: build shared libs" OFF) +option(SD_BUILD_SHARED_LIBS "sd: build shared libs" OFF) #option(SD_BUILD_SERVER "sd: build server example" ON) if(SD_CUBLAS) @@ -63,16 +63,21 @@ endif() set(SD_LIB stable-diffusion) -add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp model.h model.cpp util.h util.cpp upscaler.cpp - ggml_extend.hpp clip.hpp common.hpp unet.hpp tae.hpp esrgan.hpp lora.hpp denoiser.hpp rng.hpp rng_philox.hpp) +set(SD_LIB_INCLUDE stable-diffusion.h stable-diffusion.cpp model.h model.cpp util.h util.cpp upscaler.cpp + ggml_extend.hpp clip.hpp common.hpp unet.hpp tae.hpp esrgan.hpp lora.hpp denoiser.hpp rng.hpp rng_philox.hpp) -if(BUILD_SHARED_LIBS) +# we can get only one share lib +if(SD_BUILD_SHARED_LIBS) message("Build shared library") + set(BUILD_SHARED_LIBS OFF) + message(${SD_LIB_INCLUDE}) + add_library(${SD_LIB} SHARED ${SD_LIB_INCLUDE}) add_definitions(-DSD_BUILD_SHARED_LIB) target_compile_definitions(${SD_LIB} PRIVATE -DSD_BUILD_DLL) set(CMAKE_POSITION_INDEPENDENT_CODE ON) else() message("Build static library") + add_library(${SD_LIB} SHARED ${SD_LIB_INCLUDE}) endif() From 69de76776a75cd92082b4d2049127ac2d4f1137f Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Fri, 19 Jan 2024 20:09:44 +0800 Subject: [PATCH 02/12] fix issues mentioned in comments --- .github/workflows/build.yml | 10 ++++++++-- CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce2bbbd89..01843ef84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: id: depends run: | sudo apt-get update - sudo apt-get install build-essential zip + sudo apt-get install build-essential - name: Build id: cmake_build @@ -65,6 +65,12 @@ jobs: cp LICENSE ./build/bin/stable-diffusion.cpp.txt zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + - name: Upload artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-artifact@v3 + with: + path: | + sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip macOS-latest-cmake: @@ -212,7 +218,7 @@ jobs: ls .\build\bin throw "Can't find stable-diffusion.dll" } - 7z a rwkv-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath + 7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 82540a1be..7c728a628 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,7 @@ if(SD_BUILD_SHARED_LIBS) set(CMAKE_POSITION_INDEPENDENT_CODE ON) else() message("Build static library") - add_library(${SD_LIB} SHARED ${SD_LIB_INCLUDE}) + add_library(${SD_LIB} STATIC ${SD_LIB_INCLUDE}) endif() From aec9030d23c6df26dacf7bafabcb9fb81a1afaba Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Fri, 2 Feb 2024 15:30:47 +0800 Subject: [PATCH 03/12] try fix dylib export on windows --- stable-diffusion.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stable-diffusion.h b/stable-diffusion.h index a8c9f5329..24ef7c612 100644 --- a/stable-diffusion.h +++ b/stable-diffusion.h @@ -158,6 +158,10 @@ SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image, SD_API bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type); +SD_API void log_printf(sd_log_level_t level, const char* file, int line, const char* format, ...); + +SD_API std::string sd_basename(const std::string& path); + #ifdef __cplusplus } #endif From 633311ccab38627dc31ce4a693a9d8954761a132 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Fri, 2 Feb 2024 16:09:18 +0800 Subject: [PATCH 04/12] fix darwin and linux pack artifacts --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 01843ef84..d1348ae00 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,14 +59,14 @@ jobs: - name: Pack artifacts id: pack_artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v3 with: path: | @@ -112,14 +112,14 @@ jobs: - name: Pack artifacts id: pack_artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v3 with: path: | From cf378e859ba407a6fe2abdd276d4a75ec1be3f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=BA=E6=97=BA=E7=A2=8E=E5=86=B0=E5=86=B0?= <38837039+Cyberhan123@users.noreply.github.com> Date: Sat, 3 Feb 2024 08:27:50 +0800 Subject: [PATCH 05/12] Update build.yml --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1348ae00..30d9ff9dc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt - zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + zip sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -116,7 +116,7 @@ jobs: run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt - zip -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + zip sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} From bd56734868a8857ac2df6dd1be5871f04568d2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=BA=E6=97=BA=E7=A2=8E=E5=86=B0=E5=86=B0?= <38837039+Cyberhan123@users.noreply.github.com> Date: Sat, 3 Feb 2024 08:48:39 +0800 Subject: [PATCH 06/12] Update build.yml --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30d9ff9dc..07bcd39a4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt - zip sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -116,7 +116,7 @@ jobs: run: | cp ggml/LICENSE ./build/bin/ggml.txt cp LICENSE ./build/bin/stable-diffusion.cpp.txt - zip sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* + zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} From 34deced17243d4adf91435ca1721c54a1e111b36 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Wed, 7 Feb 2024 09:46:28 +0800 Subject: [PATCH 07/12] export preprocess_canny --- preprocessing.hpp | 2 +- stable-diffusion.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/preprocessing.hpp b/preprocessing.hpp index d0e899ca7..4807e3936 100644 --- a/preprocessing.hpp +++ b/preprocessing.hpp @@ -162,7 +162,7 @@ void threshold_hystersis(struct ggml_tensor* img, float highThreshold, float low } } -uint8_t* preprocess_canny(uint8_t* img, int width, int height, float highThreshold = 0.08f, float lowThreshold = 0.08f, float weak = 0.8f, float strong = 1.0f, bool inverse = false) { +uint8_t* preprocess_canny(uint8_t* img, int width, int height, float highThreshold, float lowThreshold, float weak, float strong, bool inverse) { struct ggml_init_params params; params.mem_size = static_cast(10 * 1024 * 1024); // 10 params.mem_buffer = NULL; diff --git a/stable-diffusion.h b/stable-diffusion.h index 24ef7c612..58ec9ace9 100644 --- a/stable-diffusion.h +++ b/stable-diffusion.h @@ -162,6 +162,8 @@ SD_API void log_printf(sd_log_level_t level, const char* file, int line, const c SD_API std::string sd_basename(const std::string& path); +SD_API uint8_t* preprocess_canny(uint8_t* img, int width, int height, float highThreshold = 0.08f, float lowThreshold = 0.08f, float weak = 0.8f, float strong = 1.0f, bool inverse = false); + #ifdef __cplusplus } #endif From 99cb442667da3dfb5010c83a9079b7959866ac61 Mon Sep 17 00:00:00 2001 From: leejet Date: Sun, 25 Feb 2024 21:54:25 +0800 Subject: [PATCH 08/12] fix: fix the issue with dynamic linking --- examples/cli/main.cpp | 3 +-- util.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 13725e740..6b74b6923 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -6,7 +6,7 @@ #include #include -#include "preprocessing.hpp" +// #include "preprocessing.hpp" #include "stable-diffusion.h" #define STB_IMAGE_IMPLEMENTATION @@ -642,7 +642,6 @@ int main(int argc, const char* argv[]) { 3, input_image_buffer}; if (params.canny_preprocess) { // apply preprocessor - LOG_INFO("Applying canny preprocessor"); control_image->data = preprocess_canny(control_image->data, control_image->width, control_image->height, diff --git a/util.cpp b/util.cpp index 27173c6a1..346886b1b 100644 --- a/util.cpp +++ b/util.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "preprocessing.hpp" #if defined(__APPLE__) && defined(__MACH__) #include From b9400ec4dd57b81a57eba963cfe58dc381e38d6e Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Sun, 25 Feb 2024 23:17:32 +0800 Subject: [PATCH 09/12] try pack cuda runtime --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07bcd39a4..76884fdd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -195,6 +195,15 @@ jobs: & $cl /O2 /GS- /kernel avx512f.c /link /nodefaultlib /entry:main .\avx512f.exe && echo "AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo "AVX512F: NO" + - name: Copy and pack Cuda runtime + id: pack_cuda_runtime + if: ${{ matrix.build == 'cuda12' }} + run: | + echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" + $dst='.\build\bin\cudart\' + robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll + 7z a cudart-llama-bin-win-cu${{ matrix.cuda }}-x64.zip $dst\* + - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} From 81175cd1971ecd9aeaebe0b200c6447510d23472 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Sun, 25 Feb 2024 23:20:00 +0800 Subject: [PATCH 10/12] change name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76884fdd2..9ab201424 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -202,7 +202,7 @@ jobs: echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" $dst='.\build\bin\cudart\' robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll - 7z a cudart-llama-bin-win-cu${{ matrix.cuda }}-x64.zip $dst\* + 7z a cudart-sd-bin-win-cu12-x64.zip $dst\* - name: Get commit hash id: commit From e3632c3040f0d160a1079867e6759501c5758306 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Sun, 25 Feb 2024 23:53:31 +0800 Subject: [PATCH 11/12] fix cudart pack --- .github/workflows/build.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ab201424..1efc68042 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -152,7 +152,7 @@ jobs: submodules: recursive - name: Install cuda-toolkit - id: cuda_toolkit + id: cuda-toolkit if: ${{ matrix.build == 'cuda12' }} uses: Jimver/cuda-toolkit@v0.2.11 with: @@ -195,15 +195,6 @@ jobs: & $cl /O2 /GS- /kernel avx512f.c /link /nodefaultlib /entry:main .\avx512f.exe && echo "AVX512F: YES" && ( echo HAS_AVX512F=1 >> $env:GITHUB_ENV ) || echo "AVX512F: NO" - - name: Copy and pack Cuda runtime - id: pack_cuda_runtime - if: ${{ matrix.build == 'cuda12' }} - run: | - echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" - $dst='.\build\bin\cudart\' - robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll - 7z a cudart-sd-bin-win-cu12-x64.zip $dst\* - - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -229,6 +220,22 @@ jobs: } 7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath + - name: Copy and pack Cuda runtime + id: pack_cuda_runtime + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' && github.event.inputs.create_release == 'true' }} + run: | + echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" + $dst='.\build\bin\cudart\' + robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll + 7z a cudart-sd-bin-win-cu12-x64.zip $dst\* + + - name: Upload Cuda runtime + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' && github.event.inputs.create_release == 'true' }} + uses: actions/upload-artifact@v3 + with: + path: | + cudart-sd-bin-win-cu12-x64.zip + - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v3 From 346416b9ab547612002ad835db086cd69ddd5340 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Mon, 26 Feb 2024 00:27:10 +0800 Subject: [PATCH 12/12] try to fix if judgment logic --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1efc68042..9a05aa5fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -222,7 +222,7 @@ jobs: - name: Copy and pack Cuda runtime id: pack_cuda_runtime - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' && github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }} run: | echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" $dst='.\build\bin\cudart\' @@ -230,7 +230,7 @@ jobs: 7z a cudart-sd-bin-win-cu12-x64.zip $dst\* - name: Upload Cuda runtime - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' && github.event.inputs.create_release == 'true' }} + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v3 with: path: |