Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 1464783

Browse files
committed
Add a small parity wait test
1 parent 6e72dc6 commit 1464783

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the libcu++ Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: nvrtc, pre-sm-70
10+
11+
// uncomment for a really verbose output detailing what test steps are being launched
12+
// #define DEBUG_TESTERS
13+
14+
#include "helpers.h"
15+
16+
#include <atomic>
17+
#include <cuda/barrier>
18+
19+
template<typename Barrier>
20+
struct barrier_and_token
21+
{
22+
using barrier_t = Barrier;
23+
using token_t = typename barrier_t::arrival_token;
24+
25+
barrier_t barrier;
26+
cuda::std::atomic<bool> parity_waiting{false};
27+
28+
template<typename ...Args>
29+
__host__ __device__
30+
barrier_and_token(Args && ...args) : barrier{ cuda::std::forward<Args>(args)... }
31+
{
32+
}
33+
};
34+
35+
struct barrier_arrive_and_wait
36+
{
37+
using async = cuda::std::true_type;
38+
39+
template<typename Data>
40+
__host__ __device__
41+
static void perform(Data & data)
42+
{
43+
while (data.parity_waiting.load(cuda::std::memory_order_acquire) == false)
44+
{
45+
data.parity_waiting.wait(false);
46+
}
47+
data.barrier.arrive_and_wait();
48+
}
49+
};
50+
51+
template <bool Phase>
52+
struct barrier_arrive_parity_wait
53+
{
54+
using async = cuda::std::true_type;
55+
56+
template<typename Data>
57+
__host__ __device__
58+
static void perform(Data & data)
59+
{
60+
data.parity_waiting.store(true, cuda::std::memory_order_release);
61+
data.parity_waiting.notify_all();
62+
cuda::barrier_wait_parity(&data.barrier, Phase);
63+
}
64+
};
65+
66+
struct clear_token
67+
{
68+
template<typename Data>
69+
__host__ __device__
70+
static void perform(Data & data)
71+
{
72+
data.parity_waiting.store(false, cuda::std::memory_order_release);
73+
}
74+
};
75+
76+
using aw_aw_pw = performer_list<
77+
barrier_arrive_and_wait,
78+
barrier_arrive_and_wait,
79+
barrier_arrive_parity_wait<false>,
80+
async_tester_fence,
81+
clear_token
82+
>;
83+
84+
void kernel_invoker()
85+
{
86+
validate_not_movable<
87+
barrier_and_token<cuda::std::barrier<>>,
88+
aw_aw_pw
89+
>(2);
90+
validate_not_movable<
91+
barrier_and_token<cuda::barrier<cuda::thread_scope_system>>,
92+
aw_aw_pw
93+
>(2);
94+
}
95+
96+
int main(int arg, char ** argv)
97+
{
98+
#ifndef __CUDA_ARCH__
99+
kernel_invoker();
100+
#endif
101+
102+
return 0;
103+
}
104+

0 commit comments

Comments
 (0)