[CCCL] 瘦身 + 补全: 移除 cudax/python/libcudacxx-tests 冗余文件, 新增 c2h 测试助手 + cmake 构建系统 + 8 个 CUDA thrust examples

变更摘要:
- 删除: cudax/ (783 files, 7.2M) — 实验性组件,竞赛不需要
- 删除: python/ (226 files, 2.0M) — Python 绑定,竞赛不需要
- 删除: libcudacxx/{test,benchmarks,codegen,cmake,share} (4432 files, 31M)
  保留: libcudacxx/include/ (1463 headers, cuda::std 编译依赖)
- 新增: c2h/ (27 files) — CUB Catch2 测试辅助头文件,编译 243 个测试必需
- 新增: cmake/ (29 files) — CCCL 原生 CMake 构建系统
- 新增: thrust/examples/cuda/ (7 files) + cpp_integration/ (1 file)
  async_reduce, custom_temporary_allocation, explicit_cuda_stream,
  global_device_vector, range_view, unwrap_pointer, wrap_pointer, device

结果: cccl_upstream 从 74M→35M (瘦身 53%), 核心内容 100% 保留:
  27/27 tuning headers, 78 benchmarks, 243 tests,
  60 thrust examples, 18 CUB examples, 全部编译头文件
This commit is contained in:
muh-bot
2026-08-03 12:39:26 +00:00
parent a2a5dd8f00
commit 24ef6a91b5
5439 changed files with 0 additions and 719516 deletions

View File

