CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
cms::alpakatools::VecArray< T, maxSize > Class Template Reference

#include <VecArray.h>

Public Types

using self = VecArray< T, maxSize >
 
using value_t = T
 

Public Member Functions

constexpr T const & back () const
 
constexpr Tback ()
 
constexpr T const * begin () const
 
constexpr Tbegin ()
 
constexpr T const * data () const
 
template<typename TAcc , class... Ts>
ALPAKA_FN_ACC int emplace_back (const TAcc &acc, Ts &&...args)
 
template<class... Ts>
constexpr int emplace_back_unsafe (Ts &&...args)
 
constexpr bool empty () const
 
constexpr T const * end () const
 
constexpr Tend ()
 
constexpr bool full () const
 
constexpr Toperator[] (int i)
 
constexpr const Toperator[] (int i) const
 
constexpr T pop_back ()
 
template<typename TAcc >
ALPAKA_FN_ACC int push_back (const TAcc &acc, const T &element)
 
constexpr int push_back_unsafe (const T &element)
 
constexpr void reset ()
 
constexpr void resize (int size)
 
constexpr int size () const
 

Static Public Member Functions

static constexpr int capacity ()
 

Private Attributes

T m_data [maxSize]
 
int m_size
 

Detailed Description

template<class T, int maxSize>
class cms::alpakatools::VecArray< T, maxSize >

Definition at line 15 of file VecArray.h.

Member Typedef Documentation

◆ self

template<class T, int maxSize>
using cms::alpakatools::VecArray< T, maxSize >::self = VecArray<T, maxSize>

Definition at line 17 of file VecArray.h.

◆ value_t

template<class T, int maxSize>
using cms::alpakatools::VecArray< T, maxSize >::value_t = T

Definition at line 18 of file VecArray.h.

Member Function Documentation

◆ back() [1/2]

template<class T, int maxSize>
constexpr T const& cms::alpakatools::VecArray< T, maxSize >::back ( ) const
inline

Definition at line 45 of file VecArray.h.

45  {
46  if (m_size > 0) {
47  return m_data[m_size - 1];
48  } else
49  return T(); //undefined behaviour
50  }
long double T

◆ back() [2/2]

template<class T, int maxSize>
constexpr T& cms::alpakatools::VecArray< T, maxSize >::back ( )
inline

Definition at line 52 of file VecArray.h.

52  {
53  if (m_size > 0) {
54  return m_data[m_size - 1];
55  } else
56  return T(); //undefined behaviour
57  }
long double T

◆ begin() [1/2]

template<class T, int maxSize>
constexpr T const* cms::alpakatools::VecArray< T, maxSize >::begin ( void  ) const
inline

Definition at line 92 of file VecArray.h.

92 { return m_data; }

◆ begin() [2/2]

template<class T, int maxSize>
constexpr T* cms::alpakatools::VecArray< T, maxSize >::begin ( void  )
inline

Definition at line 94 of file VecArray.h.

94 { return m_data; }

◆ capacity()

template<class T, int maxSize>
static constexpr int cms::alpakatools::VecArray< T, maxSize >::capacity ( )
inlinestatic

Definition at line 100 of file VecArray.h.

100 { return maxSize; }

◆ data()

template<class T, int maxSize>
constexpr T const* cms::alpakatools::VecArray< T, maxSize >::data ( ) const
inline

Definition at line 101 of file VecArray.h.

101 { return m_data; }

◆ emplace_back()

template<class T, int maxSize>
template<typename TAcc , class... Ts>
ALPAKA_FN_ACC int cms::alpakatools::VecArray< T, maxSize >::emplace_back ( const TAcc &  acc,
Ts &&...  args 
)
inline

Definition at line 73 of file VecArray.h.

73  {
74  auto previousSize = alpaka::atomicAdd(acc, &m_size, 1, alpaka::hierarchy::Blocks{});
75  if (previousSize < maxSize) {
76  (new (&m_data[previousSize]) T(std::forward<Ts>(args)...));
77  return previousSize;
78  } else {
80  return -1;
81  }
82  }
T1 atomicSub(T1 *a, T2 b)
Definition: cudaCompat.h:73
std::vector< Block > Blocks
Definition: Block.h:99
long double T
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61

◆ emplace_back_unsafe()

