From cf0248ca24310b92c761cd728dde40d671f90d76 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Mon, 10 Nov 2025 19:51:09 -0300 Subject: [PATCH] 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 619c42847..935728a0f 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -1172,7 +1172,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 519284e6a..9300f91e6 100644 --- a/model.cpp +++ b/model.cpp @@ -1293,7 +1293,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 4cea83a19..2a8dc3577 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -2085,7 +2085,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->prediction = DEFAULT_PRED; diff --git a/stable-diffusion.h b/stable-diffusion.h index 9e99d53de..e74382a58 100644 --- a/stable-diffusion.h +++ b/stable-diffusion.h @@ -268,7 +268,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, preview_t mode, int interval, bool denoised, bool noisy); -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 1aa9beff8..037f1135a 100644 --- a/util.cpp +++ b/util.cpp @@ -147,7 +147,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;