@@ -1,219 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/std/__exception/exception_macros.h>
#include <cuda/std/__utility/typeid.h>
#include <cuda/std/string_view> // IWYU pragma: keep
#include <cuda/std/type_traits>
#include <cuda/experimental/execution.cuh>
#include <exception>
#include "testing.cuh"
namespace
{
template <class... Values>
struct checked_value_receiver
{
using receiver_concept = cudax_async::receiver_t;
_CCCL_HOST_DEVICE checked_value_receiver(Values... values)
: _values{values...}
{}
_CCCL_HOST_DEVICE checked_value_receiver(checked_value_receiver&& other) noexcept
: _called{::cuda::std::exchange(other._called, true)}
, _values{::cuda::std::move(other._values)}
{}
_CCCL_HOST_DEVICE ~checked_value_receiver()
{
CHECK(_called);
}
// This overload is needed to avoid an nvcc compiler bug where a variadic
// pack is not visible within the scope of a lambda.
_CCCL_HOST_DEVICE void set_value() && noexcept
{
if constexpr (!::cuda::std::is_same_v<::cuda::std::__type_list<Values...>, ::cuda::std::__type_list<>>)
{
FAIL("expected a value completion; got no values");
}
else
{
_called = true;
}
}
template <class... As>
_CCCL_HOST_DEVICE void set_value(As... as) && noexcept
{
_called = true;
if constexpr (::cuda::std::is_same_v<::cuda::std::__type_list<Values...>, ::cuda::std::__type_list<As...>>)
{
::cuda::std::__apply(
[&](auto const&... vs) {
CHECK(((vs == as) && ...));
},
_values);
}
else
{
FAIL("expected a value completion; got a different value");
}
}
template <class Error>
_CCCL_HOST_DEVICE void set_error(Error) && noexcept
{
_called = true;
FAIL("expected a value completion; got an error");
}
_CCCL_HOST_DEVICE void set_stopped() && noexcept
{
_called = true;
FAIL("expected a value completion; got stopped");
}
bool _called = false;
::cuda::std::__tuple<Values...> _values;
};
template <class... Values>
_CCCL_DEDUCTION_GUIDE_ATTRIBUTES checked_value_receiver(Values...) -> checked_value_receiver<Values...>;
template <class Error = cudax::execution::exception_ptr>
struct checked_error_receiver
{
using receiver_concept = cudax_async::receiver_t;
template <class... As>
_CCCL_HOST_DEVICE void set_value(As...) && noexcept
{
FAIL("expected an error completion; got a value");
}
template <class Ty>
_CCCL_HOST_DEVICE void set_error(Ty ty) && noexcept
{
if constexpr (::cuda::std::is_same_v<Error, Ty>)
{
if (!::cuda::std::is_same_v<Error, cudax::execution::exception_ptr>)
{
CHECK(ty == _error);
}
}
else
{
FAIL("expected an error completion; got a different error");
}
}
_CCCL_HOST_DEVICE void set_error(cudax::execution::exception_ptr eptr) && noexcept
{
_CCCL_TRY
{
cudax::execution::rethrow_exception(eptr);
}
_CCCL_CATCH (Error & e)
{
if constexpr (cuda::std::derived_from<Error, ::std::exception>)
{
CHECK(cuda::std::string_view{e.what()} == _error.what());
}
else
{
SUCCEED();
}
}
_CCCL_CATCH (::std::exception & e)
{
#if defined(_CCCL_NO_TYPEID)
INFO("expected an error completion; got a different error. what: " << e.what());
#else
INFO("expected an error completion; got a different error. what: " << e.what() << ", type: " << typeid(e).name());
#endif
CHECK(false);
}
_CCCL_CATCH_ALL
{
INFO("expected an error completion; got a different error");
CHECK(false);
}
}
_CCCL_HOST_DEVICE void set_stopped() && noexcept
{
FAIL("expected a value completion; got stopped");
}
Error _error;
};
template <class Error>
_CCCL_DEDUCTION_GUIDE_ATTRIBUTES checked_error_receiver(Error) -> checked_error_receiver<Error>;
struct checked_stopped_receiver
{
using receiver_concept = cudax_async::receiver_t;
template <class... As>
_CCCL_HOST_DEVICE void set_value(As...) && noexcept
{
FAIL("expected a stopped completion; got a value");
}
template <class Ty>
_CCCL_HOST_DEVICE void set_error(Ty) && noexcept
{
FAIL("expected an stopped completion; got an error");
}
_CCCL_HOST_DEVICE void set_stopped() && noexcept {}
};
template <class Ty>
struct proxy_value_receiver
{
using receiver_concept = cudax_async::receiver_t;
template <class... As>
_CCCL_HOST_DEVICE void set_value(As...) && noexcept
{
FAIL("expected a value completion; got a different value");
}
_CCCL_HOST_DEVICE void set_value(Ty value) && noexcept
{
_value = value;
}
template <class Error>
_CCCL_HOST_DEVICE void set_error(Error) && noexcept
{
FAIL("expected a value completion; got an error");
}
_CCCL_HOST_DEVICE void set_stopped() && noexcept
{
FAIL("expected a value completion; got stopped");
}
Ty& _value;
};
template <class Ty>
_CCCL_DEDUCTION_GUIDE_ATTRIBUTES proxy_value_receiver(Ty&) -> proxy_value_receiver<Ty>;
} // namespace

View File

@@ -1,107 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/__utility/immovable.h>
#include <cuda/experimental/execution.cuh>
#include "testing.cuh" // IWYU pragma: keep
namespace ex = cuda::experimental::execution;
namespace
{
namespace _dummy
{
template <class Domain>
struct _attrs_t
{
_CCCL_HOST_DEVICE constexpr auto query(ex::get_completion_scheduler_t<ex::set_value_t>) const noexcept;
_CCCL_HOST_DEVICE constexpr auto query(ex::get_completion_domain_t<ex::set_value_t>) const noexcept
{
return Domain{};
}
};
template <class Rcvr>
struct _opstate_t : cuda::__immovable
{
using operation_state_concept = ex::operation_state_t;
_CCCL_HOST_DEVICE constexpr _opstate_t(Rcvr rcvr) noexcept
: _rcvr(static_cast<Rcvr&&>(rcvr))
{}
_CCCL_HOST_DEVICE constexpr void start() noexcept
{
ex::set_value(static_cast<Rcvr&&>(_rcvr));
}
Rcvr _rcvr;
};
template <class Domain>
struct _sndr_t
{
using sender_concept = ex::sender_t;
template <class Self>
_CCCL_HOST_DEVICE static _CCCL_CONSTEVAL auto get_completion_signatures() noexcept
{
return ex::completion_signatures<ex::set_value_t()>();
}
template <class Rcvr>
_CCCL_HOST_DEVICE constexpr auto connect(Rcvr rcvr) const noexcept -> _opstate_t<Rcvr>
{
return _opstate_t<Rcvr>(static_cast<Rcvr&&>(rcvr));
}
[[nodiscard]] _CCCL_HOST_DEVICE constexpr auto get_env() const noexcept
{
return _attrs_t<Domain>{};
}
};
} // namespace _dummy
//! Scheduler that returns a sender that always completes inline (successfully).
template <class Domain = ex::default_domain>
struct dummy_scheduler : _dummy::_attrs_t<Domain>
{
using scheduler_concept = ex::scheduler_t;
_CCCL_HOST_DEVICE static constexpr auto schedule() noexcept -> _dummy::_sndr_t<Domain>
{
return {};
}
_CCCL_HOST_DEVICE friend constexpr bool operator==(dummy_scheduler, dummy_scheduler) noexcept
{
return true;
}
_CCCL_HOST_DEVICE friend constexpr bool operator!=(dummy_scheduler, dummy_scheduler) noexcept
{
return false;
}
};
namespace _dummy
{
template <class Domain>
_CCCL_HOST_DEVICE constexpr auto _attrs_t<Domain>::query(ex::get_completion_scheduler_t<ex::set_value_t>) const noexcept
{
return dummy_scheduler<Domain>{};
}
} // namespace _dummy
} // namespace

