Skip to content

Commit

Permalink
Deprecate thrust::optional (NVIDIA#3307)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 15, 2025
1 parent 9092760 commit a7e05f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
32 changes: 27 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 @@ -720,7 +722,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 @@ -742,7 +744,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 @@ -1952,19 +1954,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 Down Expand Up @@ -2001,7 +2006,22 @@ _CCCL_HOST_DEVICE auto optional_map_impl(Opt&& opt, F&& f)
if (opt.has_value())
{
detail::invoke(std::forward<F>(f), *std::forward<Opt>(opt));
# if _CCCL_COMPILER(MSVC)
// MSVC fails to suppress the warning on make_optional
_CCCL_SUPPRESS_DEPRECATED_PUSH
return optional<monostate>(monostate{});
_CCCL_SUPPRESS_DEPRECATED_POP
# elif _CCCL_COMPILER(NVHPC)
// NVHPC cannot have a diagnostic pop after a return statement
_CCCL_SUPPRESS_DEPRECATED_PUSH
auto o = optional<monostate>(monostate{});
_CCCL_SUPPRESS_DEPRECATED_POP
return ::cuda::std::move(o);
# else
_CCCL_SUPPRESS_DEPRECATED_PUSH
return make_optional(monostate{});
_CCCL_SUPPRESS_DEPRECATED_POP
# endif
}

return optional<monostate>(nullopt);
Expand Down Expand Up @@ -2820,3 +2840,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 @@ -744,8 +748,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 @@ -902,9 +908,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 @@ -917,9 +925,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
{
// There's no stream to acquire!
return {};
Expand Down Expand Up @@ -974,6 +983,8 @@ _CCCL_HOST optional<unique_stream> try_acquire_stream(int device_id, unique_eage
return {};
}

_CCCL_SUPPRESS_DEPRECATED_POP

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

template <typename... Dependencies>
Expand All @@ -988,7 +999,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 @@ -998,6 +1010,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 @@ -1044,10 +1057,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

0 comments on commit a7e05f7

Please sign in to comment.