Skip to content

Commit 55cf23f

Browse files
authored
[GraphBolt] Relax memory order of cache hit case. (#7656)
1 parent 7a1f63a commit 55cf23f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

graphbolt/src/cache_policy.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ struct CacheKey {
9696
template <bool write>
9797
CacheKey& EndUse() {
9898
::cuda::std::atomic_ref ref(reference_count_);
99-
// The EndUse operation needs to synchronize with InUse and BeingWritten
100-
// operations. So we have an release-acquire ordering here.
99+
// The EndUse operation needs to synchronize with the InUse operation. So we
100+
// have an release-acquire ordering between the two.
101101
// https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering
102102
if constexpr (write) {
103103
ref.fetch_add(1, ::cuda::std::memory_order_release);
@@ -116,9 +116,10 @@ struct CacheKey {
116116

117117
bool BeingWritten() const {
118118
::cuda::std::atomic_ref ref(reference_count_);
119-
// The operations after a call to this function need to happen after the
120-
// load operation. Hence the acquire order.
121-
return ref.load(::cuda::std::memory_order_acquire) < 0;
119+
// The only operation coming after this op is the StartRead operation. Since
120+
// StartRead is a refcount increment operation, it is fine if we don't
121+
// synchronize with EndUse ops.
122+
return ref.load(::cuda::std::memory_order_relaxed) < 0;
122123
}
123124

124125
friend std::ostream& operator<<(std::ostream& os, const CacheKey& key_ref) {

0 commit comments

Comments
 (0)