View File

@@ -1,134 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/__utility/immovable.h>
#include <cuda/experimental/execution.cuh>
#include "testing.cuh" // IWYU pragma: keep
namespace
{
struct _error_scheduler_attrs_t
{
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_scheduler_t<cudax_async::set_value_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_scheduler<cudax_async::set_value_t>(env, env))
{
return cudax_async::get_completion_scheduler<cudax_async::set_value_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_scheduler_t<cudax_async::set_error_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_scheduler<cudax_async::set_error_t>(env, env))
{
return cudax_async::get_completion_scheduler<cudax_async::set_error_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_domain_t<cudax_async::set_value_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_domain<cudax_async::set_value_t>(env, env))
{
return cudax_async::get_completion_domain<cudax_async::set_value_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_domain_t<cudax_async::set_error_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_domain<cudax_async::set_error_t>(env, env))
{
return cudax_async::get_completion_domain<cudax_async::set_error_t>(env, env);
}
_CCCL_HOST_DEVICE static constexpr auto query(cudax_async::get_completion_behavior_t) noexcept
{
return cudax_async::completion_behavior::inline_completion;
}
};
//! Scheduler that returns a sender that always completes with error.
template <class Error>
struct error_scheduler : _error_scheduler_attrs_t
{
private:
template <class Rcvr>
struct _opstate_t : cuda::__immovable
{
using operation_state_concept = cudax_async::operation_state_t;
Rcvr _rcvr;
Error _err;
_CCCL_HOST_DEVICE void start() noexcept
{
cudax_async::set_error(static_cast<Rcvr&&>(_rcvr), static_cast<Error&&>(_err));
}
};
struct _sndr_t
{
using sender_concept = cudax_async::sender_t;
template <class Self>
_CCCL_HOST_DEVICE static constexpr auto get_completion_signatures()
{
return cudax_async::completion_signatures< //
cudax_async::set_value_t(), //
cudax_async::set_error_t(Error)>();
}
template <class Rcvr>
_CCCL_HOST_DEVICE auto connect(Rcvr rcvr) const -> _opstate_t<Rcvr>
{
return {{}, static_cast<Rcvr&&>(rcvr), _err};
}
_CCCL_HOST_DEVICE auto get_env() const noexcept -> _error_scheduler_attrs_t
{
return {};
}
Error _err;
};
Error _err{};
public:
using scheduler_concept = cudax_async::scheduler_t;
_CCCL_HIDE_FROM_ABI error_scheduler() = default;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE explicit constexpr error_scheduler(Error err)
: _err(static_cast<Error&&>(err))
{}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE auto schedule() const noexcept -> _sndr_t
{
return {_err};
}
_CCCL_HOST_DEVICE friend constexpr bool operator==(const error_scheduler&, const error_scheduler&) noexcept
{
return true;
}
_CCCL_HOST_DEVICE friend constexpr bool operator!=(const error_scheduler&, const error_scheduler&) noexcept
{
return false;
}
};
} // namespace

