20 #include <rmm/device_uvector.hpp>
21 #include <rmm/device_vector.hpp>
23 #include <thrust/detail/raw_pointer_cast.h>
24 #include <thrust/device_vector.h>
25 #include <thrust/host_vector.h>
26 #include <thrust/memory.h>
30 #include <type_traits>
35 constexpr std::size_t
dynamic_extent = std::numeric_limits<std::size_t>::max();
43 template <
typename T, std::
size_t Extent,
typename Derived>
45 static_assert(Extent ==
dynamic_extent,
"Only dynamic extent is supported");
59 static constexpr std::size_t
extent = Extent;
148 [[nodiscard]] constexpr
bool empty() const noexcept {
return _size == 0; }
156 constexpr Derived
first(
size_type count)
const noexcept {
return Derived(_data, count); }
166 return Derived(_data + _size - count, count);
178 return Derived(_data + offset, count);
190 template <
typename T>
194 template <
typename T,
typename Alloc>
196 std::vector<T, Alloc>> : std::true_type {
199 template <
typename T,
typename Alloc>
201 thrust::host_vector<T, Alloc>> : std::true_type {
204 template <
typename T,
typename Alloc>
206 std::basic_string<T, std::char_traits<T>, Alloc>> : std::true_type {
213 template <
typename T, std::
size_t Extent = cudf::dynamic_extent>
225 std::enable_if_t<is_host_span_supported_container<C>::value &&
226 std::is_convertible_v<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
227 std::declval<C&>().
data()))> (*)[],
228 T (*)[]>>* =
nullptr>
238 std::enable_if_t<is_host_span_supported_container<C>::value &&
239 std::is_convertible_v<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
240 std::declval<C&>().
data()))> (*)[],
241 T (*)[]>>* =
nullptr>
248 template <
typename OtherT,
249 std::size_t OtherExtent,
250 std::enable_if_t<(Extent == OtherExtent || Extent ==
dynamic_extent) &&
251 std::is_convertible_v<OtherT (*)[], T (*)[]>,
254 :
base(other.data(), other.size())
261 template <
typename T>
265 template <
typename T,
typename Alloc>
267 thrust::device_vector<T, Alloc>> : std::true_type {
270 template <
typename T>
272 rmm::device_vector<T>> : std::true_type {
275 template <
typename T>
277 rmm::device_uvector<T>> : std::true_type {
284 template <
typename T, std::
size_t Extent = cudf::dynamic_extent>
296 std::enable_if_t<is_device_span_supported_container<C>::value &&
297 std::is_convertible_v<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
298 std::declval<C&>().
data()))> (*)[],
299 T (*)[]>>* =
nullptr>
309 std::enable_if_t<is_device_span_supported_container<C>::value &&
310 std::is_convertible_v<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
311 std::declval<C&>().
data()))> (*)[],
312 T (*)[]>>* =
nullptr>
319 template <
typename OtherT,
320 std::size_t OtherExtent,
321 std::enable_if_t<(Extent == OtherExtent || Extent ==
dynamic_extent) &&
322 std::is_convertible_v<OtherT (*)[], T (*)[]>,
325 :
base(other.data(), other.size())
337 template <
typename T,
template <
typename, std::
size_t>
typename RowType>
341 std::pair<size_t, size_t>;
380 constexpr
auto count() const noexcept {
return size().first *
size().second; }
386 [[nodiscard]] constexpr
bool is_empty() const noexcept {
return count() == 0; }
410 constexpr RowType<T, dynamic_extent>
operator[](
size_t row)
const
422 [[nodiscard]] constexpr RowType<T, dynamic_extent>
front()
const {
return (*
this)[0]; }
430 [[nodiscard]] constexpr RowType<T, dynamic_extent>
back()
const
432 return (*
this)[
size().first - 1];
456 return {this->
data(), this->
size().first * this->
size().second};
466 template <
typename OtherT,
467 template <
typename,
size_t>
468 typename OtherRowType,
469 std::enable_if_t<std::is_convertible_v<OtherRowType<OtherT, dynamic_extent>,
470 RowType<T, dynamic_extent>>,
488 using host_2dspan = base_2dspan<T, host_span>;
496 using device_2dspan = base_2dspan<T, device_span>;
cudf::detail::span_base< T, Extent, device_span< T, Extent > > base
Base type.
constexpr Derived last(size_type count) const noexcept
Obtains a subspan consisting of the last N elements of the sequence.
std::remove_cv< detail::dremel_device_view const > value_type
Stored value type.
A container of nullable device data as a column of elements.
constexpr auto data() const noexcept
Returns a pointer to the beginning of the sequence.
size_type _size
rows, columns
constexpr host_span(C const &in)
int32_t size_type
Row index type for columns and tables.
constexpr host_span(C &in)
constexpr Derived first(size_type count) const noexcept
Obtains a subspan consisting of the first N elements of the sequence.
Generic class for row-major 2D spans. Not compliant with STL container semantics/syntax.
constexpr Derived subspan(size_type offset, size_type count) const noexcept
Obtains a span that is a view over the count elements of this span starting at offset.
C++20 std::span with reduced feature set.
constexpr bool empty() const noexcept
Checks if the span is empty.
constexpr RowType< T, dynamic_extent > operator[](size_t row) const
Returns a reference to the row-th element of the sequence.
constexpr reference back() const
Returns a reference to the last element in the span.
C++20 std::span with reduced feature set.
constexpr iterator end() const noexcept
Returns an iterator to the element following the last element of the span.
detail::dremel_device_view const element_type
The type of the elements in the span.
constexpr host_span(const host_span< OtherT, OtherExtent > &other) noexcept
constexpr size_type size_bytes() const noexcept
Returns the size of the sequence in bytes.
constexpr device_span(const device_span< OtherT, OtherExtent > &other) noexcept
cudf::detail::span_base< T, Extent, host_span< T, Extent > > base
Base type.
constexpr base_2dspan subspan(size_t first_row, size_t num_rows) const noexcept
Obtains a 2D span that is a view over the num_rows rows of this span starting at first_row
constexpr device_span(C const &in)
base_2dspan(T *data, size_type size) noexcept
Constructor a 2D span.
constexpr pointer data() const noexcept
Returns a pointer to the beginning of the sequence.
constexpr reference operator[](size_type idx) const
Returns a reference to the idx-th element of the sequence.
detail::dremel_device_view const const * const_pointer
The type of the pointer returned by data() const.
std::size_t size_type
The type used for the size of the span.
T * _data
pointer to the first element
static constexpr std::size_t extent
The extent of the span.
constexpr RowType< T, dynamic_extent > front() const
Returns a reference to the first element in the span.
detail::dremel_device_view const * iterator
The type of the iterator returned by begin()
std::pair< size_t, size_t > size_type
Type used to represent the dimension of the span.
constexpr base_2dspan(base_2dspan< OtherT, OtherRowType > const &other) noexcept
Construct a 2D span from another 2D span of convertible type.
constexpr bool is_empty() const noexcept
Checks if the span is empty.
detail::dremel_device_view const const & const_reference
The type of the reference returned by operator[](size_type) const.
std::ptrdiff_t difference_type
std::ptrdiff_t
constexpr std::size_t dynamic_extent
A constant used to differentiate std::span of static and dynamic extent.
constexpr span_base(span_base const &) noexcept=default
Copy constructor.
constexpr RowType< T, dynamic_extent > flat_view()
Returns a flattened span of the 2D span.
constexpr reference front() const
Returns a reference to the first element in the span.
detail::dremel_device_view const & reference
The type of the reference returned by operator[](size_type)
static constexpr size_t flatten_index(size_t row, size_t column, size_type size) noexcept
Returns flattened index of the element at the specified 2D position.
constexpr RowType< T, dynamic_extent > back() const
Returns a reference to the last element in the span.
detail::dremel_device_view const * pointer
The type of the pointer returned by data()
Device version of C++20 std::span with reduced feature set.
constexpr span_base & operator=(span_base const &) noexcept=default
Copy assignment operator.
constexpr auto size() const noexcept
Returns the size in the span as pair.
constexpr span_base(pointer data, size_type size)
Constructs a span from a pointer and a size.
constexpr auto count() const noexcept
Returns the number of elements in the span.
constexpr size_type size() const noexcept
Returns the number of elements in the span.
constexpr device_span(C &in)
constexpr iterator begin() const noexcept
Returns an iterator to the first element of the span.