21 #ifndef ROCRAND_SOBOL64_H_
22 #define ROCRAND_SOBOL64_H_
25 #define FQUALIFIERS __forceinline__ __device__
28 #include "rocrand/rocrand_common.h"
30 namespace rocrand_device {
32 template<
bool UseSharedVectors>
35 unsigned long long int d;
36 unsigned long long int i;
37 unsigned long long int vectors[64];
40 sobol64_state() : d(), i(), vectors() { }
43 sobol64_state(
const unsigned long long int d,
44 const unsigned long long int i,
45 const unsigned long long int * vectors)
48 for(
int k = 0; k < 64; k++)
50 this->vectors[k] = vectors[k];
56 struct sobol64_state<true>
58 unsigned long long int d;
59 unsigned long long int i;
60 const unsigned long long int * vectors;
63 sobol64_state() : d(), i(), vectors() { }
66 sobol64_state(
const unsigned long long int d,
67 const unsigned long long int i,
68 const unsigned long long int * vectors)
69 : d(d), i(i), vectors(vectors) { }
72 template<
bool UseSharedVectors>
77 typedef struct sobol64_state<UseSharedVectors> sobol64_state;
83 sobol64_engine(
const unsigned long long int* vectors,
const unsigned long long int offset)
84 : m_state(0, 0, vectors)
86 discard_state(offset);
91 void discard(
unsigned long long int offset)
93 discard_state(offset);
104 void discard_stride(
unsigned long long int stride)
106 discard_state_power2(stride);
110 unsigned long long int operator()()
116 unsigned long long int next()
118 unsigned long long int p = m_state.d;
124 unsigned long long int current()
const
132 void discard_state(
unsigned long long int offset)
135 const unsigned long long int g = m_state.i ^ (m_state.i >> 1ull);
137 for(
int i = 0; i < 64; i++)
139 m_state.d ^= (g & (1ull << i) ? m_state.vectors[i] : 0ull);
147 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i)];
152 void discard_state_power2(
unsigned long long int stride)
165 m_state.d ^= m_state.vectors[rightmost_zero_bit(~stride) - 1];
167 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i | (stride - 1))];
175 unsigned int rightmost_zero_bit(
unsigned long long int x)
177 #if defined(__HIP_DEVICE_COMPILE__)
178 unsigned int z = __ffsll(~x);
179 return z ? z - 1 : 0;
183 unsigned long long int y = x;
184 unsigned long long int z = 1;
196 sobol64_state m_state;
208 typedef rocrand_device::sobol64_engine<false> rocrand_state_sobol64;
223 const unsigned int offset,
224 rocrand_state_sobol64 * state)
226 *state = rocrand_state_sobol64(vectors, offset);
242 unsigned long long int rocrand(rocrand_state_sobol64 * state)
244 return state->next();
256 void skipahead(
unsigned long long int offset, rocrand_state_sobol64* state)
258 return state->discard(offset);
FQUALIFIERS unsigned long long int rocrand(rocrand_state_sobol64 *state)
Returns uniformly distributed random unsigned int value from [0; 2^64 - 1] range.
Definition: rocrand_sobol64.h:242
FQUALIFIERS void rocrand_init(const unsigned long long int *vectors, const unsigned int offset, rocrand_state_sobol64 *state)
Initialize sobol64 state.
Definition: rocrand_sobol64.h:222
FQUALIFIERS void skipahead(unsigned long long int offset, rocrand_state_sobol64 *state)
Updates sobol64 state to skip ahead by offset elements.
Definition: rocrand_sobol64.h:256
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31