https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Attributes | List of all members
Moose::Kokkos::Thread< thread_id_type, max_dimension > Class Template Reference

The Kokkos thread object that aids in converting the one-dimensional thread index into multi-dimensional thread indices. More...

#include <KokkosThread.h>

Public Types

using id_type = thread_id_type
 

Public Member Functions

template<typename... size_type>
void resize (size_type... sizes)
 Set the thread pool size and dimension. More...
 
KOKKOS_FUNCTION thread_id_type size () const
 Get the total thread pool size. More...
 
KOKKOS_FUNCTION thread_id_type size (const unsigned int dim) const
 Get the size of each dimension. More...
 
KOKKOS_FUNCTION thread_id_type operator() (const thread_id_type tid, const unsigned int dim) const
 Get the multi-dimensional thread index of a dimension given a one-dimensional thread index. More...
 

Protected Attributes

thread_id_type _size = 0
 Total thread pool size. More...
 
unsigned int _dim = 0
 Thread pool dimension. More...
 
thread_id_type _dims [max_dimension]
 Thread pool size of each dimension. More...
 
thread_id_type _strides [max_dimension]
 Thread pool stride of each dimension. More...
 

Detailed Description

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
class Moose::Kokkos::Thread< thread_id_type, max_dimension >

The Kokkos thread object that aids in converting the one-dimensional thread index into multi-dimensional thread indices.

Definition at line 29 of file KokkosThread.h.

Member Typedef Documentation

◆ id_type

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
using Moose::Kokkos::Thread< thread_id_type, max_dimension >::id_type = thread_id_type

Definition at line 37 of file KokkosThread.h.

Member Function Documentation

◆ operator()()

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
KOKKOS_FUNCTION thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::operator() ( const thread_id_type  tid,
const unsigned int  dim 
) const
inline

Get the multi-dimensional thread index of a dimension given a one-dimensional thread index.

Parameters
tidThe one-dimensional thread index
dimfor which the multi-dimensional thread index is to be returned
Returns
The multi-dimensional thread index of the dimension

Definition at line 68 of file KokkosThread.h.

69  {
70  KOKKOS_ASSERT(dim < _dim);
71 
72  return (tid / _strides[dim]) % _dims[dim];
73  }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
thread_id_type _dims[max_dimension]
Thread pool size of each dimension.
Definition: KokkosThread.h:88
thread_id_type _strides[max_dimension]
Thread pool stride of each dimension.
Definition: KokkosThread.h:92
unsigned int _dim
Thread pool dimension.
Definition: KokkosThread.h:84

◆ resize()

template<typename thread_id_type , unsigned int max_dimension>
template<typename... size_type>
void Moose::Kokkos::Thread< thread_id_type, max_dimension >::resize ( size_type...  sizes)

Set the thread pool size and dimension.

Parameters
sizesThe size of each dimension

Definition at line 99 of file KokkosThread.h.

100 {
101  static_assert((std::is_convertible<size_type, thread_id_type>::value && ...),
102  "All arguments must be convertible to thread_id_type");
103  static_assert(sizeof...(sizes) <= max_dimension, "Number of arguments exceeds maximum dimension");
104 
105  std::vector<thread_id_type> dims;
106  (dims.push_back(sizes), ...);
107 
108  uint64_t size = 1;
109  _dim = dims.size();
110 
111  for (unsigned int dim = 0; dim < _dim; ++dim)
112  {
113  _dims[dim] = dims[dim];
114  _strides[dim] = dim ? _strides[dim - 1] * dims[dim - 1] : 1;
115  size *= dims[dim];
116  }
117 
119  mooseError("Kokkos thread error: the dimensions provided (",
120  Moose::stringify(dims),
121  ") has the total size of ",
122  size,
123  " which exceeds the limit of ",
124  MooseUtils::prettyCppType<thread_id_type>(),
125  ".");
126 
127  _size = size;
128 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
auto max(const L &left, const R &right)
thread_id_type _dims[max_dimension]
Thread pool size of each dimension.
Definition: KokkosThread.h:88
thread_id_type _strides[max_dimension]
Thread pool stride of each dimension.
Definition: KokkosThread.h:92
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
thread_id_type _size
Total thread pool size.
Definition: KokkosThread.h:80
unsigned int _dim
Thread pool dimension.
Definition: KokkosThread.h:84
KOKKOS_FUNCTION thread_id_type size() const
Get the total thread pool size.
Definition: KokkosThread.h:50

◆ size() [1/2]

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
KOKKOS_FUNCTION thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::size ( ) const
inline

Get the total thread pool size.

Returns
The total thread pool size

Definition at line 50 of file KokkosThread.h.

Referenced by Moose::Kokkos::ADKernel::operator()(), Moose::Kokkos::ADIntegratedBC::operator()(), Moose::Kokkos::Kernel::operator()(), and Moose::Kokkos::IntegratedBC::operator()().

50 { return _size; }
thread_id_type _size
Total thread pool size.
Definition: KokkosThread.h:80

◆ size() [2/2]

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
KOKKOS_FUNCTION thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::size ( const unsigned int  dim) const
inline

Get the size of each dimension.

Parameters
dimThe dimension index
Returns
The dimension size

Definition at line 56 of file KokkosThread.h.

57  {
58  KOKKOS_ASSERT(dim < _dim);
59 
60  return _dims[dim];
61  }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
thread_id_type _dims[max_dimension]
Thread pool size of each dimension.
Definition: KokkosThread.h:88
unsigned int _dim
Thread pool dimension.
Definition: KokkosThread.h:84

Member Data Documentation

◆ _dim

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
unsigned int Moose::Kokkos::Thread< thread_id_type, max_dimension >::_dim = 0
protected

◆ _dims

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::_dims[max_dimension]
protected

◆ _size

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::_size = 0
protected

Total thread pool size.

Definition at line 80 of file KokkosThread.h.

Referenced by Moose::Kokkos::Thread< thread_id_type, max_dimension >::size().

◆ _strides

template<typename thread_id_type = ThreadID, unsigned int max_dimension = 4>
thread_id_type Moose::Kokkos::Thread< thread_id_type, max_dimension >::_strides[max_dimension]
protected

Thread pool stride of each dimension.

Definition at line 92 of file KokkosThread.h.

Referenced by Moose::Kokkos::Thread< thread_id_type, max_dimension >::operator()().


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