diff --git a/util.cpp b/util.cpp index c46216646..1b17bc3d6 100644 --- a/util.cpp +++ b/util.cpp @@ -12,6 +12,9 @@ #include #include #include "preprocessing.hpp" +#include "ggml-cpu.h" +#include "ggml.h" +#include "stable-diffusion.h" #if defined(__APPLE__) && defined(__MACH__) #include @@ -23,9 +26,17 @@ #include #endif -#include "ggml-cpu.h" -#include "ggml.h" -#include "stable-diffusion.h" +#ifdef _WIN32 +#define NOMINMAX +#include + +#else // Unix +#include +#include + +#endif + +namespace sd_internal { bool ends_with(const std::string& str, const std::string& ending) { if (str.length() >= ending.length()) { @@ -82,8 +93,6 @@ int round_up_to(int value, int base) { } #ifdef _WIN32 // code for windows -#define NOMINMAX -#include bool file_exists(const std::string& filename) { DWORD attributes = GetFileAttributesA(filename.c_str()); @@ -110,8 +119,6 @@ std::string get_full_path(const std::string& dir, const std::string& filename) { } #else // Unix -#include -#include bool file_exists(const std::string& filename) { struct stat buffer; @@ -145,6 +152,8 @@ std::string get_full_path(const std::string& dir, const std::string& filename) { #endif +} + // 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 @@ -183,6 +192,8 @@ int32_t get_num_physical_cores() { return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4; } +namespace sd_internal { + static sd_progress_cb_t sd_progress_cb = nullptr; void* sd_progress_cb_data = nullptr; @@ -327,6 +338,8 @@ void log_printf(sd_log_level_t level, const char* file, int line, const char* fo va_end(args); } +} + void sd_set_log_callback(sd_log_cb_t cb, void* data) { sd_log_cb = cb; sd_log_cb_data = data; @@ -343,6 +356,8 @@ void sd_set_preview_callback(sd_preview_cb_t cb, preview_t mode = PREVIEW_PROJ, sd_preview_noisy = noisy; } +namespace sd_internal { + sd_preview_cb_t sd_get_preview_callback() { return sd_preview_cb; } @@ -366,6 +381,9 @@ sd_progress_cb_t sd_get_progress_callback() { void* sd_get_progress_callback_data() { return sd_progress_cb_data; } + +} + const char* sd_get_system_info() { static char buffer[1024]; std::stringstream ss; @@ -387,6 +405,8 @@ const char* sd_get_system_info() { return buffer; } +namespace sd_internal { + sd_image_f32_t sd_image_t_to_sd_image_f32_t(sd_image_t image) { sd_image_f32_t converted_image; converted_image.width = image.width; @@ -651,3 +671,5 @@ std::vector> parse_prompt_attention(const std::str return res; } + +} diff --git a/util.h b/util.h index 5bd69a624..294b5ab7b 100644 --- a/util.h +++ b/util.h @@ -10,6 +10,8 @@ #define SAFE_STR(s) ((s) ? (s) : "") #define BOOL_STR(b) ((b) ? "true" : "false") +inline namespace sd_internal { + 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); @@ -67,4 +69,7 @@ bool sd_should_preview_noisy(); #define LOG_INFO(format, ...) log_printf(SD_LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__) #define LOG_WARN(format, ...) log_printf(SD_LOG_WARN, __FILE__, __LINE__, format, ##__VA_ARGS__) #define LOG_ERROR(format, ...) log_printf(SD_LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__) + +} + #endif // __UTIL_H__