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.

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

raft::mdarray::view

Returns an mdspan view over the owned storage.

1mdspan_type view();
2const_mdspan_type view() const;

Returns

mdspan_type or const_mdspan_type

raft::mdarray::data_handle

Returns the pointer to the owned storage.

1element_type* data_handle();
2element_type const* data_handle() const;

Returns

element_type* or element_type const*

raft::mdarray::extents

Returns the extents object that describes the array shape.

1extents_type extents() const;

Returns

extents_type

raft::mdarray::extent

Returns the size of one rank of the array.

1index_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.

1size_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.

1template <typename... IndexType>
2reference operator()(IndexType... indices);
3template <typename... IndexType>
4const_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.

1template <typename ElementType, typename Extents,
2 typename LayoutPolicy = layout_c_contiguous,
3 typename ContainerPolicy = device_container_policy<ElementType>>
4using device_mdarray =
5 mdarray<ElementType, Extents, LayoutPolicy, device_accessor<ContainerPolicy>>;

raft::host_mdarray

Source header: raft/core/host_mdarray.hpp

Owning array in host memory.

1template <typename ElementType, typename Extents,
2 typename LayoutPolicy = layout_c_contiguous,
3 typename ContainerPolicy = host_container_policy<ElementType>>
4using host_mdarray =
5 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.

1template <typename ElementType,
2 typename IndexType = std::uint32_t,
3 typename LayoutPolicy = layout_c_contiguous>
4using 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.

1template <typename ElementType,
2 typename IndexType = std::uint32_t,
3 typename LayoutPolicy = layout_c_contiguous>
4using 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.

1template <typename ElementType,
2 typename IndexType = std::uint32_t,
3 typename LayoutPolicy = layout_c_contiguous>
4using 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.

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