Ginkgo: gko::device_matrix_data< ValueType, IndexType > Class Template Reference

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
gko::device_matrix_data< ValueType, IndexType > Class Template Reference

This type is a device-side equivalent to matrix_data. More...

`#include <ginkgo/core/base/device_matrix_data.hpp>`

Inheritance diagram for gko::device_matrix_data< ValueType, IndexType >:
[legend]

## Classes
struct | arrays
| Stores the internal arrays of a device_matrix_data object. More...

## Public Types
using | value_type = ValueType
using | index_type = IndexType
using | nonzero_type = matrix_data_entry<value_type, index_type>
using | host_type = matrix_data<value_type, index_type>

## Public Member Functions
| device_matrix_data (std::shared_ptr< const Executor > exec, dim< 2 > size={}, size_type num_entries=0)
| Initializes a new device_matrix_data object.
| device_matrix_data (std::shared_ptr< const Executor > exec, const device_matrix_data &data)
| Initializes a device_matrix_data object by copying an existing object on another executor.
| device_matrix_data (std::shared_ptr< const Executor > exec, dim< 2 > size, array< index_type > row_idxs, array< index_type > col_idxs, array< value_type > values)
| Initializes a new device_matrix_data object from existing data.
template<typename InputValueType, typename RowIndexType, typename ColIndexType>
| device_matrix_data (std::shared_ptr< const Executor > exec, dim< 2 > size, std::initializer_list< RowIndexType > row_idxs, std::initializer_list< ColIndexType > col_idxs, std::initializer_list< InputValueType > values)
| Initializes a new device_matrix_data object from existing data.
host_type | copy_to_host () const
| Copies the device_matrix_data entries to the host to return a regular matrix_data object with the same dimensions and entries.
void | fill_zero ()
| Fills the matrix entries with zeros.
void | sort_row_major ()
| Sorts the matrix entries in row-major order This means that they will be sorted by row index first, and then by column index inside each row.
void | remove_zeros ()
| Removes all zero entries from the storage.
void | sum_duplicates ()
| Sums up all duplicate entries pointing to the same non-zero location.
std::shared_ptr< const Executor > | get_executor () const
| Returns the executor used to store the device_matrix_data entries.
dim< 2 > | get_size () const
| Returns the dimensions of the matrix.
size_type | get_num_elems () const
| Returns the number of stored elements of the matrix.
size_type | get_num_stored_elements () const
| Returns the number of stored elements of the matrix.
index_type * | get_row_idxs ()
| Returns a pointer to the row index array.
const index_type * | get_const_row_idxs () const
| Returns a pointer to the constant row index array.
index_type * | get_col_idxs ()
| Returns a pointer to the column index array.
const index_type * | get_const_col_idxs () const
| Returns a pointer to the constant column index array.
value_type * | get_values ()
| Returns a pointer to the value array.
const value_type * | get_const_values () const
| Returns a pointer to the constant value array.
void | resize_and_reset (size_type new_num_entries)
| Resizes the internal storage to the given number of stored matrix entries.
void | resize_and_reset (dim< 2 > new_size, size_type new_num_entries)
| Resizes the matrix and internal storage to the given dimensions.
arrays | empty_out ()
| Moves out the internal arrays of the device_matrix_data object and resets it to an empty 0x0 matrix.

## Static Public Member Functions
static device_matrix_data | create_from_host (std::shared_ptr< const Executor > exec, const host_type &data)
| Creates a device_matrix_data object from the given host data on the given executor.

## Detailed Description

template<typename ValueType, typename IndexType>
class gko::device_matrix_data< ValueType, IndexType >

This type is a device-side equivalent to matrix_data.

It stores the data necessary to initialize any matrix format in Ginkgo in individual value, column and row index arrays together with associated matrix dimensions. matrix_data uses array-of-Structs storage (AoS), while device_matrix_data uses Struct-of-Arrays (SoA).

Note
  To be used with a Ginkgo matrix type, the entry array must be sorted in row-major order, i.e. by row index, then by column index within rows. This can be achieved by calling the sort_row_major function.
  The data must not contain any duplicate (row, column) pairs.