View File

@@ -1,206 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/__utility/immovable.h>
#include <cuda/experimental/execution.cuh>
// IWYU pragma: begin_keep
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
// IWYU pragma: end_keep
#include "testing.cuh" // IWYU pragma: keep
namespace ex = cuda::experimental::execution;
#if _CCCL_HOST_COMPILATION()
namespace
{
namespace _impulse
{
struct _attrs_t
{
constexpr auto query(ex::get_completion_behavior_t) const noexcept
{
return ex::completion_behavior::asynchronous;
}
};
} // namespace _impulse
//! Scheduler that will send impulses on user's request.
//! One can obtain senders from this, connect them to receivers and start the operation states.
//! Until the scheduler is told to start the next operation, the actions in the operation states are
//! not executed. This is similar to a task scheduler, but it's single threaded. It has basic
//! thread-safety to allow it to be run with `sync_wait` (which makes us not control when the
//! operation_state object is created and started).
struct impulse_scheduler : _impulse::_attrs_t
{
private:
//! Command type that can store the action of firing up a sender
using _cmd_t = std::function<void()>;
using _cmd_vec_t = std::vector<_cmd_t>;
struct _data_t : std::enable_shared_from_this<_data_t>
{
explicit _data_t(int id)
: id_(id)
{}
int id_;
std::mutex mutex_{};
std::condition_variable cv_{};
std::vector<std::function<void()>> all_commands_{};
};
//! That data_t shared between the operation state and the actual scheduler
//! Shared pointer to allow the scheduler to be copied (not the best semantics, but it will do)
std::shared_ptr<_data_t> _data_{};
template <class Rcvr>
struct _opstate_t : cuda::__immovable
{
using operation_state_concept = ex::operation_state_t;
_data_t* _data_;
Rcvr _rcvr_;
explicit _opstate_t(_data_t* data, Rcvr&& rcvr)
: _data_(data)
, _rcvr_(static_cast<Rcvr&&>(rcvr))
{}
void start() noexcept
{
// Enqueue another command to the list of all commands
// The scheduler will start this, whenever start_next() is called
std::unique_lock lock{_data_->mutex_};
_data_->all_commands_.emplace_back([this]() {
if (ex::get_stop_token(ex::get_env(_rcvr_)).stop_requested())
{
ex::set_stopped(static_cast<Rcvr&&>(_rcvr_));
}
else
{
ex::set_value(static_cast<Rcvr&&>(_rcvr_));
}
});
_data_->cv_.notify_all();
}
};
struct _sndr_t
{
using sender_concept = ex::sender_t;
_data_t* _data_;
template <class Self>
_CCCL_HOST_DEVICE static constexpr auto get_completion_signatures()
{
return ex::completion_signatures<ex::set_value_t(), ex::set_stopped_t()>();
}
template <class Rcvr>
auto connect(Rcvr rcvr) -> _opstate_t<Rcvr>
{
return _opstate_t<Rcvr>{_data_, static_cast<Rcvr&&>(rcvr)};
}
auto get_env() const noexcept
{
return _impulse::_attrs_t{};
}
};
explicit impulse_scheduler(_data_t* data)
: _data_(data->shared_from_this())
{}
public:
using scheduler_concept = ex::scheduler_t;
impulse_scheduler()
: _data_(std::make_shared<_data_t>(0))
{}
explicit impulse_scheduler(int id)
: _data_(std::make_shared<_data_t>(id))
{}
~impulse_scheduler() = default;
//! Actually start the command from the last started operation_state
//! Returns immediately if no command registered (i.e., no operation state started)
bool try_start_next()
{
// Wait for a command that we can execute
std::unique_lock lock{_data_->mutex_};
// If there are no commands in the queue, return false
if (_data_->all_commands_.empty())
{
return false;
}
// Pop one command from the queue
auto cmd = std::move(_data_->all_commands_.front());
_data_->all_commands_.erase(_data_->all_commands_.begin());
// Exit the lock before executing the command
lock.unlock();
// Execute the command, i.e., send an impulse to the connected sender
cmd();
// Return true to signal that we started a command
return true;
}
//! Actually start the command from the last started operation_state
//! Blocks if no command registered (i.e., no operation state started)
void start_next()
{
// Wait for a command that we can execute
std::unique_lock lock{_data_->mutex_};
while (_data_->all_commands_.empty())
{
_data_->cv_.wait(lock);
}
// Pop one command from the queue
auto cmd = std::move(_data_->all_commands_.front());
_data_->all_commands_.erase(_data_->all_commands_.begin());
// Exit the lock before executing the command
lock.unlock();
// Execute the command, i.e., send an impulse to the connected sender
cmd();
}
_sndr_t schedule() const noexcept
{
return _sndr_t{_data_.get()};
}
friend bool operator==(const impulse_scheduler& a, const impulse_scheduler& b) noexcept
{
return a._data_ == b._data_;
}
friend bool operator!=(const impulse_scheduler& a, const impulse_scheduler& b) noexcept
{
return a._data_ != b._data_;
}
};
} // namespace
#endif // _CCCL_HOST_COMPILATION()

