[CCCL] Add missing CCCL components: c2h, nvbench_helper, cmake, cudax, AGENTS.md
Added 863 files from NVIDIA/cccl sparse checkout: - c2h/ (27 files): Catch2 test helpers — generators, validators, runner - nvbench_helper/ (10 files): Benchmark harness utilities - cmake/ (29 files): CMake presets and build helpers - cudax/ (794 files): Experimental CUDA extensions - AGENTS.md: NVIDIA's official AI agent instructions for CCCL - CMakePresets.json: Standardized build configurations - cccl-version.json: Version tracking Also added CCCL_ASSET_MAP.md mapping all 4295 CCCL files to competition value and PRD items. cccl_upstream now covers 100% of competition-critical assets: - 27 tuning headers (SM80/90/100 benchmark data) - 32 dispatch headers (algorithm implementations) - 60 Thrust examples (correctness verification) - 217 CUB Catch2 tests (regression matrix) - 153 CUB benchmarks (parameter space search) - 18 CUB examples (API verification) - 27 test helpers + benchmark harness - 794 cudax experimental extensions
This commit is contained in:
125
cccl_upstream/cudax/test/execution/test_on.cu
Normal file
125
cccl_upstream/cudax/test/execution/test_on.cu
Normal file
@@ -0,0 +1,125 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDA Experimental in CUDA C++ Core Libraries,
|
||||
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "testing.cuh"
|
||||
|
||||
namespace ex = cudax::execution;
|
||||
|
||||
__host__ __device__ bool _on_device() noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST, //
|
||||
({ return false; }),
|
||||
({ return true; }));
|
||||
}
|
||||
|
||||
auto const main_thread_id = ::std::this_thread::get_id();
|
||||
|
||||
void simple_start_on_thread_test()
|
||||
{
|
||||
ex::thread_context ctx;
|
||||
auto sch = ctx.get_scheduler();
|
||||
auto sndr = ex::on(sch, ex::just() | ex::then([] {
|
||||
CHECK(::std::this_thread::get_id() != main_thread_id);
|
||||
}))
|
||||
| ex::then([]() -> int {
|
||||
CHECK(::std::this_thread::get_id() == main_thread_id);
|
||||
return 42;
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
void simple_continue_on_thread_test()
|
||||
{
|
||||
ex::thread_context ctx;
|
||||
auto sch = ctx.get_scheduler();
|
||||
auto sndr = ex::just() | ex::on(sch, ex::then([] {
|
||||
CHECK(::std::this_thread::get_id() != main_thread_id);
|
||||
}))
|
||||
| ex::then([]() -> int {
|
||||
CHECK(::std::this_thread::get_id() == main_thread_id);
|
||||
return 42;
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
void simple_start_on_stream_test()
|
||||
{
|
||||
cudax::stream str{cuda::device_ref(0)};
|
||||
auto sch = cudax::stream_ref{str};
|
||||
auto sndr = ex::on(sch, ex::just(42) | ex::then([] __host__ __device__(int i) noexcept -> int {
|
||||
return _on_device() ? i : -i;
|
||||
}))
|
||||
| ex::then([] __host__ __device__(int i) noexcept -> int {
|
||||
return _on_device() ? -1 : i;
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
void simple_continue_on_stream_test()
|
||||
{
|
||||
cudax::stream str{cuda::device_ref(0)};
|
||||
auto sch = cudax::stream_ref{str};
|
||||
auto sndr = ex::just(42) | ex::on(sch, ex::then([] __host__ __device__(int i) noexcept -> int {
|
||||
return _on_device() ? i : -i;
|
||||
}))
|
||||
| ex::then([] __host__ __device__(int i) noexcept -> int {
|
||||
return _on_device() ? -1 : i;
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
void test_continues_on_updates_env()
|
||||
{
|
||||
ex::thread_context ctx;
|
||||
auto sch = ctx.get_scheduler();
|
||||
auto sndr = ex::just() | ex::on(sch, ex::let_value([] {
|
||||
return ex::read_env(ex::get_scheduler);
|
||||
}))
|
||||
| ex::then([](auto sch2) -> int {
|
||||
STATIC_REQUIRE(cuda::std::same_as<decltype(sch2), decltype(sch)>);
|
||||
return 42;
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("simple on(sch, sndr) thread test", "[on]")
|
||||
{
|
||||
simple_start_on_thread_test();
|
||||
}
|
||||
|
||||
C2H_TEST("simple on(sndr, sch, closure) thread test", "[on]")
|
||||
{
|
||||
simple_continue_on_thread_test();
|
||||
}
|
||||
|
||||
C2H_TEST("simple on(sch, sndr) stream test", "[on][stream]")
|
||||
{
|
||||
simple_start_on_stream_test();
|
||||
}
|
||||
|
||||
C2H_TEST("simple on(sndr, sch, closure) stream test", "[on][stream]")
|
||||
{
|
||||
simple_continue_on_stream_test();
|
||||
}
|
||||
|
||||
C2H_TEST("test that on(sndr, sch, closure) updates the env for closure", "[on][stream]")
|
||||
{
|
||||
test_continues_on_updates_env();
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user