Template Parameters

  ValueType | the type used to store matrix values
  IndexType | the type used to store matrix row and column indices

## Constructor & Destructor Documentation

## ◆ device_matrix_data() [1/4]

template<typename ValueType, typename IndexType>

gko::device_matrix_data< ValueType, IndexType >::device_matrix_data | ( | std::shared_ptr< const Executor > | exec,
|  | dim< 2 > | size = {},
|  | size_type | num_entries = 0 )
| explicit

Initializes a new device_matrix_data object.

It uses the given executor to allocate storage for the given number of entries and matrix dimensions.

Parameters

  exec | the executor to be used to store the matrix entries
  size | the matrix dimensions
  num_entries | the number of entries to be stored

## ◆ device_matrix_data() [2/4]

template<typename ValueType, typename IndexType>

gko::device_matrix_data< ValueType, IndexType >::device_matrix_data | ( | std::shared_ptr< const Executor > | exec,
|  | const device_matrix_data< ValueType, IndexType > & | data )

Initializes a device_matrix_data object by copying an existing object on another executor.

Parameters

  exec | the executor to be used to store the matrix entries
  data | the device_matrix data object to copy, potentially stored on another executor.

## ◆ device_matrix_data() [3/4]

template<typename ValueType, typename IndexType>

gko::device_matrix_data< ValueType, IndexType >::device_matrix_data | ( | std::shared_ptr< const Executor > | exec,
|  | dim< 2 > | size,
|  | array< index_type > | row_idxs,
|  | array< index_type > | col_idxs,
|  | array< value_type > | values )

Initializes a new device_matrix_data object from existing data.

Parameters

  size | the matrix dimensions
  values | the array containing the matrix values
  col_idxs | the array containing the matrix column indices
  row_idxs | the array containing the matrix row indices

## ◆ device_matrix_data() [4/4]

template<typename ValueType, typename IndexType>
template<typename InputValueType, typename RowIndexType, typename ColIndexType>

gko::device_matrix_data< ValueType, IndexType >::device_matrix_data | ( | std::shared_ptr< const Executor > | exec,
|  | dim< 2 > | size,
|  | std::initializer_list< RowIndexType > | row_idxs,
|  | std::initializer_list< ColIndexType > | col_idxs,
|  | std::initializer_list< InputValueType > | values )
| inline

Initializes a new device_matrix_data object from existing data.

Parameters

  size | the matrix dimensions
  values | the array containing the matrix values
  col_idxs | the array containing the matrix column indices
  row_idxs | the array containing the matrix row indices

## Member Function Documentation

## ◆ copy_to_host()

template<typename ValueType, typename IndexType>

host_type gko::device_matrix_data< ValueType, IndexType >::copy_to_host | ( |  | ) | const

Copies the device_matrix_data entries to the host to return a regular matrix_data object with the same dimensions and entries.

Returns
  a matrix_data object with the same dimensions and entries.

Referenced by gko::ReadableFromMatrixData< ValueType, IndexType >::read().

## ◆ create_from_host()

template<typename ValueType, typename IndexType>

device_matrix_data gko::device_matrix_data< ValueType, IndexType >::create_from_host | ( | std::shared_ptr< const Executor > | exec,
|  | const host_type & | data )
| static

Creates a device_matrix_data object from the given host data on the given executor.

Parameters

  exec | the executor to create the device_matrix_data on.
  data | the data to be wrapped or copied into a device_matrix_data.

Returns
  a device_matrix_data object with the same size and entries as data copied to the device executor.

## ◆ empty_out()

template<typename ValueType, typename IndexType>

arrays gko::device_matrix_data< ValueType, IndexType >::empty_out | ( |  | ) |

Moves out the internal arrays of the device_matrix_data object and resets it to an empty 0x0 matrix.

Returns
  a struct containing the internal arrays.

## ◆ get_col_idxs()

template<typename ValueType, typename IndexType>

index_type * gko::device_matrix_data< ValueType, IndexType >::get_col_idxs | ( |  | ) |
| inline

Returns a pointer to the column index array.

Returns
  a pointer to the column index array

## ◆ get_const_col_idxs()

