21 #ifndef ROCRAND_SOBOL32_H_
22 #define ROCRAND_SOBOL32_H_
25 #define FQUALIFIERS __forceinline__ __device__
28 #include "rocrand/rocrand_common.h"
30 namespace rocrand_device {
32 template<
bool UseSharedVectors>
37 unsigned int vectors[32];
40 sobol32_state() : d(), i(), vectors() { }
43 sobol32_state(
const unsigned int d,
45 const unsigned int * vectors)
48 for(
int k = 0; k < 32; k++)
50 this->vectors[k] = vectors[k];
56 struct sobol32_state<true>
60 const unsigned int * vectors;
63 sobol32_state() : d(), i(), vectors() { }
66 sobol32_state(
const unsigned int d,
68 const unsigned int * vectors)
69 : d(d), i(i), vectors(vectors) { }
72 template<
bool UseSharedVectors>
77 typedef struct sobol32_state<UseSharedVectors> sobol32_state;
83 sobol32_engine(
const unsigned int * vectors,
84 const unsigned int offset)
85 : m_state(0, 0, vectors)
87 discard_state(offset);
92 void discard(
unsigned int offset)
94 discard_state(offset);
105 void discard_stride(
unsigned int stride)
107 discard_state_power2(stride);
111 unsigned int operator()()
119 unsigned int p = m_state.d;
125 unsigned int current()
const
133 void discard_state(
unsigned int offset)
136 const unsigned int g = m_state.i ^ (m_state.i >> 1);
138 for(
int i = 0; i < 32; i++)
140 m_state.d ^= (g & (1U << i) ? m_state.vectors[i] : 0);
148 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i)];
153 void discard_state_power2(
unsigned int stride)
166 m_state.d ^= m_state.vectors[rightmost_zero_bit(~stride) - 1];
168 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i | (stride - 1))];
175 unsigned int rightmost_zero_bit(
unsigned int x)
177 #if defined(__HIP_DEVICE_COMPILE__)
178 unsigned int z = __ffs(~x);
179 return z ? z - 1 : 0;
196 sobol32_state m_state;
208 typedef rocrand_device::sobol32_engine<false> rocrand_state_sobol32;
223 const unsigned int offset,
224 rocrand_state_sobol32 * state)
226 *state = rocrand_state_sobol32(vectors, offset);
242 unsigned int rocrand(rocrand_state_sobol32 * state)
244 return state->next();
256 void skipahead(
unsigned long long offset, rocrand_state_sobol32 * state)
258 return state->discard(offset);
FQUALIFIERS void skipahead(unsigned long long offset, rocrand_state_sobol32 *state)
Updates SOBOL32 state to skip ahead by offset elements.
Definition: rocrand_sobol32.h:256
FQUALIFIERS unsigned int rocrand(rocrand_state_sobol32 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition: rocrand_sobol32.h:242
FQUALIFIERS void rocrand_init(const unsigned int *vectors, const unsigned int offset, rocrand_state_sobol32 *state)
Initialize SOBOL32 state.
Definition: rocrand_sobol32.h:222
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31