Skip to content

Commit c951357

Browse files
committed
add guard clause: --numa mirror requires OpenMP
1 parent 166b978 commit c951357

File tree

3 files changed

+7
-41
lines changed

3 files changed

+7
-41
lines changed

common/arg.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,14 +2505,19 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
25052505
"- distribute: spread execution evenly over all nodes\n"
25062506
"- isolate: only spawn threads on CPUs on the node that execution started on\n"
25072507
"- numactl: use the CPU map provided by numactl\n"
2508-
"- mirror: enable NUMA-aware model mirroring\n"
2508+
"- mirror: enable NUMA-aware model mirroring (requires OpenMP)\n"
25092509
"if run without this previously, it is recommended to drop the system page cache before using this\n"
25102510
"see https://github.com/ggml-org/llama.cpp/issues/1437",
25112511
[](common_params & params, const std::string & value) {
25122512
/**/ if (value == "distribute" || value == "") { params.numa = GGML_NUMA_STRATEGY_DISTRIBUTE; }
25132513
else if (value == "isolate") { params.numa = GGML_NUMA_STRATEGY_ISOLATE; }
25142514
else if (value == "numactl") { params.numa = GGML_NUMA_STRATEGY_NUMACTL; }
2515-
else if (value == "mirror") { params.numa = GGML_NUMA_STRATEGY_MIRROR; }
2515+
else if (value == "mirror") {
2516+
#ifndef GGML_USE_OPENMP
2517+
throw std::invalid_argument("--numa mirror requires OpenMP support (compile with -DGGML_OPENMP=ON)");
2518+
#endif
2519+
params.numa = GGML_NUMA_STRATEGY_MIRROR;
2520+
}
25162521
else { throw std::invalid_argument("invalid value"); }
25172522
}
25182523
).set_env("LLAMA_ARG_NUMA"));

common/common.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -361,44 +361,6 @@ void postprocess_cpu_params(cpu_params& cpuparams, const cpu_params* role_model)
361361
}
362362
}
363363

364-
bool cpu_mask_set_physical_cores_only(bool (&boolmask)[GGML_MAX_N_THREADS]) {
365-
#ifdef _WIN32
366-
// Windows implementation would require different approach
367-
LOG_WRN("Physical core detection is not supported on Windows\n");
368-
return false;
369-
#else
370-
std::memset(boolmask, false, sizeof(bool) * GGML_MAX_N_THREADS);
371-
372-
// Use the common topology detection logic
373-
std::vector<int> physical_cores;
374-
if (!cpu_get_physical_cores_topology(physical_cores)) {
375-
// Fallback: if we couldn't detect topology, just use all CPUs
376-
int num_cpus = std::thread::hardware_concurrency();
377-
for (int cpu = 0; cpu < num_cpus && cpu < GGML_MAX_N_THREADS; cpu++) {
378-
boolmask[cpu] = true;
379-
}
380-
LOG_WRN("Could not detect CPU topology, using all CPUs\n");
381-
return false;
382-
}
383-
384-
// Set the mask for detected physical cores
385-
for (int core_id : physical_cores) {
386-
if (core_id < GGML_MAX_N_THREADS) {
387-
boolmask[core_id] = true;
388-
}
389-
}
390-
391-
LOG("Detected %zu physical cores (excluding hyperthreads): ", physical_cores.size());
392-
for (size_t i = 0; i < physical_cores.size(); i++) {
393-
if (i > 0) LOG(", ");
394-
LOG("%d", physical_cores[i]);
395-
}
396-
LOG("\n");
397-
398-
return true;
399-
#endif
400-
}
401-
402364
bool cpu_mask_set_physical_cores_with_hyperthreading(bool (&boolmask)[GGML_MAX_N_THREADS]) {
403365
#ifdef _WIN32
404366
// Windows implementation would require different approach

common/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ int32_t cpu_get_num_physical_cores();
6767
int32_t cpu_get_num_math();
6868
int32_t cpu_detect_physical_cores_topology(); // Detect actual physical cores using CPU topology
6969
bool cpu_get_physical_cores_topology(std::vector<int> & physical_cores); // Get list of physical core IDs
70-
bool cpu_mask_set_physical_cores_only(bool(&boolmask)[GGML_MAX_N_THREADS]);
7170
bool cpu_mask_set_physical_cores_with_hyperthreading(bool(&boolmask)[GGML_MAX_N_THREADS]); // Set mask to include physical cores + hyperthread siblings
7271

7372
//

0 commit comments

Comments
 (0)