Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate thrust::optional #3307

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions thrust/thrust/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <type_traits>
#include <utility>

_CCCL_SUPPRESS_DEPRECATED_PUSH

#if _CCCL_COMPILER(MSVC, ==, 19, 00)
# define THRUST_OPTIONAL_MSVC2015
#endif
Expand All @@ -59,11 +61,11 @@ THRUST_NAMESPACE_BEGIN
#ifndef THRUST_MONOSTATE_INPLACE_MUTEX
# define THRUST_MONOSTATE_INPLACE_MUTEX
/// \brief Used to represent an optional with no data; essentially a bool
class monostate
class CCCL_DEPRECATED_BECAUSE("Use cuda::std::monostate instead") monostate
{};

/// \brief A tag type to tell optional to construct its value in-place
struct in_place_t
struct CCCL_DEPRECATED in_place_t
{
explicit in_place_t() = default;
};
Expand All @@ -72,7 +74,7 @@ static constexpr in_place_t in_place{};
#endif

template <class T>
class optional;
class CCCL_DEPRECATED_BECAUSE("Use cuda::std::optional") optional;

/// \exclude
namespace detail
Expand Down Expand Up @@ -722,7 +724,7 @@ struct optional_delete_assign_base<T, false, false>
} // namespace detail

/// \brief A tag type to represent an empty optional
struct nullopt_t
struct CCCL_DEPRECATED nullopt_t
{
struct do_not_use
{};
Expand All @@ -744,7 +746,7 @@ static constexpr
#endif // __CUDA_ARCH__
nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}};

class bad_optional_access : public std::exception
class CCCL_DEPRECATED bad_optional_access : public std::exception
{
public:
bad_optional_access() = default;
Expand Down Expand Up @@ -1954,19 +1956,22 @@ _CCCL_EXEC_CHECK_DISABLE
template <class T = detail::i_am_secret,
class U,
class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<Ret> make_optional(U&& v)
{
return optional<Ret>(std::forward<U>(v));
}

_CCCL_EXEC_CHECK_DISABLE
template <class T, class... Args>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(Args&&... args)
{
return optional<T>(in_place, std::forward<Args>(args)...);
}
_CCCL_EXEC_CHECK_DISABLE
template <class T, class U, class... Args>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(std::initializer_list<U> il, Args&&... args)
{
return optional<T>(in_place, il, std::forward<Args>(args)...);
Expand All @@ -1993,6 +1998,7 @@ _CCCL_HOST_DEVICE constexpr auto optional_map_impl(Opt&& opt, F&& f)
return opt.has_value() ? detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt)) : optional<Ret>(nullopt);
}

_CCCL_SUPPRESS_DEPRECATED_PUSH
_CCCL_EXEC_CHECK_DISABLE
template <class Opt,
class F,
Expand All @@ -2008,6 +2014,7 @@ _CCCL_HOST_DEVICE auto optional_map_impl(Opt&& opt, F&& f)

return optional<monostate>(nullopt);
}
_CCCL_SUPPRESS_DEPRECATED_POP
# else
_CCCL_EXEC_CHECK_DISABLE
template <class Opt,
Expand Down Expand Up @@ -2822,3 +2829,5 @@ struct hash<THRUST_NS_QUALIFIER::optional<T>>
}
};
} // namespace std

_CCCL_SUPPRESS_DEPRECATED_POP
33 changes: 24 additions & 9 deletions thrust/thrust/system/cuda/detail/future.inl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ struct unique_eager_future_promise_pair final
weak_promise<X, XPointer> promise;
};

struct acquired_stream final
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional

struct acquired_stream final
{
unique_stream stream;
optional<std::size_t> const acquired_from;
Expand Down Expand Up @@ -340,6 +342,8 @@ inline _CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_
template <typename X>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_eager_future<X>& parent) noexcept;

_CCCL_SUPPRESS_DEPRECATED_POP

template <typename... Dependencies>
_CCCL_HOST acquired_stream acquire_stream(int device, Dependencies&... deps) noexcept;

Expand Down Expand Up @@ -743,8 +747,10 @@ public:
stream().wait();
}

friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_POP

template <typename... Dependencies>
friend _CCCL_HOST unique_eager_event
Expand Down Expand Up @@ -901,9 +907,11 @@ public:
}
# endif

template <typename X>
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
template <typename X>
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_POP

template <typename X, typename XPointer, typename ComputeContent, typename... Dependencies>
friend _CCCL_HOST detail::unique_eager_future_promise_pair<X, XPointer>
Expand All @@ -916,9 +924,10 @@ public:

namespace detail
{
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional

template <typename X, typename Deleter>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
template <typename X, typename Deleter>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
bernhardmgruber marked this conversation as resolved.
Show resolved Hide resolved
{
// There's no stream to acquire!
return {};
Expand Down Expand Up @@ -973,6 +982,8 @@ _CCCL_HOST optional<unique_stream> try_acquire_stream(int device_id, unique_eage
return {};
}

_CCCL_SUPPRESS_DEPRECATED_POP

///////////////////////////////////////////////////////////////////////////////

template <typename... Dependencies>
Expand All @@ -987,7 +998,8 @@ template <typename... Dependencies, std::size_t I0, std::size_t... Is>
_CCCL_HOST acquired_stream
acquire_stream_impl(int device_id, std::tuple<Dependencies...>& deps, index_sequence<I0, Is...>) noexcept
{
auto tr = try_acquire_stream(device_id, std::get<I0>(deps));
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional (MSVC warnings here)
auto tr = try_acquire_stream(device_id, std::get<I0>(deps));

if (tr)
{
Expand All @@ -997,6 +1009,7 @@ acquire_stream_impl(int device_id, std::tuple<Dependencies...>& deps, index_sequ
{
return acquire_stream_impl(device_id, deps, index_sequence<Is...>{});
}
_CCCL_SUPPRESS_DEPRECATED_POP
}

template <typename... Dependencies>
Expand Down Expand Up @@ -1043,10 +1056,12 @@ create_dependencies_impl(acquired_stream& as, std::tuple<Dependencies...>& deps,
{
// We only need to wait on the current dependency if we didn't steal our
// stream from it.
_CCCL_SUPPRESS_DEPRECATED_PUSH
if (!as.acquired_from || *as.acquired_from != I0)
{
create_dependency(as.stream, std::get<I0>(deps));
}
_CCCL_SUPPRESS_DEPRECATED_POP

create_dependencies_impl(as, deps, index_sequence<Is...>{});
}
Expand Down
Loading