-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_transitions_mean.h
45 lines (40 loc) · 1.52 KB
/
find_transitions_mean.h
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
__global__ void find_transitions_mean(float *d_values, int *d_trans, int d_ppt,
int thread_count, float *d_high) {
int idx = blockIdx.x * blockDim.x * d_ppt + threadIdx.x * d_ppt;
float mean = 0;
const float thresh = 0.9;
// Tunable -- std of transition.
if (d_ppt > 2) {
for (int i = idx; i < idx + (d_ppt); i++)
mean += d_values[i];
mean /= (float)(d_ppt);
float dev = fabsf(mean - *d_high);
if (dev > thresh && mean < *d_high) {
// There may be a transition here, but be careful, you're wide..
int recurse_d_ppt = d_ppt / 2; // Both of these are always a power of 2...
int recurse_threads = MACRO_THREADS;
int recurse_blocks = floor((((float)d_ppt / (float)recurse_threads)) /
(float)recurse_d_ppt);
float *recurse_d_values = d_values + idx;
int *recurse_d_trans = d_trans + idx;
find_transitions_mean<<<recurse_blocks, recurse_threads>>>(
recurse_d_values, recurse_d_trans, recurse_d_ppt, recurse_threads,
d_high);
} else {
for (int i = idx; i < idx + d_ppt; i++)
d_values[i] = NOT_EVENT;
}
} else {
for (int i = idx; i < idx + d_ppt; i++)
mean += d_values[i];
mean /= (float)(d_ppt);
float dev = fabsf(mean - *d_high);
if (dev > thresh && mean < *d_high) {
for (int i = idx; i < idx + d_ppt; i++)
d_values[i] = mean;
} else {
for (int i = idx; i < idx + d_ppt; i++)
d_values[i] = NOT_EVENT;
}
}
}