https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | List of all members
Moose::Kokkos::JaggedArrayBase< T, inner, outer > Class Template Reference

The base class for Kokkos jagged arrays. More...

#include <KokkosJaggedArray.h>

Public Member Functions

void create (const std::vector< dof_id_type > &n)
 Allocate outer array. More...
 
void reserve (const std::array< dof_id_type, outer > &index, const std::array< dof_id_type, inner > &dimension)
 Reserve inner array for an outer array entry. More...
 
void finalize ()
 Setup array structure. More...
 
void copyToDevice ()
 Copy data from host to device. More...
 
void copyToHost ()
 Copy data from device to host. More...
 
auto & array ()
 Get the underlying data array. More...
 
KOKKOS_FUNCTION bool isFinalized () const
 Get whether the array is finalized. More...
 
KOKKOS_FUNCTION dof_id_type size () const
 Get the total data array size. More...
 
KOKKOS_FUNCTION dof_id_type n () const
 Get the total outer array size. More...
 
KOKKOS_FUNCTION dof_id_type n (unsigned int dim) const
 Get the size of a dimension of the outer array. More...
 
KOKKOS_FUNCTION auto operator[] (dof_id_type i) const
 Get an inner array. More...
 

Protected Attributes

Array< T > _data
 Sequential data array. More...
 
Array< JaggedArrayInnerDim< inner >, outer > _dims
 Dimension information of each inner array. More...
 
Array< dof_id_type, outer > _offsets
 Starting offset of each inner array into the sequential data array. More...
 
bool _finalized
 Whether the array was finalized. More...
 

Detailed Description

template<typename T, unsigned int inner, unsigned int outer>
class Moose::Kokkos::JaggedArrayBase< T, inner, outer >

The base class for Kokkos jagged arrays.

A Kokkos jagged array aids in treating jagged arrays conveniently and efficiently by using a sequential data storage and providing multi-dimensional indexing using internal dope vectors. A jagged array is divided into the inner and outer arrays. The outer array is the regular part of a jagged array. Each entry of the outer array can hold an inner array, whose size can vary with each other. Calling create() will allocate the outer array, and inner arrays should be reserved one-by-one through reserve(). Once the array structure is set, finalize() should be called. A finalized array cannot be restructured unless it is reset completely by calling create() again. The inner array returned by operator() or operator[] using the outer array index is held in a temporary wrapper object. To avoid the overhead of temporary object creation, it is recommended to store the object locally.

Template Parameters
TThe data type
innerThe inner array dimension size
outerThe outer array dimension size

Definition at line 221 of file KokkosJaggedArray.h.

Member Function Documentation

◆ array()

template<typename T, unsigned int inner, unsigned int outer>
auto& Moose::Kokkos::JaggedArrayBase< T, inner, outer >::array ( )
inline

Get the underlying data array.

Returns
The data array

Definition at line 263 of file KokkosJaggedArray.h.

263 { return _data; }
Array< T > _data
Sequential data array.

◆ copyToDevice()

template<typename T, unsigned int inner, unsigned int outer>
void Moose::Kokkos::JaggedArrayBase< T, inner, outer >::copyToDevice ( )
inline

Copy data from host to device.

Definition at line 244 of file KokkosJaggedArray.h.

245  {
246  mooseAssert(_finalized, "KokkosJaggedArray not finalized.");
247 
248  _data.copyToDevice();
249  }
Array< T > _data
Sequential data array.
bool _finalized
Whether the array was finalized.

◆ copyToHost()

template<typename T, unsigned int inner, unsigned int outer>
void Moose::Kokkos::JaggedArrayBase< T, inner, outer >::copyToHost ( )
inline

Copy data from device to host.

Definition at line 253 of file KokkosJaggedArray.h.

254  {
255  mooseAssert(_finalized, "KokkosJaggedArray not finalized.");
256 
257  _data.copyToHost();
258  }
Array< T > _data
Sequential data array.
bool _finalized
Whether the array was finalized.

◆ create()

template<typename T , unsigned int inner, unsigned int outer>
void Moose::Kokkos::JaggedArrayBase< T, inner, outer >::create ( const std::vector< dof_id_type > &  n)

Allocate outer array.

Parameters
nThe vector containing the size of each dimension for the outer array

Definition at line 328 of file KokkosJaggedArray.h.

Referenced by Moose::Kokkos::JaggedArray< T, inner, 1 >::create(), Moose::Kokkos::JaggedArray< T, inner, 2 >::create(), and Moose::Kokkos::JaggedArray< T, inner, 3 >::create().

329 {
330  _data.destroy();
331  _offsets.create(n);
332  _dims.create(n);
333 
334  _finalized = false;
335 }
Array< JaggedArrayInnerDim< inner >, outer > _dims
Dimension information of each inner array.
Array< T > _data
Sequential data array.
bool _finalized
Whether the array was finalized.
KOKKOS_FUNCTION dof_id_type n() const
Get the total outer array size.
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.

◆ finalize()

template<typename T , unsigned int inner, unsigned int outer>
void Moose::Kokkos::JaggedArrayBase< T, inner, outer >::finalize ( )

Setup array structure.

Definition at line 366 of file KokkosJaggedArray.h.

