Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
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>

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. More...
 
 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. More...
 
 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. More...
 
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)
 
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. More...
 
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. More...
 
void sum_duplicates ()
 Sums up all duplicate entries pointing to the same non-zero location. More...
 
std::shared_ptr< const Executorget_executor () const
 Returns the executor used to store the device_matrix_data entries. More...
 
dim< 2 > get_size () const
 Returns the dimensions of the matrix. More...
 
size_type get_num_elems () const
 Returns the number of stored elements of the matrix. More...
 
size_type get_num_stored_elements () const
 Returns the number of stored elements of the matrix. More...
 
index_type * get_row_idxs ()
 Returns a pointer to the row index array. More...
 
const index_type * get_const_row_idxs () const
 Returns a pointer to the constant row index array. More...
 
index_type * get_col_idxs ()
 Returns a pointer to the column index array. More...
 
const index_type * get_const_col_idxs () const
 Returns a pointer to the constant column index array. More...
 
value_type * get_values ()
 Returns a pointer to the value array. More...
 
const value_type * get_const_values () const
 Returns a pointer to the constant value array. More...
 
void resize_and_reset (size_type new_num_entries)
 Resizes the internal storage to the given number of stored matrix entries. More...
 
void resize_and_reset (dim< 2 > new_size, size_type new_num_entries)
 Resizes the matrix and internal storage to the given dimensions. More...
 
arrays empty_out ()
 Moves out the internal arrays of the device_matrix_data object and resets it to an empty 0x0 matrix. More...
 

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. More...
 

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
ValueTypethe type used to store matrix values
IndexTypethe 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
execthe executor to be used to store the matrix entries
sizethe matrix dimensions
num_entriesthe 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
execthe executor to be used to store the matrix entries
datathe 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
sizethe matrix dimensions
valuesthe array containing the matrix values
col_idxsthe array containing the matrix column indices
row_idxsthe 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

Parameters
sizethe matrix dimensions
valuesthe array containing the matrix values
col_idxsthe array containing the matrix column indices
row_idxsthe 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, int32 >::read().

◆ create_from_host()

template<typename ValueType, typename IndexType>
static 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
execthe executor to create the device_matrix_data on.
datathe 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

References gko::array< ValueType >::get_data().

◆ 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

References gko::array< ValueType >::get_const_data().

◆ 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

References gko::array< ValueType >::get_const_data().

◆ 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

References gko::array< ValueType >::get_const_data().

◆ 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.

References gko::array< ValueType >::get_executor().

◆ 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.

References gko::device_matrix_data< ValueType, IndexType >::get_num_stored_elements().

◆ 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.

References gko::array< ValueType >::get_size().

Referenced by gko::device_matrix_data< ValueType, IndexType >::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

References gko::array< ValueType >::get_data().

◆ 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

References gko::array< ValueType >::get_data().

◆ 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_sizethe new matrix dimensions.
new_num_entriesthe 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_entriesthe 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: