1 /* Copyright 2010-2014 NVIDIA Corporation. All rights reserved.
5 * The source code and/or documentation ("Licensed Deliverables") are
6 * subject to NVIDIA intellectual property rights under U.S. and
7 * international Copyright laws.
9 * The Licensed Deliverables contained herein are PROPRIETARY and
10 * CONFIDENTIAL to NVIDIA and are being provided under the terms and
11 * conditions of a form of NVIDIA software license agreement by and
12 * between NVIDIA and Licensee ("License Agreement") or electronically
13 * accepted by Licensee. Notwithstanding any terms or conditions to
14 * the contrary in the License Agreement, reproduction or disclosure
15 * of the Licensed Deliverables to any third party without the express
16 * written consent of NVIDIA is prohibited.
18 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
19 * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
20 * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. THEY ARE
21 * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
22 * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
23 * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
24 * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
25 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
26 * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
27 * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
28 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
29 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
30 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
31 * OF THESE LICENSED DELIVERABLES.
33 * U.S. Government End Users. These Licensed Deliverables are a
34 * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
35 * 1995), consisting of "commercial computer software" and "commercial
36 * computer software documentation" as such terms are used in 48
37 * C.F.R. 12.212 (SEPT 1995) and are provided to the U.S. Government
38 * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
39 * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
40 * U.S. Government End Users acquire the Licensed Deliverables with
41 * only those rights set forth herein.
43 * Any use of the Licensed Deliverables in individual and commercial
44 * software must include, in the user documentation and internal
45 * comments to the code, the above Disclaimer and U.S. Government End
48 #ifndef CURAND_NORMAL_STATIC_H
49 #define CURAND_NORMAL_STATIC_H
51 #define QUALIFIERS_STATIC __host__ __device__ __forceinline__
53 QUALIFIERS_STATIC float _curand_normal_icdf(unsigned int x)
55 #if __CUDA_ARCH__ > 0 || defined(HOST_HAVE_ERFCINVF)
56 float s = CURAND_SQRT2;
57 // Mirror to avoid loss of precision
58 if(x > 0x80000000UL) {
62 float p = x * CURAND_2POW32_INV + (CURAND_2POW32_INV/2.0f);
63 // p is in (0, 0.5], 2p is in (0, 1]
64 return s * erfcinvf(2.0f * p);
66 x++; //suppress warnings
71 QUALIFIERS_STATIC float _curand_normal_icdf(unsigned long long x)
73 #if __CUDA_ARCH__ > 0 || defined(HOST_HAVE_ERFCINVF)
74 unsigned int t = (unsigned int)(x >> 32);
75 float s = CURAND_SQRT2;
76 // Mirror to avoid loss of precision
77 if(t > 0x80000000UL) {
81 float p = t * CURAND_2POW32_INV + (CURAND_2POW32_INV/2.0f);
82 // p is in (0, 0.5], 2p is in (0, 1]
83 return s * erfcinvf(2.0f * p);
90 QUALIFIERS_STATIC double _curand_normal_icdf_double(unsigned int x)
92 #if __CUDA_ARCH__ > 0 || defined(HOST_HAVE_ERFCINVF)
93 double s = CURAND_SQRT2_DOUBLE;
94 // Mirror to avoid loss of precision
95 if(x > 0x80000000UL) {
99 double p = x * CURAND_2POW32_INV_DOUBLE + (CURAND_2POW32_INV_DOUBLE/2.0);
100 // p is in (0, 0.5], 2p is in (0, 1]
101 return s * erfcinv(2.0 * p);
108 QUALIFIERS_STATIC double _curand_normal_icdf_double(unsigned long long x)
110 #if __CUDA_ARCH__ > 0 || defined(HOST_HAVE_ERFCINVF)
111 double s = CURAND_SQRT2_DOUBLE;
113 // Mirror to avoid loss of precision
114 if(x > 0x10000000000000UL) {
115 x = 0x1fffffffffffffUL - x;
118 double p = x * CURAND_2POW53_INV_DOUBLE + (CURAND_2POW53_INV_DOUBLE/2.0);
119 // p is in (0, 0.5], 2p is in (0, 1]
120 return s * erfcinv(2.0 * p);
126 #undef QUALIFIERS_STATIC