/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/develop/projects/rocrand/library/include/rocrand/rocrand_normal.h Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/develop/projects/rocrand/library/include/rocrand/rocrand_normal.h Source File#

API library: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/develop/projects/rocrand/library/include/rocrand/rocrand_normal.h Source File
rocrand_normal.h
1 // Copyright (c) 2017-2026 Advanced Micro Devices, Inc. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef ROCRAND_NORMAL_H_
22 #define ROCRAND_NORMAL_H_
23 
29 #include "rocrand/rocrand_lfsr113.h"
30 #include "rocrand/rocrand_mrg31k3p.h"
31 #include "rocrand/rocrand_mrg32k3a.h"
32 #include "rocrand/rocrand_mtgp32.h"
33 #include "rocrand/rocrand_philox4x32_10.h"
34 #include "rocrand/rocrand_scrambled_sobol32.h"
35 #include "rocrand/rocrand_scrambled_sobol64.h"
36 #include "rocrand/rocrand_sobol32.h"
37 #include "rocrand/rocrand_sobol64.h"
38 #include "rocrand/rocrand_threefry2x32_20.h"
39 #include "rocrand/rocrand_threefry2x64_20.h"
40 #include "rocrand/rocrand_threefry4x32_20.h"
41 #include "rocrand/rocrand_threefry4x64_20.h"
42 #include "rocrand/rocrand_xorwow.h"
43 
44 #include "rocrand/rocrand_uniform.h"
45 
46 #include <hip/hip_runtime.h>
47 
48 #include <math.h>
49 
50 namespace rocrand_device
51 {
52 namespace detail
53 {
54 
55 __forceinline__ __device__ __host__
56 float2 box_muller(unsigned int x, unsigned int y)
57 {
58  float2 result;
59  float u = fmaf(x, ROCRAND_2POW32_INV, ROCRAND_2POW32_INV);
60  float v = fmaf(y, ROCRAND_2POW32_INV_2PI, ROCRAND_2POW32_INV_2PI);
61 
62  float s = sqrtf(-2.0f * logf(u));
63 #ifdef __HIP_DEVICE_COMPILE__
64  __sincosf(v, &result.x, &result.y);
65  result.x *= s;
66  result.y *= s;
67 #else
68  result.x = sinf(v) * s;
69  result.y = cosf(v) * s;
70 #endif
71  return result;
72 }
73 
74 __forceinline__ __device__ __host__
75 float2 box_muller(unsigned long long v)
76 {
77  unsigned int x = static_cast<unsigned int>(v);
78  unsigned int y = static_cast<unsigned int>(v >> 32);
79 
80  return box_muller(x, y);
81 }
82 
83 __forceinline__ __device__ __host__
84 double2 box_muller_double(uint4 v)
85 {
86  double2 result;
87  unsigned long long int v1
88  = (unsigned long long int)v.x ^ ((unsigned long long int)v.y << (53 - 32));
89  double u = fma(static_cast<double>(v1), ROCRAND_2POW53_INV_DOUBLE, ROCRAND_2POW53_INV_DOUBLE);
90  unsigned long long int v2
91  = (unsigned long long int)v.z ^ ((unsigned long long int)v.w << (53 - 32));
92  double w = fma(static_cast<double>(v2),
93  ROCRAND_2POW53_INV_DOUBLE * 2.0,
94  ROCRAND_2POW53_INV_DOUBLE * 2.0);
95  double s = sqrt(-2.0 * log(u));
96 #ifdef __HIP_DEVICE_COMPILE__
97  sincospi(w, &result.x, &result.y);
98  result.x *= s;
99  result.y *= s;
100 #else
101  result.x = sin(w * ROCRAND_PI_DOUBLE) * s;
102  result.y = cos(w * ROCRAND_PI_DOUBLE) * s;
103 #endif
104  return result;
105 }
106 
107 __forceinline__ __device__ __host__
108 double2 box_muller_double(ulonglong2 v)
109 {
110  unsigned int x = static_cast<unsigned int>(v.x);
111  unsigned int y = static_cast<unsigned int>(v.x >> 32);
112  unsigned int z = static_cast<unsigned int>(v.y);
113  unsigned int w = static_cast<unsigned int>(v.y >> 32);
114 
115  return box_muller_double(make_uint4(x, y, z, w));
116 }
117 
118 __forceinline__ __device__ __host__
119 __half2 box_muller_half(unsigned short x, unsigned short y)
120 {
121 #if defined(ROCRAND_HALF_MATH_SUPPORTED)
122  __half u = __float2half(fmaf(x, ROCRAND_2POW16_INV, ROCRAND_2POW16_INV));
123  __half v = __float2half(fmaf(y, ROCRAND_2POW16_INV_2PI, ROCRAND_2POW16_INV_2PI));
124  __half s = hsqrt(__hmul(__float2half(-2.0f), hlog(u)));
125  return __half2{__hmul(hsin(v), s), __hmul(hcos(v), s)};
126 #else
127  float2 r;
128  float u = fmaf(x, ROCRAND_2POW16_INV, ROCRAND_2POW16_INV);
129  float v = fmaf(y, ROCRAND_2POW16_INV_2PI, ROCRAND_2POW16_INV_2PI);
130  float s = sqrtf(-2.0f * logf(u));
131  #ifdef __HIP_DEVICE_COMPILE__
132  __sincosf(v, &r.x, &r.y);
133  r.x *= s;
134  r.y *= s;
135  #else
136  r.x = sinf(v) * s;
137  r.y = cosf(v) * s;
138  #endif
139  return __half2{__float2half(r.x), __float2half(r.y)};
140 #endif
141 }
142 
143 template<typename state_type>
144 __forceinline__ __device__ __host__
145 float2 mrg_box_muller(unsigned int x, unsigned int y)
146 {
147  float2 result;
148  float u = rocrand_device::detail::mrg_uniform_distribution<state_type>(x);
149  float v = rocrand_device::detail::mrg_uniform_distribution<state_type>(y) * ROCRAND_2PI;
150  float s = sqrtf(-2.0f * logf(u));
151 #ifdef __HIP_DEVICE_COMPILE__
152  __sincosf(v, &result.x, &result.y);
153  result.x *= s;
154  result.y *= s;
155 #else
156  result.x = sinf(v) * s;
157  result.y = cosf(v) * s;
158 #endif
159  return result;
160 }
161 
162 template<typename state_type>
163 __forceinline__ __device__ __host__
164 double2 mrg_box_muller_double(unsigned int x, unsigned int y)
165 {
166  double2 result;
167  double u = rocrand_device::detail::mrg_uniform_distribution<state_type>(x);
168  double v = rocrand_device::detail::mrg_uniform_distribution<state_type>(y) * 2.0;
169  double s = sqrt(-2.0 * log(u));
170 #ifdef __HIP_DEVICE_COMPILE__
171  sincospi(v, &result.x, &result.y);
172  result.x *= s;
173  result.y *= s;
174 #else
175  result.x = sin(v * ROCRAND_PI_DOUBLE) * s;
176  result.y = cos(v * ROCRAND_PI_DOUBLE) * s;
177 #endif
178  return result;
179 }
180 
181 __forceinline__ __device__ __host__
182 float roc_f_erfinv(float x)
183 {
184  float tt1, tt2, lnx, sgn;
185  sgn = (x < 0.0f) ? -1.0f : 1.0f;
186 
187  x = (1.0f - x) * (1.0f + x);
188  lnx = logf(x);
189 
190 #ifdef __HIP_DEVICE_COMPILE__
191  if(isnan(lnx))
192 #else
193  if(std::isnan(lnx))
194 #endif
195  return 1.0f;
196 #ifdef __HIP_DEVICE_COMPILE__
197  else if(isinf(lnx))
198 #else
199  else if(std::isinf(lnx))
200 #endif
201  return 0.0f;
202 
203  tt1 = 2.0f / (ROCRAND_PI * 0.147f) + 0.5f * lnx;
204  tt2 = 1.0f / (0.147f) * lnx;
205 
206  return (sgn * sqrtf(-tt1 + sqrtf(tt1 * tt1 - tt2)));
207 }
208 
209 __forceinline__ __device__ __host__
210 double roc_d_erfinv(double x)
211 {
212  double tt1, tt2, lnx, sgn;
213  sgn = (x < 0.0) ? -1.0 : 1.0;
214 
215  x = (1.0 - x) * (1.0 + x);
216  lnx = log(x);
217 
218 #ifdef __HIP_DEVICE_COMPILE__
219  if(isnan(lnx))
220 #else
221  if(std::isnan(lnx))
222 #endif
223  return 1.0;
224 #ifdef __HIP_DEVICE_COMPILE__
225  else if(isinf(lnx))
226 #else
227  else if(std::isinf(lnx))
228 #endif
229  return 0.0;
230 
231  tt1 = 2.0 / (ROCRAND_PI_DOUBLE * 0.147) + 0.5 * lnx;
232  tt2 = 1.0 / (0.147) * lnx;
233 
234  return (sgn * sqrt(-tt1 + sqrt(tt1 * tt1 - tt2)));
235 }
236 
237 __forceinline__ __device__ __host__
238 float normal_distribution(unsigned int x)
239 {
240  float p = ::rocrand_device::detail::uniform_distribution(x);
241  float v = ROCRAND_SQRT2 * ::rocrand_device::detail::roc_f_erfinv(2.0f * p - 1.0f);
242  return v;
243 }
244 
245 __forceinline__ __device__ __host__
246 float normal_distribution(unsigned long long int x)
247 {
248  float p = ::rocrand_device::detail::uniform_distribution(x);
249  float v = ROCRAND_SQRT2 * ::rocrand_device::detail::roc_f_erfinv(2.0f * p - 1.0f);
250  return v;
251 }
252 
253 __forceinline__ __device__ __host__
254 float2 normal_distribution2(unsigned int v1, unsigned int v2)
255 {
256  return ::rocrand_device::detail::box_muller(v1, v2);
257 }
258 
259 __forceinline__ __device__ __host__
260 float2 normal_distribution2(uint2 v)
261 {
262  return ::rocrand_device::detail::box_muller(v.x, v.y);
263 }
264 
265 __forceinline__ __device__ __host__
266 float2 normal_distribution2(unsigned long long v)
267 {
268  return ::rocrand_device::detail::box_muller(v);
269 }
270 
271 __forceinline__ __device__ __host__
272 float4 normal_distribution4(uint4 v)
273 {
274  float2 r1 = ::rocrand_device::detail::box_muller(v.x, v.y);
275  float2 r2 = ::rocrand_device::detail::box_muller(v.z, v.w);
276  return float4{r1.x, r1.y, r2.x, r2.y};
277 }
278 
279 __forceinline__ __device__ __host__
280 float4 normal_distribution4(longlong2 v)
281 {
282  float2 r1 = ::rocrand_device::detail::box_muller(v.x);
283  float2 r2 = ::rocrand_device::detail::box_muller(v.y);
284  return float4{r1.x, r1.y, r2.x, r2.y};
285 }
286 
287 __forceinline__ __device__ __host__
288 float4 normal_distribution4(unsigned long long v1, unsigned long long v2)
289 {
290  float2 r1 = ::rocrand_device::detail::box_muller(v1);
291  float2 r2 = ::rocrand_device::detail::box_muller(v2);
292  return float4{r1.x, r1.y, r2.x, r2.y};
293 }
294 
295 __forceinline__ __device__ __host__
296 double normal_distribution_double(unsigned int x)
297 {
298  double p = ::rocrand_device::detail::uniform_distribution_double(x);
299  double v = ROCRAND_SQRT2 * ::rocrand_device::detail::roc_d_erfinv(2.0 * p - 1.0);
300  return v;
301 }
302 
303 __forceinline__ __device__ __host__
304 double normal_distribution_double(unsigned long long int x)
305 {
306  double p = ::rocrand_device::detail::uniform_distribution_double(x);
307  double v = ROCRAND_SQRT2 * ::rocrand_device::detail::roc_d_erfinv(2.0 * p - 1.0);
308  return v;
309 }
310 
311 __forceinline__ __device__ __host__
312 double2 normal_distribution_double2(uint4 v)
313 {
314  return ::rocrand_device::detail::box_muller_double(v);
315 }
316 
317 __forceinline__ __device__ __host__
318 double2 normal_distribution_double2(ulonglong2 v)
319 {
320  return ::rocrand_device::detail::box_muller_double(v);
321 }
322 
323 __forceinline__ __device__ __host__
324 __half2 normal_distribution_half2(unsigned int v)
325 {
326  return ::rocrand_device::detail::box_muller_half(static_cast<unsigned short>(v),
327  static_cast<unsigned short>(v >> 16));
328 }
329 
330 __forceinline__ __device__ __host__
331 __half2 normal_distribution_half2(unsigned long long v)
332 {
333  return ::rocrand_device::detail::box_muller_half(static_cast<unsigned short>(v),
334  static_cast<unsigned short>(v >> 32));
335 }
336 
337 template<typename state_type>
338 __forceinline__ __device__ __host__
339 float2 mrg_normal_distribution2(unsigned int v1, unsigned int v2)
340 {
341  return ::rocrand_device::detail::mrg_box_muller<state_type>(v1, v2);
342 }
343 
344 template<typename state_type>
345 __forceinline__ __device__ __host__
346 double2 mrg_normal_distribution_double2(unsigned int v1, unsigned int v2)
347 {
348  return ::rocrand_device::detail::mrg_box_muller_double<state_type>(v1, v2);
349 }
350 
351 template<typename state_type>
352 __forceinline__ __device__ __host__
353 __half2 mrg_normal_distribution_half2(unsigned int v)
354 {
355  v = rocrand_device::detail::mrg_uniform_distribution_uint<state_type>(v);
356  return ::rocrand_device::detail::box_muller_half(static_cast<unsigned short>(v),
357  static_cast<unsigned short>(v >> 16));
358 }
359 
360 } // end namespace detail
361 } // end namespace rocrand_device
362 
377 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
378 __forceinline__ __device__ __host__
379 float rocrand_normal(rocrand_state_philox4x32_10* state)
380 {
381  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_philox4x32_10> bm_helper;
382 
383  if(bm_helper::has_float(state))
384  {
385  return bm_helper::get_float(state);
386  }
387 
388  auto state1 = rocrand(state);
389  auto state2 = rocrand(state);
390 
391  float2 r = rocrand_device::detail::normal_distribution2(state1, state2);
392  bm_helper::save_float(state, r.y);
393  return r.x;
394 }
395 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
396 
411 __forceinline__ __device__ __host__
412 float2 rocrand_normal2(rocrand_state_philox4x32_10* state)
413 {
414  auto state1 = rocrand(state);
415  auto state2 = rocrand(state);
416 
417  return rocrand_device::detail::normal_distribution2(state1, state2);
418 }
419 
434 __forceinline__ __device__ __host__
435 float4 rocrand_normal4(rocrand_state_philox4x32_10* state)
436 {
437  return rocrand_device::detail::normal_distribution4(rocrand4(state));
438 }
439 
454 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
455 __forceinline__ __device__ __host__
456 double rocrand_normal_double(rocrand_state_philox4x32_10* state)
457 {
458  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_philox4x32_10> bm_helper;
459 
460  if(bm_helper::has_double(state))
461  {
462  return bm_helper::get_double(state);
463  }
464  double2 r = rocrand_device::detail::normal_distribution_double2(rocrand4(state));
465  bm_helper::save_double(state, r.y);
466  return r.x;
467 }
468 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
469 
484 __forceinline__ __device__ __host__
485 double2 rocrand_normal_double2(rocrand_state_philox4x32_10* state)
486 {
487  return rocrand_device::detail::normal_distribution_double2(rocrand4(state));
488 }
489 
504 __forceinline__ __device__ __host__
505 double4 rocrand_normal_double4(rocrand_state_philox4x32_10* state)
506 {
507  double2 r1, r2;
508  r1 = rocrand_device::detail::normal_distribution_double2(rocrand4(state));
509  r2 = rocrand_device::detail::normal_distribution_double2(rocrand4(state));
510  return double4{r1.x, r1.y, r2.x, r2.y};
511 }
512 
527 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
528 __forceinline__ __device__ __host__
529 float rocrand_normal(rocrand_state_mrg31k3p* state)
530 {
531  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_mrg31k3p> bm_helper;
532 
533  if(bm_helper::has_float(state))
534  {
535  return bm_helper::get_float(state);
536  }
537 
538  auto state1 = state->next();
539  auto state2 = state->next();
540 
541  float2 r
542  = rocrand_device::detail::mrg_normal_distribution2<rocrand_state_mrg31k3p>(state1, state2);
543  bm_helper::save_float(state, r.y);
544  return r.x;
545 }
546 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
547 
562 __forceinline__ __device__ __host__
563 float2 rocrand_normal2(rocrand_state_mrg31k3p* state)
564 {
565  auto state1 = state->next();
566  auto state2 = state->next();
567 
568  return rocrand_device::detail::mrg_normal_distribution2<rocrand_state_mrg31k3p>(state1, state2);
569 }
570 
585 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
586 __forceinline__ __device__ __host__
587 double rocrand_normal_double(rocrand_state_mrg31k3p* state)
588 {
589  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_mrg31k3p> bm_helper;
590 
591  if(bm_helper::has_double(state))
592  {
593  return bm_helper::get_double(state);
594  }
595 
596  auto state1 = state->next();
597  auto state2 = state->next();
598 
599  double2 r
600  = rocrand_device::detail::mrg_normal_distribution_double2<rocrand_state_mrg31k3p>(state1,
601  state2);
602  bm_helper::save_double(state, r.y);
603  return r.x;
604 }
605 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
606 
621 __forceinline__ __device__ __host__
622 double2 rocrand_normal_double2(rocrand_state_mrg31k3p* state)
623 {
624  auto state1 = state->next();
625  auto state2 = state->next();
626 
627  return rocrand_device::detail::mrg_normal_distribution_double2<rocrand_state_mrg31k3p>(state1,
628  state2);
629 }
630 
645 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
646 __forceinline__ __device__ __host__
647 float rocrand_normal(rocrand_state_mrg32k3a* state)
648 {
649  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_mrg32k3a> bm_helper;
650 
651  if(bm_helper::has_float(state))
652  {
653  return bm_helper::get_float(state);
654  }
655 
656  auto state1 = state->next();
657  auto state2 = state->next();
658 
659  float2 r
660  = rocrand_device::detail::mrg_normal_distribution2<rocrand_state_mrg32k3a>(state1, state2);
661  bm_helper::save_float(state, r.y);
662  return r.x;
663 }
664 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
665 
680 __forceinline__ __device__ __host__
681 float2 rocrand_normal2(rocrand_state_mrg32k3a* state)
682 {
683  auto state1 = state->next();
684  auto state2 = state->next();
685 
686  return rocrand_device::detail::mrg_normal_distribution2<rocrand_state_mrg32k3a>(state1, state2);
687 }
688 
703 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
704 __forceinline__ __device__ __host__
705 double rocrand_normal_double(rocrand_state_mrg32k3a* state)
706 {
707  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_mrg32k3a> bm_helper;
708 
709  if(bm_helper::has_double(state))
710  {
711  return bm_helper::get_double(state);
712  }
713 
714  auto state1 = state->next();
715  auto state2 = state->next();
716 
717  double2 r
718  = rocrand_device::detail::mrg_normal_distribution_double2<rocrand_state_mrg32k3a>(state1,
719  state2);
720  bm_helper::save_double(state, r.y);
721  return r.x;
722 }
723 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
724 
739 __forceinline__ __device__ __host__
740 double2 rocrand_normal_double2(rocrand_state_mrg32k3a* state)
741 {
742  auto state1 = state->next();
743  auto state2 = state->next();
744 
745  return rocrand_device::detail::mrg_normal_distribution_double2<rocrand_state_mrg32k3a>(state1,
746  state2);
747 }
748 
763 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
764 __forceinline__ __device__ __host__
765 float rocrand_normal(rocrand_state_xorwow* state)
766 {
767  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_xorwow> bm_helper;
768 
769  if(bm_helper::has_float(state))
770  {
771  return bm_helper::get_float(state);
772  }
773  auto state1 = rocrand(state);
774  auto state2 = rocrand(state);
775  float2 r = rocrand_device::detail::normal_distribution2(state1, state2);
776  bm_helper::save_float(state, r.y);
777  return r.x;
778 }
779 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
780 
795 __forceinline__ __device__ __host__
796 float2 rocrand_normal2(rocrand_state_xorwow* state)
797 {
798  auto state1 = rocrand(state);
799  auto state2 = rocrand(state);
800  return rocrand_device::detail::normal_distribution2(state1, state2);
801 }
802 
817 #ifndef ROCRAND_DETAIL_BM_NOT_IN_STATE
818 __forceinline__ __device__ __host__
819 double rocrand_normal_double(rocrand_state_xorwow* state)
820 {
821  typedef rocrand_device::detail::engine_boxmuller_helper<rocrand_state_xorwow> bm_helper;
822 
823  if(bm_helper::has_double(state))
824  {
825  return bm_helper::get_double(state);
826  }
827 
828  auto state1 = rocrand(state);
829  auto state2 = rocrand(state);
830  auto state3 = rocrand(state);
831  auto state4 = rocrand(state);
832 
833  double2 r = rocrand_device::detail::normal_distribution_double2(
834  uint4{state1, state2, state3, state4});
835  bm_helper::save_double(state, r.y);
836  return r.x;
837 }
838 #endif // ROCRAND_DETAIL_BM_NOT_IN_STATE
839 
854 __forceinline__ __device__ __host__
855 double2 rocrand_normal_double2(rocrand_state_xorwow* state)
856 {
857  auto state1 = rocrand(state);
858  auto state2 = rocrand(state);
859  auto state3 = rocrand(state);
860  auto state4 = rocrand(state);
861 
862  return rocrand_device::detail::normal_distribution_double2(
863  uint4{state1, state2, state3, state4});
864 }
865 
878 __forceinline__ __device__
879 float rocrand_normal(rocrand_state_mtgp32* state)
880 {
881  return rocrand_device::detail::normal_distribution(rocrand(state));
882 }
883 
898 __forceinline__ __device__
899 float2 rocrand_normal2(rocrand_state_mtgp32* state)
900 {
901  auto state1 = rocrand(state);
902  auto state2 = rocrand(state);
903  return rocrand_device::detail::normal_distribution2(state1, state2);
904 }
905 
918 __forceinline__ __device__
919 double rocrand_normal_double(rocrand_state_mtgp32* state)
920 {
921  return rocrand_device::detail::normal_distribution_double(rocrand(state));
922 }
923 
938 __forceinline__ __device__
939 double2 rocrand_normal_double2(rocrand_state_mtgp32* state)
940 {
941  auto state1 = rocrand(state);
942  auto state2 = rocrand(state);
943  auto state3 = rocrand(state);
944  auto state4 = rocrand(state);
945 
946  return rocrand_device::detail::normal_distribution_double2(
947  uint4{state1, state2, state3, state4});
948 }
949 
962 __forceinline__ __device__ __host__
963 float rocrand_normal(rocrand_state_sobol32* state)
964 {
965  return rocrand_device::detail::normal_distribution(rocrand(state));
966 }
967 
980 __forceinline__ __device__ __host__
981 double rocrand_normal_double(rocrand_state_sobol32* state)
982 {
983  return rocrand_device::detail::normal_distribution_double(rocrand(state));
984 }
985 
998 __forceinline__ __device__ __host__
999 float rocrand_normal(rocrand_state_scrambled_sobol32* state)
1000 {
1001  return rocrand_device::detail::normal_distribution(rocrand(state));
1002 }
1003 
1016 __forceinline__ __device__ __host__
1017 double rocrand_normal_double(rocrand_state_scrambled_sobol32* state)
1018 {
1019  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1020 }
1021 
1034 __forceinline__ __device__ __host__
1035 float rocrand_normal(rocrand_state_sobol64* state)
1036 {
1037  return rocrand_device::detail::normal_distribution(rocrand(state));
1038 }
1039 
1052 __forceinline__ __device__ __host__
1053 double rocrand_normal_double(rocrand_state_sobol64* state)
1054 {
1055  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1056 }
1057 
1070 __forceinline__ __device__ __host__
1071 float rocrand_normal(rocrand_state_scrambled_sobol64* state)
1072 {
1073  return rocrand_device::detail::normal_distribution(rocrand(state));
1074 }
1075 
1088 __forceinline__ __device__ __host__
1089 double rocrand_normal_double(rocrand_state_scrambled_sobol64* state)
1090 {
1091  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1092 }
1093 
1106 __forceinline__ __device__ __host__
1107 float rocrand_normal(rocrand_state_lfsr113* state)
1108 {
1109  return rocrand_device::detail::normal_distribution(rocrand(state));
1110 }
1111 
1126 __forceinline__ __device__ __host__
1127 float2 rocrand_normal2(rocrand_state_lfsr113* state)
1128 {
1129  auto state1 = rocrand(state);
1130  auto state2 = rocrand(state);
1131 
1132  return rocrand_device::detail::normal_distribution2(state1, state2);
1133 }
1134 
1147 __forceinline__ __device__ __host__
1148 double rocrand_normal_double(rocrand_state_lfsr113* state)
1149 {
1150  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1151 }
1152 
1167 __forceinline__ __device__ __host__
1168 double2 rocrand_normal_double2(rocrand_state_lfsr113* state)
1169 {
1170  auto state1 = rocrand(state);
1171  auto state2 = rocrand(state);
1172  auto state3 = rocrand(state);
1173  auto state4 = rocrand(state);
1174 
1175  return rocrand_device::detail::normal_distribution_double2(
1176  uint4{state1, state2, state3, state4});
1177 }
1178 
1191 __forceinline__ __device__ __host__
1192 float rocrand_normal(rocrand_state_threefry2x32_20* state)
1193 {
1194  return rocrand_device::detail::normal_distribution(rocrand(state));
1195 }
1196 
1211 __forceinline__ __device__ __host__
1212 float2 rocrand_normal2(rocrand_state_threefry2x32_20* state)
1213 {
1214  return rocrand_device::detail::normal_distribution2(rocrand2(state));
1215 }
1216 
1229 __forceinline__ __device__ __host__
1230 double rocrand_normal_double(rocrand_state_threefry2x32_20* state)
1231 {
1232  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1233 }
1234 
1249 __forceinline__ __device__ __host__
1250 double2 rocrand_normal_double2(rocrand_state_threefry2x32_20* state)
1251 {
1252  auto state1 = rocrand2(state);
1253  auto state2 = rocrand2(state);
1254 
1255  return rocrand_device::detail::normal_distribution_double2(
1256  uint4{state1.x, state1.y, state2.x, state2.y});
1257 }
1258 
1271 __forceinline__ __device__ __host__
1272 float rocrand_normal(rocrand_state_threefry2x64_20* state)
1273 {
1274  return rocrand_device::detail::normal_distribution(rocrand(state));
1275 }
1276 
1291 __forceinline__ __device__ __host__
1292 float2 rocrand_normal2(rocrand_state_threefry2x64_20* state)
1293 {
1294  return rocrand_device::detail::normal_distribution2(rocrand(state));
1295 }
1296 
1309 __forceinline__ __device__ __host__
1310 double rocrand_normal_double(rocrand_state_threefry2x64_20* state)
1311 {
1312  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1313 }
1314 
1329 __forceinline__ __device__ __host__
1330 double2 rocrand_normal_double2(rocrand_state_threefry2x64_20* state)
1331 {
1332  return rocrand_device::detail::normal_distribution_double2(rocrand2(state));
1333 }
1334 
1347 __forceinline__ __device__ __host__
1348 float rocrand_normal(rocrand_state_threefry4x32_20* state)
1349 {
1350  return rocrand_device::detail::normal_distribution(rocrand(state));
1351 }
1352 
1367 __forceinline__ __device__ __host__
1368 float2 rocrand_normal2(rocrand_state_threefry4x32_20* state)
1369 {
1370  auto state1 = rocrand(state);
1371  auto state2 = rocrand(state);
1372 
1373  return rocrand_device::detail::normal_distribution2(state1, state2);
1374 }
1375 
1388 __forceinline__ __device__ __host__
1389 double rocrand_normal_double(rocrand_state_threefry4x32_20* state)
1390 {
1391  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1392 }
1393 
1408 __forceinline__ __device__ __host__
1409 double2 rocrand_normal_double2(rocrand_state_threefry4x32_20* state)
1410 {
1411  return rocrand_device::detail::normal_distribution_double2(rocrand4(state));
1412 }
1413 
1426 __forceinline__ __device__ __host__
1427 float rocrand_normal(rocrand_state_threefry4x64_20* state)
1428 {
1429  return rocrand_device::detail::normal_distribution(rocrand(state));
1430 }
1431 
1446 __forceinline__ __device__ __host__
1447 float2 rocrand_normal2(rocrand_state_threefry4x64_20* state)
1448 {
1449  auto state1 = rocrand(state);
1450  auto state2 = rocrand(state);
1451 
1452  return rocrand_device::detail::normal_distribution2(state1, state2);
1453 }
1454 
1467 __forceinline__ __device__ __host__
1468 double rocrand_normal_double(rocrand_state_threefry4x64_20* state)
1469 {
1470  return rocrand_device::detail::normal_distribution_double(rocrand(state));
1471 }
1472 
1487 __forceinline__ __device__ __host__
1488 double2 rocrand_normal_double2(rocrand_state_threefry4x64_20* state)
1489 {
1490  auto state1 = rocrand(state);
1491  auto state2 = rocrand(state);
1492 
1493  return rocrand_device::detail::normal_distribution_double2(ulonglong2{state1, state2});
1494 }
1495  // end of group rocranddevice
1497 
1498 #endif // ROCRAND_NORMAL_H_
__forceinline__ __device__ __host__ double4 rocrand_normal_double4(rocrand_state_philox4x32_10 *state)
Returns four normally distributed double values.
Definition: rocrand_normal.h:505
__forceinline__ __device__ __host__ double2 rocrand_normal_double2(rocrand_state_philox4x32_10 *state)
Returns two normally distributed double values.
Definition: rocrand_normal.h:485
__forceinline__ __device__ __host__ float rocrand_normal(rocrand_state_philox4x32_10 *state)
Returns a normally distributed float value.
Definition: rocrand_normal.h:379
__forceinline__ __device__ __host__ 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:377
__forceinline__ __device__ __host__ double rocrand_normal_double(rocrand_state_philox4x32_10 *state)
Returns a normally distributed double value.
Definition: rocrand_normal.h:456
__forceinline__ __device__ __host__ float4 rocrand_normal4(rocrand_state_philox4x32_10 *state)
Returns four normally distributed float values.
Definition: rocrand_normal.h:435
__forceinline__ __device__ __host__ unsigned int rocrand(rocrand_state_lfsr113 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition: rocrand_lfsr113.h:277
__forceinline__ __device__ __host__ float2 rocrand_normal2(rocrand_state_philox4x32_10 *state)
Returns two normally distributed float values.
Definition: rocrand_normal.h:412