OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / curand_normal_static.h
1  /* Copyright 2010-2014 NVIDIA Corporation.  All rights reserved.
2   *
3   * NOTICE TO LICENSEE:
4   *
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.
8   *
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.
17   *
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.
32   *
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.
42   *
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
46   * Users Notice.
47   */
48 #ifndef CURAND_NORMAL_STATIC_H
49 #define CURAND_NORMAL_STATIC_H
50
51 #define QUALIFIERS_STATIC __host__ __device__ __forceinline__
52
53 QUALIFIERS_STATIC float _curand_normal_icdf(unsigned int x)
54 {
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) {
59         x = 0xffffffffUL - x;
60         s = -s;
61     }
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);
65 #else
66     x++;    //suppress warnings
67     return 0.0f;
68 #endif
69 }
70
71 QUALIFIERS_STATIC float _curand_normal_icdf(unsigned long long x)
72 {
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) {
78         t = 0xffffffffUL - t;
79         s = -s;
80     }
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);
84 #else
85     x++;
86     return 0.0f;
87 #endif
88 }
89
90 QUALIFIERS_STATIC double _curand_normal_icdf_double(unsigned int x)
91 {
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) {
96         x = 0xffffffffUL - x;
97         s = -s;
98     }
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);
102 #else
103     x++;
104     return 0.0;
105 #endif
106 }
107
108 QUALIFIERS_STATIC double _curand_normal_icdf_double(unsigned long long x)
109 {
110 #if __CUDA_ARCH__ > 0 || defined(HOST_HAVE_ERFCINVF)
111     double s = CURAND_SQRT2_DOUBLE;
112     x >>= 11;
113     // Mirror to avoid loss of precision
114     if(x > 0x10000000000000UL) {
115         x = 0x1fffffffffffffUL - x;
116         s = -s;
117     }
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);
121 #else
122     x++;
123     return 0.0;
124 #endif
125 }
126 #undef QUALIFIERS_STATIC
127 #endif