View File

@@ -1,190 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/std/concepts>
#include <cuda/std/optional>
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <cuda/experimental/execution.cuh>
namespace _retry_detail
{
namespace ex = ::cuda::experimental::execution;
template <class From, class To>
using _copy_cvref_t = ::cuda::std::__copy_cvref_t<From, To>;
// _conv needed so we can emplace construct non-movable types into
// a cuda::std::optional.
template <class F>
struct _conv
{
using result_type = decltype(::cuda::std::declval<F>()());
operator result_type() &&
{
return static_cast<F&&>(f_)();
}
F f_;
};
template <class F>
_conv(F) -> _conv<F>;
///////////////////////////////////////////////////////////////////////////////
// retry algorithm:
template <class S, class R>
struct _opstate;
// pass through all customizations except set_error, which retries the operation.
template <class S, class R>
struct _retry_receiver
{
using receiver_concept = ex::receiver_t;
template <class... Ts>
void set_value(Ts&&... ts) && noexcept
{
ex::set_value(::cuda::std::move(o_->r_), static_cast<Ts&&>(ts)...);
}
template <class Error>
void set_error(Error&&) && noexcept
{
o_->_retry(); // This causes the op to be retried
}
void set_stopped() && noexcept
{
ex::set_stopped(static_cast<R&&>(o_->r_));
}
[[nodiscard]]
auto get_env() const noexcept -> ex::env_of_t<R>
{
return ex::get_env(o_->r_);
}
_opstate<S, R>* o_;
};
// Hold the nested operation state in an optional so we can
// re-construct and re-start it if the operation fails.
template <class S, class R>
struct _opstate
{
using operation_state_concept = ex::operation_state_t;
using _nested_op_t = ex::connect_result_t<S&, _retry_receiver<S, R>>;
explicit _opstate(S s, R r)
: s_(static_cast<S&&>(s))
, r_(static_cast<R&&>(r))
, o_{_connect()}
{}
_opstate(_opstate&&) = delete;
[[nodiscard]] auto _connect() noexcept
{
return _conv{[this] {
return ex::connect(s_, _retry_receiver<S, R>{this});
}};
}
void _retry() noexcept
{
_CCCL_TRY
{
o_.emplace(_connect()); // potentially throwing
ex::start(*o_);
}
_CCCL_CATCH_ALL
{
ex::set_error(static_cast<R&&>(r_), ex::current_exception());
}
}
void start() & noexcept
{
ex::start(*o_);
}
private:
friend struct _retry_receiver<S, R>;
S s_;
R r_;
::cuda::std::optional<_nested_op_t> o_;
};
struct _swallow_signature
{
template <class... _Ts>
_CCCL_CONSTEVAL auto operator()() const noexcept
{
return ex::completion_signatures{};
}
};
template <class S>
struct _retry_sender
{
using sender_concept = ex::sender_t;
explicit _retry_sender(S s)
: s_(static_cast<S&&>(s))
{}
template <class Self, class... Env>
static _CCCL_CONSTEVAL auto get_completion_signatures()
{
return ex::transform_completion_signatures(
ex::get_child_completion_signatures<Self&, S, Env...>(),
{},
_swallow_signature{},
{},
ex::completion_signatures<ex::set_error_t(ex::exception_ptr)>{});
}
template <class R>
[[nodiscard]] auto connect(R r) && -> _opstate<S, R>
{
return _opstate<S, R>{::cuda::std::move(*this).s_, ::cuda::std::move(r)};
}
template <class R>
[[nodiscard]] auto connect(R r) const& -> _opstate<S, R>
{
return _opstate<S, R>{s_, ::cuda::std::move(r)};
}
auto get_env() const noexcept -> ex::env_of_t<S>
{
return ex::get_env(s_);
}
private:
S s_;
};
} // namespace _retry_detail
struct retry_t
{
template <class S>
[[nodiscard]] auto operator()(S s) const -> _retry_detail::_retry_sender<S>
{
return _retry_detail::_retry_sender<S>{static_cast<S&&>(s)};
}
};
inline constexpr retry_t retry{};

