Dense Array Views

View as Markdown

Dense array views describe memory owned somewhere else. They carry the pointer, shape, layout, memory-space accessor, and constness needed by NVIDIA cuVS C++ APIs without allocating or freeing data.

raft::mdspan

Source header: raft/core/mdspan.hpp

Generic multi-dimensional non-owning view.

template <typename ElementType, typename Extents, typename LayoutPolicy,
typename AccessorPolicy>
class mdspan;

raft::mdspan::data_handle

Returns the pointer held by the non-owning view.

element_type* data_handle() const;

Returns

element_type*

raft::mdspan::extents

Returns the extents object that describes the view shape.

extents_type extents() const;

Returns

extents_type

raft::mdspan::extent

Returns the size of one rank of the view.

index_type extent(std::size_t r) const noexcept;

Parameters

NameTypeDescription
rstd::size_tRank to query.

Returns

index_type

raft::mdspan::stride

Returns the stride for one rank of a strided view.

index_type stride(std::size_t r) const;

Parameters

NameTypeDescription
rstd::size_tRank to query.

Returns

index_type

raft::mdspan::size

Returns the total number of elements described by the view.

size_type size() const;

Returns

size_type

raft::mdspan::empty

Reports whether the view describes zero elements.

bool empty() const;

Returns

bool

raft::mdspan::operator()

Indexes into the view with one coordinate per rank.

template <typename... IndexType>
reference operator()(IndexType... indices) const;

Parameters

NameTypeDescription
indicesIndexType...Coordinates into the view, one per rank.

Returns

reference

raft::device_mdspan

Source header: raft/core/device_mdspan.hpp

Non-owning view over device-accessible memory.

template <typename ElementType,
typename Extents,
typename LayoutPolicy = layout_c_contiguous,
typename AccessorPolicy = cuda::std::default_accessor<ElementType>>
using device_mdspan =
mdspan<ElementType, Extents, LayoutPolicy, device_accessor<AccessorPolicy>>;

raft::host_mdspan

Source header: raft/core/host_mdspan.hpp

Non-owning view over host memory.

template <typename ElementType,
typename Extents,
typename LayoutPolicy = layout_c_contiguous,
typename AccessorPolicy = cuda::std::default_accessor<ElementType>>
using host_mdspan =
mdspan<ElementType, Extents, LayoutPolicy, host_accessor<AccessorPolicy>>;

raft::device_matrix_view

Source header: raft/core/device_mdspan.hpp

Common device view alias for matrix arguments.

template <typename ElementType,
typename IndexType = std::uint32_t,
typename LayoutPolicy = layout_c_contiguous>
using device_matrix_view =
device_mdspan<ElementType, matrix_extent<IndexType>, LayoutPolicy>;

raft::device_vector_view

Source header: raft/core/device_mdspan.hpp

Common device view alias for vector arguments.

template <typename ElementType,
typename IndexType = std::uint32_t,
typename LayoutPolicy = layout_c_contiguous>
using device_vector_view =
device_mdspan<ElementType, vector_extent<IndexType>, LayoutPolicy>;

raft::device_scalar_view

Source header: raft/core/device_mdspan.hpp

Common device view alias for scalar arguments.

template <typename ElementType, typename IndexType = std::uint32_t>
using device_scalar_view = device_mdspan<ElementType, scalar_extent<IndexType>>;

raft::host_matrix_view

Source header: raft/core/host_mdspan.hpp

Common host view alias for matrix arguments.

template <typename ElementType,
typename IndexType = std::uint32_t,
typename LayoutPolicy = layout_c_contiguous>
using host_matrix_view =
host_mdspan<ElementType, matrix_extent<IndexType>, LayoutPolicy>;

raft::host_vector_view

Source header: raft/core/host_mdspan.hpp

Common host view alias for vector arguments.

template <typename ElementType,
typename IndexType = std::uint32_t,
typename LayoutPolicy = layout_c_contiguous>
using host_vector_view =
host_mdspan<ElementType, vector_extent<IndexType>, LayoutPolicy>;

raft::host_scalar_view

Source header: raft/core/host_mdspan.hpp

Common host view alias for scalar arguments.

template <typename ElementType, typename IndexType = std::uint32_t>
using host_scalar_view = host_mdspan<ElementType, scalar_extent<IndexType>>;

raft::span

Source header: raft/core/span.hpp

Lightweight one-dimensional non-owning view. NVIDIA cuVS public APIs usually prefer device_vector_view and host_vector_view for one-dimensional buffers.

template <typename ElementType, std::size_t Extent>
class span;

raft::span::data

Returns the pointer held by the span.

element_type* data() const;

Returns

element_type*

raft::span::size

Returns the number of elements in the span.

size_type size() const;

Returns

size_type

raft::span::empty

Reports whether the span contains zero elements.

bool empty() const;

Returns

bool

raft::span::operator[]

Indexes into the span.

reference operator[](size_type idx) const;

Parameters

NameTypeDescription
idxsize_typeElement index.

Returns

reference

raft::span::begin

Returns an iterator to the first element.

iterator begin() const;

Returns

iterator

raft::span::end

Returns an iterator one past the last element.

iterator end() const;

Returns

iterator