template<class T, int maxSize>
template<class... Ts>
constexpr int cms::alpakatools::VecArray< T, maxSize >::emplace_back_unsafe ( Ts &&...  args)
inline

Definition at line 33 of file VecArray.h.

33  {
34  auto previousSize = m_size;
35  m_size++;
36  if (previousSize < maxSize) {
37  (new (&m_data[previousSize]) T(std::forward<Ts>(args)...));
38  return previousSize;
39  } else {
40  --m_size;
41  return -1;
42  }
43  }
long double T

◆ empty()

template<class T, int maxSize>
constexpr bool cms::alpakatools::VecArray< T, maxSize >::empty ( void  ) const
inline

Definition at line 103 of file VecArray.h.

103 { return 0 == m_size; }

◆ end() [1/2]

template<class T, int maxSize>
constexpr T const* cms::alpakatools::VecArray< T, maxSize >::end ( void  ) const
inline

Definition at line 93 of file VecArray.h.

93 { return m_data + m_size; }

◆ end() [2/2]

template<class T, int maxSize>
constexpr T* cms::alpakatools::VecArray< T, maxSize >::end ( void  )
inline

Definition at line 95 of file VecArray.h.

95 { return m_data + m_size; }

◆ full()

template<class T, int maxSize>
constexpr bool cms::alpakatools::VecArray< T, maxSize >::full ( ) const
inline

Definition at line 104 of file VecArray.h.

◆ operator[]() [1/2]

template<class T, int maxSize>
constexpr T& cms::alpakatools::VecArray< T, maxSize >::operator[] ( int  i)
inline

Definition at line 97 of file VecArray.h.

97 { return m_data[i]; }

◆ operator[]() [2/2]

template<class T, int maxSize>
constexpr const T& cms::alpakatools::VecArray< T, maxSize >::operator[] ( int  i) const
inline

Definition at line 98 of file VecArray.h.

98 { return m_data[i]; }

◆ pop_back()

template<class T, int maxSize>
constexpr T cms::alpakatools::VecArray< T, maxSize >::pop_back ( )
inline

Definition at line 84 of file VecArray.h.

84  {
85  if (m_size > 0) {
86  auto previousSize = m_size--;
87  return m_data[previousSize - 1];
88  } else
89  return T();
90  }
long double T

◆ push_back()

template<class T, int maxSize>
template<typename TAcc >
ALPAKA_FN_ACC int cms::alpakatools::VecArray< T, maxSize >::push_back ( const TAcc &  acc,
const T element 
)
inline

Definition at line 61 of file VecArray.h.

61  {
62  auto previousSize = alpaka::atomicAdd(acc, &m_size, 1, alpaka::hierarchy::Blocks{});
63  if (previousSize < maxSize) {
64  m_data[previousSize] = element;
65  return previousSize;
66  } else {
68  return -1;
69  }
70  }
T1 atomicSub(T1 *a, T2 b)
Definition: cudaCompat.h:73
std::vector< Block > Blocks
Definition: Block.h:99
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61

◆ push_back_unsafe()

template<class T, int maxSize>
constexpr int cms::alpakatools::VecArray< T, maxSize >::push_back_unsafe ( const T element)
inline

Definition at line 20 of file VecArray.h.

20  {
21  auto previousSize = m_size;
22  m_size++;
23  if (previousSize < maxSize) {
24  m_data[previousSize] = element;
25  return previousSize;
26  } else {
27  --m_size;
28  return -1;
29  }
30  }

◆ reset()

template<class T, int maxSize>
constexpr void cms::alpakatools::VecArray< T, maxSize >::reset ( void  )
inline

Definition at line 99 of file VecArray.h.

99 { m_size = 0; }

◆ resize()

template<class T, int maxSize>
constexpr void cms::alpakatools::VecArray< T, maxSize >::resize ( int  size)
inline

Definition at line 102 of file VecArray.h.

102 { m_size = size; }
constexpr int size() const
Definition: VecArray.h:96

◆ size()

template<class T, int maxSize>
constexpr int cms::alpakatools::VecArray< T, maxSize >::size ( void  ) const
inline

Member Data Documentation

◆ m_data

template<class T, int maxSize>
T cms::alpakatools::VecArray< T, maxSize >::m_data[maxSize]
private

◆ m_size

template<class T, int maxSize>
int cms::alpakatools::VecArray< T, maxSize >::m_size
private