Skip to content

Commit

Permalink
feat: print seed value when args.seed < 0
Browse files Browse the repository at this point in the history
  • Loading branch information
leejet committed Aug 22, 2023
1 parent 721cb32 commit 0d7f04b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <random>
Expand Down Expand Up @@ -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<std::string> 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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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[]) {
Expand Down

0 comments on commit 0d7f04b

Please sign in to comment.