From 0d7f04b135cd48e8d62aecd09a52eb2afa482744 Mon Sep 17 00:00:00 2001 From: leejet Date: Tue, 22 Aug 2023 23:03:17 +0800 Subject: [PATCH] feat: print seed value when args.seed < 0 --- examples/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index 0412d43..6cae6ac 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -28,18 +29,17 @@ #define TXT2IMG "txt2img" #define IMG2IMG "img2img" -// get_num_physical_cores is copy from +// 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() { #ifdef __linux__ // enumerate the set of thread siblings, num entries is num cores std::unordered_set siblings; - for (uint32_t cpu=0; cpu < UINT32_MAX; ++cpu) { - std::ifstream thread_siblings("/sys/devices/system/cpu" - + std::to_string(cpu) + "/topology/thread_siblings"); + for (uint32_t cpu = 0; cpu < UINT32_MAX; ++cpu) { + std::ifstream thread_siblings("/sys/devices/system/cpu" + std::to_string(cpu) + "/topology/thread_siblings"); if (!thread_siblings.is_open()) { - break; // no more cpus + break; // no more cpus } std::string line; if (std::getline(thread_siblings, line)) { @@ -61,7 +61,7 @@ int32_t get_num_physical_cores() { return num_physical_cores; } #elif defined(_WIN32) - //TODO: Implement + // TODO: Implement #endif unsigned int n_threads = std::thread::hardware_concurrency(); return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4; @@ -282,6 +282,11 @@ void parse_args(int argc, const char* argv[], Option* opt) { fprintf(stderr, "error: can only work with strength in [0.0, 1.0]\n"); exit(1); } + + if (opt->seed < 0) { + srand((int)time(NULL)); + opt->seed = rand(); + } } int main(int argc, const char* argv[]) {