[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:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -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{};
|
||||
@@ -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
|
||||
@@ -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)...);
|
||||
}
|
||||
@@ -1,269 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/std/execution>
|
||||
#include <cuda/std/type_traits>
|
||||
|
||||
#include <cuda/experimental/container.cuh>
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
#include <cuda/experimental/memory_resource.cuh>
|
||||
|
||||
#include <testing.cuh>
|
||||
|
||||
namespace cudax = cuda::experimental;
|
||||
using env_t = cudax::env_t<cuda::mr::device_accessible>;
|
||||
|
||||
struct test_resource
|
||||
{
|
||||
void* allocate_sync(size_t, size_t)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
void* allocate(cuda::stream_ref, size_t, size_t)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
void deallocate_sync(void*, size_t, size_t) noexcept {}
|
||||
void deallocate(cuda::stream_ref, void*, size_t, size_t) noexcept {}
|
||||
|
||||
constexpr bool operator==(const test_resource&) const noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const test_resource&) const noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
friend void get_property(const test_resource&, cuda::mr::device_accessible) noexcept {}
|
||||
};
|
||||
|
||||
C2H_TEST("env_t is queryable for all properties we want", "[execution][env]")
|
||||
{
|
||||
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cuda::get_stream_t>);
|
||||
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cuda::mr::get_memory_resource_t>);
|
||||
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cudax::execution::get_execution_policy_t>);
|
||||
}
|
||||
|
||||
C2H_TEST("env_t is default constructible", "[execution][env]")
|
||||
{
|
||||
env_t env{cuda::device_default_memory_pool(cuda::device_ref{0})};
|
||||
CHECK(env.query(cuda::get_stream) == cuda::invalid_stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == cuda::device_default_memory_pool(cuda::device_ref{0}));
|
||||
}
|
||||
|
||||
C2H_TEST("env_t is constructible from an any_resource", "[execution][env]")
|
||||
{
|
||||
const cuda::mr::any_resource<cuda::mr::device_accessible> mr{test_resource{}};
|
||||
|
||||
SECTION("Passing an any_resource")
|
||||
{
|
||||
env_t env{mr};
|
||||
CHECK(env.query(cuda::get_stream) == cuda::invalid_stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource and a stream")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{mr, stream};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource, a stream and a policy")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{mr, stream, cuda::std::execution::par_unseq};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK((env.query(cudax::execution::get_execution_policy) == cuda::std::execution::par_unseq));
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
}
|
||||
|
||||
C2H_TEST("env_t is constructible from an any_resource passed as an rvalue", "[execution][env]")
|
||||
{
|
||||
SECTION("Passing an any_resource")
|
||||
{
|
||||
env_t env{cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}}};
|
||||
CHECK(env.query(cuda::get_stream) == cuda::invalid_stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource)
|
||||
== cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}});
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource and a stream")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}}, stream};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource)
|
||||
== cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}});
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource, a stream and a policy")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{
|
||||
cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}}, stream, cuda::std::execution::par_unseq};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cuda::std::execution::par_unseq);
|
||||
CHECK(env.query(cuda::mr::get_memory_resource)
|
||||
== cuda::mr::any_resource<cuda::mr::device_accessible>{test_resource{}});
|
||||
}
|
||||
}
|
||||
|
||||
C2H_TEST("env_t is constructible from a resource", "[execution][env]")
|
||||
{
|
||||
test_resource mr{};
|
||||
|
||||
SECTION("Passing an any_resource")
|
||||
{
|
||||
env_t env{mr};
|
||||
CHECK(env.query(cuda::get_stream) == cuda::invalid_stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource and a stream")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{mr, stream};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource, a stream and a policy")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{mr, stream, cuda::std::execution::par_unseq};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cuda::std::execution::par_unseq);
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
|
||||
}
|
||||
}
|
||||
|
||||
C2H_TEST("env_t is constructible from a resource passed as an rvalue", "[execution][env]")
|
||||
{
|
||||
SECTION("Passing an any_resource")
|
||||
{
|
||||
env_t env{test_resource{}};
|
||||
CHECK(env.query(cuda::get_stream) == cuda::invalid_stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource and a stream")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{test_resource{}, stream};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cudax::execution::any_execution_policy{});
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
|
||||
}
|
||||
|
||||
SECTION("Passing an any_resource, a stream and a policy")
|
||||
{
|
||||
cudax::stream stream{cuda::device_ref{0}};
|
||||
env_t env{test_resource{}, stream, cuda::std::execution::par_unseq};
|
||||
CHECK(env.query(cuda::get_stream) == stream);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == cuda::std::execution::par_unseq);
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
|
||||
}
|
||||
}
|
||||
|
||||
struct some_env_t
|
||||
{
|
||||
test_resource res_{};
|
||||
cudax::stream stream_{cuda::device_ref{0}};
|
||||
cudax::execution::any_execution_policy policy_ = cuda::std::execution::par_unseq;
|
||||
|
||||
const test_resource& query(cuda::mr::get_memory_resource_t) const noexcept
|
||||
{
|
||||
return res_;
|
||||
}
|
||||
|
||||
cudax::stream_ref query(cuda::get_stream_t) const noexcept
|
||||
{
|
||||
return stream_;
|
||||
}
|
||||
|
||||
cudax::execution::any_execution_policy query(cudax::execution::get_execution_policy_t) const noexcept
|
||||
{
|
||||
return policy_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("env_t is constructible from a suitable env", "[execution][env]")
|
||||
{
|
||||
some_env_t other_env{};
|
||||
env_t env{other_env};
|
||||
CHECK(env.query(cuda::get_stream) == other_env.stream_);
|
||||
CHECK(env.query(cudax::execution::get_execution_policy) == other_env.policy_);
|
||||
CHECK(env.query(cuda::mr::get_memory_resource) == other_env.res_);
|
||||
}
|
||||
|
||||
template <bool WithResource, bool WithStream, bool WithPolicy>
|
||||
struct bad_env_t
|
||||
{
|
||||
test_resource res_{};
|
||||
cudax::stream stream_{cuda::device_ref{0}};
|
||||
cudax::execution::any_execution_policy policy_ = cuda::std::execution::par_unseq;
|
||||
|
||||
template <bool Enable = WithResource, cuda::std::enable_if_t<Enable, int> = 0>
|
||||
const test_resource& query(cuda::mr::get_memory_resource_t) const noexcept
|
||||
{
|
||||
return res_;
|
||||
}
|
||||
|
||||
template <bool Enable = WithStream, cuda::std::enable_if_t<Enable, int> = 0>
|
||||
cudax::stream_ref query(cuda::get_stream_t) const noexcept
|
||||
{
|
||||
return stream_;
|
||||
}
|
||||
|
||||
template <bool Enable = WithPolicy, cuda::std::enable_if_t<Enable, int> = 0>
|
||||
cudax::execution::any_execution_policy query(cudax::execution::get_execution_policy_t) const noexcept
|
||||
{
|
||||
return policy_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("env_t is not constructible from a env missing queries", "[execution][env]")
|
||||
{
|
||||
STATIC_REQUIRE(cuda::std::is_constructible_v<env_t, bad_env_t<true, true, true>>);
|
||||
STATIC_REQUIRE(!cuda::std::is_constructible_v<env_t, bad_env_t<false, true, true>>);
|
||||
STATIC_REQUIRE(!cuda::std::is_constructible_v<env_t, bad_env_t<true, false, true>>);
|
||||
STATIC_REQUIRE(!cuda::std::is_constructible_v<env_t, bad_env_t<true, true, false>>);
|
||||
}
|
||||
|
||||
C2H_TEST("Can use query to construct various objects", "[execution][env]")
|
||||
{
|
||||
SECTION("Can create an any_resource")
|
||||
{
|
||||
env_t env{test_resource{}};
|
||||
cuda::mr::any_synchronous_resource<cuda::mr::device_accessible> resource = env.query(cuda::mr::get_memory_resource);
|
||||
CHECK(resource == test_resource{});
|
||||
}
|
||||
|
||||
SECTION("Can create an __uninitialized_async_buffer")
|
||||
{
|
||||
cudax::stream stream_{cuda::device_ref{0}};
|
||||
env_t env{test_resource{}, stream_};
|
||||
cuda::__uninitialized_async_buffer<int, cuda::mr::device_accessible> buf{
|
||||
env.query(cuda::mr::get_memory_resource), env.query(cuda::get_stream), 0ull};
|
||||
CHECK(buf.memory_resource() == test_resource{});
|
||||
CHECK(buf.stream() == stream_);
|
||||
}
|
||||
}
|
||||
@@ -1,142 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/std/type_traits>
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include <testing.cuh>
|
||||
|
||||
namespace execution = cuda::experimental::execution;
|
||||
|
||||
struct with_get_execution_policy_const_lvalue
|
||||
{
|
||||
execution::any_execution_policy pol_ = execution::seq;
|
||||
|
||||
const execution::any_execution_policy& get_execution_policy() const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Can call get_execution_policy on a type with a get_execution_policy method that returns a const lvalue",
|
||||
"[execution][policies]")
|
||||
{
|
||||
with_get_execution_policy_const_lvalue val{};
|
||||
auto&& res = cuda::experimental::execution::get_execution_policy(val);
|
||||
STATIC_REQUIRE(cuda::std::is_same_v<decltype(res), execution::any_execution_policy&&>);
|
||||
CHECK(val.pol_ == res);
|
||||
}
|
||||
|
||||
struct with_get_execution_policy_rvalue
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy get_execution_policy() const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Can call get_execution_policy on a type with a get_execution_policy method returns an rvalue",
|
||||
"[execution][policies]")
|
||||
{
|
||||
with_get_execution_policy_rvalue val{};
|
||||
auto&& res = cuda::experimental::execution::get_execution_policy(val);
|
||||
STATIC_REQUIRE(cuda::std::is_same_v<decltype(res), execution::any_execution_policy&&>);
|
||||
CHECK(val.pol_ == res);
|
||||
}
|
||||
|
||||
struct with_get_execution_policy_non_const
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy get_execution_policy() noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Cannot call get_execution_policy on a type with a non-const get_execution_policy method",
|
||||
"[execution][policies]")
|
||||
{
|
||||
STATIC_REQUIRE(!::cuda::std::is_invocable_v<cuda::experimental::execution::get_execution_policy_t,
|
||||
const with_get_execution_policy_non_const&>);
|
||||
}
|
||||
|
||||
struct env_with_query_const_ref
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy query(cuda::experimental::execution::get_execution_policy_t) const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Can call get_execution_policy on an env with a get_execution_policy query that returns a const lvalue",
|
||||
"[execution][policies]")
|
||||
{
|
||||
env_with_query_const_ref val{};
|
||||
auto&& res = cuda::experimental::execution::get_execution_policy(val);
|
||||
STATIC_REQUIRE(cuda::std::is_same_v<decltype(res), execution::any_execution_policy&&>);
|
||||
CHECK(val.pol_ == res);
|
||||
}
|
||||
|
||||
struct env_with_query_rvalue
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy query(cuda::experimental::execution::get_execution_policy_t) const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Can call get_execution_policy on an env with a get_execution_policy query that returns an rvalue",
|
||||
"[execution][policies]")
|
||||
{
|
||||
env_with_query_rvalue val{};
|
||||
auto&& res = cuda::experimental::execution::get_execution_policy(val);
|
||||
STATIC_REQUIRE(cuda::std::is_same_v<decltype(res), execution::any_execution_policy&&>);
|
||||
CHECK(val.pol_ == res);
|
||||
}
|
||||
|
||||
struct env_with_query_non_const
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy query(cuda::experimental::execution::get_execution_policy_t) noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Cannot call get_execution_policy on an env with a non-const query", "[execution][policies]")
|
||||
{
|
||||
STATIC_REQUIRE(
|
||||
!::cuda::std::is_invocable_v<cuda::experimental::execution::get_execution_policy_t, const env_with_query_non_const&>);
|
||||
}
|
||||
|
||||
struct env_with_query_and_method
|
||||
{
|
||||
execution::any_execution_policy pol_{};
|
||||
|
||||
execution::any_execution_policy get_execution_policy() const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
|
||||
execution::any_execution_policy query(cuda::experimental::execution::get_execution_policy_t) const noexcept
|
||||
{
|
||||
return pol_;
|
||||
}
|
||||
};
|
||||
C2H_TEST("Can call get_execution_policy on a type with both get_execution_policy and query", "[execution][policies]")
|
||||
{
|
||||
env_with_query_and_method val{};
|
||||
auto&& res = cuda::experimental::execution::get_execution_policy(val);
|
||||
STATIC_REQUIRE(cuda::std::is_same_v<decltype(res), execution::any_execution_policy&&>);
|
||||
CHECK(val.pol_ == res);
|
||||
}
|
||||
@@ -1,34 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/std/execution>
|
||||
#include <cuda/std/type_traits>
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include <testing.cuh>
|
||||
|
||||
namespace cudax = cuda::experimental;
|
||||
|
||||
template <class T, class U>
|
||||
using is_same = cuda::std::is_same<cuda::std::remove_cvref_t<T>, U>;
|
||||
|
||||
C2H_TEST("Execution policies", "[execution][policies]")
|
||||
{
|
||||
namespace execution = cuda::std::execution;
|
||||
SECTION("Individual options")
|
||||
{
|
||||
cudax::execution::any_execution_policy pol = execution::seq;
|
||||
pol = execution::par;
|
||||
pol = execution::par_unseq;
|
||||
pol = execution::unseq;
|
||||
CHECK(pol == execution::unseq);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,140 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Include this first
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
// Then include the test helpers
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
// NOLINTBEGIN(misc-unused-using-decls)
|
||||
using cuda::experimental::execution::completion_signatures;
|
||||
using cuda::experimental::execution::set_error;
|
||||
using cuda::experimental::execution::set_error_t;
|
||||
using cuda::experimental::execution::set_stopped;
|
||||
using cuda::experimental::execution::set_stopped_t;
|
||||
using cuda::experimental::execution::set_value;
|
||||
using cuda::experimental::execution::set_value_t;
|
||||
// NOLINTEND(misc-unused-using-decls)
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("", "[utilities][completion_signatures]")
|
||||
{
|
||||
STATIC_REQUIRE(completion_signatures{} == completion_signatures{});
|
||||
STATIC_REQUIRE_FALSE(completion_signatures{} != completion_signatures{});
|
||||
}
|
||||
|
||||
// Additional tests for completion_signatures
|
||||
C2H_TEST("completion_signatures_basic", "[utilities][completion_signatures]")
|
||||
{
|
||||
constexpr auto cs_empty = completion_signatures<>{};
|
||||
constexpr auto cs_value = completion_signatures<set_value_t(int)>{};
|
||||
constexpr auto cs_error = completion_signatures<set_error_t(float)>{};
|
||||
constexpr auto cs_stopped = completion_signatures<set_stopped_t()>{};
|
||||
constexpr auto cs_all = completion_signatures<set_value_t(int), set_error_t(float), set_stopped_t()>{};
|
||||
|
||||
// Test size
|
||||
STATIC_REQUIRE(cs_empty.size() == 0);
|
||||
STATIC_REQUIRE(cs_value.size() == 1);
|
||||
STATIC_REQUIRE(cs_all.size() == 3);
|
||||
|
||||
// Test contains
|
||||
STATIC_REQUIRE(cs_value.contains(static_cast<set_value_t (*)(int)>(nullptr)));
|
||||
STATIC_REQUIRE_FALSE(cs_value.contains(static_cast<set_error_t (*)(float)>(nullptr)));
|
||||
STATIC_REQUIRE(cs_all.contains(static_cast<set_stopped_t (*)()>(nullptr)));
|
||||
|
||||
// Test count
|
||||
STATIC_REQUIRE(cs_all.count(set_value) == 1);
|
||||
STATIC_REQUIRE(cs_all.count(set_error) == 1);
|
||||
STATIC_REQUIRE(cs_all.count(set_stopped) == 1);
|
||||
|
||||
// Test operator==
|
||||
STATIC_REQUIRE(cs_value == cs_value);
|
||||
STATIC_REQUIRE_FALSE(cs_value == cs_error);
|
||||
STATIC_REQUIRE(cs_empty == cs_empty);
|
||||
STATIC_REQUIRE(cs_all == cs_all);
|
||||
STATIC_REQUIRE(completion_signatures<set_value_t(int), set_error_t(float)>{}
|
||||
== completion_signatures<set_error_t(float), set_value_t(int)>{});
|
||||
|
||||
// Test operator!=
|
||||
STATIC_REQUIRE(cs_value != cs_error);
|
||||
STATIC_REQUIRE_FALSE(cs_all != cs_all);
|
||||
|
||||
// Test operator+
|
||||
STATIC_REQUIRE((cs_value + cs_error) == completion_signatures<set_value_t(int), set_error_t(float)>{});
|
||||
STATIC_REQUIRE((cs_empty + cs_value) == cs_value);
|
||||
STATIC_REQUIRE((cs_value + cs_empty) == cs_value);
|
||||
|
||||
// Test operator-
|
||||
STATIC_REQUIRE((cs_all - cs_value) == completion_signatures<set_error_t(float), set_stopped_t()>{});
|
||||
STATIC_REQUIRE((cs_all - cs_error) == completion_signatures<set_value_t(int), set_stopped_t()>{});
|
||||
STATIC_REQUIRE((cs_all - cs_stopped) == completion_signatures<set_value_t(int), set_error_t(float)>{});
|
||||
STATIC_REQUIRE((cs_all - cs_all) == completion_signatures<>{});
|
||||
STATIC_REQUIRE((cs_value - cs_error) == cs_value);
|
||||
}
|
||||
|
||||
// Test select
|
||||
C2H_TEST("completion_signatures_select", "[utilities][completion_signatures]")
|
||||
{
|
||||
constexpr auto cs = completion_signatures<set_value_t(int), set_error_t(float), set_stopped_t()>{};
|
||||
|
||||
// select(set_value) should return only set_value_t(int)
|
||||
constexpr auto v = cs.select(set_value);
|
||||
STATIC_REQUIRE(v.size() == 1);
|
||||
STATIC_REQUIRE(v.contains<set_value_t(int)>());
|
||||
|
||||
// select(set_error) should return only set_error_t(float)
|
||||
constexpr auto e = cs.select(set_error);
|
||||
STATIC_REQUIRE(e.size() == 1);
|
||||
STATIC_REQUIRE(e.contains<set_error_t(float)>());
|
||||
|
||||
// select(set_stopped) should return only set_stopped_t()
|
||||
constexpr auto s = cs.select(set_stopped);
|
||||
STATIC_REQUIRE(s.size() == 1);
|
||||
STATIC_REQUIRE(s.contains<set_stopped_t()>());
|
||||
}
|
||||
|
||||
// Test filter
|
||||
struct filter_value_only
|
||||
{
|
||||
template <class Sig>
|
||||
constexpr bool operator()(Sig*) const noexcept
|
||||
{
|
||||
return cuda::experimental::execution::__detail::__signature_disposition<Sig>
|
||||
== cuda::experimental::execution::__disposition::__value;
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("completion_signatures_filter", "[utilities][completion_signatures]")
|
||||
{
|
||||
constexpr auto cs = completion_signatures<set_value_t(int), set_error_t(float), set_stopped_t()>{};
|
||||
constexpr auto filtered = cs.filter(filter_value_only{});
|
||||
STATIC_REQUIRE(filtered.size() == 1);
|
||||
STATIC_REQUIRE(filtered.contains<set_value_t(int)>());
|
||||
}
|
||||
|
||||
// Test apply
|
||||
struct count_signatures
|
||||
{
|
||||
template <class... Sigs>
|
||||
constexpr int operator()(Sigs*...) const noexcept
|
||||
{
|
||||
return sizeof...(Sigs);
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("completion_signatures_apply", "[utilities][completion_signatures]")
|
||||
{
|
||||
constexpr auto cs = completion_signatures<set_value_t(int), set_error_t(float), set_stopped_t()>{};
|
||||
constexpr int count = cs.apply(count_signatures{});
|
||||
STATIC_REQUIRE(count == 3);
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,86 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/dummy_scheduler.cuh"
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace ex = ::cuda::experimental::execution;
|
||||
|
||||
struct not_a_receiver
|
||||
{};
|
||||
|
||||
struct a_receiver
|
||||
{
|
||||
using receiver_concept = ex::receiver_t;
|
||||
a_receiver(a_receiver&&) = default;
|
||||
|
||||
void set_value(int) && noexcept {}
|
||||
void set_stopped() && noexcept {}
|
||||
};
|
||||
|
||||
C2H_TEST("tests for the receiver concepts", "[concepts]")
|
||||
{
|
||||
static_assert(!ex::receiver<not_a_receiver>);
|
||||
static_assert(ex::receiver<a_receiver>);
|
||||
|
||||
using yes_completions = ex::completion_signatures<ex::set_value_t(int), ex::set_stopped_t()>;
|
||||
static_assert(ex::receiver_of<a_receiver, yes_completions>);
|
||||
|
||||
using no_completions =
|
||||
ex::completion_signatures<ex::set_value_t(int), ex::set_stopped_t(), ex::set_error_t(ex::exception_ptr)>;
|
||||
static_assert(!ex::receiver_of<a_receiver, no_completions>);
|
||||
}
|
||||
|
||||
struct not_a_sender
|
||||
{};
|
||||
|
||||
struct a_sender
|
||||
{
|
||||
using sender_concept = ex::sender_t;
|
||||
|
||||
template <class _Self>
|
||||
static constexpr auto get_completion_signatures()
|
||||
{
|
||||
return ex::completion_signatures<ex::set_value_t(int), ex::set_stopped_t()>{};
|
||||
}
|
||||
};
|
||||
|
||||
struct non_constexpr_complsigs
|
||||
{
|
||||
using sender_concept = ex::sender_t;
|
||||
|
||||
template <class _Self, class...>
|
||||
_CCCL_HOST_DEVICE static auto get_completion_signatures()
|
||||
{
|
||||
return ex::completion_signatures<ex::set_value_t(int), ex::set_stopped_t()>{};
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("tests for the sender concepts", "[concepts]")
|
||||
{
|
||||
static_assert(!ex::sender<not_a_sender>);
|
||||
static_assert(ex::sender<a_sender>);
|
||||
|
||||
static_assert(ex::sender_in<a_sender>);
|
||||
static_assert(ex::sender_in<a_sender, ex::env<>>);
|
||||
|
||||
static_assert(ex::sender<non_constexpr_complsigs>);
|
||||
static_assert(!ex::sender_in<non_constexpr_complsigs>);
|
||||
static_assert(!ex::sender_in<non_constexpr_complsigs, ex::env<>>);
|
||||
|
||||
[[maybe_unused]] auto read_env = ex::read_env(ex::get_scheduler);
|
||||
using read_env_t = decltype(read_env);
|
||||
static_assert(ex::sender<read_env_t>);
|
||||
static_assert(!ex::sender_in<read_env_t>);
|
||||
static_assert(!ex::sender_in<read_env_t, ex::env<>>);
|
||||
static_assert(ex::sender_in<read_env_t, ex::prop<ex::get_scheduler_t, dummy_scheduler<>>>);
|
||||
}
|
||||
@@ -1,58 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Include this first
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
// Then include the test helpers
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh"
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("simple use of conditional runs exactly one of the two closures", "[adaptors][conditional]")
|
||||
{
|
||||
for (int i = 42; i < 44; ++i)
|
||||
{
|
||||
bool even{false};
|
||||
bool odd{false};
|
||||
|
||||
auto sndr1 =
|
||||
ex::just(i)
|
||||
| ex::conditional(
|
||||
[](int i) {
|
||||
return i % 2 == 0;
|
||||
},
|
||||
ex::then([&](int) {
|
||||
even = true;
|
||||
}),
|
||||
ex::then([&](int) {
|
||||
odd = true;
|
||||
}));
|
||||
|
||||
check_value_types<types<>>(sndr1);
|
||||
check_sends_stopped<false>(sndr1);
|
||||
#if _CCCL_HAS_EXCEPTIONS()
|
||||
check_error_types<ex::exception_ptr>(sndr1);
|
||||
#else // ^^^ _CCCL_HAS_EXCEPTIONS() ^^^ / vvv !_CCCL_HAS_EXCEPTIONS() vvv
|
||||
check_error_types<>(sndr1);
|
||||
#endif // !_CCCL_HAS_EXCEPTIONS()
|
||||
|
||||
auto op = ex::connect(std::move(sndr1), checked_value_receiver<>{});
|
||||
ex::start(op);
|
||||
|
||||
CHECK(even == (i % 2 == 0));
|
||||
CHECK(odd == (i % 2 == 1));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,217 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
//
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/dummy_scheduler.cuh"
|
||||
#include "common/error_scheduler.cuh"
|
||||
#include "common/impulse_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/stopped_scheduler.cuh"
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("continues_on simple example", "[adaptors][continues_on]")
|
||||
{
|
||||
auto snd = ex::continues_on(ex::just(13), ex::inline_scheduler{});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
|
||||
static_assert(ex::get_completion_behavior<decltype(snd)>() == ex::completion_behavior::inline_completion);
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the right value
|
||||
}
|
||||
|
||||
#if _CCCL_HOST_COMPILATION()
|
||||
|
||||
C2H_TEST("continues_on can be piped", "[adaptors][continues_on]")
|
||||
{
|
||||
// Just continues_on a value to the impulse scheduler
|
||||
bool called{false};
|
||||
auto sched = impulse_scheduler{};
|
||||
auto snd = ex::just(13) //
|
||||
| ex::continues_on(sched) //
|
||||
| ex::then([&](int val) {
|
||||
called = true;
|
||||
return val;
|
||||
});
|
||||
static_assert(ex::get_completion_behavior<decltype(snd)>() == ex::completion_behavior::asynchronous);
|
||||
// Start the operation
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
|
||||
// The value will be available when the scheduler will execute the next operation
|
||||
REQUIRE(!called);
|
||||
sched.start_next();
|
||||
REQUIRE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on calls the receiver when the scheduler dictates", "[adaptors][continues_on]")
|
||||
{
|
||||
bool called{false};
|
||||
impulse_scheduler sched;
|
||||
auto snd = ex::then(ex::continues_on(ex::just(13), sched), [&](int val) {
|
||||
called = true;
|
||||
return val;
|
||||
});
|
||||
auto op = ex::connect(snd, checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
// Up until this point, the scheduler didn't start any task; no effect expected
|
||||
CHECK(!called);
|
||||
|
||||
// Tell the scheduler to start executing one task
|
||||
sched.start_next();
|
||||
CHECK(called);
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on calls the given sender when the scheduler dictates", "[adaptors][continues_on]")
|
||||
{
|
||||
int counter{0};
|
||||
auto snd_base = ex::just() //
|
||||
| ex::then([&]() -> int {
|
||||
++counter;
|
||||
return 19;
|
||||
});
|
||||
|
||||
impulse_scheduler sched;
|
||||
auto snd = ex::then(ex::continues_on(std::move(snd_base), sched), [&](int val) {
|
||||
++counter;
|
||||
return val;
|
||||
});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{19});
|
||||
ex::start(op);
|
||||
// The sender is started, even if the scheduler hasn't yet triggered
|
||||
CHECK(counter == 1);
|
||||
// ... but didn't send the value to the receiver yet
|
||||
|
||||
// Tell the scheduler to start executing one task
|
||||
sched.start_next();
|
||||
|
||||
// Now the base sender is called, and a value is sent to the receiver
|
||||
CHECK(counter == 2);
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on works when changing threads", "[adaptors][continues_on]")
|
||||
{
|
||||
ex::thread_context thread;
|
||||
bool called{false};
|
||||
|
||||
{
|
||||
// lunch some work on the thread pool
|
||||
auto snd = ex::continues_on(ex::just(), thread.get_scheduler()) //
|
||||
| ex::then([&] {
|
||||
called = true;
|
||||
});
|
||||
ex::start_detached(std::move(snd));
|
||||
}
|
||||
|
||||
thread.join();
|
||||
|
||||
// the work should be executed
|
||||
REQUIRE(called);
|
||||
}
|
||||
|
||||
#endif // _CCCL_HOST_COMPILATION()
|
||||
|
||||
C2H_TEST("continues_on can be called with rvalue ref scheduler", "[adaptors][continues_on]")
|
||||
{
|
||||
auto snd = ex::continues_on(ex::just(13), dummy_scheduler<>{});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the right value
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on can be called with const ref scheduler", "[adaptors][continues_on]")
|
||||
{
|
||||
const dummy_scheduler<> sched;
|
||||
auto snd = ex::continues_on(ex::just(13), sched);
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the right value
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on can be called with ref scheduler", "[adaptors][continues_on]")
|
||||
{
|
||||
dummy_scheduler<> sched;
|
||||
auto snd = ex::continues_on(ex::just(13), sched);
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the right value
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on forwards set_error calls", "[adaptors][continues_on]")
|
||||
{
|
||||
auto ec = error_code{std::errc::invalid_argument};
|
||||
error_scheduler<error_code> sched{ec};
|
||||
auto snd = ex::continues_on(ex::just(13), sched);
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{ec});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive an error
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on forwards set_error calls of other types", "[adaptors][continues_on]")
|
||||
{
|
||||
error_scheduler<string> sched{string{"error"}};
|
||||
auto snd = ex::continues_on(ex::just(13), sched);
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{string{"error"}});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive an error
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on forwards set_stopped calls", "[adaptors][continues_on]")
|
||||
{
|
||||
stopped_scheduler sched{};
|
||||
auto snd = ex::continues_on(ex::just(13), sched);
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the stopped signal
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on has the values_type corresponding to the given values", "[adaptors][continues_on]")
|
||||
{
|
||||
dummy_scheduler<> sched{};
|
||||
|
||||
check_value_types<types<int>>(ex::continues_on(ex::just(1), sched));
|
||||
check_value_types<types<int, double>>(ex::continues_on(ex::just(3, 0.14), sched));
|
||||
check_value_types<types<int, double, string>>(ex::continues_on(ex::just(3, 0.14, string{"pi"}), sched));
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on keeps error_types from scheduler's sender", "[adaptors][continues_on]")
|
||||
{
|
||||
dummy_scheduler<> sched1{};
|
||||
error_scheduler<std::error_code> sched2{std::make_error_code(std::errc::invalid_argument)};
|
||||
error_scheduler<int> sched3{43};
|
||||
|
||||
check_error_types<>(ex::continues_on(ex::just(1), sched1));
|
||||
check_error_types<std::error_code>(ex::continues_on(ex::just(2), sched2));
|
||||
check_error_types<int>(ex::continues_on(ex::just(3), sched3));
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on sends an exception_ptr if value types are potentially throwing when copied",
|
||||
"[adaptors][continues_on]")
|
||||
{
|
||||
dummy_scheduler<> sched{};
|
||||
check_error_types<ex::exception_ptr>(ex::continues_on(ex::just(potentially_throwing{}), sched));
|
||||
}
|
||||
|
||||
C2H_TEST("continues_on keeps sends_stopped from scheduler's sender", "[adaptors][continues_on]")
|
||||
{
|
||||
dummy_scheduler<> sched1{};
|
||||
stopped_scheduler sched2{};
|
||||
|
||||
check_sends_stopped<false>(ex::continues_on(ex::just(1), sched1));
|
||||
check_sends_stopped<true>(ex::continues_on(ex::just_stopped(), sched1));
|
||||
check_sends_stopped<true>(ex::continues_on(ex::just(3), sched2));
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,90 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include <system_error>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/dummy_scheduler.cuh"
|
||||
|
||||
#if _CCCL_COMPILER(GCC, <, 12)
|
||||
// suppress buggy warning on older gcc versions
|
||||
_CCCL_DIAG_SUPPRESS_GCC("-Wmissing-field-initializers")
|
||||
#endif
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct test_domain
|
||||
{};
|
||||
|
||||
C2H_TEST("simple test of just sender factory", "[just]")
|
||||
{
|
||||
auto sndr = ex::just(42);
|
||||
using Sndr = decltype(sndr);
|
||||
STATIC_REQUIRE(ex::sender<Sndr>);
|
||||
|
||||
auto op = ex::connect(sndr, checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
|
||||
STATIC_CHECK(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::inline_completion);
|
||||
STATIC_CHECK(!cudax::__callable<ex::get_completion_scheduler_t<ex::set_value_t>, ex::env_of_t<Sndr>>);
|
||||
STATIC_CHECK(!cudax::__callable<ex::get_completion_domain_t<ex::set_value_t>, ex::env_of_t<Sndr>>);
|
||||
|
||||
constexpr auto sch = dummy_scheduler<test_domain>{};
|
||||
constexpr auto env = ex::prop{ex::get_scheduler, sch};
|
||||
STATIC_CHECK(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(sndr), env) == sch);
|
||||
STATIC_CHECK(
|
||||
cuda::std::is_same_v<decltype(ex::get_completion_domain<ex::set_value_t>(ex::get_env(sndr), env)), test_domain>);
|
||||
}
|
||||
|
||||
C2H_TEST("simple test of just_error sender factory", "[just]")
|
||||
{
|
||||
auto ec = ::std::errc::invalid_argument;
|
||||
auto sndr = ex::just_error(ec);
|
||||
using Sndr = decltype(sndr);
|
||||
STATIC_REQUIRE(ex::sender<Sndr>);
|
||||
|
||||
auto op = ex::connect(sndr, checked_error_receiver{ec});
|
||||
ex::start(op);
|
||||
|
||||
STATIC_REQUIRE(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::inline_completion);
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_scheduler_t<ex::set_error_t>, ex::env_of_t<Sndr>>);
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_domain_t<ex::set_error_t>, ex::env_of_t<Sndr>>);
|
||||
|
||||
constexpr auto sch = dummy_scheduler<test_domain>{};
|
||||
constexpr auto env = ex::prop{ex::get_scheduler, sch};
|
||||
STATIC_CHECK(ex::get_completion_scheduler<ex::set_error_t>(ex::get_env(sndr), env) == sch);
|
||||
STATIC_CHECK(
|
||||
cuda::std::is_same_v<decltype(ex::get_completion_domain<ex::set_error_t>(ex::get_env(sndr), env)), test_domain>);
|
||||
}
|
||||
|
||||
C2H_TEST("simple test of just_stopped sender factory", "[just]")
|
||||
{
|
||||
auto sndr = ex::just_stopped();
|
||||
using Sndr = decltype(sndr);
|
||||
STATIC_REQUIRE(ex::sender<Sndr>);
|
||||
|
||||
auto op = ex::connect(sndr, checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
|
||||
STATIC_REQUIRE(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::inline_completion);
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_scheduler_t<ex::set_stopped_t>, ex::env_of_t<Sndr>>);
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_domain_t<ex::set_stopped_t>, ex::env_of_t<Sndr>>);
|
||||
|
||||
constexpr auto sch = dummy_scheduler<test_domain>{};
|
||||
constexpr auto env = ex::prop{ex::get_scheduler, sch};
|
||||
STATIC_CHECK(ex::get_completion_scheduler<ex::set_stopped_t>(ex::get_env(sndr), env) == sch);
|
||||
STATIC_CHECK(
|
||||
cuda::std::is_same_v<decltype(ex::get_completion_domain<ex::set_stopped_t>(ex::get_env(sndr), env)), test_domain>);
|
||||
}
|
||||
} // anonymous namespace
|
||||
@@ -1,509 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
// IWYU pragma: keep
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/dummy_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/error_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/impulse_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/stopped_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Return a different sender when we invoke this custom defined let_value implementation
|
||||
struct let_value_test_domain
|
||||
{
|
||||
_CCCL_TEMPLATE(class Sender, class Env)
|
||||
_CCCL_REQUIRES(ex::sender_for<Sender, ex::let_value_t>)
|
||||
static auto transform_sender(ex::set_value_t, Sender&&, const Env&)
|
||||
{
|
||||
return ex::just(std::string{"hallo"});
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("let_value returns a sender", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::let_value(ex::just(), [] {
|
||||
return ex::just();
|
||||
});
|
||||
using Sndr = decltype(sndr);
|
||||
static_assert(ex::sender<Sndr>);
|
||||
static_assert(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::inline_completion);
|
||||
(void) sndr;
|
||||
}
|
||||
|
||||
C2H_TEST("let_value with environment returns a sender", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::let_value(ex::just(), [] {
|
||||
return ex::just();
|
||||
});
|
||||
using Sndr = decltype(sndr);
|
||||
static_assert(ex::sender_in<Sndr, ex::env<>>);
|
||||
static_assert(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::inline_completion);
|
||||
(void) sndr;
|
||||
}
|
||||
|
||||
C2H_TEST("let_value simple example", "[adaptors][let_value]")
|
||||
{
|
||||
bool called{false};
|
||||
auto sndr = ex::let_value(ex::just(), [&] {
|
||||
called = true;
|
||||
return ex::just();
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_value_receiver{});
|
||||
ex::start(op);
|
||||
// The receiver checks that it's called
|
||||
// we also check that the function was invoked
|
||||
CHECK(called);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be piped", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([] {
|
||||
return ex::just();
|
||||
});
|
||||
(void) sndr;
|
||||
}
|
||||
|
||||
C2H_TEST("let_value returning void can we waited on", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([] {
|
||||
return ex::just();
|
||||
});
|
||||
ex::sync_wait(std::move(sndr));
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used to produce values", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([] {
|
||||
return ex::just(13);
|
||||
});
|
||||
wait_for_value(std::move(sndr), 13);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used to transform values", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just(13) | ex::let_value([](int& x) {
|
||||
return ex::just(x + 4);
|
||||
});
|
||||
wait_for_value(std::move(sndr), 17);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used with multiple parameters", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just(3, 0.1415) | ex::let_value([](int& x, double y) {
|
||||
return ex::just(x + y);
|
||||
});
|
||||
wait_for_value(std::move(sndr), 3.1415); // NOLINT(modernize-use-std-numbers)
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used to change the sender", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just(13) | ex::let_value([](int& x) {
|
||||
return ex::just_error(x + 4);
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_error_receiver{13 + 4});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
#if _CCCL_HOST_COMPILATION()
|
||||
|
||||
auto is_prime(int x) -> bool
|
||||
{
|
||||
if (x > 2 && (x % 2 == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int d = 3;
|
||||
while (d * d < x)
|
||||
{
|
||||
if (x % d == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
d += 2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used for composition", "[adaptors][let_value]")
|
||||
{
|
||||
bool called1{false};
|
||||
bool called2{false};
|
||||
bool called3{false};
|
||||
auto f1 = [&](int& x) {
|
||||
called1 = true;
|
||||
return ex::just(2 * x);
|
||||
};
|
||||
auto f2 = [&](int& x) {
|
||||
called2 = true;
|
||||
return ex::just(x + 3);
|
||||
};
|
||||
auto f3 = [&](int& x) {
|
||||
called3 = true;
|
||||
if (!is_prime(x))
|
||||
{
|
||||
throw std::logic_error("not prime");
|
||||
}
|
||||
return ex::just(x);
|
||||
};
|
||||
auto sndr = ex::just(13) //
|
||||
| ex::let_value(f1) //
|
||||
| ex::let_value(f2) //
|
||||
| ex::let_value(f3) //
|
||||
;
|
||||
wait_for_value(std::move(sndr), 29);
|
||||
CHECK(called1);
|
||||
CHECK(called2);
|
||||
CHECK(called3);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can throw, and set_error will be called", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just(13) //
|
||||
| ex::let_value([](int&) -> decltype(ex::just(0)) {
|
||||
throw std::logic_error{"err"};
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_error_receiver{std::logic_error{"err"}});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used with just_error", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just_error(std::string{"err"}) //
|
||||
| ex::let_value([]() {
|
||||
return ex::just(17);
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_error_receiver{std::string{"err"}});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be used with just_stopped", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::just_stopped() | ex::let_value([]() {
|
||||
return ex::just(17);
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value function is not called on error", "[adaptors][let_value]")
|
||||
{
|
||||
bool called{false};
|
||||
error_scheduler<int> sched{-1};
|
||||
auto sndr = ex::just(13) //
|
||||
| ex::continues_on(sched) //
|
||||
| ex::let_value([&](int& x) {
|
||||
called = true;
|
||||
return ex::just(x + 5);
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_error_receiver{-1});
|
||||
ex::start(op);
|
||||
CHECK_FALSE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value function is not called when cancelled", "[adaptors][let_value]")
|
||||
{
|
||||
bool called{false};
|
||||
stopped_scheduler sched;
|
||||
auto sndr = ex::just(13) //
|
||||
| ex::continues_on(sched) //
|
||||
| ex::let_value([&](int& x) {
|
||||
called = true;
|
||||
return ex::just(x + 5);
|
||||
});
|
||||
auto op = ex::connect(std::move(sndr), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
CHECK_FALSE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value exposes a parameter that is destructed when the main operation is destructed",
|
||||
"[adaptors][let_value]")
|
||||
{
|
||||
// Type that sets into a received boolean when the dtor is called
|
||||
struct my_type
|
||||
{
|
||||
bool* p_called_{nullptr};
|
||||
|
||||
explicit my_type(bool* p_called)
|
||||
: p_called_(p_called)
|
||||
{}
|
||||
|
||||
my_type(my_type&& rhs)
|
||||
: p_called_(rhs.p_called_)
|
||||
{
|
||||
rhs.p_called_ = nullptr;
|
||||
}
|
||||
|
||||
auto operator=(my_type&& rhs) -> my_type&
|
||||
{
|
||||
if (p_called_)
|
||||
{
|
||||
*p_called_ = true;
|
||||
}
|
||||
p_called_ = rhs.p_called_;
|
||||
rhs.p_called_ = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~my_type()
|
||||
{
|
||||
if (p_called_)
|
||||
{
|
||||
*p_called_ = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool param_destructed{false};
|
||||
bool fun_called{false};
|
||||
impulse_scheduler sched;
|
||||
|
||||
auto sndr = ex::just(my_type(¶m_destructed)) //
|
||||
| ex::let_value([&](const my_type&) {
|
||||
CHECK_FALSE(param_destructed);
|
||||
fun_called = true;
|
||||
return ex::just(13) | ex::continues_on(sched);
|
||||
});
|
||||
|
||||
{
|
||||
int res{0};
|
||||
auto op = ex::connect(std::move(sndr), proxy_value_receiver{res});
|
||||
ex::start(op);
|
||||
// The function is called immediately after starting the operation
|
||||
CHECK(fun_called);
|
||||
// As the returned sender didn't complete yet, the parameter must still be alive
|
||||
CHECK_FALSE(param_destructed);
|
||||
CHECK(res == 0);
|
||||
|
||||
// Now, tell the scheduler to execute the final operation
|
||||
sched.start_next();
|
||||
|
||||
// The parameter is going to be destructed when the op is destructed; it should be valid now
|
||||
CHECK_FALSE(param_destructed);
|
||||
CHECK(res == 13);
|
||||
}
|
||||
|
||||
// At this point everything can be destructed
|
||||
CHECK(param_destructed);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value works when changing threads", "[adaptors][let_value]")
|
||||
{
|
||||
ex::thread_context worker;
|
||||
cuda::std::atomic<bool> called{false};
|
||||
{
|
||||
// lunch some work on the worker thread
|
||||
auto sndr =
|
||||
ex::just(7) //
|
||||
| ex::continues_on(worker.get_scheduler()) //
|
||||
| ex::let_value([](int& x) {
|
||||
return ex::just(x * 2 - 1);
|
||||
}) //
|
||||
| ex::then([&](int x) {
|
||||
CHECK(x == 13);
|
||||
called.store(true);
|
||||
});
|
||||
|
||||
using Sndr = decltype(sndr);
|
||||
|
||||
static_assert(ex::get_completion_behavior<Sndr>() == ex::completion_behavior::asynchronous);
|
||||
ex::start_detached(std::move(sndr));
|
||||
}
|
||||
worker.join();
|
||||
// the work should be executed
|
||||
REQUIRE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("let_value has the values_type corresponding to the given values", "[adaptors][let_value]")
|
||||
{
|
||||
check_value_types<types<int>>(ex::just() | ex::let_value([] {
|
||||
return ex::just(7);
|
||||
}));
|
||||
check_value_types<types<double>>(ex::just() | ex::let_value([] {
|
||||
return ex::just(3.14);
|
||||
}));
|
||||
check_value_types<types<movable>>(ex::just() | ex::let_value([] {
|
||||
return ex::just(movable{0});
|
||||
}));
|
||||
}
|
||||
|
||||
C2H_TEST("let_value keeps error_types from input sender", "[adaptors][let_value]")
|
||||
{
|
||||
dummy_scheduler sched1{};
|
||||
error_scheduler sched2{ex::exception_ptr{}};
|
||||
error_scheduler<int> sched3{43};
|
||||
|
||||
check_error_types<ex::exception_ptr>( //
|
||||
ex::just() | ex::continues_on(sched1) | ex::let_value([] {
|
||||
return ex::just();
|
||||
}));
|
||||
check_error_types<ex::exception_ptr>( //
|
||||
ex::just() | ex::continues_on(sched2) | ex::let_value([] {
|
||||
return ex::just();
|
||||
}));
|
||||
check_error_types<int, ex::exception_ptr>( //
|
||||
ex::just() | ex::continues_on(sched3) | ex::let_value([] {
|
||||
return ex::just();
|
||||
}));
|
||||
|
||||
// NOT YET SUPPORTED
|
||||
// check_error_types<>( //
|
||||
// ex::just() | ex::continues_on(sched1) | ex::let_value([]_CCCL_HOST_DEVICE() noexcept {
|
||||
// return ex::just();
|
||||
// }));
|
||||
// check_error_types<ex::exception_ptr>( //
|
||||
// ex::just() | ex::continues_on(sched2) | ex::let_value([]_CCCL_HOST_DEVICE() noexcept {
|
||||
// return ex::just();
|
||||
// }));
|
||||
// check_error_types<int>( //
|
||||
// ex::just() | ex::continues_on(sched3) | ex::let_value([]_CCCL_HOST_DEVICE() noexcept {
|
||||
// return ex::just();
|
||||
// }));
|
||||
}
|
||||
|
||||
C2H_TEST("let_value keeps sends_stopped from input sender", "[adaptors][let_value]")
|
||||
{
|
||||
dummy_scheduler sched1{};
|
||||
stopped_scheduler sched2{};
|
||||
|
||||
check_sends_stopped<false>( //
|
||||
ex::just() | ex::continues_on(sched1) | ex::let_value([] {
|
||||
return ex::just();
|
||||
}));
|
||||
check_sends_stopped<true>( //
|
||||
ex::just() | ex::continues_on(sched2) | ex::let_value([] {
|
||||
return ex::just();
|
||||
}));
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can be customized", "[adaptors][let_value]")
|
||||
{
|
||||
auto env = ex::prop{ex::get_domain, let_value_test_domain{}};
|
||||
// The customization will return a different value
|
||||
auto sndr = ex::just(std::string{"hello"}) //
|
||||
| ex::let_value([](std::string& x) {
|
||||
return ex::just(x + ", world");
|
||||
});
|
||||
wait_for_value_with_env(std::move(sndr), env, std::string{"hallo"});
|
||||
}
|
||||
|
||||
C2H_TEST("let_value can nest", "[adaptors][let_value]")
|
||||
{
|
||||
auto work = ex::just(2) //
|
||||
| ex::let_value([](int x) { //
|
||||
return ex::just() //
|
||||
| ex::let_value([=] { //
|
||||
return ex::just(x);
|
||||
});
|
||||
});
|
||||
wait_for_value(std::move(work), 2);
|
||||
}
|
||||
|
||||
constexpr struct test_query_t : ex::forwarding_query_t
|
||||
{
|
||||
template <class Env>
|
||||
_CCCL_HOST_DEVICE_API constexpr auto operator()(const Env& env) const noexcept -> decltype(env.query(*this))
|
||||
{
|
||||
return env.query(*this);
|
||||
}
|
||||
} test_query{};
|
||||
|
||||
C2H_TEST("let_value works when the function returns a dependent sender", "[adaptors][let_value]")
|
||||
{
|
||||
auto sndr = ex::write_env(ex::just() | ex::let_value([] {
|
||||
return ex::read_env(test_query);
|
||||
}),
|
||||
ex::prop{test_query, 42});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
// NOT YET SUPPORTED
|
||||
// struct bad_receiver
|
||||
// {
|
||||
// using receiver_concept = ex::receiver_t;
|
||||
|
||||
// bad_receiver(bool& completed) noexcept
|
||||
// : completed_{completed}
|
||||
// {}
|
||||
|
||||
// bad_receiver(bad_receiver&& other) noexcept(false) // BAD!
|
||||
// : completed_(other.completed_)
|
||||
// {}
|
||||
|
||||
// void set_value() noexcept
|
||||
// {
|
||||
// completed_ = true;
|
||||
// }
|
||||
|
||||
// bool& completed_;
|
||||
// };
|
||||
|
||||
// C2H_TEST("let_value does not add ex::exception_ptr even if the receiver is bad", "[adaptors][let_value]")
|
||||
// {
|
||||
// auto sndr = ex::let_value(ex::just(), []_CCCL_HOST_DEVICE() noexcept {
|
||||
// return ex::just();
|
||||
// });
|
||||
// check_error_types<>(sndr);
|
||||
// bool completed{false};
|
||||
// auto op = ex::connect(std::move(sndr), bad_receiver{completed}); // should compile
|
||||
// ex::start(op);
|
||||
// CHECK(completed);
|
||||
// }
|
||||
|
||||
#endif // _CCCL_HOST_COMPILATION()
|
||||
|
||||
#if !_CCCL_CUDA_COMPILER(NVCC) && !defined(_CCCL_CLANG_TIDY_INVOKED)
|
||||
// This example causes nvcc to segfault, and clang-tidy to error out with
|
||||
//
|
||||
// cudax/test/execution/test_let_value.cu:487:17: error: static assertion failed due to requirement
|
||||
// '::cuda::std::is_same_v<cuda::experimental::execution::default_domain, (anonymous
|
||||
// namespace)::let_value_test_domain2>' [clang-diagnostic-error]
|
||||
//
|
||||
// 487 | static_assert(::cuda::std::is_same_v<decltype(result), let_value_test_domain2>);
|
||||
// | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
struct let_value_test_domain2
|
||||
{};
|
||||
|
||||
C2H_TEST("let_value predecessor's domain is accessible via the receiver connected to the secondary sender",
|
||||
"[adaptors][let_value]")
|
||||
{
|
||||
auto attrs = ex::prop{ex::get_completion_domain<ex::set_value_t>, let_value_test_domain2{}};
|
||||
using Sndr2 = decltype(ex::read_env(ex::get_domain));
|
||||
|
||||
auto sndr = ex::just() //
|
||||
| ex::write_attrs(attrs) //
|
||||
| ex::let_value([]() noexcept -> Sndr2 {
|
||||
return ex::read_env(ex::get_domain);
|
||||
});
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
static_assert(::cuda::std::is_same_v<decltype(result), let_value_test_domain2>);
|
||||
(void) result;
|
||||
}
|
||||
#endif // !_CCCL_CUDA_COMPILER(NVCC)
|
||||
|
||||
C2H_TEST("let_value has the correct completion domain", "[adaptors][let_value]")
|
||||
{
|
||||
auto attrs = ex::prop{ex::get_completion_domain<ex::set_value_t>, let_value_test_domain{}};
|
||||
auto sndr = ex::just() | ex::let_value([=] {
|
||||
return ex::write_attrs(ex::just(), attrs);
|
||||
});
|
||||
auto dom = ex::get_completion_domain<ex::set_value_t>(ex::get_env(sndr));
|
||||
static_assert(::cuda::std::is_same_v<decltype(dom), let_value_test_domain>);
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,125 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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
|
||||
@@ -1,48 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Include this first
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
// Then include the test helpers
|
||||
#include <nv/target>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh"
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("simple use of sequence executes both child operations", "[adaptors][sequence]")
|
||||
{
|
||||
bool flag1{false};
|
||||
bool flag2{false};
|
||||
|
||||
auto sndr1 = ex::sequence(
|
||||
ex::just() | ex::then([&] {
|
||||
flag1 = true;
|
||||
}),
|
||||
ex::just() | ex::then([&] {
|
||||
flag2 = true;
|
||||
}));
|
||||
|
||||
check_value_types<types<>>(sndr1);
|
||||
check_sends_stopped<false>(sndr1);
|
||||
check_error_types<ex::exception_ptr>(sndr1);
|
||||
|
||||
auto op = ex::connect(std::move(sndr1), checked_value_receiver<>{});
|
||||
ex::start(op);
|
||||
|
||||
CHECK(flag1);
|
||||
CHECK(flag2);
|
||||
}
|
||||
} // namespace
|
||||
@@ -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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "../common/testing.cuh" // IWYU pragma: keep
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/dummy_scheduler.cuh"
|
||||
#include "common/error_scheduler.cuh"
|
||||
#include "common/stopped_scheduler.cuh"
|
||||
#include "common/utility.cuh"
|
||||
|
||||
#if _CCCL_HOST_COMPILATION()
|
||||
# include "common/impulse_scheduler.cuh"
|
||||
#endif
|
||||
|
||||
#if _CCCL_COMPILER(GCC, <, 12)
|
||||
// suppress buggy warning on older gcc versions
|
||||
_CCCL_DIAG_SUPPRESS_GCC("-Wmissing-field-initializers")
|
||||
#endif
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("starts_on simple example", "[adaptors][starts_on]")
|
||||
{
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the right value
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on can be piped", "[adaptors][starts_on]")
|
||||
{
|
||||
// Use starts_on with the inline scheduler and pipe with then
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just(42)) //
|
||||
| ex::then([](int val) {
|
||||
return val * 2;
|
||||
});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{84});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the transformed value
|
||||
}
|
||||
|
||||
#if _CCCL_HOST_COMPILATION()
|
||||
|
||||
C2H_TEST("starts_on with impulse scheduler", "[adaptors][starts_on]")
|
||||
{
|
||||
bool sender_executed = false;
|
||||
|
||||
impulse_scheduler sched;
|
||||
auto snd = ex::starts_on(sched, ex::just() | ex::then([&]() {
|
||||
sender_executed = true;
|
||||
return 13;
|
||||
}));
|
||||
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{13});
|
||||
ex::start(op);
|
||||
|
||||
// At this point, the scheduler should have been started but the sender not yet executed
|
||||
REQUIRE(!sender_executed);
|
||||
|
||||
// Tell the scheduler to start executing one task
|
||||
sched.start_next();
|
||||
|
||||
// Now the sender should be executed
|
||||
REQUIRE(sender_executed);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on execution order", "[adaptors][starts_on]")
|
||||
{
|
||||
int counter = 0;
|
||||
impulse_scheduler sched;
|
||||
|
||||
auto snd = ex::starts_on(sched, ex::just() | ex::then([&]() {
|
||||
return ++counter;
|
||||
}));
|
||||
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{1});
|
||||
ex::start(op);
|
||||
|
||||
// Counter should still be 0 since scheduler hasn't executed yet
|
||||
CHECK(counter == 0);
|
||||
|
||||
// Tell the scheduler to start executing
|
||||
sched.start_next();
|
||||
|
||||
// Now the sender should have executed and incremented counter
|
||||
CHECK(counter == 1);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on with thread context", "[adaptors][starts_on]")
|
||||
{
|
||||
ex::thread_context thread;
|
||||
bool executed = false;
|
||||
|
||||
auto snd = ex::starts_on(thread.get_scheduler(), ex::just() | ex::then([&]() {
|
||||
executed = true;
|
||||
return 123;
|
||||
}));
|
||||
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{123});
|
||||
ex::start(op);
|
||||
|
||||
thread.join();
|
||||
|
||||
// The work should have been executed on the thread
|
||||
REQUIRE(executed);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
C2H_TEST("starts_on can be called with rvalue ref scheduler", "[adaptors][starts_on]")
|
||||
{
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on can be called with const ref scheduler", "[adaptors][starts_on]")
|
||||
{
|
||||
const dummy_scheduler<> sched;
|
||||
auto snd = ex::starts_on(sched, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on can be called with ref scheduler", "[adaptors][starts_on]")
|
||||
{
|
||||
dummy_scheduler<> sched;
|
||||
auto snd = ex::starts_on(sched, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on forwards scheduler errors", "[adaptors][starts_on]")
|
||||
{
|
||||
auto ec = error_code{std::errc::invalid_argument};
|
||||
error_scheduler<error_code> sched{ec};
|
||||
auto snd = ex::starts_on(sched, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{ec});
|
||||
ex::start(op);
|
||||
// The receiver checks if we receive the error from the scheduler
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on forwards scheduler errors of other types", "[adaptors][starts_on]")
|
||||
{
|
||||
error_scheduler<string> sched{string{"scheduler error"}};
|
||||
auto snd = ex::starts_on(sched, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{string{"scheduler error"}});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on forwards scheduler stopped signal", "[adaptors][starts_on]")
|
||||
{
|
||||
stopped_scheduler sched{};
|
||||
auto snd = ex::starts_on(sched, ex::just(42));
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on forwards sender errors", "[adaptors][starts_on]")
|
||||
{
|
||||
auto ec = error_code{std::errc::operation_not_permitted};
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just_error(ec));
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{ec});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on forwards sender stopped signal", "[adaptors][starts_on]")
|
||||
{
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just_stopped());
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on preserves multiple values", "[adaptors][starts_on]")
|
||||
{
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::just(1, 2.5, string{"hello"}));
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{1, 2.5, string{"hello"}});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on has the values_type corresponding to the child sender", "[adaptors][starts_on]")
|
||||
{
|
||||
dummy_scheduler<> sched{};
|
||||
|
||||
check_value_types<types<int>>(ex::starts_on(sched, ex::just(1)));
|
||||
check_value_types<types<int, double>>(ex::starts_on(sched, ex::just(3, 0.14)));
|
||||
check_value_types<types<int, double, string>>(ex::starts_on(sched, ex::just(3, 0.14, string{"pi"})));
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on includes error_types from both scheduler and sender", "[adaptors][starts_on]")
|
||||
{
|
||||
dummy_scheduler<> sched1{};
|
||||
error_scheduler<std::error_code> sched2{std::make_error_code(std::errc::invalid_argument)};
|
||||
error_scheduler<int> sched3{43};
|
||||
|
||||
// Inline scheduler has no errors, sender has no errors
|
||||
check_error_types<>(ex::starts_on(sched1, ex::just(1)));
|
||||
|
||||
// Error scheduler has std::error_code, sender has no errors
|
||||
check_error_types<std::error_code>(ex::starts_on(sched2, ex::just(2)));
|
||||
|
||||
// Error scheduler has int, sender has no errors
|
||||
check_error_types<int>(ex::starts_on(sched3, ex::just(3)));
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on sends_stopped includes both scheduler and sender", "[adaptors][starts_on]")
|
||||
{
|
||||
dummy_scheduler<> sched1{};
|
||||
error_scheduler<error_code> sched2{error_code{std::errc::invalid_argument}};
|
||||
stopped_scheduler sched3{};
|
||||
|
||||
// Neither scheduler nor sender sends stopped
|
||||
check_sends_stopped<false>(ex::starts_on(sched1, ex::just(1)));
|
||||
|
||||
// Scheduler does not send stopped but the sender does
|
||||
check_sends_stopped<true>(ex::starts_on(sched2, ex::just_stopped()));
|
||||
|
||||
// Scheduler sends stopped, sender doesn't
|
||||
check_sends_stopped<true>(ex::starts_on(sched3, ex::just(3)));
|
||||
}
|
||||
|
||||
C2H_TEST("starts_on works with const sender", "[adaptors][starts_on]")
|
||||
{
|
||||
const auto base_sender = ex::just(42);
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, base_sender);
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
struct test_domain
|
||||
{};
|
||||
|
||||
C2H_TEST("starts_on has the right completion scheduler", "[adaptors][starts_on]")
|
||||
{
|
||||
SECTION("thread scheduler with a sender that completes inline")
|
||||
{
|
||||
ex::thread_context thread;
|
||||
auto sch = thread.get_scheduler();
|
||||
auto snd = ex::starts_on(sch, ex::just());
|
||||
CHECK(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd), ex::env{}) == sch);
|
||||
}
|
||||
|
||||
SECTION("thread scheduler with a sender that completes on another thread")
|
||||
{
|
||||
ex::thread_context thread1, thread2;
|
||||
auto sch1 = thread1.get_scheduler(), sch2 = thread2.get_scheduler();
|
||||
auto snd = ex::starts_on(sch1, ex::starts_on(sch2, ex::just()));
|
||||
CHECK(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd), ex::env{}) == sch2);
|
||||
}
|
||||
|
||||
SECTION("inline scheduler with inline sender completion with a given starting scheduler")
|
||||
{
|
||||
ex::thread_context thread;
|
||||
auto sch = thread.get_scheduler();
|
||||
auto env = ex::prop{ex::get_scheduler, sch};
|
||||
auto snd = ex::starts_on(ex::inline_scheduler{}, ex::just());
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_scheduler_t<ex::set_value_t>, ex::env_of_t<decltype(snd)>>);
|
||||
CHECK(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd), env) == sch);
|
||||
}
|
||||
|
||||
SECTION("inline scheduler with inline sender completion with an inline starting scheduler")
|
||||
{
|
||||
constexpr auto sch = ex::inline_scheduler{};
|
||||
[[maybe_unused]] constexpr auto env = ex::prop{ex::get_scheduler, sch};
|
||||
[[maybe_unused]] constexpr auto snd = ex::starts_on(sch, ex::just());
|
||||
using snd_t = decltype(snd);
|
||||
STATIC_REQUIRE(!cudax::__callable<ex::get_completion_scheduler_t<ex::set_value_t>, ex::env_of_t<snd_t>>);
|
||||
STATIC_REQUIRE(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd), env) == sch);
|
||||
}
|
||||
|
||||
SECTION("inline scheduler but sender knows where it completes")
|
||||
{
|
||||
ex::thread_context thread;
|
||||
auto sch = thread.get_scheduler();
|
||||
auto snd = ex::starts_on(dummy_scheduler{}, ex::schedule(sch));
|
||||
CHECK(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd)) == sch);
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
@@ -1,256 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Include this first
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
// Then include the test helpers
|
||||
#include <thrust/equal.h>
|
||||
|
||||
#include <cuda/std/cstddef>
|
||||
|
||||
#include <cuda/experimental/container.cuh>
|
||||
#include <cuda/experimental/memory_resource.cuh>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
_CCCL_BEGIN_NV_DIAG_SUPPRESS(177) // function "_is_on_device" was declared but never referenced
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
__host__ __device__ bool _is_on_device() noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST, //
|
||||
({ return false; }),
|
||||
({ return true; }));
|
||||
}
|
||||
|
||||
struct _say_hello
|
||||
{
|
||||
__device__ int operator()() const
|
||||
{
|
||||
CHECK(_is_on_device());
|
||||
printf("Hello from lambda on device!\n");
|
||||
return value;
|
||||
}
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
// This is an "un-visitable" sender that does not have a tag type.
|
||||
template <class Sndr>
|
||||
struct _CCCL_TYPE_VISIBILITY_DEFAULT unknown_sender : Sndr
|
||||
{
|
||||
_CCCL_HOST_DEVICE_API explicit unknown_sender(Sndr sndr) noexcept
|
||||
: Sndr(cuda::std::move(sndr))
|
||||
{}
|
||||
};
|
||||
|
||||
void stream_context_test1()
|
||||
{
|
||||
ex::stream_context ctx{cuda::device_ref{0}};
|
||||
auto sched = ctx.get_scheduler();
|
||||
static_assert(ex::__is_scheduler<decltype(sched)>);
|
||||
|
||||
auto sndr = ex::schedule(sched) //
|
||||
| ex::then([] __host__ __device__() noexcept -> bool {
|
||||
return _is_on_device();
|
||||
});
|
||||
|
||||
auto [on_device] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(on_device);
|
||||
}
|
||||
|
||||
void stream_context_test2()
|
||||
{
|
||||
ex::thread_context tctx;
|
||||
ex::stream_context sctx{cuda::device_ref{0}};
|
||||
auto sch = sctx.get_scheduler();
|
||||
|
||||
auto start = //
|
||||
ex::schedule(sch) // begin work on the GPU
|
||||
| ex::then(_say_hello{42}) // enqueue a function object on the GPU
|
||||
| ex::then([] __device__(int i) noexcept -> int { // enqueue a lambda on the GPU
|
||||
CHECK(_is_on_device());
|
||||
printf("Hello again from lambda on device! i = %d\n", i);
|
||||
return i + 1;
|
||||
})
|
||||
| ex::continues_on(tctx.get_scheduler()) // continue work on the CPU
|
||||
| ex::then([] __host__ __device__(int i) -> int { // run a lambda on the CPU
|
||||
CHECK(!_is_on_device());
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(printf("Hello from lambda on host! i = %d\n", i);),
|
||||
(printf("OOPS! still on the device! i = %d\n", i);))
|
||||
return i;
|
||||
});
|
||||
|
||||
// run the ex, wait for it to finish, and get the result
|
||||
auto [i] = ex::sync_wait(std::move(start)).value();
|
||||
CHECK(i == 43);
|
||||
printf("All done on the host! result = %d\n", i);
|
||||
}
|
||||
|
||||
void stream_ref_as_scheduler()
|
||||
{
|
||||
ex::thread_context tctx;
|
||||
cudax::stream sctx{cuda::device_ref{0}};
|
||||
auto sch = sctx.get_scheduler();
|
||||
static_assert(ex::__is_scheduler<decltype(sch)>);
|
||||
|
||||
auto start = //
|
||||
ex::schedule(sch) // begin work on the GPU
|
||||
| ex::then(_say_hello{42}) // enqueue a function object on the GPU
|
||||
| ex::then([] __device__(int i) noexcept -> int { // enqueue a lambda on the GPU
|
||||
CHECK(_is_on_device());
|
||||
printf("Hello again from lambda on device! i = %d\n", i);
|
||||
return i + 1;
|
||||
})
|
||||
| ex::continues_on(tctx.get_scheduler()) // continue work on the CPU
|
||||
| ex::then([] __host__ __device__(int i) noexcept -> int { // run a lambda on the CPU
|
||||
CHECK(!_is_on_device());
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(printf("Hello from lambda on host! i = %d\n", i);),
|
||||
(printf("OOPS! still on the device! i = %d\n", i);))
|
||||
return i;
|
||||
});
|
||||
|
||||
// run the ex, wait for it to finish, and get the result
|
||||
auto [i] = ex::sync_wait(std::move(start)).value();
|
||||
CHECK(i == 43);
|
||||
printf("All done on the host! result = %d\n", i);
|
||||
}
|
||||
|
||||
void bulk_on_stream_scheduler()
|
||||
{
|
||||
cuda::device_ref _dev{0};
|
||||
cudax::stream sctx{_dev};
|
||||
auto sch = sctx.get_scheduler();
|
||||
|
||||
using _env_t = cudax::env_t<cuda::mr::device_accessible>;
|
||||
auto mr = cuda::device_default_memory_pool(_dev);
|
||||
auto mr2 = cuda::mr::any_resource<cuda::mr::device_accessible>(mr);
|
||||
_env_t env{mr, cuda::get_stream(sch), ex::par_unseq};
|
||||
auto buf = cuda::make_buffer<int>(sctx, mr2, 10, 40, env); // a device buffer of 10 integers, initialized to 40
|
||||
cuda::std::span data{buf};
|
||||
|
||||
auto start = //
|
||||
ex::schedule(sch) // begin work on the GPU
|
||||
| ex::then([data] __host__ __device__() -> cuda::std::span<int> {
|
||||
printf("Hello from lambda on device!\n");
|
||||
return data;
|
||||
})
|
||||
// enqueue a bulk kernel on the GPU
|
||||
| ex::bulk(ex::par_unseq, 10, [] __host__ __device__(int i, cuda::std::span<int> data) -> void {
|
||||
printf("Hello from bulk kernel on device! i = %d\n", i);
|
||||
CHECK(_is_on_device());
|
||||
CHECK(static_cast<::cuda::std::size_t>(i) < data.size());
|
||||
data[i] += 2;
|
||||
});
|
||||
|
||||
auto expected = cuda::make_buffer<int>(sctx, mr2, 10, 42, env); // a device buffer of 10 integers, initialized
|
||||
// to 42
|
||||
|
||||
// start the sender and wait for it to finish
|
||||
auto [span] = ex::sync_wait(std::move(start)).value();
|
||||
|
||||
CHECK(thrust::equal(thrust::device, span.begin(), span.end(), expected.begin()));
|
||||
}
|
||||
|
||||
void stream_adapt_non_visitable_sender()
|
||||
{
|
||||
ex::stream_context ctx{cuda::device_ref{0}};
|
||||
auto with_sched = ex::prop{ex::get_scheduler, ctx.get_scheduler()};
|
||||
|
||||
auto sndr = unknown_sender{ex::just(42)};
|
||||
auto [i] = ex::sync_wait(sndr, with_sched).value();
|
||||
CHECK(i == 42);
|
||||
}
|
||||
|
||||
void starts_on_with_stream_scheduler1()
|
||||
{
|
||||
cuda::device_ref _dev{0};
|
||||
cudax::stream sctx{_dev};
|
||||
ex::thread_context tctx;
|
||||
auto sch = sctx.get_scheduler();
|
||||
|
||||
auto start = ex::starts_on(sch, ex::just() | ex::then([] __device__() noexcept -> int {
|
||||
return 42;
|
||||
}));
|
||||
|
||||
auto [i] = ex::sync_wait(std::move(start)).value();
|
||||
CHECK(i == 42);
|
||||
}
|
||||
|
||||
void starts_on_with_stream_scheduler2()
|
||||
{
|
||||
cuda::device_ref _dev{0};
|
||||
cudax::stream sctx{_dev};
|
||||
ex::thread_context tctx;
|
||||
auto sch = sctx.get_scheduler();
|
||||
|
||||
auto start =
|
||||
ex::starts_on(sch, ex::just() | ex::then([] __device__() noexcept -> int {
|
||||
return 42;
|
||||
}))
|
||||
| ex::continues_on(tctx.get_scheduler()) // continue work on the CPU
|
||||
| ex::then([] __host__ __device__(int i) noexcept -> int {
|
||||
return i + 1;
|
||||
});
|
||||
|
||||
auto [i] = ex::sync_wait(std::move(start)).value();
|
||||
CHECK(i == 43);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// Test code is placed in separate functions to avoid an nvc++ issue with
|
||||
// extended lambdas in functions with internal linkage (as is the case
|
||||
// with C2H tests).
|
||||
|
||||
C2H_TEST("a simple use of the stream context", "[context][stream]")
|
||||
{
|
||||
REQUIRE_NOTHROW(stream_context_test1());
|
||||
}
|
||||
|
||||
C2H_TEST("another simple use of the stream context", "[context][stream]")
|
||||
{
|
||||
REQUIRE_NOTHROW(stream_context_test2());
|
||||
}
|
||||
|
||||
C2H_TEST("use stream_ref as a scheduler", "[context][stream]")
|
||||
{
|
||||
REQUIRE_NOTHROW(stream_ref_as_scheduler());
|
||||
}
|
||||
|
||||
C2H_TEST("launch a bulk kernel", "[context][stream]")
|
||||
{
|
||||
REQUIRE_NOTHROW(bulk_on_stream_scheduler());
|
||||
}
|
||||
|
||||
C2H_TEST("run an unknown sender on a stream", "[context][stream]")
|
||||
{
|
||||
REQUIRE_NOTHROW(stream_adapt_non_visitable_sender());
|
||||
}
|
||||
|
||||
C2H_TEST("use starts_on with a stream scheduler", "[context][stream]")
|
||||
{
|
||||
SECTION("starts_on that completes on the stream scheduler")
|
||||
{
|
||||
REQUIRE_NOTHROW(starts_on_with_stream_scheduler1());
|
||||
}
|
||||
|
||||
SECTION("starts_on that completes on the thread scheduler")
|
||||
{
|
||||
REQUIRE_NOTHROW(starts_on_with_stream_scheduler2());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,94 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/checked_receiver.cuh" // IWYU pragma: keep
|
||||
#include "common/dummy_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/error_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/stopped_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/utility.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("simple task_scheduler test", "[scheduler][task_scheduler]")
|
||||
{
|
||||
ex::task_scheduler sched{dummy_scheduler{}};
|
||||
STATIC_CHECK(ex::scheduler<decltype(sched)>);
|
||||
auto sndr = sched.schedule();
|
||||
STATIC_CHECK(ex::sender<decltype(sndr)>);
|
||||
auto op = ex::connect(cuda::std::move(sndr), checked_value_receiver{});
|
||||
ex::start(op);
|
||||
// The receiver checks that it's called
|
||||
}
|
||||
|
||||
C2H_TEST("task_scheduler starts work on the correct execution context", "[scheduler][task_scheduler]")
|
||||
{
|
||||
ex::thread_context ctx;
|
||||
ex::task_scheduler sched{ctx.get_scheduler()};
|
||||
auto sndr = ex::starts_on(sched, ex::just() | ex::then([] {
|
||||
return ::std::this_thread::get_id();
|
||||
}));
|
||||
auto [tid] = ex::sync_wait(cuda::std::move(sndr)).value();
|
||||
CHECK(tid == ctx.get_id());
|
||||
}
|
||||
|
||||
#if !_CCCL_HOST_COMPILATION()
|
||||
static __device__ bool g_called = false;
|
||||
#else
|
||||
static bool g_called = false;
|
||||
#endif
|
||||
|
||||
template <class Sndr>
|
||||
struct protect : private Sndr
|
||||
{
|
||||
using sender_concept = ex::sender_t;
|
||||
_CCCL_HOST_DEVICE_API explicit protect(Sndr sndr)
|
||||
: Sndr{cuda::std::move(sndr)}
|
||||
{}
|
||||
using Sndr::connect;
|
||||
using Sndr::get_completion_signatures;
|
||||
using Sndr::get_env;
|
||||
};
|
||||
|
||||
struct test_domain
|
||||
{
|
||||
_CCCL_TEMPLATE(class Sndr, class Env)
|
||||
_CCCL_REQUIRES(ex::sender_for<Sndr, ex::bulk_chunked_t>)
|
||||
_CCCL_HOST_DEVICE_API auto transform_sender(ex::set_value_t, Sndr sndr, const Env&) const
|
||||
{
|
||||
return ex::then(protect{cuda::std::move(sndr)}, []() noexcept {
|
||||
g_called = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("bulk_unchunked dispatches correctly through task_scheduler", "[scheduler][task_scheduler]")
|
||||
{
|
||||
ex::task_scheduler sched{dummy_scheduler<test_domain>{}};
|
||||
auto sndr = ex::on(sched, ex::just(-1) | ex::bulk_chunked(ex::par_unseq, 100, [](int, int, int&) {}));
|
||||
g_called = false;
|
||||
auto [val] = ex::sync_wait(cuda::std::move(sndr)).value();
|
||||
CHECK(val == -1);
|
||||
CHECK(g_called);
|
||||
}
|
||||
|
||||
C2H_TEST("bulk dispatches correctly through task_scheduler", "[scheduler][task_scheduler]")
|
||||
{
|
||||
ex::task_scheduler sched{dummy_scheduler<test_domain>{}};
|
||||
auto sndr = ex::on(sched, ex::just(-1) | ex::bulk(ex::par_unseq, 100, [](int, int&) {}));
|
||||
g_called = false;
|
||||
auto [val] = ex::sync_wait(cuda::std::move(sndr)).value();
|
||||
CHECK(val == -1);
|
||||
CHECK(g_called);
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,288 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/dummy_scheduler.cuh"
|
||||
#include "common/error_scheduler.cuh"
|
||||
#include "common/stopped_scheduler.cuh"
|
||||
#include "common/utility.cuh"
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr struct get_frob_t : cuda::std::execution::__basic_query<get_frob_t>
|
||||
{
|
||||
_CCCL_HOST_DEVICE static constexpr bool query(ex::forwarding_query_t) noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} get_frob;
|
||||
|
||||
C2H_TEST("then returns a sender", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::then(ex::just(), [] {});
|
||||
static_assert(ex::sender<decltype(snd)>);
|
||||
(void) snd;
|
||||
}
|
||||
|
||||
C2H_TEST("then with environment returns a sender", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::then(ex::just(), [] {});
|
||||
static_assert(ex::sender_in<decltype(snd), ex::env<>>);
|
||||
(void) snd;
|
||||
}
|
||||
|
||||
C2H_TEST("then simple example", "[adaptors][then]")
|
||||
{
|
||||
bool called{false};
|
||||
auto snd = ex::then(ex::just(), [&] {
|
||||
called = true;
|
||||
});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{});
|
||||
ex::start(op);
|
||||
// The receiver checks that it's called
|
||||
// we also check that the function was invoked
|
||||
CHECK(called);
|
||||
}
|
||||
|
||||
C2H_TEST("then can be piped", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just() | ex::then([] {});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
(void) snd;
|
||||
}
|
||||
|
||||
C2H_TEST("then returning void can be waited on", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just() | ex::then([] {});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
ex::sync_wait(std::move(snd));
|
||||
}
|
||||
|
||||
C2H_TEST("then can be used to transform the value", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just(13) | ex::then([](int x) -> int {
|
||||
return 2 * x + 1;
|
||||
});
|
||||
wait_for_value(std::move(snd), 27);
|
||||
}
|
||||
|
||||
C2H_TEST("then can be used to change the value type", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just(3) | ex::then([](int x) -> double {
|
||||
return x + 0.1415;
|
||||
});
|
||||
wait_for_value(std::move(snd), 3.1415); // NOLINT(modernize-use-std-numbers)
|
||||
}
|
||||
|
||||
C2H_TEST("then can be used with multiple parameters", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just(3, 0.1415) | ex::then([](int x, double y) -> double {
|
||||
return x + y;
|
||||
});
|
||||
wait_for_value(std::move(snd), 3.1415); // NOLINT(modernize-use-std-numbers)
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_EXCEPTIONS() && _CCCL_HOST_COMPILATION()
|
||||
C2H_TEST("then can throw, and set_error will be called", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just(13) | ex::then([](int) -> int {
|
||||
throw std::logic_error{"err"};
|
||||
});
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{std::logic_error{"err"}});
|
||||
ex::start(op);
|
||||
}
|
||||
#endif // _CCCL_HAS_EXCEPTIONS() && _CCCL_HOST_COMPILATION()
|
||||
|
||||
C2H_TEST("then can be used with just_error", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just_error(string{"err"}) | ex::then([]() -> int {
|
||||
return 17;
|
||||
});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{string{"err"}});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("then can be used with just_stopped", "[adaptors][then]")
|
||||
{
|
||||
auto snd = ex::just_stopped() | ex::then([]() -> int {
|
||||
return 17;
|
||||
});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("then function is not called on error", "[adaptors][then]")
|
||||
{
|
||||
bool called{false};
|
||||
error_scheduler sched{-1};
|
||||
auto snd = ex::just(13) | ex::continues_on(sched) | ex::then([&](int x) -> int {
|
||||
called = true;
|
||||
return x + 5;
|
||||
});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{-1});
|
||||
ex::start(op);
|
||||
CHECK_FALSE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("then function is not called when cancelled", "[adaptors][then]")
|
||||
{
|
||||
bool called{false};
|
||||
stopped_scheduler sched;
|
||||
auto snd = ex::just(13) | ex::continues_on(sched) | ex::then([&](int x) -> int {
|
||||
called = true;
|
||||
return x + 5;
|
||||
});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
CHECK_FALSE(called);
|
||||
}
|
||||
|
||||
C2H_TEST("then advertises completion schedulers", "[adaptors][then]")
|
||||
{
|
||||
dummy_scheduler sched{};
|
||||
|
||||
SECTION("for value channel")
|
||||
{
|
||||
auto snd = ex::schedule(sched) | ex::then([] {});
|
||||
STATIC_REQUIRE(ex::sender<decltype(snd)>);
|
||||
REQUIRE(ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd)) == sched);
|
||||
}
|
||||
}
|
||||
|
||||
C2H_TEST("then forwards env", "[adaptors][then]")
|
||||
{
|
||||
SECTION("returns env by value")
|
||||
{
|
||||
auto snd = ex::just(0) | ex::write_attrs(ex::prop{get_frob, 100}) | ex::then([](int) {});
|
||||
CHECK(get_frob(ex::get_env(snd)) == 100);
|
||||
}
|
||||
|
||||
SECTION("returns env by reference")
|
||||
{
|
||||
auto snd = ex::just(0) | ex::write_attrs(ex::prop{get_frob, 100}) | ex::then([](int) {});
|
||||
CHECK(get_frob(ex::get_env(snd)) == 100);
|
||||
}
|
||||
}
|
||||
|
||||
C2H_TEST("then has the values_type corresponding to the given values", "[adaptors][then]")
|
||||
{
|
||||
check_value_types<types<int>>(ex::just() | ex::then([] {
|
||||
return 7;
|
||||
}));
|
||||
check_value_types<types<double>>(ex::just() | ex::then([] {
|
||||
return 3.14;
|
||||
}));
|
||||
check_value_types<types<string>>(ex::just() | ex::then([] {
|
||||
return string{"hello"};
|
||||
}));
|
||||
}
|
||||
|
||||
C2H_TEST("then keeps error_types from input sender", "[adaptors][then]")
|
||||
{
|
||||
dummy_scheduler sched1{};
|
||||
error_scheduler sched2{error_code{std::errc::invalid_argument}};
|
||||
error_scheduler sched3{43};
|
||||
|
||||
check_error_types(ex::just() | ex::continues_on(sched1) | ex::then([]() noexcept {}));
|
||||
check_error_types<error_code>(ex::just() | ex::continues_on(sched2) | ex::then([]() noexcept {}));
|
||||
check_error_types<ex::exception_ptr, int>(ex::just() | ex::continues_on(sched3) | ex::then([] {}));
|
||||
}
|
||||
|
||||
C2H_TEST("then keeps sends_stopped from input sender", "[adaptors][then]")
|
||||
{
|
||||
dummy_scheduler sched1{};
|
||||
error_scheduler sched2{error_code{std::errc::invalid_argument}};
|
||||
stopped_scheduler sched3{};
|
||||
|
||||
check_sends_stopped<false>(ex::just() | ex::continues_on(sched1) | ex::then([] {}));
|
||||
check_sends_stopped<false>(ex::just() | ex::continues_on(sched2) | ex::then([] {}));
|
||||
check_sends_stopped<true>(ex::just() | ex::continues_on(sched3) | ex::then([] {}));
|
||||
}
|
||||
|
||||
C2H_TEST("then can return by reference", "[adaptors][then]")
|
||||
{
|
||||
string str("hello"), *pstr = &str;
|
||||
auto snd = ex::just() | ex::then([pstr]() noexcept -> decltype(auto) {
|
||||
return *pstr;
|
||||
});
|
||||
check_value_types<types<string&>>(snd);
|
||||
check_error_types<>(snd);
|
||||
check_sends_stopped<false>(snd);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_EXCEPTIONS() && _CCCL_HOST_COMPILATION()
|
||||
|
||||
struct throws_on_copy
|
||||
{
|
||||
throws_on_copy() = default;
|
||||
throws_on_copy(throws_on_copy&&) = default;
|
||||
throws_on_copy(const throws_on_copy&)
|
||||
{
|
||||
throw std::runtime_error{"copy"};
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("sync_wait can handle when then() returns a throws-on-copy type by reference", "[adaptors][then][sync_wait]")
|
||||
{
|
||||
ex::thread_context worker{};
|
||||
throws_on_copy local, *plocal = &local;
|
||||
auto snd = ex::schedule(worker.get_scheduler()) | ex::then([pstr = plocal]() noexcept -> decltype(auto) {
|
||||
return *pstr;
|
||||
});
|
||||
check_value_types<types<throws_on_copy&>>(snd);
|
||||
check_error_types<>(snd);
|
||||
check_sends_stopped<true>(snd);
|
||||
CHECK_THROWS_AS(ex::sync_wait(std::move(snd)), std::runtime_error);
|
||||
worker.join();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Return a different sender when we invoke this custom defined then implementation
|
||||
struct then_test_domain
|
||||
{
|
||||
_CCCL_TEMPLATE(class Sender, class Env)
|
||||
_CCCL_REQUIRES(cuda::std::same_as<ex::tag_of_t<Sender>, ex::then_t>)
|
||||
_CCCL_HOST_DEVICE static auto transform_sender(ex::set_value_t, Sender&&, Env&&)
|
||||
{
|
||||
return ex::just(string{"ciao"});
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("then can be customized early", "[adaptors][then]")
|
||||
{
|
||||
// The customization will return a different value
|
||||
dummy_scheduler<then_test_domain> sched;
|
||||
auto snd = ex::just(string{"hello"}) | ex::continues_on(sched) | ex::then([](string x) {
|
||||
return x + ", world";
|
||||
});
|
||||
wait_for_value(std::move(snd), string{"ciao"});
|
||||
}
|
||||
|
||||
C2H_TEST("then can be customized late", "[adaptors][then]")
|
||||
{
|
||||
// The customization will return a different value
|
||||
dummy_scheduler<then_test_domain> sched;
|
||||
auto snd = ex::just(string{"hello"})
|
||||
| ex::on(sched, ex::then([](string x) {
|
||||
return x + ", world";
|
||||
}))
|
||||
| ex::write_env(ex::prop{ex::get_scheduler, dummy_scheduler()});
|
||||
wait_for_value(std::move(snd), string{"ciao"});
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,97 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "./common/retry.cuh"
|
||||
#include "testing.cuh"
|
||||
|
||||
namespace ex = ::cuda::experimental::execution;
|
||||
|
||||
#if !_CCCL_DEVICE_COMPILATION()
|
||||
|
||||
namespace
|
||||
{
|
||||
struct try_again
|
||||
{};
|
||||
|
||||
class fails_alot
|
||||
{
|
||||
template <class Receiver>
|
||||
struct operation;
|
||||
|
||||
public:
|
||||
using sender_concept = ex::sender_t;
|
||||
|
||||
fails_alot() = default;
|
||||
|
||||
__host__ fails_alot(fails_alot&& other) noexcept
|
||||
: counter_(std::move(other.counter_))
|
||||
{}
|
||||
|
||||
__host__ fails_alot(const fails_alot& other) noexcept
|
||||
: counter_(other.counter_)
|
||||
{}
|
||||
|
||||
template <class Receiver>
|
||||
[[nodiscard]] auto connect(Receiver rcvr) const noexcept -> operation<Receiver>
|
||||
{
|
||||
return operation<Receiver>{static_cast<Receiver&&>(rcvr), --*counter_};
|
||||
}
|
||||
|
||||
template <class...>
|
||||
static _CCCL_CONSTEVAL auto get_completion_signatures() noexcept
|
||||
{
|
||||
return ex::completion_signatures<ex::set_value_t(), ex::set_error_t(try_again)>{};
|
||||
}
|
||||
|
||||
private:
|
||||
template <class Receiver>
|
||||
struct operation
|
||||
{
|
||||
void start() & noexcept
|
||||
{
|
||||
if (counter_ == 0)
|
||||
{
|
||||
ex::set_value(static_cast<Receiver&&>(rcvr_));
|
||||
}
|
||||
else
|
||||
{
|
||||
ex::set_error(static_cast<Receiver&&>(rcvr_), try_again{});
|
||||
}
|
||||
}
|
||||
|
||||
Receiver rcvr_;
|
||||
int counter_;
|
||||
};
|
||||
|
||||
std::shared_ptr<int> counter_ = std::make_shared<int>(1'000'000);
|
||||
};
|
||||
|
||||
// #if defined(REQUIRE_TERMINATE)
|
||||
// // For some reason, when compiling with nvc++, the forked process dies with SIGSEGV
|
||||
// // but the error code returned from ::wait reports success, so this test fails.
|
||||
// TEST_CASE("running deeply recursing algo blows the stack", "[schedulers][trampoline_scheduler]") {
|
||||
|
||||
// auto recurse_deeply = retry(fails_alot{});
|
||||
// REQUIRE_TERMINATE([&] { sync_wait(std::move(recurse_deeply)); });
|
||||
// }
|
||||
// #endif
|
||||
|
||||
TEST_CASE("running deeply recursing algo on trampoline_scheduler doesn't blow the stack",
|
||||
"[scheduler][trampoline_scheduler]")
|
||||
{
|
||||
ex::trampoline_scheduler sched;
|
||||
auto recurse_deeply = retry(ex::on(sched, fails_alot{}));
|
||||
ex::sync_wait(std::move(recurse_deeply));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#endif // !_CCCL_DEVICE_COMPILATION()
|
||||
@@ -1,81 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/std/__algorithm/max.h>
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace
|
||||
{
|
||||
struct S0
|
||||
{};
|
||||
struct S1
|
||||
{
|
||||
int a;
|
||||
};
|
||||
struct S2
|
||||
{
|
||||
int a, b;
|
||||
};
|
||||
static_assert(cudax_async::structured_binding_size<S0> == 0);
|
||||
static_assert(cudax_async::structured_binding_size<S1> == 1);
|
||||
static_assert(cudax_async::structured_binding_size<S2> == 2);
|
||||
|
||||
template <class Fn>
|
||||
struct recursive_lambda
|
||||
{
|
||||
template <class... Args>
|
||||
auto operator()(Args&&... args)
|
||||
{
|
||||
return fn(*this, cuda::std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
Fn fn;
|
||||
};
|
||||
|
||||
template <class Fn>
|
||||
recursive_lambda(Fn) -> recursive_lambda<Fn>;
|
||||
|
||||
C2H_TEST("sender visitation API works", "[visit]")
|
||||
{
|
||||
int leaves = 0;
|
||||
int depth = 0;
|
||||
|
||||
auto snd = cudax_async::when_all(
|
||||
cudax_async::just(3), //
|
||||
cudax_async::just(0.1415),
|
||||
cudax_async::then(cudax_async::just(0.1415), [](double f) {
|
||||
return f;
|
||||
}));
|
||||
auto snd1 = std::move(snd) | cudax_async::then([](int x, double y, double z) {
|
||||
return x + y + z;
|
||||
});
|
||||
|
||||
auto count_leaves = recursive_lambda{[](auto& self, int& leaves, auto, auto&, auto&... child) {
|
||||
leaves += (sizeof...(child) == 0);
|
||||
((cudax_async::visit(self, child, leaves)), ...);
|
||||
}};
|
||||
|
||||
cudax_async::visit(count_leaves, snd1, leaves);
|
||||
CHECK(leaves == 3);
|
||||
|
||||
auto max_depth = recursive_lambda{[i = 0](auto& self, int& depth, auto, auto&, auto&... child) mutable {
|
||||
++i;
|
||||
depth = cuda::std::max(depth, i);
|
||||
((cudax_async::visit(self, child, depth)), ...);
|
||||
--i;
|
||||
}};
|
||||
|
||||
cudax_async::visit(max_depth, snd1, depth);
|
||||
CHECK(depth == 4);
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,261 +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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/std/__tuple_dir/ignore.h>
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/error_scheduler.cuh"
|
||||
#include "common/impulse_scheduler.cuh" // IWYU pragma: keep
|
||||
#include "common/stopped_scheduler.cuh"
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
C2H_TEST("when_all simple example", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(3), ex::just(0.1415));
|
||||
auto snd1 = std::move(snd) | ex::then([](int x, double y) {
|
||||
return x + y;
|
||||
});
|
||||
auto op = ex::connect(std::move(snd1), checked_value_receiver{3.1415});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all returning two values can be waited on", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(2), ex::just(3));
|
||||
check_values(std::move(snd), 2, 3);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all with 5 senders", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(2), ex::just(3), ex::just(5), ex::just(7), ex::just(11));
|
||||
check_values(std::move(snd), 2, 3, 5, 7, 11);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all with just one sender", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(2));
|
||||
check_values(std::move(snd), 2);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all with move-only types", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(movable(2)));
|
||||
check_values(std::move(snd), movable(2));
|
||||
}
|
||||
|
||||
C2H_TEST("when_all with no senders", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all();
|
||||
check_values(std::move(snd));
|
||||
}
|
||||
|
||||
C2H_TEST("when_all when one sender sends void", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(2), ex::just());
|
||||
check_values(std::move(snd), 2);
|
||||
}
|
||||
|
||||
#if !defined(__CUDA_ARCH__)
|
||||
|
||||
C2H_TEST("when_all completes when children complete", "[when_all]")
|
||||
{
|
||||
impulse_scheduler sched;
|
||||
bool called{false};
|
||||
auto snd = ex::when_all(ex::just(11) | ex::continues_on(sched),
|
||||
ex::just(13) | ex::continues_on(sched),
|
||||
ex::just(17) | ex::continues_on(sched))
|
||||
| ex::then([&](int a, int b, int c) {
|
||||
called = true;
|
||||
return a + b + c;
|
||||
});
|
||||
auto op = ex::connect(std::move(snd), checked_value_receiver{41});
|
||||
ex::start(op);
|
||||
// The when_all scheduler will complete only after 3 impulses
|
||||
CHECK_FALSE(called);
|
||||
sched.start_next();
|
||||
CHECK_FALSE(called);
|
||||
sched.start_next();
|
||||
CHECK_FALSE(called);
|
||||
sched.start_next();
|
||||
CHECK(called);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
C2H_TEST("when_all can be used with just_*", "[when_all]")
|
||||
{
|
||||
auto snd = ex::when_all(ex::just(2), ex::just_error(42), ex::just_stopped());
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all terminates with error if one child terminates with error", "[when_all]")
|
||||
{
|
||||
error_scheduler sched{42};
|
||||
auto snd = ex::when_all(ex::just(2), ex::just(5) | ex::continues_on(sched), ex::just(7));
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{42});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all terminates with stopped if one child is cancelled", "[when_all]")
|
||||
{
|
||||
stopped_scheduler sched;
|
||||
auto snd = ex::when_all(ex::just(2), ex::just(5) | ex::continues_on(sched), ex::just(7));
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
}
|
||||
|
||||
#if !defined(__CUDA_ARCH__)
|
||||
|
||||
C2H_TEST("when_all cancels remaining children if error is detected", "[when_all]")
|
||||
{
|
||||
impulse_scheduler sched;
|
||||
error_scheduler err_sched{42};
|
||||
bool called1{false};
|
||||
bool called3{false};
|
||||
bool cancelled{false};
|
||||
auto snd = ex::when_all(
|
||||
ex::starts_on(sched, ex::just()) | ex::then([&] {
|
||||
called1 = true;
|
||||
}),
|
||||
ex::starts_on(sched, ex::just(5) | ex::continues_on(err_sched)),
|
||||
ex::starts_on(sched, ex::just()) | ex::then([&] {
|
||||
called3 = true;
|
||||
}) | ex::let_stopped([&] {
|
||||
cancelled = true;
|
||||
return ex::just();
|
||||
}));
|
||||
auto op = ex::connect(std::move(snd), checked_error_receiver{42});
|
||||
ex::start(op);
|
||||
// The first child will complete; the third one will be cancelled
|
||||
CHECK_FALSE(called1);
|
||||
CHECK_FALSE(called3);
|
||||
sched.start_next(); // start the first child
|
||||
CHECK(called1);
|
||||
sched.start_next(); // start the second child; this will generate an error
|
||||
CHECK_FALSE(called3);
|
||||
sched.start_next(); // start the third child
|
||||
CHECK_FALSE(called3);
|
||||
CHECK(cancelled);
|
||||
}
|
||||
|
||||
C2H_TEST("when_all cancels remaining children if cancel is detected", "[when_all]")
|
||||
{
|
||||
stopped_scheduler stopped_sched;
|
||||
impulse_scheduler sched;
|
||||
bool called1{false};
|
||||
bool called3{false};
|
||||
bool cancelled{false};
|
||||
auto snd = ex::when_all(
|
||||
ex::starts_on(sched, ex::just()) | ex::then([&] {
|
||||
called1 = true;
|
||||
}),
|
||||
ex::starts_on(sched, ex::just(5) | ex::continues_on(stopped_sched)),
|
||||
ex::starts_on(sched, ex::just()) | ex::then([&] {
|
||||
called3 = true;
|
||||
}) | ex::let_stopped([&] {
|
||||
cancelled = true;
|
||||
return ex::just();
|
||||
}));
|
||||
auto op = ex::connect(std::move(snd), checked_stopped_receiver{});
|
||||
ex::start(op);
|
||||
// The first child will complete; the third one will be cancelled
|
||||
CHECK_FALSE(called1);
|
||||
CHECK_FALSE(called3);
|
||||
sched.start_next(); // start the first child
|
||||
CHECK(called1);
|
||||
sched.start_next(); // start the second child; this will call set_stopped
|
||||
CHECK_FALSE(called3);
|
||||
sched.start_next(); // start the third child
|
||||
CHECK_FALSE(called3);
|
||||
CHECK(cancelled);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class... Ts>
|
||||
struct just_ref
|
||||
{
|
||||
using sender_concept = ex::sender_t;
|
||||
|
||||
template <class Self, class... Env>
|
||||
_CCCL_HOST_DEVICE static constexpr auto get_completion_signatures()
|
||||
{
|
||||
return ex::completion_signatures<ex::set_value_t(Ts & ...)>{};
|
||||
}
|
||||
|
||||
_CCCL_HOST_DEVICE just_ref connect(cuda::std::__ignore_t) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
C2H_TEST("when_all has the values_type based on the children, decayed and as rvalue "
|
||||
"references",
|
||||
"[when_all]")
|
||||
{
|
||||
check_value_types<types<int>>(ex::when_all(ex::just(13)));
|
||||
check_value_types<types<double>>(ex::when_all(ex::just(3.14)));
|
||||
check_value_types<types<int, double>>(ex::when_all(ex::just(3, 0.14)));
|
||||
|
||||
check_value_types<types<>>(ex::when_all(ex::just()));
|
||||
|
||||
check_value_types<types<int, double>>(ex::when_all(ex::just(3), ex::just(0.14)));
|
||||
check_value_types<types<int, double, int, double>>(ex::when_all(ex::just(3), ex::just(0.14), ex::just(1, 0.4142)));
|
||||
|
||||
// if one child returns void, then the value is simply missing
|
||||
check_value_types<types<int, double>>(ex::when_all(ex::just(3), ex::just(), ex::just(0.14)));
|
||||
|
||||
// if one child has no value completion, the when_all has no value
|
||||
// completion
|
||||
check_value_types<>(ex::when_all(ex::just(3), ex::just_stopped(), ex::just(0.14)));
|
||||
|
||||
// if children send references, they get decayed
|
||||
check_value_types<types<int, double>>(ex::when_all(just_ref<int>(), just_ref<double>()));
|
||||
}
|
||||
|
||||
C2H_TEST("when_all has the error_types based on the children", "[when_all]")
|
||||
{
|
||||
check_error_types<int>(ex::when_all(ex::just_error(13)));
|
||||
|
||||
check_error_types<double>(ex::when_all(ex::just_error(3.14)));
|
||||
|
||||
check_error_types<>(ex::when_all(ex::just()));
|
||||
|
||||
check_error_types<int, double>(ex::when_all(ex::just_error(3), ex::just_error(0.14)));
|
||||
|
||||
check_error_types<int, double, string>(
|
||||
ex::when_all(ex::just_error(3), ex::just_error(0.14), ex::just_error(string{"err"})));
|
||||
|
||||
check_error_types<error_code>(
|
||||
ex::when_all(ex::just(13), ex::just_error(error_code{std::errc::invalid_argument}), ex::just_stopped()));
|
||||
|
||||
// if the child sends something with a potentially throwing decay-copy,
|
||||
// the when_all has an exception_ptr error completion.
|
||||
check_error_types<ex::exception_ptr>(ex::when_all(just_ref<potentially_throwing>()));
|
||||
}
|
||||
|
||||
C2H_TEST("when_all has the sends_stopped == true", "[when_all]")
|
||||
{
|
||||
check_sends_stopped<true>(ex::when_all(ex::just(13)));
|
||||
check_sends_stopped<true>(ex::when_all(ex::just_error(-1)));
|
||||
check_sends_stopped<true>(ex::when_all(ex::just_stopped()));
|
||||
|
||||
check_sends_stopped<true>(ex::when_all(ex::just(3), ex::just(0.14)));
|
||||
check_sends_stopped<true>(ex::when_all(ex::just(3), ex::just_error(-1), ex::just_stopped()));
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,31 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "testing.cuh" // IWYU pragma: keep
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_domain
|
||||
{};
|
||||
|
||||
C2H_TEST("basic test of write_attrs", "[write_attrs]")
|
||||
{
|
||||
auto sndr = cudax_async::just(42) | cudax_async::write_attrs(cudax_async::prop{cudax_async::get_domain, my_domain{}});
|
||||
[[maybe_unused]] auto domain = cudax_async::get_domain(cudax_async::get_env(sndr));
|
||||
STATIC_REQUIRE(std::is_same_v<decltype(domain), my_domain>);
|
||||
|
||||
// Check that the sender can be connected and started
|
||||
auto op = cudax_async::connect(std::move(sndr), checked_value_receiver{42});
|
||||
cudax_async::start(op);
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,98 +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) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/execution.cuh>
|
||||
|
||||
#include "common/checked_receiver.cuh"
|
||||
#include "common/utility.cuh"
|
||||
#include "testing.cuh"
|
||||
|
||||
namespace ex = cuda::experimental::execution;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Custom domain for testing
|
||||
struct my_domain
|
||||
{};
|
||||
|
||||
// Simple test query
|
||||
struct query1_t : ex::forwarding_query_t
|
||||
{
|
||||
template <class Env>
|
||||
_CCCL_HOST_DEVICE_API auto operator()(const Env& env) const noexcept -> decltype(env.query(*this))
|
||||
{
|
||||
return env.query(*this);
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr auto query1 = query1_t{};
|
||||
} // namespace
|
||||
|
||||
C2H_TEST("write_env basic functionality", "[write_env][adaptors]")
|
||||
{
|
||||
// Test that write_env wraps a sender and adds environment information
|
||||
auto env = ex::prop{query1, 42};
|
||||
auto sndr = ex::write_env(ex::just(42), env);
|
||||
|
||||
auto op = ex::connect(std::move(sndr), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
// the receiver will check the result
|
||||
}
|
||||
|
||||
C2H_TEST("write_env pipe syntax", "[write_env][adaptors]")
|
||||
{
|
||||
// Test that write_env supports pipe syntax (sndr | write_env(env))
|
||||
auto env = ex::prop{query1, 42};
|
||||
auto sndr = ex::just(42) | ex::write_env(env);
|
||||
|
||||
auto op = ex::connect(std::move(sndr), checked_value_receiver{42});
|
||||
ex::start(op);
|
||||
// the receiver will check the result
|
||||
}
|
||||
|
||||
#if _CCCL_HOST_COMPILATION()
|
||||
C2H_TEST("write_env updates the receiver's environment", "[write_env][adaptors]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([]() {
|
||||
return ex::read_env(query1);
|
||||
})
|
||||
| ex::write_env(ex::prop{query1, 42});
|
||||
|
||||
auto [result] = ex::sync_wait(std::move(sndr)).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
|
||||
struct fake_allocator
|
||||
{};
|
||||
|
||||
C2H_TEST("write_env does not hide the receiver's environment", "[write_env][adaptors]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([]() {
|
||||
return ex::read_env(ex::get_allocator);
|
||||
})
|
||||
| ex::write_env(ex::prop{query1, 42});
|
||||
|
||||
auto env = ex::prop{ex::get_allocator, fake_allocator{}};
|
||||
auto [result] = ex::sync_wait(std::move(sndr), env).value();
|
||||
STATIC_REQUIRE(std::is_same_v<decltype(result), fake_allocator>);
|
||||
}
|
||||
|
||||
C2H_TEST("write_env prefers the passed env over the receiver's env", "[write_env][adaptors]")
|
||||
{
|
||||
auto sndr = ex::just() | ex::let_value([]() {
|
||||
return ex::read_env(query1);
|
||||
})
|
||||
| ex::write_env(ex::prop{query1, 42});
|
||||
|
||||
auto env = ex::prop{query1, 100};
|
||||
auto [result] = ex::sync_wait(std::move(sndr), env).value();
|
||||
CHECK(result == 42);
|
||||
}
|
||||
#endif // _CCCL_HOST_COMPILATION()
|
||||
Reference in New Issue
Block a user