Public Types | Public Member Functions | Static Public Attributes | List of all members
cudf::host_span< T, Extent > Struct Template Reference

Host span, a non-owning view over a contiguous sequence of host-accessible elements. More...

#include <cudf/utilities/span.hpp>

Public Types

using element_type = typename span_type::element_type
 Element type.
 
using value_type = typename span_type::value_type
 Stored value type.
 
using size_type = typename span_type::size_type
 Size type.
 
using difference_type = typename span_type::difference_type
 std::ptrdiff_t
 
using pointer = typename span_type::pointer
 Pointer returned by data()
 
using const_pointer = typename span_type::const_pointer
 Pointer returned by data() const.
 
using reference = typename span_type::reference
 Reference returned by operator[].
 
using const_reference = typename span_type::const_reference
 Const reference to an element.
 
using iterator = pointer
 The type of the iterator returned by begin()
 

Public Member Functions

constexpr CUDF_HOST_DEVICE host_span (T *data, std::size_t size)
 Constructs a span from a pointer and a size. More...
 
constexpr CUDF_HOST_DEVICE host_span (T *data, std::size_t size, bool is_device_accessible)
 Constructor from pointer, size and device-accessibility flag. More...
 
template<typename C , std::enable_if_t< is_host_span_supported_container< C >::value &&std::is_convertible_v< std::remove_pointer_t< decltype(thrust::raw_pointer_cast(std::declval< C & >().data()))>(*)[], T(*)[]> , * = nullptr>
constexpr host_span (C &in)
 
template<typename C , std::enable_if_t< is_host_span_supported_container< C >::value &&std::is_convertible_v< std::remove_pointer_t< decltype(thrust::raw_pointer_cast(std::declval< C & >().data()))>(*)[], T(*)[]> , * = nullptr>
constexpr host_span (C const &in)
 
template<typename OtherT , std::size_t OtherExtent, std::enable_if_t<(Extent==OtherExtent||Extent==dynamic_extent) &&std::is_convertible_v< OtherT(*)[], T(*)[]>, void > * = nullptr>
constexpr host_span (host_span< OtherT, OtherExtent > const &other) noexcept
 
constexpr reference operator[] (size_type idx) const
 Returns a reference to the idx-th element of the sequence. More...
 
constexpr reference front () const
 Returns a reference to the first element in the span. More...
 
constexpr reference back () const
 Returns a reference to the last element in the span. More...
 
constexpr CUDF_HOST_DEVICE iterator begin () const noexcept
 Returns an iterator to the first element of the span. More...
 
constexpr CUDF_HOST_DEVICE iterator end () const noexcept
 Returns an iterator to the element following the last element of the span. More...
 
constexpr CUDF_HOST_DEVICE pointer data () const noexcept
 Returns a pointer to the beginning of the sequence. More...
 
constexpr CUDF_HOST_DEVICE size_type size () const noexcept
 Returns the number of elements in the span. More...
 
constexpr CUDF_HOST_DEVICE size_type size_bytes () const noexcept
 Returns the size of the sequence in bytes. More...
 
constexpr CUDF_HOST_DEVICE bool empty () const noexcept
 Checks if the span is empty. More...
 
constexpr host_span first (size_type count) const noexcept
 Obtains a subspan consisting of the first count elements of the sequence. More...
 
constexpr host_span last (size_type count) const noexcept
 Obtains a subspan consisting of the last count elements of the sequence. More...
 
bool is_device_accessible () const
 Returns whether the data is device accessible (e.g. pinned memory) More...
 
constexpr CUDF_HOST_DEVICE host_span 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. More...
 
constexpr operator std::span< T > () const noexcept
 Returns a standard span instance. More...
 

Static Public Attributes

static constexpr std::size_t extent = span_type::extent
 The extent of the span.
 

Detailed Description

template<typename T, std::size_t Extent = cudf::dynamic_extent>
struct cudf::host_span< T, Extent >

Host span, a non-owning view over a contiguous sequence of host-accessible elements.

Backed by cuda::std::span, with additional support for constructing from cudf-supported host containers and for tracking whether the underlying memory is device accessible (e.g. pinned memory), which enables copy engine optimizations.

Definition at line 65 of file span.hpp.

Constructor & Destructor Documentation

◆ host_span() [1/5]

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE cudf::host_span< T, Extent >::host_span ( T *  data,
std::size_t  size 
)
inlineconstexpr

Constructs a span from a pointer and a size.

Note
This needs to be host-device, as it's used by a host-device function in base_2dspan
Parameters
dataPointer to the first element in the span
sizeThe number of elements in the span

Definition at line 92 of file span.hpp.

◆ host_span() [2/5]

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE cudf::host_span< T, Extent >::host_span ( T *  data,
std::size_t  size,
bool  is_device_accessible 
)
inlineconstexpr

Constructor from pointer, size and device-accessibility flag.

Note
This needs to be host-device, as it's used by a host-device function in base_2dspan
Parameters
dataPointer to the first element in the span
sizeThe number of elements in the span
is_device_accessibleWhether the data is device accessible (e.g. pinned memory)

Definition at line 103 of file span.hpp.

◆ host_span() [3/5]

template<typename T , std::size_t Extent = cudf::dynamic_extent>
template<typename C , std::enable_if_t< is_host_span_supported_container< C >::value &&std::is_convertible_v< std::remove_pointer_t< decltype(thrust::raw_pointer_cast(std::declval< C & >().data()))>(*)[], T(*)[]> , * = nullptr>
constexpr cudf::host_span< T, Extent >::host_span ( C &  in)
inlineconstexpr