View File

@@ -1,120 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/__utility/immovable.h>
#include <cuda/experimental/execution.cuh>
#include "testing.cuh" // IWYU pragma: keep
namespace
{
struct _stopped_scheduler_attrs_t
{
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_scheduler_t<cudax_async::set_value_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_scheduler<cudax_async::set_value_t>(env, env))
{
return cudax_async::get_completion_scheduler<cudax_async::set_value_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_scheduler_t<cudax_async::set_stopped_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_scheduler<cudax_async::set_stopped_t>(env, env))
{
return cudax_async::get_completion_scheduler<cudax_async::set_stopped_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_domain_t<cudax_async::set_value_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_domain<cudax_async::set_value_t>(env, env))
{
return cudax_async::get_completion_domain<cudax_async::set_value_t>(env, env);
}
template <class _Env>
_CCCL_HOST_DEVICE auto
query(cudax_async::get_completion_domain_t<cudax_async::set_stopped_t>, const _Env& env) const noexcept
-> decltype(cudax_async::get_completion_domain<cudax_async::set_stopped_t>(env, env))
{
return cudax_async::get_completion_domain<cudax_async::set_stopped_t>(env, env);
}
_CCCL_HOST_DEVICE static constexpr auto query(cudax_async::get_completion_behavior_t) noexcept
{
return cudax_async::completion_behavior::inline_completion;
}
};
//! Scheduler that returns a sender that always completes with stopped.
struct stopped_scheduler : _stopped_scheduler_attrs_t
{
private:
template <class Rcvr>
struct _opstate_t : cuda::__immovable
{
using operation_state_concept = cudax_async::operation_state_t;
Rcvr _rcvr;
_CCCL_HOST_DEVICE void start() noexcept
{
cudax_async::set_stopped(static_cast<Rcvr&&>(_rcvr));
}
};
struct _sndr_t
{
using sender_concept = cudax_async::sender_t;
template <class Self>
_CCCL_HOST_DEVICE static constexpr auto get_completion_signatures()
{
return cudax_async::completion_signatures<cudax_async::set_value_t(), cudax_async::set_stopped_t()>();
}
template <class Rcvr>
_CCCL_HOST_DEVICE auto connect(Rcvr rcvr) const noexcept -> _opstate_t<Rcvr>
{
return {{}, static_cast<Rcvr&&>(rcvr)};
}
_CCCL_HOST_DEVICE auto get_env() const noexcept -> _stopped_scheduler_attrs_t
{
return {};
}
};
public:
using scheduler_concept = cudax_async::scheduler_t;
stopped_scheduler() = default;
_CCCL_HOST_DEVICE auto schedule() const noexcept -> _sndr_t
{
return {};
}
_CCCL_HOST_DEVICE friend constexpr bool operator==(stopped_scheduler, stopped_scheduler) noexcept
{
return true;
}
_CCCL_HOST_DEVICE friend constexpr bool operator!=(stopped_scheduler, stopped_scheduler) noexcept
{
return false;
}
};
} // namespace

View File

