From f284d0c2806fb87865163f5599c6084bdf627ad1 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Mon, 10 Nov 2025 19:51:09 -0300 Subject: [PATCH 1/2] chore: add sd_ prefix to get_num_physical_cores This helps avoid a name conflict (for instance with the original function) when linking against the library. --- examples/cli/main.cpp | 2 +- model.cpp | 2 +- stable-diffusion.cpp | 2 +- stable-diffusion.h | 2 +- util.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index ed3f849d4..bc5444281 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -1306,7 +1306,7 @@ void parse_args(int argc, const char** argv, SDParams& params) { } if (params.n_threads <= 0) { - params.n_threads = get_num_physical_cores(); + params.n_threads = sd_get_num_physical_cores(); } if ((params.mode == IMG_GEN || params.mode == VID_GEN) && params.prompt.length() == 0) { diff --git a/model.cpp b/model.cpp index 05afde947..3d7185706 100644 --- a/model.cpp +++ b/model.cpp @@ -1352,7 +1352,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, int n_thread std::atomic copy_to_backend_time_ms(0); std::atomic convert_time_ms(0); - int num_threads_to_use = n_threads_p > 0 ? n_threads_p : get_num_physical_cores(); + int num_threads_to_use = n_threads_p > 0 ? n_threads_p : sd_get_num_physical_cores(); LOG_DEBUG("using %d threads for model loading", num_threads_to_use); int64_t start_time = ggml_time_ms(); diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 074290d84..5b14c4e6a 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -2452,7 +2452,7 @@ void sd_ctx_params_init(sd_ctx_params_t* sd_ctx_params) { *sd_ctx_params = {}; sd_ctx_params->vae_decode_only = true; sd_ctx_params->free_params_immediately = true; - sd_ctx_params->n_threads = get_num_physical_cores(); + sd_ctx_params->n_threads = sd_get_num_physical_cores(); sd_ctx_params->wtype = SD_TYPE_COUNT; sd_ctx_params->rng_type = CUDA_RNG; sd_ctx_params->sampler_rng_type = RNG_TYPE_COUNT; diff --git a/stable-diffusion.h b/stable-diffusion.h index 0cbefd971..b0d3ee672 100644 --- a/stable-diffusion.h +++ b/stable-diffusion.h @@ -288,7 +288,7 @@ typedef void (*sd_preview_cb_t)(int step, int frame_count, sd_image_t* frames, b SD_API void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data); SD_API void sd_set_progress_callback(sd_progress_cb_t cb, void* data); SD_API void sd_set_preview_callback(sd_preview_cb_t cb, enum preview_t mode, int interval, bool denoised, bool noisy, void* data); -SD_API int32_t get_num_physical_cores(); +SD_API int32_t sd_get_num_physical_cores(); SD_API const char* sd_get_system_info(); SD_API const char* sd_type_name(enum sd_type_t type); diff --git a/util.cpp b/util.cpp index f101c3b7a..c82092ec2 100644 --- a/util.cpp +++ b/util.cpp @@ -148,7 +148,7 @@ std::string get_full_path(const std::string& dir, const std::string& filename) { // get_num_physical_cores is copy from // https://github.com/ggerganov/llama.cpp/blob/master/examples/common.cpp // LICENSE: https://github.com/ggerganov/llama.cpp/blob/master/LICENSE -int32_t get_num_physical_cores() { +int32_t sd_get_num_physical_cores() { #ifdef __linux__ // enumerate the set of thread siblings, num entries is num cores std::unordered_set siblings; From dc66e20249082904061c4adbda5f61eee3fdf163 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Sun, 30 Nov 2025 11:33:30 -0300 Subject: [PATCH 2/2] chore: add sd_ prefix to format() Avoid a symbol conflict with the same named function from libllama. Fixes #1011 --- model.cpp | 8 ++++---- util.cpp | 2 +- util.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model.cpp b/model.cpp index 3d7185706..c9593c33f 100644 --- a/model.cpp +++ b/model.cpp @@ -265,8 +265,8 @@ void convert_tensor(void* src, } else { auto qtype = ggml_get_type_traits(src_type); if (qtype->to_float == nullptr) { - throw std::runtime_error(format("type %s unsupported for integer quantization: no dequantization available", - ggml_type_name(src_type))); + throw std::runtime_error(sd_format("type %s unsupported for integer quantization: no dequantization available", + ggml_type_name(src_type))); } qtype->to_float(src, (float*)dst, n); } @@ -275,8 +275,8 @@ void convert_tensor(void* src, // src_type is quantized => dst_type == GGML_TYPE_F16 or dst_type is quantized auto qtype = ggml_get_type_traits(src_type); if (qtype->to_float == nullptr) { - throw std::runtime_error(format("type %s unsupported for integer quantization: no dequantization available", - ggml_type_name(src_type))); + throw std::runtime_error(sd_format("type %s unsupported for integer quantization: no dequantization available", + ggml_type_name(src_type))); } std::vector buf; buf.resize(sizeof(float) * n); diff --git a/util.cpp b/util.cpp index c82092ec2..68250a910 100644 --- a/util.cpp +++ b/util.cpp @@ -57,7 +57,7 @@ void replace_all_chars(std::string& str, char target, char replacement) { } } -std::string format(const char* fmt, ...) { +std::string sd_format(const char* fmt, ...) { va_list ap; va_list ap2; va_start(ap, fmt); diff --git a/util.h b/util.h index 2721f29ee..61ca9334a 100644 --- a/util.h +++ b/util.h @@ -14,7 +14,7 @@ bool ends_with(const std::string& str, const std::string& ending); bool starts_with(const std::string& str, const std::string& start); bool contains(const std::string& str, const std::string& substr); -std::string format(const char* fmt, ...); +std::string sd_format(const char* fmt, ...); void replace_all_chars(std::string& str, char target, char replacement);