//===----------------------------------------------------------------------===// // // Part of libcu++, the C++ Standard Library for your entire system, // 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 // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// // UNSUPPORTED: pre-sm-70 #include #include "cuda_space_selector.h" #include "large_type.h" template class SourceSelector, template class DestSelector, template class BarrierSelector, cuda::thread_scope BarrierScope, typename... CompletionF> __host__ __device__ __noinline__ void test_fully_specialized() { SourceSelector source_sel; typename DestSelector::template offsetted dest_sel; BarrierSelector, constructor_initializer> bar_sel; T* source = source_sel.construct(static_cast(12)); T* dest = dest_sel.construct(static_cast(0)); cuda::barrier* bar = bar_sel.construct(1); assert(*source == 12); assert(*dest == 0); cuda::memcpy_async(dest, source, sizeof(T), *bar); bar->arrive_and_wait(); assert(*source == 12); assert(*dest == 12); *source = 24; cuda::memcpy_async(static_cast(dest), static_cast(source), sizeof(T), *bar); bar->arrive_and_wait(); assert(*source == 24); assert(*dest == 24); } struct completion { __host__ __device__ void operator()() const {} }; template class SourceSelector, template class DestSelector, template class BarrierSelector> __host__ __device__ __noinline__ void test_select_scope() { test_fully_specialized(); test_fully_specialized(); test_fully_specialized(); // Test one of the scopes with a non-default completion. Testing them all would make this test take twice as much time // to compile. Selected block scope because the block scope barrier with the default completion has a special path, so // this tests both that the API entrypoints accept barriers with arbitrary completion function, and that the // synchronization mechanism detects it correctly. test_fully_specialized(); test_fully_specialized(); } template class SourceSelector, template class DestSelector> __host__ __device__ __noinline__ void test_select_barrier() { test_select_scope(); NV_IF_TARGET(NV_IS_DEVICE, (test_select_scope(); test_select_scope();)) } template class SourceSelector> __host__ __device__ __noinline__ void test_select_destination() { test_select_barrier(); NV_IF_TARGET(NV_IS_DEVICE, (test_select_barrier(); test_select_barrier();)) } template __host__ __device__ __noinline__ void test_select_source() { test_select_destination(); NV_IF_TARGET( NV_IS_DEVICE, (test_select_destination(); test_select_destination();)) }