Skip to content

Commit facefba

Browse files
Extend cub::FutureValue (#4075)
Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
1 parent 5087d1b commit facefba

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

cub/cub/util_type.cuh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,12 @@ struct FutureValue
262262
{
263263
using value_type = T;
264264
using iterator_type = IterT;
265+
265266
explicit _CCCL_HOST_DEVICE _CCCL_FORCEINLINE FutureValue(IterT iter)
266267
: m_iter(iter)
267268
{}
268-
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE operator T()
269+
270+
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE operator T() const noexcept
269271
{
270272
return *m_iter;
271273
}
@@ -274,6 +276,9 @@ private:
274276
IterT m_iter;
275277
};
276278

279+
template <typename IterT>
280+
FutureValue(IterT) -> FutureValue<detail::it_value_t<IterT>, IterT>;
281+
277282
namespace detail
278283
{
279284

cub/test/catch2_test_util_type.cu

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,23 @@ C2H_TEST("Test CustomHalf", "[util][type]")
107107
CHECK(cuda::std::numeric_limits<half_t>::max() == half_t::max());
108108
CHECK(cuda::std::numeric_limits<half_t>::lowest() == half_t::lowest());
109109
}
110+
111+
C2H_TEST("Test FutureValue", "[util][type]")
112+
{
113+
// read
114+
int value;
115+
cub::FutureValue<int> fv{&value};
116+
value = 42;
117+
CHECK(fv == 42);
118+
value = 43;
119+
CHECK(fv == 43);
120+
121+
// CTAD
122+
cub::FutureValue fv2{&value};
123+
STATIC_REQUIRE(::cuda::std::is_same_v<decltype(fv2), cub::FutureValue<int, int*>>);
124+
125+
c2h::device_vector<int> v(0);
126+
cub::FutureValue fv3{v.begin()};
127+
STATIC_REQUIRE(
128+
::cuda::std::is_same_v<decltype(fv3), cub::FutureValue<int, typename c2h::device_vector<int>::iterator>>);
129+
}

0 commit comments

Comments
 (0)