-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_wave.cl
More file actions
48 lines (39 loc) · 1.03 KB
/
extract_wave.cl
File metadata and controls
48 lines (39 loc) · 1.03 KB
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
/* Kernel for waveform extraction */
__kernel void waveextract(
__global const unsigned short* restrict buffer,
int npixels,
int nsamples,
int ws,
__global unsigned short* restrict maxres,
__global unsigned short* restrict timeres)
{
int gid = get_global_id(0);
long sumn = 0;
long sumd = 0;
// terribru slow s[j] access to global memory (false sharing) copy s to local buffer.
//unsigned short* s = (unsigned short*) (buffer + gid * nsamples);
int j;
for(j=0; j<ws; j++) {
sumn += (buffer+gid*nsamples)[j] * j;
sumd += (buffer+gid*nsamples)[j];
}
unsigned short max = sumd;
double t = 0;
if(sumd != 0)
t = sumn / (double)sumd;
double maxt = t;
long maxj = 0;
for(j=1; j<nsamples-ws; j++) {
sumn = sumn - (buffer+gid*nsamples)[j-1] * (j-1) + (buffer+gid*nsamples)[j+ws-1] * (j+ws-1);
sumd = sumd - (buffer+gid*nsamples)[j-1] + (buffer+gid*nsamples)[j+ws-1];
if(sumd > max) {
max = sumd;
if(sumd != 0)
t = sumn / (double)sumd;
maxt = t;
maxj = j;
}
}
maxres[gid] = max;
timeres[gid] = maxt;
}