-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Numa #1556
Merged
Merged
Numa #1556
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6fc5f17
detect NUMA systems and pin work threads to nodes (linux)
zrm 0d23f8c
disable mmap prefetch/readahead for NUMA systems
zrm 9d058c2
avoid sending finalize op to thread pool if it does nothing
zrm 2c1b5ae
silence robot
zrm 8502d51
fix args
zrm bf83dcb
make --numa a param
zrm b71dfe6
recommendation that n_nodes evenly divide n_threads did not warrant s…
zrm adaad10
lower synchronization overhead
zrm c31d51d
statically allocate
zrm 2f5bb46
move numa state to g_state
zrm 4b94582
add description for --numa
zrm 90a0e65
Merge branch 'master' into HEAD
ggerganov d0e3596
ggml : minor style changes
ggerganov 67ba34e
ggml : minor style + try fix sanitizer build
ggerganov 8f98035
Merge branch 'master' into HEAD
ggerganov 0fe4b00
llama : allow to initialize backend with NUMA support
ggerganov 875a1e1
llama : avoid ggml include in llama-util.h
ggerganov 4a555b4
ggml : style / formatting
ggerganov 81a40e9
ggml : fix handling of ops with n_threads > n_tasks > 1
ggerganov 9aec2b7
server : utilize numa parameter
ggerganov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
disable mmap prefetch/readahead for NUMA systems
- Loading branch information
commit 0d23f8ce8da6bb13d557233c7b76a5563055fcf5
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -163,6 +163,9 @@ static std::string llama_format_win_err(DWORD err) { | |||||||
} | ||||||||
#endif | ||||||||
|
||||||||
extern "C" { | ||||||||
bool ggml_is_numa(); | ||||||||
} | ||||||||
struct llama_mmap { | ||||||||
void * addr; | ||||||||
size_t size; | ||||||||
|
@@ -176,8 +179,10 @@ struct llama_mmap { | |||||||
size = file->size; | ||||||||
int fd = fileno(file->fp); | ||||||||
int flags = MAP_SHARED; | ||||||||
// prefetch/readahead impairs performance on NUMA systems | ||||||||
if (ggml_is_numa()) prefetch = 0; | ||||||||
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. warning: statement should be inside braces [readability-braces-around-statements]
Suggested change
|
||||||||
#ifdef __linux__ | ||||||||
flags |= MAP_POPULATE; | ||||||||
if (prefetch) flags |= MAP_POPULATE; | ||||||||
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. warning: statement should be inside braces [readability-braces-around-statements]
Suggested change
|
||||||||
#endif | ||||||||
addr = mmap(NULL, file->size, PROT_READ, flags, fd, 0); | ||||||||
if (addr == MAP_FAILED) { | ||||||||
|
@@ -191,6 +196,14 @@ struct llama_mmap { | |||||||
strerror(errno)); | ||||||||
} | ||||||||
} | ||||||||
if (ggml_is_numa()) { | ||||||||
// advise the kernel not to use readahead | ||||||||
// (because the next page might not belong on the same node) | ||||||||
if (madvise(addr, file->size, MADV_RANDOM)) { | ||||||||
fprintf(stderr, "warning: madvise(.., MADV_RANDOM) failed: %s\n", | ||||||||
strerror(errno)); | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
~llama_mmap() { | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be avoided. Probably utilize new
GGML_USE_NUMA
defineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function is still needed, because even if NUMA support is compiled in, there are some operations that only make sense if the system actually has more than one NUMA node. It also makes it easier to disable those operations, because that function always returns false if ggml_numa_init() is never called, so we can add a --numa option and not call ggml_numa_init() otherwise, causing those operations to be disabled. The latest commits do this.