Skip to content

Commit 0d7f04b

Browse files
committed
feat: print seed value when args.seed < 0
1 parent 721cb32 commit 0d7f04b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

examples/main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
#include <ctime>
23
#include <fstream>
34
#include <iostream>
45
#include <random>
@@ -28,18 +29,17 @@
2829
#define TXT2IMG "txt2img"
2930
#define IMG2IMG "img2img"
3031

31-
// get_num_physical_cores is copy from
32+
// get_num_physical_cores is copy from
3233
// https://github.com/ggerganov/llama.cpp/blob/master/examples/common.cpp
3334
// LICENSE: https://github.com/ggerganov/llama.cpp/blob/master/LICENSE
3435
int32_t get_num_physical_cores() {
3536
#ifdef __linux__
3637
// enumerate the set of thread siblings, num entries is num cores
3738
std::unordered_set<std::string> siblings;
38-
for (uint32_t cpu=0; cpu < UINT32_MAX; ++cpu) {
39-
std::ifstream thread_siblings("/sys/devices/system/cpu"
40-
+ std::to_string(cpu) + "/topology/thread_siblings");
39+
for (uint32_t cpu = 0; cpu < UINT32_MAX; ++cpu) {
40+
std::ifstream thread_siblings("/sys/devices/system/cpu" + std::to_string(cpu) + "/topology/thread_siblings");
4141
if (!thread_siblings.is_open()) {
42-
break; // no more cpus
42+
break; // no more cpus
4343
}
4444
std::string line;
4545
if (std::getline(thread_siblings, line)) {
@@ -61,7 +61,7 @@ int32_t get_num_physical_cores() {
6161
return num_physical_cores;
6262
}
6363
#elif defined(_WIN32)
64-
//TODO: Implement
64+
// TODO: Implement
6565
#endif
6666
unsigned int n_threads = std::thread::hardware_concurrency();
6767
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) {
282282
fprintf(stderr, "error: can only work with strength in [0.0, 1.0]\n");
283283
exit(1);
284284
}
285+
286+
if (opt->seed < 0) {
287+
srand((int)time(NULL));
288+
opt->seed = rand();
289+
}
285290
}
286291

287292
int main(int argc, const char* argv[]) {

0 commit comments

Comments
 (0)