-
Notifications
You must be signed in to change notification settings - Fork 359
thread context for omp parallel to pass thread local allocator #644
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
Open
ltan1ms
wants to merge
2
commits into
BANN_save_load_one_file
Choose a base branch
from
ltan1ms/thread_context_for_omp
base: BANN_save_load_one_file
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #pragma once | ||
|
|
||
| #ifndef _THREAD_CONTEXT_H_ | ||
| #define _THREAD_CONTEXT_H_ | ||
|
|
||
| void SetContextFuncs(void *getter, void *setter); | ||
|
|
||
| class OmpParallelContext | ||
| { | ||
| public: | ||
| OmpParallelContext(); | ||
| OmpParallelContext(const OmpParallelContext& other); | ||
| ~OmpParallelContext(); | ||
|
|
||
| private: | ||
| void* m_savedContext; | ||
| }; | ||
|
|
||
| class DefaultThreadContext | ||
| { | ||
| public: | ||
| DefaultThreadContext(); | ||
| ~DefaultThreadContext(); | ||
|
|
||
| void* SavedContext(); | ||
|
|
||
| private: | ||
| void* m_savedContext; | ||
| }; | ||
|
|
||
| class ThreadContext | ||
| { | ||
| public: | ||
| ThreadContext(void* context); | ||
| ~ThreadContext(); | ||
|
|
||
| private: | ||
| void* m_savedContext; | ||
| }; | ||
|
|
||
| class SavePartitionContext | ||
| { | ||
| public: | ||
| SavePartitionContext(); | ||
| ~SavePartitionContext(); | ||
| void* SavedContext(); | ||
|
|
||
| private: | ||
| void* m_savedContext; | ||
| }; | ||
| #endif | ||
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -15,6 +15,9 @@ | |
| #if defined(RELEASE_UNUSED_TCMALLOC_MEMORY_AT_CHECKPOINTS) && defined(DISKANN_BUILD) | ||
| #include "gperftools/malloc_extension.h" | ||
| #endif | ||
| #ifdef _ANN_ALLOCATOR | ||
| #include "thread_context.h" | ||
| #endif | ||
|
|
||
| #ifdef _WINDOWS | ||
| #include <xmmintrin.h> | ||
|
|
@@ -1566,7 +1569,12 @@ template <typename T, typename TagT, typename LabelT> void Index<T, TagT, LabelT | |
|
|
||
| diskann::Timer link_timer; | ||
|
|
||
| #ifdef _ANN_ALLOCATOR | ||
| OmpParallelContext context; | ||
| #pragma omp parallel for schedule(dynamic, 2048) firstprivate(context) | ||
| #else | ||
| #pragma omp parallel for schedule(dynamic, 2048) | ||
| #endif | ||
| for (int64_t node_ctr = 0; node_ctr < (int64_t)(visit_order.size()); node_ctr++) | ||
| { | ||
| auto node = visit_order[node_ctr]; | ||
|
|
@@ -1605,7 +1613,11 @@ template <typename T, typename TagT, typename LabelT> void Index<T, TagT, LabelT | |
| { | ||
| diskann::cout << "Starting final cleanup.." << std::flush; | ||
| } | ||
| #ifdef _ANN_ALLOCATOR | ||
| #pragma omp parallel for schedule(dynamic, 2048) firstprivate(context) | ||
|
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. Should we also call
Contributor
Author
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. it's defined by line 1573. |
||
| #else | ||
| #pragma omp parallel for schedule(dynamic, 2048) | ||
| #endif | ||
| for (int64_t node_ctr = 0; node_ctr < (int64_t)(visit_order.size()); node_ctr++) | ||
| { | ||
| auto node = visit_order[node_ctr]; | ||
|
|
@@ -1649,7 +1661,12 @@ void Index<T, TagT, LabelT>::prune_all_neighbors(const uint32_t max_degree, cons | |
| _filtered_index = true; | ||
|
|
||
| diskann::Timer timer; | ||
| #ifdef _ANN_ALLOCATOR | ||
| OmpParallelContext context; | ||
| #pragma omp parallel for firstprivate(context) | ||
| #else | ||
| #pragma omp parallel for | ||
| #endif | ||
| for (int64_t node = 0; node < (int64_t)(_max_points + _num_frozen_pts); node++) | ||
| { | ||
| if ((size_t)node < _nd || (size_t)node >= _max_points) | ||
|
|
@@ -2718,7 +2735,12 @@ consolidation_report Index<T, TagT, LabelT>::consolidate_deletes(const IndexWrit | |
|
|
||
| uint32_t num_calls_to_process_delete = 0; | ||
| diskann::Timer timer; | ||
| #ifdef _ANN_ALLOCATOR | ||
| OmpParallelContext context; | ||
| #pragma omp parallel for num_threads(num_threads) schedule(dynamic, 8192) reduction(+ : num_calls_to_process_delete) firstprivate(context) | ||
| #else | ||
| #pragma omp parallel for num_threads(num_threads) schedule(dynamic, 8192) reduction(+ : num_calls_to_process_delete) | ||
| #endif | ||
| for (int64_t loc = 0; loc < (int64_t)_max_points; loc++) | ||
| { | ||
| if (old_delete_set->find((uint32_t)loc) == old_delete_set->end() && !_empty_slots.is_in_set((uint32_t)loc)) | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #include "inc/Helper/ThreadContext.h" | ||
|
|
||
| void* DummyGet() { return nullptr; } | ||
| void DummySet(void* context) {} | ||
|
|
||
| typedef void* (*GetOmpContextFuncType)(); | ||
| typedef void (*SetOmpContextFuncType)(void *); | ||
|
|
||
| GetOmpContextFuncType s_getOmpContextFunc = &DummyGet; | ||
| SetOmpContextFuncType s_setOmpContextFunc = &DummySet; | ||
|
|
||
| void SetContextFuncs(void *getter, void *setter) | ||
| { | ||
| s_getOmpContextFunc = (GetOmpContextFuncType)getter; | ||
| s_setOmpContextFunc = (SetOmpContextFuncType)setter; | ||
| } | ||
|
|
||
| OmpParallelContext::OmpParallelContext() | ||
| { | ||
| m_savedContext = (*s_getOmpContextFunc)(); | ||
| } | ||
| OmpParallelContext::OmpParallelContext(const OmpParallelContext& other) | ||
| { | ||
| m_savedContext = other.m_savedContext; | ||
| (*s_setOmpContextFunc)(m_savedContext); | ||
| } | ||
| OmpParallelContext::~OmpParallelContext() | ||
| { | ||
| (*s_setOmpContextFunc)(m_savedContext); | ||
| } | ||
|
|
||
| DefaultThreadContext::DefaultThreadContext() | ||
| { | ||
| m_savedContext = (*s_getOmpContextFunc)(); | ||
| (*s_setOmpContextFunc)(nullptr); | ||
| } | ||
|
|
||
| DefaultThreadContext::~DefaultThreadContext() | ||
| { | ||
| (*s_setOmpContextFunc)(m_savedContext); | ||
| } | ||
|
|
||
| void* DefaultThreadContext::SavedContext() | ||
| { | ||
| return m_savedContext; | ||
| } | ||
|
|
||
| ThreadContext::ThreadContext(void* context) | ||
| { | ||
| m_savedContext = (*s_getOmpContextFunc)(); | ||
| (*s_setOmpContextFunc)(context); | ||
| } | ||
|
|
||
| ThreadContext::~ThreadContext() | ||
| { | ||
| (*s_setOmpContextFunc)(m_savedContext); | ||
| } | ||
|
|
||
| SavePartitionContext::SavePartitionContext() | ||
| { | ||
| // Save the current allocator address, but not do allocator switch | ||
| m_savedContext = (*s_getOmpContextFunc)(); | ||
| } | ||
|
|
||
| SavePartitionContext::~SavePartitionContext() | ||
| { | ||
| // No switch, so nothing to do here | ||
| } | ||
|
|
||
| void *SavePartitionContext::SavedContext() | ||
| { | ||
| return m_savedContext; | ||
| } |
Oops, something went wrong.
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.
Will using
#pragma onceinstead be better?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.
good catch, will add.
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.
Fixed now.