feat: support ggml backend select and enhance the build system#1368
Open
Cyberhan123 wants to merge 32 commits intoleejet:masterfrom
Open
feat: support ggml backend select and enhance the build system#1368Cyberhan123 wants to merge 32 commits intoleejet:masterfrom
Cyberhan123 wants to merge 32 commits intoleejet:masterfrom
Conversation
fix sdxl conditionner backends fix sd3 backend display
…end support, and eliminate hard-coded backend references.
There was a problem hiding this comment.
Pull request overview
This PR adds runtime GGML backend device selection (including multi-backend setups and RPC devices) and refactors the CMake build/install packaging to better support these new backend workflows.
Changes:
- Introduces named-backend initialization helpers and new C API utilities to list available devices and register RPC devices.
- Extends
sd_ctx_params_tto allow selecting devices per model component (diffusion/CLIP/VAE/ControlNet/etc.) and updates model/component construction accordingly. - Restructures the CMake build into subdirectories and adds install artifacts (pkg-config + CMake package config), plus updates CLI/server docs and flags.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/z_image.hpp | Switches backend-specific numeric workarounds from compile-time macros to runtime backend detection. |
| src/qwen_image.hpp | Same as above (runtime Vulkan precision workaround). |
| src/common_block.hpp | Same as above (runtime Vulkan precision workaround). |
| src/util.h | Adds sd_backend_is() declaration and includes ggml backend header. |
| src/util.cpp | Implements sd_backend_is(). |
| src/ggml_extend.hpp | Adds named-backend init helpers; extends LoRA adapter interfaces to be backend-aware; updates cast/sync helpers. |
| src/lora.hpp | Passes backend through LoRA weight-diff/cast paths so Vulkan-specific casting can be applied correctly. |
| src/conditioner.hpp | Enables multiple backends for multi-encoder conditioners; adds per-encoder backend accessors. |
| src/stable-diffusion.cpp | Implements per-component backend initialization, RPC device registration, and backend/device listing APIs; refactors backend usage throughout initialization and LoRA flows. |
| src/upscaler.cpp | Adds backend device selection for upscaler initialization via named backend. |
| src/model.cpp | Removes backend-specific includes (moving toward backend-agnostic compilation). |
| include/stable-diffusion.h | Extends sd_ctx_params_t with per-component device strings; extends upscaler API; adds device listing + RPC registration APIs. |
| examples/common/common.hpp | Adds CLI/server flags and wiring for per-component backend devices; adjusts option parsing flow control. |
| examples/cli/main.cpp | Adds --rpc and --list-devices; passes selected upscaler backend device into the upscaler API. |
| examples/cli/README.md | Documents new CLI flags and backend device selection options. |
| examples/server/README.md | Documents new server flags and backend device selection options; removes CPU-only component toggles. |
| examples/CMakeLists.txt | Adjusts examples build flags/includes and subdirectories. |
| docs/rpc.md | New documentation for building/using RPC server setups with this project. |
| src/CMakeLists.txt | New src-level library target definition. |
| cmake/common.cmake | New shared compile-flag helpers (warnings/sanitizers). |
| cmake/build-info.cmake | New build metadata extraction (git commit/count, compiler, target). |
| cmake/sd.pc.in | Adds pkg-config template for installation. |
| cmake/sd-config.cmake.in | Adds CMake package config template for installation. |
| CMakeLists.txt | Major build refactor: module path, shared/static defaults, ggml option transitions, add src/ subdir build, and install/package generation. |
Comments suppressed due to low confidence (1)
CMakeLists.txt:160
- The
if(GGML_SYCL)block callstarget_compile_options(${SD_LIB} ...)before${SD_LIB}is created (the target is defined later insrc/CMakeLists.txt). This will fail configuration whenGGML_SYCL=ON. Move the SYCL-specifictarget_compile_options()call to afteradd_subdirectory(src)(or apply the flags via variables/target properties insidesrc/CMakeLists.txt).
# Is this needed?
if(GGML_SYCL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -fsycl")
# disable fast-math on host, see:
# https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-10/fp-model-fp.html
if (WIN32)
set(SYCL_COMPILE_OPTIONS /fp:precise)
else()
set(SYCL_COMPILE_OPTIONS -fp-model=precise)
endif()
message("-- Turn off fast-math for host in SYCL backend")
target_compile_options(${SD_LIB} PRIVATE ${SYCL_COMPILE_OPTIONS})
endif()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR requires merging with previous PR : #1184