Skip to content

refactor: call CPU backend functions dynamically#1591

Open
wbruna wants to merge 1 commit into
leejet:masterfrom
wbruna:sd_cpu_dynamic
Open

refactor: call CPU backend functions dynamically#1591
wbruna wants to merge 1 commit into
leejet:masterfrom
wbruna:sd_cpu_dynamic

Conversation

@wbruna
Copy link
Copy Markdown
Contributor

@wbruna wbruna commented Jun 1, 2026

Summary

Replaces ggml_backend_cpu_init, ggml_backend_is_cpu, ggml_backend_cpu_set_n_threads functions with dynamic ggml backend calls, and avoids ggml_cpu_has_* by getting the flags with a function provided by ggml.

These functions are not available without native CPU builds. With these changes, I was able to build and run sd.cpp with a runtime-selected CPU backend (-DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON).

It changes the CPU info log, since ggml only reports the active flags, but I've tried to keep the formatting similar:

[DEBUG] main.cpp:598 - System Info:
SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | BMI2 = 1 | OPENMP = 1 | REPACK = 1 |

Related Issue / Discussion

Should fix #1567, although the issue with GGML_MAX_NAME would remain.

Could help with #1589, #1588, #1483, #1351 by allowing binary releases using dynamically-selected ggml CPU backends.

Complements the runtime backend selection (#1448).

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] build:ld error

1 participant