-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[OFFLOAD][OPENMP] 6.0 compatible interop interface #143491
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8694e6e
[OFFLOAD][OPENMP] 6.0 compatible interop interface
adurang 81c7402
Add missed ext API and minor fix
adurang 0a28255
Fix format
adurang b1a9e10
Fix corner cases related to atexit ordering in PerThreadTable
adurang b72e46a
fix format
adurang fd69d49
remove unnecessary conditions
adurang fbca384
another corner case when unloading
adurang f5715cd
make version 32bits to simplify codegen
adurang 82fa72d
Fix sporadic race condition with helper threads on deinit
adurang 0c29ac6
change const to constexpr
adurang 0440af0
address review comments
adurang 85eb7a7
Add asserts; Bury virtual interfaces
adurang 5774a89
Add error handling to create/releaseInterop
adurang a1f81c3
Remove interfaces with implicity DeviceTy from interop object
adurang 6395c45
Adjust format
adurang e4827f6
reorder dep_pack fields
adurang b27b3af
Rename some symbols according to reviews
adurang 742a6b7
move some code to cpp file
adurang 9c33d32
rework comment
adurang 2830a9c
address suggestions from reviews
adurang 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
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| //===-- PerThreadTable.h -- PerThread Storage Structure ----*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Table indexed with one entry per thread. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef OFFLOAD_PERTHREADTABLE_H | ||
| #define OFFLOAD_PERTHREADTABLE_H | ||
|
|
||
| #include <list> | ||
| #include <memory> | ||
| #include <mutex> | ||
|
|
||
| // Using an STL container (such as std::vector) indexed by thread ID has | ||
| // too many race conditions issues so we store each thread entry into a | ||
| // thread_local variable. | ||
| // T is the container type used to store the objects, e.g., std::vector, | ||
| // std::set, etc. by each thread. O is the type of the stored objects e.g., | ||
| // omp_interop_val_t *, ... | ||
|
|
||
| template <typename ContainerType, typename ObjectType> struct PerThreadTable { | ||
| using iterator = typename ContainerType::iterator; | ||
|
|
||
| struct PerThreadData { | ||
| size_t NElements = 0; | ||
| std::unique_ptr<ContainerType> ThEntry; | ||
| }; | ||
|
|
||
| std::mutex Mtx; | ||
| std::list<std::shared_ptr<PerThreadData>> ThreadDataList; | ||
|
|
||
| // define default constructors, disable copy and move constructors | ||
| PerThreadTable() = default; | ||
| PerThreadTable(const PerThreadTable &) = delete; | ||
| PerThreadTable(PerThreadTable &&) = delete; | ||
| PerThreadTable &operator=(const PerThreadTable &) = delete; | ||
| PerThreadTable &operator=(PerThreadTable &&) = delete; | ||
| ~PerThreadTable() { | ||
| std::lock_guard<std::mutex> Lock(Mtx); | ||
| ThreadDataList.clear(); | ||
| } | ||
|
|
||
| private: | ||
| PerThreadData &getThreadData() { | ||
| static thread_local std::shared_ptr<PerThreadData> ThData = nullptr; | ||
| if (!ThData) { | ||
| ThData = std::make_shared<PerThreadData>(); | ||
| std::lock_guard<std::mutex> Lock(Mtx); | ||
| ThreadDataList.push_back(ThData); | ||
| } | ||
| return *ThData; | ||
| } | ||
|
|
||
| protected: | ||
| ContainerType &getThreadEntry() { | ||
| auto &ThData = getThreadData(); | ||
| if (ThData.ThEntry) | ||
| return *ThData.ThEntry; | ||
| ThData.ThEntry = std::make_unique<ContainerType>(); | ||
| return *ThData.ThEntry; | ||
| } | ||
|
|
||
| size_t &getThreadNElements() { | ||
| auto &ThData = getThreadData(); | ||
| return ThData.NElements; | ||
| } | ||
|
|
||
| public: | ||
| void add(ObjectType obj) { | ||
| auto &Entry = getThreadEntry(); | ||
| auto &NElements = getThreadNElements(); | ||
| NElements++; | ||
| Entry.add(obj); | ||
| } | ||
|
|
||
| iterator erase(iterator it) { | ||
| auto &Entry = getThreadEntry(); | ||
| auto &NElements = getThreadNElements(); | ||
| NElements--; | ||
| return Entry.erase(it); | ||
| } | ||
|
|
||
| size_t size() { return getThreadNElements(); } | ||
|
|
||
| // Iterators to traverse objects owned by | ||
| // the current thread | ||
| iterator begin() { | ||
| auto &Entry = getThreadEntry(); | ||
| return Entry.begin(); | ||
| } | ||
| iterator end() { | ||
| auto &Entry = getThreadEntry(); | ||
| return Entry.end(); | ||
| } | ||
|
|
||
| template <class F> void clear(F f) { | ||
| std::lock_guard<std::mutex> Lock(Mtx); | ||
| for (auto ThData : ThreadDataList) { | ||
| if (!ThData->ThEntry || ThData->NElements == 0) | ||
| continue; | ||
| ThData->ThEntry->clear(f); | ||
| ThData->NElements = 0; | ||
| } | ||
| ThreadDataList.clear(); | ||
| } | ||
| }; | ||
|
|
||
| #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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.