-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_lombscargle.cu
170 lines (149 loc) · 5.54 KB
/
_lombscargle.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2019-2020, NVIDIA CORPORATION.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////////////
// LOMBSCARGLE //
///////////////////////////////////////////////////////////////////////////////
// Build
/*
nvcc --fatbin -std=c++11 --use_fast_math \
--generate-code arch=compute_35,code=sm_35 \
--generate-code arch=compute_35,code=sm_37 \
--generate-code arch=compute_50,code=sm_50 \
--generate-code arch=compute_50,code=sm_52 \
--generate-code arch=compute_53,code=sm_53 \
--generate-code arch=compute_60,code=sm_60 \
--generate-code arch=compute_61,code=sm_61 \
--generate-code arch=compute_62,code=sm_62 \
--generate-code arch=compute_70,code=sm_70 \
--generate-code arch=compute_72,code=sm_72 \
--generate-code arch=compute_75,code=[sm_75,compute_75] \
_lombscargle.cu -odir .
*/
extern "C" {
__global__ void _cupy_lombscargle_float32(
const int x_shape,
const int freqs_shape,
const float * __restrict__ x,
const float * __restrict__ y,
const float * __restrict__ freqs,
float * __restrict__ pgram,
const float * __restrict__ y_dot
) {
const int tx {
static_cast<int>( blockIdx.x * blockDim.x + threadIdx.x ) };
const int stride { static_cast<int>( blockDim.x * gridDim.x ) };
float yD {};
if ( y_dot[0] == 0 ) {
yD = 1.0f;
} else {
yD = 2.0f / y_dot[0];
}
for ( int tid = tx; tid < freqs_shape; tid += stride ) {
float freq { freqs[tid] };
float xc {};
float xs {};
float cc {};
float ss {};
float cs {};
float c {};
float s {};
for ( int j = 0; j < x_shape; j++ ) {
c = cosf( freq * x[j] );
s = sinf( freq * x[j] );
xc += y[j] * c;
xs += y[j] * s;
cc += c * c;
ss += s * s;
cs += c * s;
}
float tau { atan2f( 2.0f * cs, cc - ss ) / ( 2.0f * freq ) };
float c_tau { cosf(freq * tau) };
float s_tau { sinf(freq * tau) };
float c_tau2 { c_tau * c_tau };
float s_tau2 { s_tau * s_tau };
float cs_tau { 2.0f * c_tau * s_tau };
pgram[tid] = (
0.5f * (
(
( c_tau * xc + s_tau * xs )
* ( c_tau * xc + s_tau * xs )
/ ( c_tau2 * cc + cs_tau * cs + s_tau2 * ss )
)
+ (
( c_tau * xs - s_tau * xc )
* ( c_tau * xs - s_tau * xc )
/ ( c_tau2 * ss - cs_tau * cs + s_tau2 * cc )
)
)
) * yD;
}
}
__global__ void _cupy_lombscargle_float64(
const int x_shape,
const int freqs_shape,
const double * __restrict__ x,
const double * __restrict__ y,
const double * __restrict__ freqs,
double * __restrict__ pgram,
const double * __restrict__ y_dot
) {
const int tx {
static_cast<int>( blockIdx.x * blockDim.x + threadIdx.x ) };
const int stride { static_cast<int>( blockDim.x * gridDim.x ) };
double yD {};
if ( y_dot[0] == 0 ) {
yD = 1.0;
} else {
yD = 2.0 / y_dot[0];
}
for ( int tid = tx; tid < freqs_shape; tid += stride ) {
double freq { freqs[tid] };
double xc {};
double xs {};
double cc {};
double ss {};
double cs {};
double c {};
double s {};
for ( int j = 0; j < x_shape; j++ ) {
c = cos( freq * x[j] );
s = sin( freq * x[j] );
xc += y[j] * c;
xs += y[j] * s;
cc += c * c;
ss += s * s;
cs += c * s;
}
double tau { atan2( 2.0 * cs, cc - ss ) / ( 2.0 * freq ) };
double c_tau { cos(freq * tau) };
double s_tau { sin(freq * tau) };
double c_tau2 { c_tau * c_tau };
double s_tau2 { s_tau * s_tau };
double cs_tau { 2.0 * c_tau * s_tau };
pgram[tid] = (
0.5 * (
(
( c_tau * xc + s_tau * xs )
* ( c_tau * xc + s_tau * xs )
/ ( c_tau2 * cc + cs_tau * cs + s_tau2 * ss )
)
+ (
( c_tau * xs - s_tau * xc )
* ( c_tau * xs - s_tau * xc )
/ ( c_tau2 * ss - cs_tau * cs + s_tau2 * cc )
)
)
) * yD;
}
}
}