@@ -1,290 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cuda/std/__string/char_traits.h>
#include <cuda/std/__type_traits/copy_cvref.h>
#include <cuda/experimental/execution.cuh>
#include <iostream>
#include "testing.cuh" // IWYU pragma: keep
// Workaround for https://github.com/llvm/llvm-project/issues/113087
#if defined(__clang__) && __cpp_lib_tuple_like >= 202207L
# define C2H_CHECK_TUPLE(...) CHECK((__VA_ARGS__))
#else
# define C2H_CHECK_TUPLE(...) CHECK(__VA_ARGS__)
#endif
//! A move-only type
struct movable
{
_CCCL_HOST_DEVICE movable(int value)
: value_(value)
{}
movable(movable&&) = default;
_CCCL_HOST_DEVICE friend bool operator==(const movable& a, const movable& b) noexcept
{
return a.value_ == b.value_;
}
_CCCL_HOST_DEVICE friend bool operator!=(const movable& a, const movable& b) noexcept
{
return a.value_ != b.value_;
}
friend std::ostream& operator<<(std::ostream& os, const movable& self)
{
os << "movable{" << self.value_ << "}";
return os;
}
_CCCL_HOST_DEVICE int value() const
{
return value_;
} // silence warning of unused private field
private:
int value_;
};
//! A type with potentially throwing move/copy constructors
struct potentially_throwing
{
potentially_throwing() = default;
_CCCL_HOST_DEVICE potentially_throwing(potentially_throwing&&) noexcept(false) {}
_CCCL_HOST_DEVICE
potentially_throwing(const potentially_throwing&) noexcept(false) // NOLINT(modernize-use-equals-default)
{}
_CCCL_HOST_DEVICE potentially_throwing& operator=(potentially_throwing&&) noexcept(false)
{
return *this;
}
// NOLINTNEXTLINE(modernize-use-equals-default)
_CCCL_HOST_DEVICE potentially_throwing& operator=(const potentially_throwing&) noexcept(false)
{
return *this;
}
friend std::ostream& operator<<(std::ostream& os, const potentially_throwing&)
{
os << "potentially_throwing{}";
return os;
}
};
struct non_default_constructible
{
_CCCL_HOST_DEVICE constexpr explicit non_default_constructible(int value) noexcept
: value_(value)
{}
_CCCL_HOST_DEVICE friend constexpr bool
operator==(const non_default_constructible& a, const non_default_constructible& b) noexcept
{
return a.value_ == b.value_;
}
_CCCL_HOST_DEVICE friend constexpr bool
operator!=(const non_default_constructible& a, const non_default_constructible& b) noexcept
{
return a.value_ != b.value_;
}
friend std::ostream& operator<<(std::ostream& os, const non_default_constructible& self)
{
os << "non_default_constructible{" << self.value_ << "}";
return os;
}
int value_;
};
struct string
{
string() = default;
_CCCL_HOST_DEVICE /*implicit*/ string(char const* c)
: len(cuda::std::char_traits<char>::length(c))
, str(cuda::std::char_traits<char>::copy(new char[len + 1], c, len + 1))
{}
_CCCL_HOST_DEVICE string(string&& other) noexcept
: len(cuda::std::exchange(other.len, 0))
, str(cuda::std::exchange(other.str, nullptr))
{}
_CCCL_HOST_DEVICE string(const string& other)
: string(string(other.c_str()))
{}
_CCCL_HOST_DEVICE ~string()
{
delete[] str;
}
_CCCL_HOST_DEVICE void swap(string& other) noexcept
{
cuda::std::swap(len, other.len);
cuda::std::swap(str, other.str);
}
_CCCL_HOST_DEVICE string& operator=(string other) noexcept
{
swap(other);
return *this;
}
_CCCL_HOST_DEVICE string operator+(string const& other) const
{
string result;
result.len = len + other.len;
result.str = new char[result.len + 1];
cuda::std::char_traits<char>::copy(result.str, str, len);
cuda::std::char_traits<char>::copy(result.str + len, other.str, other.len + 1);
return result;
}
_CCCL_HOST_DEVICE friend bool operator==(const string& left, const string& right) noexcept
{
return left.size() == right.size() && cuda::std::char_traits<char>::compare(left.str, right.str, left.size()) == 0;
}
_CCCL_HOST_DEVICE friend bool operator!=(const string& left, const string& right) noexcept
{
return !(left == right);
}
friend std::ostream& operator<<(std::ostream& os, const string& self)
{
os << "string{" << self.str << "}";
return os;
}
_CCCL_HOST_DEVICE cuda::std::size_t size() const
{
return len;
}
_CCCL_HOST_DEVICE const char* c_str() const
{
return str;
}
private:
cuda::std::size_t len{};
char* str{};
};
struct error_code
{
_CCCL_HOST_DEVICE friend bool operator==(const error_code& left, const error_code& right) noexcept
{
return left.ec == right.ec;
}
_CCCL_HOST_DEVICE friend bool operator!=(const error_code& left, const error_code& right) noexcept
{
return !(left == right);
}
friend std::ostream& operator<<(std::ostream& os, const error_code& self)
{
os << "error_code{" << static_cast<int>(self.ec) << "}";
return os;
}
std::errc ec;
};
template <class Sndr, class... Values>
void check_values(Sndr&& sndr, const Values&... values) noexcept
{
try
{
auto opt = cudax_async::sync_wait(static_cast<Sndr&&>(sndr));
if (!opt)
{
FAIL("Expected value completion; got stopped instead.");
}
else
{
auto&& vals = *opt;
CHECK(vals == ::cuda::std::tie(values...));
}
}
catch (...)
{
FAIL("Expected value completion; got error instead.");
}
}
template <class... Ts>
using types = ::cuda::std::__type_list<Ts...>;
template <class... Values, class Sndr>
_CCCL_HOST_DEVICE void check_value_types(Sndr&&) noexcept
{
using actual_t = cudax_async::value_types_of_t<Sndr, cudax_async::env<>, types, ::cuda::std::__make_type_set>;
if constexpr (!::cuda::std::__type_set_eq_v<actual_t, Values...>)
{
::cuda::std::__type_list<Values...> hard_error = actual_t{}; // Force the compiler to tell us the types involved.
static_assert(::cuda::std::__type_set_eq_v<actual_t, Values...>, "value_types_of_t does not match expected types");
}
}
template <class... Errors, class Sndr>
_CCCL_HOST_DEVICE void check_error_types(Sndr&&) noexcept
{
using actual_t = cudax_async::error_types_of_t<Sndr, cudax_async::env<>, ::cuda::std::__make_type_set>;
if constexpr (!::cuda::std::__type_set_eq_v<actual_t, Errors...>)
{
::cuda::std::__type_list<Errors...> hard_error = actual_t{}; // Force the compiler to tell us the types involved.
static_assert(::cuda::std::__type_set_eq_v<actual_t, Errors...>, "error_types_of_t does not match expected types");
}
}
template <bool SendsStopped, class Sndr>
_CCCL_HOST_DEVICE void check_sends_stopped(Sndr&&) noexcept
{
static_assert(cudax_async::sends_stopped<Sndr> == SendsStopped, "sends_stopped does not match expected value");
}
template <class Sndr, class Env, class... Ts>
inline void wait_for_value_with_env(Sndr&& snd, Env&& env, Ts&&... val)
{
using values_t = ::cuda::std::tuple<::cuda::std::decay_t<Ts>...>;
::cuda::std::optional<values_t> res = cudax_async::sync_wait(static_cast<Sndr&&>(snd), static_cast<Env&&>(env));
CHECK(res.has_value());
values_t expected(static_cast<Ts&&>(val)...);
if constexpr (::cuda::std::tuple_size_v<values_t> == 1)
{
C2H_CHECK_TUPLE(::cuda::std::get<0>(res.value()) == ::cuda::std::get<0>(expected));
}
else
{
C2H_CHECK_TUPLE(res.value() == expected);
}
}
template <class Sndr, class... Ts>
inline void wait_for_value(Sndr&& snd, Ts&&... val)
{
wait_for_value_with_env(static_cast<Sndr&&>(snd), cudax_async::env<>{}, static_cast<Ts&&>(val)...);
}