-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(perf/UX): Use num physical cores by default, warn about E/P cores #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
1caa4dc
f181c28
8694318
e032535
b17d54e
02b0fe8
3fa8837
e524ce9
81edec9
1a6c8cf
9ee4719
df2d350
42c297b
4a98a0f
710c4bb
f1c19d8
496d291
2fbc90f
78761b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#if defined (_WIN32) | ||
#include <fcntl.h> | ||
#include <io.h> | ||
#include <windows.h> | ||
#pragma comment(lib,"kernel32.lib") | ||
extern "C" __declspec(dllimport) void* __stdcall GetStdHandle(unsigned long nStdHandle); | ||
extern "C" __declspec(dllimport) int __stdcall GetConsoleMode(void* hConsoleHandle, unsigned long* lpMode); | ||
|
@@ -23,17 +24,41 @@ extern "C" __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int | |
#define CP_UTF8 65001 | ||
#endif | ||
|
||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { | ||
// determine sensible default number of threads. | ||
// std::thread::hardware_concurrency may not be equal to the number of cores, or may return 0. | ||
int32_t get_num_physical_cores() { | ||
#ifdef __linux__ | ||
std::ifstream cpuinfo("/proc/cpuinfo"); | ||
params.n_threads = std::count(std::istream_iterator<std::string>(cpuinfo), | ||
std::istream_iterator<std::string>(), | ||
std::string("processor")); | ||
std::string line; | ||
while (std::getline(cpuinfo, line)) { | ||
if (line.find("cpu cores") != std::string::npos) { | ||
line.erase(0, line.find(": ") + 2); | ||
try { | ||
return (int32_t) std::stoul(line); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you mean. What do you suggest? |
||
} catch (std::invalid_argument& e) {} // Ignore if we could not parse | ||
} | ||
jon-chuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#elif defined(__APPLE__) && defined(__MACH__) | ||
int num_physical_cores; | ||
jon-chuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size_t len = sizeof(num_physical_cores); | ||
int result = sysctlbyname("hw.perflevel0.physicalcpu", &num_physical_cores, &len, NULL, 0); | ||
if (result == 0) { | ||
return (int32_t) num_physical_cores; | ||
} | ||
result = sysctlbyname("hw.physicalcpu", &num_physical_cores, &len, NULL, 0); | ||
if (result == 0) { | ||
return (int32_t) num_physical_cores; | ||
} | ||
#elif defined(_WIN32) | ||
SYSTEM_INFO sysinfo; | ||
GetNativeSystemInfo(&sysinfo); | ||
return (in32_t) sysinfo.dwNumberOfProcessors; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this typo and the problems with the |
||
#endif | ||
if (params.n_threads == 0) { | ||
params.n_threads = std::max(1, (int32_t) std::thread::hardware_concurrency()); | ||
return -1; | ||
} | ||
|
||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { | ||
// Clip if not a valid number of threads | ||
if (params.n_threads <= 0) { | ||
params.n_threads = std::max(1, std::min(8, (int32_t) std::thread::hardware_concurrency())); | ||
} | ||
|
||
bool invalid_param = false; | ||
|
Uh oh!
There was an error while loading. Please reload this page.