Eigen::internal::UniformRandomGenerator< T > Class Template Reference

#include <TensorRandom.h>

Public Member Functions

EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UniformRandomGenerator (uint64_t seed=0)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UniformRandomGenerator (const UniformRandomGenerator &other)
 
template<typename Index >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator() (Index i) const
 
template<typename Packet , typename Index >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp (Index i) const
 

Static Public Attributes

static constexpr bool PacketAccess = true
 

Private Attributes

uint64_t m_state
 

Constructor & Destructor Documentation

◆ UniformRandomGenerator() [1/2]

126  {
127  m_state = PCG_XSH_RS_state(seed);
128 #ifdef EIGEN_USE_SYCL
129  // In SYCL it is not possible to build PCG_XSH_RS_state in one step.
130  // Therefore, we need two steps to initializate the m_state.
131  // IN SYCL, the constructor of the functor is s called on the CPU
132  // and we get the clock seed here from the CPU. However, This seed is
133  // the same for all the thread. As unlike CUDA, the thread.ID, BlockID, etc is not a global function.
134  // and only available on the Operator() function (which is called on the GPU).
135  // Thus for CUDA (((CLOCK + global_thread_id)* 6364136223846793005ULL) + 0xda3e39cb94b95bdbULL) is passed to each
136  // thread but for SYCL ((CLOCK * 6364136223846793005ULL) + 0xda3e39cb94b95bdbULL) is passed to each thread and each
137  // thread adds the (global_thread_id* 6364136223846793005ULL) for itself only once, in order to complete the
138  // construction similar to CUDA Therefore, the thread Id injection is not available at this stage.
139  // However when the operator() is called the thread ID will be available. So inside the operator,
140  // we add the thrreadID, BlockId,... (which is equivalent of i)
141  // to the seed and construct the unique m_state per thead similar to cuda.
142  m_exec_once = false;
143 #endif
144  }
uint64_t m_state
Definition: TensorRandom.h:185
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE uint64_t PCG_XSH_RS_state(uint64_t seed)
Definition: TensorRandom.h:41

References Eigen::internal::UniformRandomGenerator< T >::m_state, and Eigen::internal::PCG_XSH_RS_state().

◆ UniformRandomGenerator() [2/2]

145  {
146  m_state = other.m_state;
147 #ifdef EIGEN_USE_SYCL
148  m_exec_once = other.m_exec_once;
149 #endif
150  }

References Eigen::internal::UniformRandomGenerator< T >::m_state.

Member Function Documentation

◆ operator()()

template<typename T >
template<typename Index >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T Eigen::internal::UniformRandomGenerator< T >::operator() ( Index  i) const
inline
153  {
154 #ifdef EIGEN_USE_SYCL
155  if (!m_exec_once) {
156  // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread
157  // The (i * 6364136223846793005ULL) is the remaining part of the PCG_XSH_RS_state on the GPU side
158  m_state += (i * 6364136223846793005ULL);
159  m_exec_once = true;
160  }
161 #endif
162  T result = RandomToTypeUniform<T>(&m_state, i);
163  return result;
164  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References i, and Eigen::internal::UniformRandomGenerator< T >::m_state.

◆ packetOp()

template<typename T >
template<typename Packet , typename Index >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet Eigen::internal::UniformRandomGenerator< T >::packetOp ( Index  i) const
inline
167  {
168  const int packetSize = internal::unpacket_traits<Packet>::size;
169  EIGEN_ALIGN_MAX T values[packetSize];
170 #ifdef EIGEN_USE_SYCL
171  if (!m_exec_once) {
172  // This is the second stage of adding thread Id to the CPU clock seed and build unique seed per thread
173  m_state += (i * 6364136223846793005ULL);
174  m_exec_once = true;
175  }
176 #endif
178  for (int j = 0; j < packetSize; ++j) {
179  values[j] = RandomToTypeUniform<T>(&m_state, i);
180  }
181  return internal::pload<Packet>(values);
182  }
#define EIGEN_ALIGN_MAX
Definition: ConfigureVectorization.h:146
#define EIGEN_UNROLL_LOOP
Definition: Macros.h:1298
@ size
Definition: GenericPacketMath.h:139
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References EIGEN_ALIGN_MAX, EIGEN_UNROLL_LOOP, i, j, and Eigen::internal::UniformRandomGenerator< T >::m_state.

Member Data Documentation

◆ m_state

◆ PacketAccess

template<typename T >
constexpr bool Eigen::internal::UniformRandomGenerator< T >::PacketAccess = true
staticconstexpr

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