21 #ifndef ROCRAND_SOBOL64_H_
22 #define ROCRAND_SOBOL64_H_
24 #include <hip/hip_runtime.h>
26 namespace rocrand_device
29 template<
bool UseSharedVectors>
32 unsigned long long int d;
33 unsigned long long int i;
34 unsigned long long int vectors[64];
36 __forceinline__ __device__ __host__
41 __forceinline__ __device__ __host__
42 sobol64_state(
const unsigned long long int d,
43 const unsigned long long int i,
44 const unsigned long long int* vectors)
47 for(
int k = 0; k < 64; k++)
49 this->vectors[k] = vectors[k];
55 struct sobol64_state<true>
57 unsigned long long int d;
58 unsigned long long int i;
59 const unsigned long long int* vectors;
61 __forceinline__ __device__ __host__
66 __forceinline__ __device__ __host__
67 sobol64_state(
const unsigned long long int d,
68 const unsigned long long int i,
69 const unsigned long long int* vectors)
70 : d(d), i(i), vectors(vectors)
74 template<
bool UseSharedVectors>
78 typedef struct sobol64_state<UseSharedVectors> sobol64_state;
80 __forceinline__ __device__ __host__
84 __forceinline__ __device__ __host__
85 sobol64_engine(
const unsigned long long int* vectors,
const unsigned long long int offset)
86 : m_state(0, 0, vectors)
88 discard_state(offset);
92 __forceinline__ __device__ __host__
93 void discard(
unsigned long long int offset)
95 discard_state(offset);
98 __forceinline__ __device__ __host__
105 __forceinline__ __device__ __host__
106 void discard_stride(
unsigned long long int stride)
108 discard_state_power2(stride);
111 __forceinline__ __device__ __host__
112 unsigned long long int operator()()
117 __forceinline__ __device__ __host__
118 unsigned long long int next()
120 unsigned long long int p = m_state.d;
125 __forceinline__ __device__ __host__
126 unsigned long long int current()
const
131 __forceinline__ __device__ __host__
132 static constexpr
bool uses_shared_vectors()
134 return UseSharedVectors;
139 __forceinline__ __device__ __host__
140 void discard_state(
unsigned long long int offset)
143 const unsigned long long int g = m_state.i ^ (m_state.i >> 1ull);
145 for(
int i = 0; i < 64; i++)
147 m_state.d ^= (g & (1ull << i) ? m_state.vectors[i] : 0ull);
152 __forceinline__ __device__ __host__
155 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i)];
159 __forceinline__ __device__ __host__
160 void discard_state_power2(
unsigned long long int stride)
173 m_state.d ^= m_state.vectors[rightmost_zero_bit(~stride) - 1];
175 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i | (stride - 1))];
182 __forceinline__ __device__ __host__
183 unsigned int rightmost_zero_bit(
unsigned long long int x)
185 #if defined(__HIP_DEVICE_COMPILE__)
186 unsigned int z = __ffsll(~x);
187 return z ? z - 1 : 0;
191 unsigned long long int y = x;
192 unsigned long long int z = 1;
204 sobol64_state m_state;
216 typedef rocrand_device::sobol64_engine<false> rocrand_state_sobol64;
229 __forceinline__ __device__ __host__
231 const unsigned long long int offset,
232 rocrand_state_sobol64* state)
234 *state = rocrand_state_sobol64(vectors, offset);
249 __forceinline__ __device__ __host__
250 unsigned long long int rocrand(rocrand_state_sobol64* state)
252 return state->next();
263 __forceinline__ __device__ __host__
264 void skipahead(
unsigned long long int offset, rocrand_state_sobol64* state)
266 return state->discard(offset);
__forceinline__ __device__ __host__ void rocrand_init(const unsigned long long int *vectors, const unsigned long long int offset, rocrand_state_sobol64 *state)
Initialize sobol64 state.
Definition: rocrand_sobol64.h:230
__forceinline__ __device__ __host__ unsigned long long int rocrand(rocrand_state_sobol64 *state)
Returns uniformly distributed random unsigned long long int value from [0; 2^64 - 1] range.
Definition: rocrand_sobol64.h:250
__forceinline__ __device__ __host__ void skipahead(unsigned long long int offset, rocrand_state_sobol64 *state)
Updates sobol64 state to skip ahead by offset elements.
Definition: rocrand_sobol64.h:264