1
1
#include < stdio.h>
2
+ #include < ctime>
2
3
#include < fstream>
3
4
#include < iostream>
4
5
#include < random>
28
29
#define TXT2IMG " txt2img"
29
30
#define IMG2IMG " img2img"
30
31
31
- // get_num_physical_cores is copy from
32
+ // get_num_physical_cores is copy from
32
33
// https://github.com/ggerganov/llama.cpp/blob/master/examples/common.cpp
33
34
// LICENSE: https://github.com/ggerganov/llama.cpp/blob/master/LICENSE
34
35
int32_t get_num_physical_cores () {
35
36
#ifdef __linux__
36
37
// enumerate the set of thread siblings, num entries is num cores
37
38
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" );
41
41
if (!thread_siblings.is_open ()) {
42
- break ; // no more cpus
42
+ break ; // no more cpus
43
43
}
44
44
std::string line;
45
45
if (std::getline (thread_siblings, line)) {
@@ -61,7 +61,7 @@ int32_t get_num_physical_cores() {
61
61
return num_physical_cores;
62
62
}
63
63
#elif defined(_WIN32)
64
- // TODO: Implement
64
+ // TODO: Implement
65
65
#endif
66
66
unsigned int n_threads = std::thread::hardware_concurrency ();
67
67
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) {
282
282
fprintf (stderr, " error: can only work with strength in [0.0, 1.0]\n " );
283
283
exit (1 );
284
284
}
285
+
286
+ if (opt->seed < 0 ) {
287
+ srand ((int )time (NULL ));
288
+ opt->seed = rand ();
289
+ }
285
290
}
286
291
287
292
int main (int argc, const char * argv[]) {
0 commit comments