21 #ifndef ROCRAND_SOBOL64_H_
22 #define ROCRAND_SOBOL64_H_
24 #include "rocrand/rocrand_common.h"
26 namespace rocrand_device {
28 template<
bool UseSharedVectors>
31 unsigned long long int d;
32 unsigned long long int i;
33 unsigned long long int vectors[64];
35 __forceinline__ __device__ __host__ sobol64_state() : d(), i(), vectors() {}
37 __forceinline__ __device__ __host__ sobol64_state(
const unsigned long long int d,
38 const unsigned long long int i,
39 const unsigned long long int* vectors)
42 for(
int k = 0; k < 64; k++)
44 this->vectors[k] = vectors[k];
50 struct sobol64_state<true>
52 unsigned long long int d;
53 unsigned long long int i;
54 const unsigned long long int * vectors;
56 __forceinline__ __device__ __host__ sobol64_state() : d(), i(), vectors() {}
58 __forceinline__ __device__ __host__ sobol64_state(
const unsigned long long int d,
59 const unsigned long long int i,
60 const unsigned long long int* vectors)
61 : d(d), i(i), vectors(vectors)
65 template<
bool UseSharedVectors>
70 typedef struct sobol64_state<UseSharedVectors> sobol64_state;
72 __forceinline__ __device__ __host__ sobol64_engine() {}
74 __forceinline__ __device__ __host__ sobol64_engine(
const unsigned long long int* vectors,
75 const unsigned long long int offset)
76 : m_state(0, 0, vectors)
78 discard_state(offset);
82 __forceinline__ __device__ __host__
void discard(
unsigned long long int offset)
84 discard_state(offset);
87 __forceinline__ __device__ __host__
void discard()
93 __forceinline__ __device__ __host__
void discard_stride(
unsigned long long int stride)
95 discard_state_power2(stride);
98 __forceinline__ __device__ __host__
unsigned long long int operator()()
103 __forceinline__ __device__ __host__
unsigned long long int next()
105 unsigned long long int p = m_state.d;
110 __forceinline__ __device__ __host__
unsigned long long int current()
const
115 __forceinline__ __device__ __host__
static constexpr
bool uses_shared_vectors()
117 return UseSharedVectors;
122 __forceinline__ __device__ __host__
void discard_state(
unsigned long long int offset)
125 const unsigned long long int g = m_state.i ^ (m_state.i >> 1ull);
127 for(
int i = 0; i < 64; i++)
129 m_state.d ^= (g & (1ull << i) ? m_state.vectors[i] : 0ull);
134 __forceinline__ __device__ __host__
void discard_state()
136 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i)];
140 __forceinline__ __device__ __host__
void discard_state_power2(
unsigned long long int stride)
153 m_state.d ^= m_state.vectors[rightmost_zero_bit(~stride) - 1];
155 m_state.d ^= m_state.vectors[rightmost_zero_bit(m_state.i | (stride - 1))];
162 __forceinline__ __device__ __host__
unsigned int rightmost_zero_bit(
unsigned long long int x)
164 #if defined(__HIP_DEVICE_COMPILE__)
165 unsigned int z = __ffsll(~x);
166 return z ? z - 1 : 0;
170 unsigned long long int y = x;
171 unsigned long long int z = 1;
183 sobol64_state m_state;
195 typedef rocrand_device::sobol64_engine<false> rocrand_state_sobol64;
208 __forceinline__ __device__ __host__
void rocrand_init(
const unsigned long long int* vectors,
209 const unsigned int offset,
210 rocrand_state_sobol64* state)
212 *state = rocrand_state_sobol64(vectors, offset);
227 __forceinline__ __device__ __host__
unsigned long long int rocrand(rocrand_state_sobol64* state)
229 return state->next();
240 __forceinline__ __device__ __host__
void skipahead(
unsigned long long int offset,
241 rocrand_state_sobol64* state)
243 return state->discard(offset);
__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:227
__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:240
__forceinline__ __device__ __host__ void rocrand_init(const unsigned long long int *vectors, const unsigned int offset, rocrand_state_sobol64 *state)
Initialize sobol64 state.
Definition: rocrand_sobol64.h:208