Constructor from container

Parameters
inThe container to construct the span from

Definition at line 117 of file span.hpp.

◆ host_span() [4/5]

template<typename T , std::size_t Extent = cudf::dynamic_extent>
template<typename C , std::enable_if_t< is_host_span_supported_container< C >::value &&std::is_convertible_v< std::remove_pointer_t< decltype(thrust::raw_pointer_cast(std::declval< C & >().data()))>(*)[], T(*)[]> , * = nullptr>
constexpr cudf::host_span< T, Extent >::host_span ( C const &  in)
inlineconstexpr

Constructor from const container

Parameters
inThe container to construct the span from

Definition at line 130 of file span.hpp.

◆ host_span() [5/5]

template<typename T , std::size_t Extent = cudf::dynamic_extent>
template<typename OtherT , std::size_t OtherExtent, std::enable_if_t<(Extent==OtherExtent||Extent==dynamic_extent) &&std::is_convertible_v< OtherT(*)[], T(*)[]>, void > * = nullptr>
constexpr cudf::host_span< T, Extent >::host_span ( host_span< OtherT, OtherExtent > const &  other)
inlineconstexprnoexcept
Parameters
otherThe span to copy

Definition at line 141 of file span.hpp.

Member Function Documentation

◆ back()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr reference cudf::host_span< T, Extent >::back ( ) const
inlineconstexpr

Returns a reference to the last element in the span.

Calling back on an empty span results in undefined behavior.

Returns
Reference to the last element in the span

Definition at line 179 of file span.hpp.

◆ begin()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE iterator cudf::host_span< T, Extent >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator to the first element of the span.

If the span is empty, the returned iterator will be equal to end().

Returns
An iterator to the first element of the span

Definition at line 188 of file span.hpp.

◆ data()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE pointer cudf::host_span< T, Extent >::data ( ) const
inlineconstexprnoexcept

Returns a pointer to the beginning of the sequence.

Returns
A pointer to the first element of the span

Definition at line 205 of file span.hpp.

◆ empty()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE bool cudf::host_span< T, Extent >::empty ( ) const
inlineconstexprnoexcept

Checks if the span is empty.

Returns
True if the span is empty, false otherwise

Definition at line 228 of file span.hpp.

◆ end()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE iterator cudf::host_span< T, Extent >::end ( ) const
inlineconstexprnoexcept

Returns an iterator to the element following the last element of the span.

This element acts as a placeholder; attempting to access it results in undefined behavior.

Returns
An iterator to the element following the last element of the span

Definition at line 196 of file span.hpp.

◆ first()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr host_span cudf::host_span< T, Extent >::first ( size_type  count) const
inlineconstexprnoexcept

Obtains a subspan consisting of the first count elements of the sequence.

Parameters
countNumber of elements from the beginning of this span to put in the subspan.
Returns
A subspan of the first count elements of the sequence

Definition at line 236 of file span.hpp.

◆ front()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr reference cudf::host_span< T, Extent >::front ( ) const
inlineconstexpr

Returns a reference to the first element in the span.

Calling front on an empty span results in undefined behavior.

Returns
Reference to the first element in the span

Definition at line 170 of file span.hpp.

◆ is_device_accessible()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
bool cudf::host_span< T, Extent >::is_device_accessible ( ) const
inline

Returns whether the data is device accessible (e.g. pinned memory)

Returns
true if the data is device accessible

Definition at line 257 of file span.hpp.

◆ last()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr host_span cudf::host_span< T, Extent >::last ( size_type  count) const
inlineconstexprnoexcept

Obtains a subspan consisting of the last count elements of the sequence.

Parameters
countNumber of elements from the end of this span to put in the subspan
Returns
A subspan of the last count elements of the sequence

Definition at line 247 of file span.hpp.

◆ operator std::span< T >()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr cudf::host_span< T, Extent >::operator std::span< T > ( ) const
inlineconstexprnoexcept

Returns a standard span instance.

Returns
Standard span instance

Definition at line 277 of file span.hpp.

◆ operator[]()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr reference cudf::host_span< T, Extent >::operator[] ( size_type  idx) const
inlineconstexpr

Returns a reference to the idx-th element of the sequence.

The behavior is undefined if idx is out of range (i.e., if it is greater than or equal to size()).

Parameters
idxthe index of the element to access
Returns
A reference to the idx-th element of the sequence, i.e., data()[idx]

Definition at line 156 of file span.hpp.

◆ size()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE size_type cudf::host_span< T, Extent >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the span.

Returns
The number of elements in the span

Definition at line 212 of file span.hpp.

◆ size_bytes()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE size_type cudf::host_span< T, Extent >::size_bytes ( ) const
inlineconstexprnoexcept

Returns the size of the sequence in bytes.

Returns
The size of the sequence in bytes

Definition at line 218 of file span.hpp.

◆ subspan()

template<typename T , std::size_t Extent = cudf::dynamic_extent>
constexpr CUDF_HOST_DEVICE host_span cudf::host_span< T, Extent >::subspan ( size_type  offset,
size_type  count 
) const
inlineconstexprnoexcept

Obtains a span that is a view over the count elements of this span starting at offset.

Parameters
offsetThe offset of the first element in the subspan
countThe number of elements in the subspan
Returns
A subspan of the sequence, of requested count and offset

Definition at line 266 of file span.hpp.


The documentation for this struct was generated from the following file: