Skip to content
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

Minor improvement on device syncer #231

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions include/mscclpp/concurrency_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef MSCCLPP_CONCURRENCY_DEVICE_HPP_
#define MSCCLPP_CONCURRENCY_DEVICE_HPP_

#include "atomic_device.hpp"
#include "poll_device.hpp"

namespace mscclpp {
Expand All @@ -29,17 +30,11 @@ struct DeviceSyncer {
if (threadIdx.x == 0) {
// Need a `__threadfence()` before to flip `flag`.
__threadfence();
int tmp = isIncFlag_ ^ 1;
if (tmp) {
if (atomicInc(&count_, maxOldCnt) == maxOldCnt) {
flag_ = 1;
}
POLL_MAYBE_JAILBREAK(!flag_, maxSpinCount);
unsigned int tmp = isIncFlag_ ^ 1;
if (atomicInc(&count_, maxOldCnt) == maxOldCnt) {
atomicStore(&flag_, tmp, memoryOrderRelaxed);
} else {
if (atomicInc(&count_, maxOldCnt) == maxOldCnt) {
flag_ = 0;
}
POLL_MAYBE_JAILBREAK(flag_, maxSpinCount);
POLL_MAYBE_JAILBREAK((atomicLoad(&flag_, memoryOrderRelaxed) != tmp), maxSpinCount);
}
isIncFlag_ = tmp;
}
Expand All @@ -51,11 +46,11 @@ struct DeviceSyncer {

private:
/// The flag to indicate whether the barrier is reached by the latest thread.
volatile int flag_;
unsigned int flag_;
/// The counter of synchronized blocks.
unsigned int count_;
/// The flag to indicate whether to increase or decrease @ref flag_.
int isIncFlag_;
unsigned int isIncFlag_;
chhwang marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace mscclpp
Expand Down
Loading