gko::matrix::view#

Each of Dense, Coo, Csr, Ell, Sellp and Hybrid exposes device_view and const_device_view types, together with the member functions get_device_view() and get_const_device_view(). A view is a small, trivially copyable struct of sizes and raw pointers, meant to be passed by value into kernel code or across library boundaries. The pointers refer to memory on the matrix’s executor and stay valid as long as the matrix is alive and not resized.

// A read-only view of A's arrays, e.g. to pass into a kernel.
auto view = A->get_const_device_view();
auto num_rows = view.size[0];
auto num_entries = view.num_stored_elements;
const int* row_ptrs = view.row_ptrs;  // col_idxs and values likewise

The view types live in <ginkgo/core/matrix/device_views.hpp>. get_device_view() returns a view with mutable pointers; as_const() converts it to its const counterpart.

Views#

template<typename ValueType>
struct dense#

Non-owning view of a matrix::Dense to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries. The data is stored in row-major order.

Template Parameters:

ValueType – the value type used to store matrix entries.

Public Functions

inline constexpr dense(
dim<2> size,
size_type stride,
ValueType *values,
)#

Constructs a dense view from size, stride and values.

inline constexpr dense<const ValueType> as_const() const#

Returns a const view of the same values

inline constexpr ValueType &operator()(
size_type row,
size_type col,
) const#

Subscript operator accessing the given row and column

template<typename ValueType, typename IndexType>
struct coo#

Non-owning view of a matrix::Coo to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries.

Template Parameters:
  • ValueType – the value type used to store matrix entries.

  • IndexType – the index type used to store row and column indices.

Public Functions

inline constexpr coo(
dim<2> size,
size_type num_stored_elements,
ValueType *values,
IndexType *row_idxs,
IndexType *col_idxs,
)#

Constructs a coo view from size, nnz, values, row and column indices.

inline constexpr coo<const ValueType, const IndexType> as_const(
) const#

Returns a const view of the same data

template<typename ValueType, typename IndexType>
struct csr#

Non-owning view of a matrix::Csr to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries.

Template Parameters:
  • ValueType – the value type used to store matrix entries.

  • IndexType – the index type used to store row and column indices.

Public Functions

inline constexpr csr(
dim<2> size,
size_type num_stored_elements,
ValueType *values,
IndexType *row_ptrs,
IndexType *col_idxs,
)#

Constructs a coo view from size, nnz, values, row pointers, and column indices.

inline constexpr csr<const ValueType, const IndexType> as_const(
) const#

Returns a const view of the same data

template<typename ValueType, typename IndexType>
struct ell#

Non-owning view of a matrix::Ell to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries.

Template Parameters:
  • ValueType – the value type used to store matrix values.

  • IndexType – the index type used to store matrix columns.

Public Functions

inline constexpr ell(
dim<2> size,
size_type num_stored_elements_per_row,
size_type stride,
ValueType *values,
IndexType *col_idxs,
)#

Constructs a ell view

inline constexpr ell<const ValueType, const IndexType> as_const(
) const#

Returns a const view of the same values

inline constexpr ValueType &val_at(
size_type row,
size_type idx,
) const#

accessing the value of the idx-th element within the given row

inline constexpr IndexType &col_at(
size_type row,
size_type idx,
) const#

accessing the column index of the idx-th element within the given row

template<typename ValueType, typename IndexType>
struct sellp#

Non-owning view of a matrix::Sellp to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries.

Template Parameters:
  • ValueType – the value type used to store matrix values.

  • IndexType – the index type used to store matrix columns.

Public Functions

inline constexpr sellp(
dim<2> size,
size_type slice_size,
size_type stride_factor,
size_type total_cols,
ValueType *values,
IndexType *col_idxs,
adapt_size_type *slice_lengths,
adapt_size_type *slice_sets,
)#

Constructs a sellp view

inline constexpr sellp<const ValueType, const IndexType> as_const(
) const#

Returns a const view of the same values

inline constexpr ValueType &val_at(
size_type row,
size_type slice_set,
size_type idx,
) const#

accessing the value of the idx-th element within the given row

inline constexpr IndexType &col_at(
size_type row,
size_type slice_set,
size_type idx,
) const#

accessing the column index of the idx-th element within the given row

template<typename ValueType, typename IndexType>
struct hybrid#

Non-owning view of a matrix::Hybrid to be used inside device kernels. This type is used to provide a simple and stable ABI for passing data between libraries.

Template Parameters:
  • ValueType – the value type used to store matrix values.

  • IndexType – the index type used to store matrix columns.

Public Functions

inline constexpr hybrid(
ell<ValueType, IndexType> ell_,
coo<ValueType, IndexType> coo_,
)#

Constructs a hybrid view

inline constexpr hybrid<const ValueType, const IndexType> as_const(
) const#

Returns a const view of the same values

See also