From 0bd9ca6d840e057328c3bdb961b8471442650521 Mon Sep 17 00:00:00 2001 From: Wesley Maxey Date: Thu, 22 Jul 2021 22:25:53 -0700 Subject: [PATCH] Add a small parity wait test --- .../heterogeneous/barrier_parity.pass.cpp | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .upstream-tests/test/heterogeneous/barrier_parity.pass.cpp diff --git a/.upstream-tests/test/heterogeneous/barrier_parity.pass.cpp b/.upstream-tests/test/heterogeneous/barrier_parity.pass.cpp new file mode 100644 index 0000000000..7d3976e43d --- /dev/null +++ b/.upstream-tests/test/heterogeneous/barrier_parity.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// Part of the libcu++ 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: nvrtc, pre-sm-70 + +// uncomment for a really verbose output detailing what test steps are being launched +// #define DEBUG_TESTERS + +#include "helpers.h" + +#include +#include + +template +struct barrier_and_token +{ + using barrier_t = Barrier; + using token_t = typename barrier_t::arrival_token; + + barrier_t barrier; + cuda::std::atomic parity_waiting{false}; + + template + __host__ __device__ + barrier_and_token(Args && ...args) : barrier{ cuda::std::forward(args)... } + { + } +}; + +struct barrier_arrive_and_wait +{ + using async = cuda::std::true_type; + + template + __host__ __device__ + static void perform(Data & data) + { + while (data.parity_waiting.load(cuda::std::memory_order_acquire) == false) + { + data.parity_waiting.wait(false); + } + data.barrier.arrive_and_wait(); + } +}; + +template +struct barrier_arrive_parity_wait +{ + using async = cuda::std::true_type; + + template + __host__ __device__ + static void perform(Data & data) + { + data.parity_waiting.store(true, cuda::std::memory_order_release); + data.parity_waiting.notify_all(); + cuda::barrier_wait_parity(&data.barrier, Phase); + } +}; + +struct clear_token +{ + template + __host__ __device__ + static void perform(Data & data) + { + data.parity_waiting.store(false, cuda::std::memory_order_release); + } +}; + +using a_w_apw = performer_list< + barrier_arrive_parity_wait, + barrier_arrive_and_wait, + barrier_arrive_and_wait, + async_tester_fence, + clear_token +>; + +void kernel_invoker() +{ + validate_not_movable< + barrier_and_token>, + a_w_apw + >(2); + validate_not_movable< + barrier_and_token>, + a_w_apw + >(2); +} + +int main(int arg, char ** argv) +{ +#ifndef __CUDA_ARCH__ + kernel_invoker(); +#endif + + return 0; +} +