26 #ifndef ROCRAND_UNIFORM_H_
27 #define ROCRAND_UNIFORM_H_
31 #define FQUALIFIERS __forceinline__ __device__
34 #include "rocrand/rocrand_lfsr113.h"
35 #include "rocrand/rocrand_mrg31k3p.h"
36 #include "rocrand/rocrand_mrg32k3a.h"
37 #include "rocrand/rocrand_mtgp32.h"
38 #include "rocrand/rocrand_philox4x32_10.h"
39 #include "rocrand/rocrand_scrambled_sobol32.h"
40 #include "rocrand/rocrand_scrambled_sobol64.h"
41 #include "rocrand/rocrand_sobol32.h"
42 #include "rocrand/rocrand_sobol64.h"
43 #include "rocrand/rocrand_threefry2x32_20.h"
44 #include "rocrand/rocrand_threefry2x64_20.h"
45 #include "rocrand/rocrand_threefry4x32_20.h"
46 #include "rocrand/rocrand_threefry4x64_20.h"
47 #include "rocrand/rocrand_xorwow.h"
49 #include "rocrand/rocrand_common.h"
51 namespace rocrand_device {
60 union two_uints_to_ulong
62 two_uints uint2_value;
63 unsigned long long int ulong_value;
69 float uniform_distribution(
unsigned int v)
71 return ROCRAND_2POW32_INV + (v * ROCRAND_2POW32_INV);
77 float uniform_distribution(
unsigned long long int v)
79 return ROCRAND_2POW32_INV + (v >> 32) * ROCRAND_2POW32_INV;
83 float4 uniform_distribution4(uint4 v)
86 ROCRAND_2POW32_INV + (v.x * ROCRAND_2POW32_INV),
87 ROCRAND_2POW32_INV + (v.y * ROCRAND_2POW32_INV),
88 ROCRAND_2POW32_INV + (v.z * ROCRAND_2POW32_INV),
89 ROCRAND_2POW32_INV + (v.w * ROCRAND_2POW32_INV)
93 FQUALIFIERS float4 uniform_distribution4(ulonglong4 v)
95 return float4{ROCRAND_2POW64_INV + (v.x * ROCRAND_2POW64_INV),
96 ROCRAND_2POW64_INV + (v.y * ROCRAND_2POW64_INV),
97 ROCRAND_2POW64_INV + (v.z * ROCRAND_2POW64_INV),
98 ROCRAND_2POW64_INV + (v.w * ROCRAND_2POW64_INV)};
104 double uniform_distribution_double(
unsigned int v)
106 return ROCRAND_2POW32_INV_DOUBLE + (v * ROCRAND_2POW32_INV_DOUBLE);
110 double uniform_distribution_double(
unsigned int v1,
unsigned int v2)
112 two_uints_to_ulong v;
113 v.uint2_value.x = v1;
114 v.uint2_value.y = (v2 >> 11);
115 return ROCRAND_2POW53_INV_DOUBLE + (v.ulong_value * ROCRAND_2POW53_INV_DOUBLE);
119 double uniform_distribution_double(
unsigned long long int v)
121 return ROCRAND_2POW53_INV_DOUBLE + (
124 (v >> 11) * ROCRAND_2POW53_INV_DOUBLE
129 double2 uniform_distribution_double2(uint4 v)
132 uniform_distribution_double(v.x, v.y),
133 uniform_distribution_double(v.z, v.w)
138 double4 uniform_distribution_double4(uint4 v1, uint4 v2)
141 uniform_distribution_double(v1.x, v1.y),
142 uniform_distribution_double(v1.z, v1.w),
143 uniform_distribution_double(v2.x, v2.y),
144 uniform_distribution_double(v2.z, v2.w)
148 FQUALIFIERS double2 uniform_distribution_double2(ulonglong2 v)
150 return double2{uniform_distribution_double(v.x), uniform_distribution_double(v.y)};
153 FQUALIFIERS double2 uniform_distribution_double2(ulonglong4 v)
155 return double2{uniform_distribution_double(v.x), uniform_distribution_double(v.y)};
158 FQUALIFIERS double4 uniform_distribution_double4(ulonglong4 v)
160 return double4{uniform_distribution_double(v.x),
161 uniform_distribution_double(v.z),
162 uniform_distribution_double(v.x),
163 uniform_distribution_double(v.z)};
167 __half uniform_distribution_half(
unsigned short v)
169 return __float2half(ROCRAND_2POW16_INV + (v * ROCRAND_2POW16_INV));
174 template<
typename state_type>
175 FQUALIFIERS unsigned int mrg_uniform_distribution_uint(
unsigned int v) =
delete;
178 FQUALIFIERS unsigned int mrg_uniform_distribution_uint<rocrand_state_mrg31k3p>(
unsigned int v)
180 return static_cast<unsigned int>((v - 1) * ROCRAND_MRG31K3P_UINT32_NORM);
184 FQUALIFIERS unsigned int mrg_uniform_distribution_uint<rocrand_state_mrg32k3a>(
unsigned int v)
186 return static_cast<unsigned int>((v - 1) * ROCRAND_MRG32K3A_UINT_NORM);
191 template<
typename state_type>
192 FQUALIFIERS float mrg_uniform_distribution(
unsigned int v) =
delete;
195 FQUALIFIERS float mrg_uniform_distribution<rocrand_state_mrg31k3p>(
unsigned int v)
197 double ret =
static_cast<double>(v) * ROCRAND_MRG31K3P_NORM_DOUBLE;
198 return static_cast<float>(ret);
202 FQUALIFIERS float mrg_uniform_distribution<rocrand_state_mrg32k3a>(
unsigned int v)
204 double ret =
static_cast<double>(v) * ROCRAND_MRG32K3A_NORM_DOUBLE;
205 return static_cast<float>(ret);
210 template<
typename state_type>
211 FQUALIFIERS double mrg_uniform_distribution_double(
unsigned int v) =
delete;
214 FQUALIFIERS double mrg_uniform_distribution_double<rocrand_state_mrg31k3p>(
unsigned int v)
216 double ret =
static_cast<double>(v) * ROCRAND_MRG31K3P_NORM_DOUBLE;
221 FQUALIFIERS double mrg_uniform_distribution_double<rocrand_state_mrg32k3a>(
unsigned int v)
223 double ret =
static_cast<double>(v) * ROCRAND_MRG32K3A_NORM_DOUBLE;
245 return rocrand_device::detail::uniform_distribution(
rocrand(state));
267 rocrand_device::detail::uniform_distribution(state1),
268 rocrand_device::detail::uniform_distribution(state2)
287 return rocrand_device::detail::uniform_distribution4(
rocrand4(state));
308 return rocrand_device::detail::uniform_distribution_double(state1, state2);
326 return rocrand_device::detail::uniform_distribution_double2(
rocrand4(state));
344 return rocrand_device::detail::uniform_distribution_double4(
rocrand4(state),
rocrand4(state));
361 return rocrand_device::detail::mrg_uniform_distribution<rocrand_state_mrg31k3p>(state->next());
381 return rocrand_device::detail::mrg_uniform_distribution_double<rocrand_state_mrg31k3p>(
400 return rocrand_device::detail::mrg_uniform_distribution<rocrand_state_mrg32k3a>(state->next());
421 return rocrand_device::detail::mrg_uniform_distribution_double<rocrand_state_mrg32k3a>(
440 return rocrand_device::detail::uniform_distribution(
rocrand(state));
461 return rocrand_device::detail::uniform_distribution_double(state1, state2);
479 return rocrand_device::detail::uniform_distribution(
rocrand(state));
500 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
518 return rocrand_device::detail::uniform_distribution(
rocrand(state));
539 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
557 return rocrand_device::detail::uniform_distribution(
rocrand(state));
578 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
596 return rocrand_device::detail::uniform_distribution(
rocrand(state));
614 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
632 return rocrand_device::detail::uniform_distribution(
rocrand(state));
650 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
668 return rocrand_device::detail::uniform_distribution(
rocrand(state));
689 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
706 return rocrand_device::detail::uniform_distribution(
rocrand(state));
726 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
743 return rocrand_device::detail::uniform_distribution(
rocrand(state));
763 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
780 return rocrand_device::detail::uniform_distribution(
rocrand(state));
800 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
817 return rocrand_device::detail::uniform_distribution(
rocrand(state));
837 return rocrand_device::detail::uniform_distribution_double(
rocrand(state));
FQUALIFIERS float2 rocrand_uniform2(rocrand_state_philox4x32_10 *state)
Returns two uniformly distributed random float values from (0; 1] range.
Definition: rocrand_uniform.h:261
FQUALIFIERS double4 rocrand_uniform_double4(rocrand_state_philox4x32_10 *state)
Returns four uniformly distributed random double values from (0; 1] range.
Definition: rocrand_uniform.h:342
FQUALIFIERS double rocrand_uniform_double(rocrand_state_philox4x32_10 *state)
Returns a uniformly distributed random double value from (0; 1] range.
Definition: rocrand_uniform.h:303
FQUALIFIERS unsigned int rocrand(rocrand_state_lfsr113 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition: rocrand_lfsr113.h:253
FQUALIFIERS float rocrand_uniform(rocrand_state_philox4x32_10 *state)
Returns a uniformly distributed random float value from (0; 1] range.
Definition: rocrand_uniform.h:243
FQUALIFIERS uint4 rocrand4(rocrand_state_philox4x32_10 *state)
Returns four uniformly distributed random unsigned int values from [0; 2^32 - 1] range.
Definition: rocrand_philox4x32_10.h:410
FQUALIFIERS float4 rocrand_uniform4(rocrand_state_philox4x32_10 *state)
Returns four uniformly distributed random float values from (0; 1] range.
Definition: rocrand_uniform.h:285
FQUALIFIERS double2 rocrand_uniform_double2(rocrand_state_philox4x32_10 *state)
Returns two uniformly distributed random double values from (0; 1] range.
Definition: rocrand_uniform.h:324
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31