-
Notifications
You must be signed in to change notification settings - Fork 51
Parallelize tuning across GPUs #2179
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
base: develop
Are you sure you want to change the base?
Changes from all commits
3b92772
31dca63
4e7c234
5e0338e
4d71e33
eb8dff6
70d021d
735fb2b
d36e62d
e01d4b1
a3c15e8
cf2046e
8d6dbc3
df88112
af53625
e8d29d1
95f771b
e6a985b
2c48a92
34fffb6
b6d7bea
e3e8add
90414e7
c8d7bd8
1c55901
305f5df
9dded74
e1f04bb
1ef64bb
f93b4cd
a620622
94bef8b
aa99327
924536d
9709f5b
8f4e6b2
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //===- ConcurrentQueue.h - Simple MPMC queue --------------------*- C++ -*-===// | ||
| // | ||
| // Part of the rocMLIR 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef ROCMLIR_TUNING_DRIVER_CONCURRENT_QUEUE_H | ||
| #define ROCMLIR_TUNING_DRIVER_CONCURRENT_QUEUE_H | ||
|
|
||
| #include "llvm/Support/Compiler.h" | ||
|
|
||
| #include <atomic> | ||
| #include <condition_variable> | ||
| #include <mutex> | ||
| #include <queue> | ||
|
|
||
| namespace rocmlir::tuningdriver { | ||
|
|
||
| template <typename T> | ||
| class ConcurrentQueue { | ||
| public: | ||
| template <typename U> | ||
| bool push(U &&item) { | ||
| if (LLVM_UNLIKELY(done.load(std::memory_order_relaxed))) | ||
| return false; // Early exit if terminated | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> lock(mtx); | ||
| if (LLVM_UNLIKELY(done.load(std::memory_order_relaxed))) | ||
| return false; // Double-check after acquiring the lock | ||
|
|
||
| queue.emplace(std::forward<U>(item)); | ||
| } | ||
|
|
||
| cv.notify_one(); | ||
| return true; | ||
| } | ||
|
|
||
| bool pop(T &item) { | ||
| std::unique_lock<std::mutex> lock(mtx); | ||
| cv.wait(lock, [this] { | ||
| return !queue.empty() || done.load(std::memory_order_relaxed); | ||
| }); | ||
umangyadav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (LLVM_UNLIKELY(queue.empty())) | ||
| return false; | ||
|
|
||
| item = std::move(queue.front()); | ||
| queue.pop(); | ||
| return true; | ||
| } | ||
|
|
||
| void terminate() { | ||
| done.store(true, std::memory_order_relaxed); | ||
| cv.notify_all(); | ||
| } | ||
|
|
||
| bool isTerminated() const { return done.load(std::memory_order_relaxed); } | ||
|
|
||
| private: | ||
| std::queue<T> queue; | ||
| std::mutex mtx; | ||
| std::condition_variable cv; | ||
| std::atomic<bool> done{false}; | ||
| }; | ||
|
|
||
| } // namespace rocmlir::tuningdriver | ||
|
|
||
| #endif // ROCMLIR_TUNING_DRIVER_CONCURRENT_QUEUE_H | ||
|
Contributor
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. unrelated but it'd be nice if we refactor
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. Good point. Will do.
Contributor
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. we can do this in another PR if that's ok? as it's unrelated to this change. |
Uh oh!
There was an error while loading. Please reload this page.