21 #ifndef ROCRAND_SOBOL32_H_
22 #define ROCRAND_SOBOL32_H_
24 #include <hip/hip_runtime.h>
26 namespace rocrand_device
29 template<
bool UseSharedVectors>
34 unsigned int vectors[32];
36 __forceinline__ __device__ __host__
41 __forceinline__ __device__ __host__
42 sobol32_state(
const unsigned int d,
const unsigned int i,
const unsigned int* vectors)
45 for(
int k = 0; k < 32; k++)
47 this->vectors[k] = vectors[k];
53 struct sobol32_state<true>
57 const unsigned int* vectors;
59 __forceinline__ __device__ __host__
64 __forceinline__ __device__ __host__
65 sobol32_state(
const unsigned int d,
const unsigned int i,
const unsigned int* vectors)
66 : d(d), i(i), vectors(vectors)
70 template<
bool UseSharedVectors>
74 typedef struct sobol32_state<UseSharedVectors> sobol32_state;
76 __forceinline__ __device__ __host__
80 __forceinline__ __device__ __host__
81 sobol32_engine(
const unsigned int* vectors,
const unsigned int offset)
82 : m_state(0, 0, vectors)
84 discard_state(offset);
88 __forceinline__ __device__ __host__
89 void discard(
unsigned int offset)
91 discard_state(offset);
94 __forceinline__ __device__ __host__
101 __forceinline__ __device__ __host__
102 void discard_stride(
unsigned int stride)
104 discard_state_power2(stride);
107 __forceinline__ __device__ __host__
108 unsigned int operator()()
113 __forceinline__ __device__ __host__
116 unsigned int p = m_state.d;
121 __forceinline__ __device__ __host__
122 unsigned int current()
const
127 __forceinline__ __device__ __host__
128 static constexpr
bool uses_shared_vectors()
130 return UseSharedVectors;
135 __forceinline__ __device__ __host__
136 void discard_state(
unsigned int offset)
139 const unsigned int g = m_state.i ^ (m_state.i >> 1);
141 for(
int i = 0; i < 32; i++)
143 m_state.d ^= (g & (1U << i) ? m_state.vectors[i] : 0);
148 __forceinline__ __device__ __host__
151 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i)];
155 __forceinline__ __device__ __host__
156 void discard_state_power2(
unsigned int stride)
169 m_state.d ^= m_state.vectors[rightmost_zero_bit(~stride) - 1];
171 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i | (stride - 1))];
179 __forceinline__ __device__ __host__
180 unsigned int rightmost_zero_bit(
unsigned int x)
182 #if defined(__HIP_DEVICE_COMPILE__)
183 unsigned int z = __ffs(~x);
184 return z ? z - 1 : 31;
203 sobol32_state m_state;
215 typedef rocrand_device::sobol32_engine<false> rocrand_state_sobol32;
228 __forceinline__ __device__ __host__
230 const unsigned int offset,
231 rocrand_state_sobol32* state)
233 *state = rocrand_state_sobol32(vectors, offset);
248 __forceinline__ __device__ __host__
249 unsigned int rocrand(rocrand_state_sobol32* state)
251 return state->next();
262 __forceinline__ __device__ __host__
263 void skipahead(
unsigned long long offset, rocrand_state_sobol32* state)
265 return state->discard(offset);
__forceinline__ __device__ __host__ unsigned int rocrand(rocrand_state_sobol32 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition: rocrand_sobol32.h:249
__forceinline__ __device__ __host__ void rocrand_init(const unsigned int *vectors, const unsigned int offset, rocrand_state_sobol32 *state)
Initialize SOBOL32 state.
Definition: rocrand_sobol32.h:229
__forceinline__ __device__ __host__ void skipahead(unsigned long long offset, rocrand_state_sobol32 *state)
Updates SOBOL32 state to skip ahead by offset elements.
Definition: rocrand_sobol32.h:263