CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
102 lines
4.2 KiB
C++
102 lines
4.2 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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 <cuda/barrier>
|
|
|
|
#include "cuda_space_selector.h"
|
|
#include "large_type.h"
|
|
|
|
template <class T,
|
|
template <typename, typename> class SourceSelector,
|
|
template <typename, typename> class DestSelector,
|
|
template <typename, typename> class BarrierSelector,
|
|
cuda::thread_scope BarrierScope,
|
|
typename... CompletionF>
|
|
__host__ __device__ __noinline__ void test_fully_specialized()
|
|
{
|
|
SourceSelector<T, constructor_initializer> source_sel;
|
|
typename DestSelector<T, constructor_initializer>::template offsetted<decltype(source_sel)::shared_offset> dest_sel;
|
|
BarrierSelector<cuda::barrier<BarrierScope, CompletionF...>, constructor_initializer> bar_sel;
|
|
|
|
T* source = source_sel.construct(static_cast<T>(12));
|
|
T* dest = dest_sel.construct(static_cast<T>(0));
|
|
cuda::barrier<BarrierScope, CompletionF...>* 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<void*>(dest), static_cast<void*>(source), sizeof(T), *bar);
|
|
|
|
bar->arrive_and_wait();
|
|
|
|
assert(*source == 24);
|
|
assert(*dest == 24);
|
|
}
|
|
|
|
struct completion
|
|
{
|
|
__host__ __device__ void operator()() const {}
|
|
};
|
|
|
|
template <class T,
|
|
template <typename, typename> class SourceSelector,
|
|
template <typename, typename> class DestSelector,
|
|
template <typename, typename> class BarrierSelector>
|
|
__host__ __device__ __noinline__ void test_select_scope()
|
|
{
|
|
test_fully_specialized<T, SourceSelector, DestSelector, BarrierSelector, cuda::thread_scope_system>();
|
|
test_fully_specialized<T, SourceSelector, DestSelector, BarrierSelector, cuda::thread_scope_device>();
|
|
test_fully_specialized<T, SourceSelector, DestSelector, BarrierSelector, cuda::thread_scope_block>();
|
|
// 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<T, SourceSelector, DestSelector, BarrierSelector, cuda::thread_scope_block, completion>();
|
|
test_fully_specialized<T, SourceSelector, DestSelector, BarrierSelector, cuda::thread_scope_thread>();
|
|
}
|
|
|
|
template <class T, template <typename, typename> class SourceSelector, template <typename, typename> class DestSelector>
|
|
__host__ __device__ __noinline__ void test_select_barrier()
|
|
{
|
|
test_select_scope<T, SourceSelector, DestSelector, local_memory_selector>();
|
|
NV_IF_TARGET(NV_IS_DEVICE,
|
|
(test_select_scope<T, SourceSelector, DestSelector, shared_memory_selector>();
|
|
test_select_scope<T, SourceSelector, DestSelector, global_memory_selector>();))
|
|
}
|
|
|
|
template <class T, template <typename, typename> class SourceSelector>
|
|
__host__ __device__ __noinline__ void test_select_destination()
|
|
{
|
|
test_select_barrier<T, SourceSelector, local_memory_selector>();
|
|
NV_IF_TARGET(NV_IS_DEVICE,
|
|
(test_select_barrier<T, SourceSelector, shared_memory_selector>();
|
|
test_select_barrier<T, SourceSelector, global_memory_selector>();))
|
|
}
|
|
|
|
template <class T>
|
|
__host__ __device__ __noinline__ void test_select_source()
|
|
{
|
|
test_select_destination<T, local_memory_selector>();
|
|
NV_IF_TARGET(
|
|
NV_IS_DEVICE,
|
|
(test_select_destination<T, shared_memory_selector>(); test_select_destination<T, global_memory_selector>();))
|
|
}
|