template<typename ValueType, typename IndexType>

const index_type * gko::device_matrix_data< ValueType, IndexType >::get_const_col_idxs | ( |  | ) | const
| inline

Returns a pointer to the constant column index array.

Returns
  a pointer to the constant column index array

## ◆ get_const_row_idxs()

template<typename ValueType, typename IndexType>

const index_type * gko::device_matrix_data< ValueType, IndexType >::get_const_row_idxs | ( |  | ) | const
| inline

Returns a pointer to the constant row index array.

Returns
  a pointer to the constant row index array

## ◆ get_const_values()

template<typename ValueType, typename IndexType>

const value_type * gko::device_matrix_data< ValueType, IndexType >::get_const_values | ( |  | ) | const
| inline

Returns a pointer to the constant value array.

Returns
  a pointer to the constant value array

## ◆ get_executor()

template<typename ValueType, typename IndexType>

std::shared_ptr< const Executor > gko::device_matrix_data< ValueType, IndexType >::get_executor | ( |  | ) | const
| inline

Returns the executor used to store the device_matrix_data entries.

Returns
  the executor used to store the device_matrix_data entries.

## ◆ get_num_elems()

template<typename ValueType, typename IndexType>

size_type gko::device_matrix_data< ValueType, IndexType >::get_num_elems | ( |  | ) | const
| inline

Returns the number of stored elements of the matrix.

Returns
  the number of stored elements of the matrix.

## ◆ get_num_stored_elements()

template<typename ValueType, typename IndexType>

size_type gko::device_matrix_data< ValueType, IndexType >::get_num_stored_elements | ( |  | ) | const
| inline

Returns the number of stored elements of the matrix.

Returns
  the number of stored elements of the matrix.

Referenced by gko::device_matrix_data< ValueType, int64 >::get_num_elems().

## ◆ get_row_idxs()

template<typename ValueType, typename IndexType>

index_type * gko::device_matrix_data< ValueType, IndexType >::get_row_idxs | ( |  | ) |
| inline

Returns a pointer to the row index array.

Returns
  a pointer to the row index array

## ◆ get_size()

template<typename ValueType, typename IndexType>

dim< 2 > gko::device_matrix_data< ValueType, IndexType >::get_size | ( |  | ) | const
| inline

Returns the dimensions of the matrix.

Returns
  the dimensions of the matrix.

## ◆ get_values()

template<typename ValueType, typename IndexType>

value_type * gko::device_matrix_data< ValueType, IndexType >::get_values | ( |  | ) |
| inline

Returns a pointer to the value array.

Returns
  a pointer to the value array

## ◆ remove_zeros()

template<typename ValueType, typename IndexType>

void gko::device_matrix_data< ValueType, IndexType >::remove_zeros | ( |  | ) |

Removes all zero entries from the storage.

This does not modify the storage if there are no zero entries, and keeps the relative order of nonzero entries otherwise.

## ◆ resize_and_reset() [1/2]

template<typename ValueType, typename IndexType>

void gko::device_matrix_data< ValueType, IndexType >::resize_and_reset | ( | dim< 2 > | new_size,
|  | size_type | new_num_entries )

Resizes the matrix and internal storage to the given dimensions.

The resulting storage should be assumed uninitialized.

Parameters

  new_size | the new matrix dimensions.
  new_num_entries | the new number of stored matrix entries.

## ◆ resize_and_reset() [2/2]

template<typename ValueType, typename IndexType>

void gko::device_matrix_data< ValueType, IndexType >::resize_and_reset | ( | size_type | new_num_entries | ) |

Resizes the internal storage to the given number of stored matrix entries.

The resulting storage should be assumed uninitialized.

Parameters

  new_num_entries | the new number of stored matrix entries.

## ◆ sum_duplicates()

template<typename ValueType, typename IndexType>

void gko::device_matrix_data< ValueType, IndexType >::sum_duplicates | ( |  | ) |

Sums up all duplicate entries pointing to the same non-zero location.

The output will be sorted in row-major order, and it will only reallocate if duplicates exist.

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

- ginkgo/core/base/device_matrix_data.hpp