CMS 3D CMS Logo

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

#include <VecArray.h>

Public Types

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

Public Member Functions

constexpr Tback () const
 
constexpr T const * begin () const
 
constexpr Tbegin ()
 
constexpr T const * data () const
 
template<class... Ts>
__device__ int emplace_back (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 ()
 
__device__ int push_back (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::cuda::VecArray< T, maxSize >

Definition at line 14 of file VecArray.h.

Member Typedef Documentation

◆ self

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

Definition at line 16 of file VecArray.h.

◆ value_t

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

Definition at line 17 of file VecArray.h.

Member Function Documentation

◆ back()

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

Definition at line 44 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data, and cms::cuda::VecArray< T, maxSize >::m_size.

44  {
45  if (m_size > 0) {
46  return m_data[m_size - 1];
47  } else
48  return T(); //undefined behaviour
49  }
T m_data[maxSize]
Definition: VecArray.h:98
long double T

◆ begin() [1/2]

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

Definition at line 83 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data.

83 { return m_data; }
T m_data[maxSize]
Definition: VecArray.h:98

◆ begin() [2/2]

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

Definition at line 85 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data.

85 { return m_data; }
T m_data[maxSize]
Definition: VecArray.h:98

◆ capacity()

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

Definition at line 91 of file VecArray.h.

References reco_skim_cfg_mod::maxSize.

◆ data()

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

Definition at line 92 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data.

92 { return m_data; }
T m_data[maxSize]
Definition: VecArray.h:98

◆ emplace_back()

template<class T , int maxSize>
template<class... Ts>
__device__ int cms::cuda::VecArray< T, maxSize >::emplace_back ( Ts &&...  args)
inline

Definition at line 64 of file VecArray.h.

References writedatasetfile::args, cms::cudacompat::atomicAdd(), cms::cudacompat::atomicSub(), cms::cuda::VecArray< T, maxSize >::m_data, cms::cuda::VecArray< T, maxSize >::m_size, and reco_skim_cfg_mod::maxSize.

64  {
65  auto previousSize = atomicAdd(&m_size, 1);
66  if (previousSize < maxSize) {
67  (new (&m_data[previousSize]) T(std::forward<Ts>(args)...));
68  return previousSize;
69  } else {
70  atomicSub(&m_size, 1);
71  return -1;
72  }
73  }
T1 atomicSub(T1 *a, T2 b)
Definition: cudaCompat.h:73
T m_data[maxSize]
Definition: VecArray.h:98
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::cuda::VecArray< T, maxSize >::emplace_back_unsafe ( Ts &&...  args)
inline

Definition at line 32 of file VecArray.h.

References writedatasetfile::args, cms::cuda::VecArray< T, maxSize >::m_data, cms::cuda::VecArray< T, maxSize >::m_size, and reco_skim_cfg_mod::maxSize.

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

◆ empty()

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

Definition at line 94 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_size.

94 { return 0 == m_size; }

◆ end() [1/2]

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

◆ end() [2/2]

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

◆ full()

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

◆ operator[]() [1/2]

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

Definition at line 88 of file VecArray.h.

References mps_fire::i, and cms::cuda::VecArray< T, maxSize >::m_data.

88 { return m_data[i]; }
T m_data[maxSize]
Definition: VecArray.h:98

◆ operator[]() [2/2]

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

Definition at line 89 of file VecArray.h.

References mps_fire::i, and cms::cuda::VecArray< T, maxSize >::m_data.

89 { return m_data[i]; }
T m_data[maxSize]
Definition: VecArray.h:98

◆ pop_back()

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

Definition at line 75 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data, and cms::cuda::VecArray< T, maxSize >::m_size.

75  {
76  if (m_size > 0) {
77  auto previousSize = m_size--;
78  return m_data[previousSize - 1];
79  } else
80  return T();
81  }
T m_data[maxSize]
Definition: VecArray.h:98
long double T

◆ push_back()

template<class T , int maxSize>
__device__ int cms::cuda::VecArray< T, maxSize >::push_back ( const T element)
inline

Definition at line 52 of file VecArray.h.

References cms::cudacompat::atomicAdd(), cms::cudacompat::atomicSub(), cms::cuda::VecArray< T, maxSize >::m_data, cms::cuda::VecArray< T, maxSize >::m_size, and reco_skim_cfg_mod::maxSize.

52  {
53  auto previousSize = atomicAdd(&m_size, 1);
54  if (previousSize < maxSize) {
55  m_data[previousSize] = element;
56  return previousSize;
57  } else {
58  atomicSub(&m_size, 1);
59  return -1;
60  }
61  }
T1 atomicSub(T1 *a, T2 b)
Definition: cudaCompat.h:73
T m_data[maxSize]
Definition: VecArray.h:98
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61

◆ push_back_unsafe()

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

Definition at line 19 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_data, cms::cuda::VecArray< T, maxSize >::m_size, and reco_skim_cfg_mod::maxSize.

19  {
20  auto previousSize = m_size;
21  m_size++;
22  if (previousSize < maxSize) {
23  m_data[previousSize] = element;
24  return previousSize;
25  } else {
26  --m_size;
27  return -1;
28  }
29  }
T m_data[maxSize]
Definition: VecArray.h:98

◆ reset()

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

Definition at line 90 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_size.

90 { m_size = 0; }

◆ resize()

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

Definition at line 93 of file VecArray.h.

References cms::cuda::VecArray< T, maxSize >::m_size, and cms::cuda::VecArray< T, maxSize >::size().

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

◆ size()

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

Member Data Documentation

◆ m_data

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

◆ m_size

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