Skip to content

Commit a0b2d5f

Browse files
committed
Merge 'origin/master' into hipblas
2 parents 8bab456 + 2a5ee02 commit a0b2d5f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ifndef LLAMA_NO_ACCELERATE
115115
endif
116116
endif
117117
ifdef LLAMA_OPENBLAS
118-
CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas
118+
CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas -I/usr/include/openblas
119119
ifneq ($(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release 2>/dev/null),)
120120
LDFLAGS += -lopenblas -lcblas
121121
else

examples/common.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <iterator>
99
#include <algorithm>
1010
#include <sstream>
11+
#include <unordered_set>
1112

1213
#if defined(__APPLE__) && defined(__MACH__)
1314
#include <sys/types.h>
@@ -28,21 +29,21 @@
2829

2930
int32_t get_num_physical_cores() {
3031
#ifdef __linux__
31-
std::ifstream cpuinfo("/proc/cpuinfo");
32-
std::string line;
33-
while (std::getline(cpuinfo, line)) {
34-
std::size_t pos = line.find("cpu cores");
35-
if (pos != std::string::npos) {
36-
pos = line.find(": ", pos);
37-
if (pos != std::string::npos) {
38-
try {
39-
// Extract the number and return it
40-
return static_cast<int32_t>(std::stoul(line.substr(pos + 2)));
41-
} catch (const std::invalid_argument &) {
42-
// Ignore if we could not parse
43-
}
44-
}
32+
// enumerate the set of thread siblings, num entries is num cores
33+
std::unordered_set<std::string> siblings;
34+
for (uint32_t cpu=0; cpu < UINT32_MAX; ++cpu) {
35+
std::ifstream thread_siblings("/sys/devices/system/cpu"
36+
+ std::to_string(cpu) + "/topology/thread_siblings");
37+
if (!thread_siblings.is_open()) {
38+
break; // no more cpus
4539
}
40+
std::string line;
41+
if (std::getline(thread_siblings, line)) {
42+
siblings.insert(line);
43+
}
44+
}
45+
if (siblings.size() > 0) {
46+
return static_cast<int32_t>(siblings.size());
4647
}
4748
#elif defined(__APPLE__) && defined(__MACH__)
4849
int32_t num_physical_cores;

0 commit comments

Comments
 (0)