-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_halo.cl
49 lines (40 loc) · 1.4 KB
/
load_halo.cl
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
__kernel void
load_halo(__global __read_only int *image,
__global __read_only int *output,
__local int *buffer,
int img_w, int img_h,
int buf_w, int buf_h,
const int halo) // width of halo on one side
{
// Global position of output pixel
const int x = get_global_id(0);
const int y = get_global_id(1);
// Local position relative to (0, 0) in workgroup
const int lx = get_local_id(0);
const int ly = get_local_id(1);
// coordinates of the upper left corner of the buffer in image
// space, including halo
const int buf_corner_x = x - lx - halo;
const int buf_corner_y = y - ly - halo;
// coordinates of our pixel in the local buffer
const int buf_x = lx + halo;
const int buf_y = ly + halo;
// 1D index of thread within our work-group
const int idx_1D = ly * get_local_size(0) + lx;
int row;
if (idx_1D < buf_w)
for (row = 0; row < buf_h; row++) {
buffer[row * buf_w + idx_1D] = \
FETCH(image, img_w, img_h,
buf_corner_x + idx_1D,
buf_corner_y + row);
}
barrier(CLK_LOCAL_MEM_FENCE);
// Processing code here...
//
// Should only use buffer, buf_x, buf_y.
// write output
if ((y < img_h) && (x < img_w)) // stay in bounds
output[y * img_w + x] = \
buffer[buf_y * buf_w + buf_x];
}