367 {
368  mooseAssert(!_finalized, "KokkosJaggedArray already finalized.");
369 
370  dof_id_type stride = 1;
371 
372  for (dof_id_type o = 0; o < _offsets.size(); ++o)
373  {
374  stride = 1;
375 
376  for (unsigned int i = 0; i < inner; ++i)
377  stride *= _dims[o][i];
378 
379  _offsets[o] = stride;
380  }
381 
382  std::exclusive_scan(_offsets.begin(), _offsets.end(), _offsets.begin(), 0);
383 
384  _dims.copyToDevice();
385  _offsets.copyToDevice();
386  _data.create(_offsets.last() + stride);
387 
388  _finalized = true;
389 }
Array< JaggedArrayInnerDim< inner >, outer > _dims
Dimension information of each inner array.
Array< T > _data
Sequential data array.
bool _finalized
Whether the array was finalized.
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.
uint8_t dof_id_type

◆ isFinalized()

template<typename T, unsigned int inner, unsigned int outer>
KOKKOS_FUNCTION bool Moose::Kokkos::JaggedArrayBase< T, inner, outer >::isFinalized ( ) const
inline

Get whether the array is finalized.

Returns
Whether the array is finalized

Definition at line 269 of file KokkosJaggedArray.h.

269 { return _finalized; }
bool _finalized
Whether the array was finalized.

◆ n() [1/2]

template<typename T, unsigned int inner, unsigned int outer>
KOKKOS_FUNCTION dof_id_type Moose::Kokkos::JaggedArrayBase< T, inner, outer >::n ( ) const
inline

Get the total outer array size.

Returns
The total outer array size

Definition at line 279 of file KokkosJaggedArray.h.

279 { return _offsets.size(); }
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.

◆ n() [2/2]

template<typename T, unsigned int inner, unsigned int outer>
KOKKOS_FUNCTION dof_id_type Moose::Kokkos::JaggedArrayBase< T, inner, outer >::n ( unsigned int  dim) const
inline

Get the size of a dimension of the outer array.

Parameters
dimThe dimension index
Returns
The size of the dimension of the outer array

Definition at line 285 of file KokkosJaggedArray.h.

285 { return _offsets.n(dim); }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:162
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.

◆ operator[]()

template<typename T, unsigned int inner, unsigned int outer>
KOKKOS_FUNCTION auto Moose::Kokkos::JaggedArrayBase< T, inner, outer >::operator[] ( dof_id_type  i) const
inline

Get an inner array.

Parameters
iThe dimensionless outer array index
Returns
The inner array wrapper object

Definition at line 291 of file KokkosJaggedArray.h.

292  {
293  auto data = &_data[_offsets[i]];
294  const auto & dim = _dims[i];
295 
296  return JaggedArrayInnerData<T, inner>(data, dim);
297  }
Array< JaggedArrayInnerDim< inner >, outer > _dims
Dimension information of each inner array.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:162
Array< T > _data
Sequential data array.
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.

◆ reserve()

template<typename T , unsigned int inner, unsigned int outer>
void Moose::Kokkos::JaggedArrayBase< T, inner, outer >::reserve ( const std::array< dof_id_type, outer > &  index,
const std::array< dof_id_type, inner > &  dimension 
)

Reserve inner array for an outer array entry.

Parameters
indexThe array containing the index for the outer array
dimensionThe array containing the size of each dimension for the inner array

Definition at line 339 of file KokkosJaggedArray.h.

341 {
342  mooseAssert(!_finalized, "KokkosJaggedArray already finalized.");
343 
344  dof_id_type idx = 0;
345  dof_id_type stride = 1;
346 
347  for (unsigned int o = 0; o < outer; ++o)
348  {
349  idx += index[o] * stride;
350  stride *= _offsets.n(o);
351  }
352 
353  stride = 1;
354 
355  for (unsigned int i = 0; i < inner; ++i)
356  {
357  stride *= dimension[i];
358 
359  _dims[idx].dim[i] = dimension[i];
360  _dims[idx].stride[i] = stride;
361  }
362 }
Array< JaggedArrayInnerDim< inner >, outer > _dims
Dimension information of each inner array.
bool _finalized
Whether the array was finalized.
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
uint8_t dof_id_type

◆ size()

template<typename T, unsigned int inner, unsigned int outer>
KOKKOS_FUNCTION dof_id_type Moose::Kokkos::JaggedArrayBase< T, inner, outer >::size ( ) const
inline

Get the total data array size.

Returns
The total data array size

Definition at line 274 of file KokkosJaggedArray.h.

274 { return _data.size(); }
Array< T > _data
Sequential data array.

Member Data Documentation

◆ _data

template<typename T, unsigned int inner, unsigned int outer>
Array<T> Moose::Kokkos::JaggedArrayBase< T, inner, outer >::_data
protected

◆ _dims

template<typename T, unsigned int inner, unsigned int outer>
Array<JaggedArrayInnerDim<inner>, outer> Moose::Kokkos::JaggedArrayBase< T, inner, outer >::_dims
protected

Dimension information of each inner array.

Definition at line 308 of file KokkosJaggedArray.h.

Referenced by Moose::Kokkos::JaggedArrayBase< T, inner, 1 >::operator[]().

◆ _finalized

template<typename T, unsigned int inner, unsigned int outer>
bool Moose::Kokkos::JaggedArrayBase< T, inner, outer >::_finalized
protected

◆ _offsets

template<typename T, unsigned int inner, unsigned int outer>
Array<dof_id_type, outer> Moose::Kokkos::JaggedArrayBase< T, inner, outer >::_offsets
protected

Starting offset of each inner array into the sequential data array.

Definition at line 312 of file KokkosJaggedArray.h.

Referenced by Moose::Kokkos::JaggedArrayBase< T, inner, 1 >::n(), and Moose::Kokkos::JaggedArrayBase< T, inner, 1 >::operator[]().


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