Owning Dense Arrays

View as Markdown

Owning arrays allocate storage and release it when the object is destroyed. They are commonly used in examples, tests, index objects, and user code that needs RAFT to allocate inputs, outputs, or staging buffers.

raft::mdarray

Source header: raft/core/mdarray.hpp

Generic owning multi-dimensional array.

template <typename ElementType, typename Extents, typename LayoutPolicy,
typename ContainerPolicy>
class mdarray;

raft::mdarray::view

Returns an mdspan view over the owned storage.

mdspan_type view();
const_mdspan_type view() const;

Returns

mdspan_type or const_mdspan_type

raft::mdarray::data_handle

Returns the pointer to the owned storage.

element_type* data_handle();
element_type const* data_handle() const;

Returns

element_type* or element_type const*

raft::mdarray::extents

Returns the extents object that describes the array shape.

extents_type extents() const;

Returns

extents_type

raft::mdarray::extent

Returns the size of one rank of the array.

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

Parameters

NameTypeDescription
rstd::size_tRank to query.

Returns

index_type

raft::mdarray::size

Returns the total number of elements in the array.

size_type size() const;

Returns

size_type

raft::mdarray::operator()

Indexes into the array. For device arrays, use this sparingly because element access may require device-host movement.

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

Parameters

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

Returns

reference or const_reference

raft::device_mdarray

Source header: raft/core/device_mdarray.hpp

Owning array in device-accessible memory.

template <typename ElementType, typename Extents,
typename LayoutPolicy = layout_c_contiguous,
typename ContainerPolicy = device_container_policy<ElementType>>
using device_mdarray =
mdarray<ElementType, Extents, LayoutPolicy, device_accessor<ContainerPolicy>>;

raft::host_mdarray

Source header: raft/core/host_mdarray.hpp

Owning array in host memory.

template <typename ElementType, typename Extents,
typename LayoutPolicy = layout_c_contiguous,
typename ContainerPolicy = host_container_policy<ElementType>>
using host_mdarray =
mdarray<ElementType, Extents, LayoutPolicy, host_accessor<ContainerPolicy>>;

raft::device_matrix

Source header: raft/core/device_mdarray.hpp

Owning device matrix alias used for datasets, outputs, and temporary storage.

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

raft::device_vector

Source header: raft/core/device_mdarray.hpp

Owning device vector alias used for outputs and temporary storage.

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

raft::host_matrix

Source header: raft/core/host_mdarray.hpp

Owning host matrix alias used for CPU-resident data and staging.

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

raft::host_vector

Source header: raft/core/host_mdarray.hpp

Owning host vector alias used for CPU-resident data and staging.

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