22#include <unordered_set>
27int32_t countPhysicalCores()
31 std::unordered_set<std::string> siblings;
32 for (uint32_t cpu = 0; cpu < UINT32_MAX; ++cpu)
34 std::ifstream thread_siblings(
"/sys/devices/system/cpu/cpu" + std::to_string(cpu) +
35 "/topology/thread_siblings");
36 if (!thread_siblings.is_open())
42 if (std::getline(thread_siblings, line))
44 siblings.insert(line);
47 if (!siblings.empty())
49 return static_cast<int32_t
>(siblings.size());
53 unsigned int n_threads = std::thread::hardware_concurrency();
54 return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 1;
73 _max_num_threads = max_num_threads > -1 ? max_num_threads : countPhysicalCores();
74 _ruy_context->set_max_num_threads(_max_num_threads);
79 if (_ggml_context ==
nullptr)
80 _ggml_context = std::unique_ptr<ggml_context, decltype(&ggml_free)>(
81 ggml_init({.mem_size = 0, .mem_buffer =
nullptr, .no_alloc =
true}), &ggml_free);
void setMaxNumThreads(int max_num_threads)
int getConfigInt(const std::string &key)