|
|
@ -65,36 +65,40 @@ __kernel void |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int index = get_global_id(0); index < nthreads; |
|
|
|
int index = get_global_id(0); |
|
|
|
index += get_global_size(0)) |
|
|
|
if (index >= nthreads) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int pw = index % pooled_width; |
|
|
|
|
|
|
|
const int xx = index / pooled_width; |
|
|
|
|
|
|
|
const int ph = xx % pooled_height; |
|
|
|
|
|
|
|
const int ch = xx / pooled_height; |
|
|
|
|
|
|
|
int hstart = ph * STRIDE_H - PAD_H; |
|
|
|
|
|
|
|
int wstart = pw * STRIDE_W - PAD_W; |
|
|
|
|
|
|
|
Dtype maxval = -FLT_MAX; |
|
|
|
|
|
|
|
int maxidx = -1; |
|
|
|
|
|
|
|
int in_offset = ch * height * width; |
|
|
|
|
|
|
|
for (int h = 0; h < KERNEL_H; ++h) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const int pw = index % pooled_width; |
|
|
|
int off_y = hstart + h; |
|
|
|
const int ph = (index / pooled_width) % pooled_height; |
|
|
|
if (off_y >= 0 && off_y < height) |
|
|
|
const int c = (index / pooled_width / pooled_height) % channels; |
|
|
|
{ |
|
|
|
const int n = index / pooled_width / pooled_height / channels; |
|
|
|
for (int w = 0; w < KERNEL_W; ++w) |
|
|
|
int hstart = ph * STRIDE_H - PAD_H; |
|
|
|
{ |
|
|
|
int wstart = pw * STRIDE_W - PAD_W; |
|
|
|
int off_x = wstart + w; |
|
|
|
const int hend = min(hstart + KERNEL_H, height); |
|
|
|
if (off_x >= 0 && off_x < width) |
|
|
|
const int wend = min(wstart + KERNEL_W, width); |
|
|
|
{ |
|
|
|
hstart = max(hstart, (int)0); |
|
|
|
Dtype val = bottom_data[in_offset + off_y * width + off_x]; |
|
|
|
wstart = max(wstart, (int)0); |
|
|
|
maxidx = (val > maxval) ? (off_y * width + off_x) : maxidx; |
|
|
|
Dtype maxval = -FLT_MAX; |
|
|
|
maxval = fmax(val, maxval); |
|
|
|
int maxidx = -1; |
|
|
|
|
|
|
|
__global const Dtype* bottom_slice = bottom_data |
|
|
|
|
|
|
|
+ (n * channels + c) * height * width; |
|
|
|
|
|
|
|
for (int h = hstart; h < hend; ++h) { |
|
|
|
|
|
|
|
for (int w = wstart; w < wend; ++w) { |
|
|
|
|
|
|
|
if (bottom_slice[h * width + w] > maxval) { |
|
|
|
|
|
|
|
maxidx = h * width + w; |
|
|
|
|
|
|
|
maxval = bottom_slice[maxidx]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
top_data[index] = maxval; |
|
|
|
} |
|
|
|
|
|
|
|
top_data[index] = maxval; |
|
|
|
#ifdef HAVE_MASK |
|
|
|
#ifdef HAVE_MASK |
|
|
|
mask[index] = maxidx; |
|
|
|
mask[index] = maxidx; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#elif defined KERNEL_AVE_POOL |
|
|
|
#elif defined KERNEL_AVE_POOL |
|
|
@ -105,43 +109,42 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)( |
|
|
|
const int pooled_height, const int pooled_width, |
|
|
|
const int pooled_height, const int pooled_width, |
|
|
|
__global Dtype* top_data) |
|
|
|
__global Dtype* top_data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int index = get_global_id(0); index < nthreads; |
|
|
|
int index = get_global_id(0); |
|
|
|
index += get_global_size(0)) |
|
|
|
if (index >= nthreads) |
|
|
|
{ |
|
|
|
return; |
|
|
|
{ |
|
|
|
|
|
|
|
const int pw = index % pooled_width; |
|
|
|
const int pw = index % pooled_width; |
|
|
|
const int ph = (index / pooled_width) % pooled_height; |
|
|
|
const int xx = index / pooled_width; |
|
|
|
const int c = (index / pooled_width / pooled_height) % channels; |
|
|
|
const int ph = xx % pooled_height; |
|
|
|
const int n = index / pooled_width / pooled_height / channels; |
|
|
|
const int ch = xx / pooled_height; |
|
|
|
int hstart = ph * STRIDE_H - PAD_H; |
|
|
|
int hstart = ph * STRIDE_H - PAD_H; |
|
|
|
int wstart = pw * STRIDE_W - PAD_W; |
|
|
|
int wstart = pw * STRIDE_W - PAD_W; |
|
|
|
int hend = min(hstart + KERNEL_H, height + PAD_H); |
|
|
|
int hend = min(hstart + KERNEL_H, height + PAD_H); |
|
|
|
int wend = min(wstart + KERNEL_W, width + PAD_W); |
|
|
|
int wend = min(wstart + KERNEL_W, width + PAD_W); |
|
|
|
int pool_size; |
|
|
|
int pool_size; |
|
|
|
#ifdef AVE_POOL_PADDING_AREA |
|
|
|
#ifdef AVE_POOL_PADDING_AREA |
|
|
|
pool_size = (hend - hstart) * (wend - wstart); |
|
|
|
pool_size = (hend - hstart) * (wend - wstart); |
|
|
|
hstart = max(hstart, (int)0); |
|
|
|
hstart = max(hstart, (int)0); |
|
|
|
wstart = max(wstart, (int)0); |
|
|
|
wstart = max(wstart, (int)0); |
|
|
|
hend = min(hend, height); |
|
|
|
hend = min(hend, height); |
|
|
|
wend = min(wend, width); |
|
|
|
wend = min(wend, width); |
|
|
|
#else |
|
|
|
#else |
|
|
|
hstart = max(hstart, (int)0); |
|
|
|
hstart = max(hstart, (int)0); |
|
|
|
wstart = max(wstart, (int)0); |
|
|
|
wstart = max(wstart, (int)0); |
|
|
|
hend = min(hend, height); |
|
|
|
hend = min(hend, height); |
|
|
|
wend = min(wend, width); |
|
|
|
wend = min(wend, width); |
|
|
|
pool_size = (hend - hstart) * (wend - wstart); |
|
|
|
pool_size = (hend - hstart) * (wend - wstart); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
Dtype aveval = 0; |
|
|
|
Dtype aveval = 0; |
|
|
|
__global const Dtype* bottom_slice = bottom_data |
|
|
|
int in_offset = ch * height * width; |
|
|
|
+ (n * channels + c) * height * width; |
|
|
|
for (int h = hstart; h < hend; ++h) |
|
|
|
for (int h = hstart; h < hend; ++h) { |
|
|
|
{ |
|
|
|
for (int w = wstart; w < wend; ++w) { |
|
|
|
for (int w = wstart; w < wend; ++w) |
|
|
|
aveval += bottom_slice[h * width + w]; |
|
|
|
{ |
|
|
|
} |
|
|
|
aveval += bottom_data[in_offset + h * width + w]; |
|
|
|
} |
|
|
|
|
|
|
|
top_data[index] = aveval / pool_size; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
top_data[index] = aveval / pool_size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#elif defined KERNEL_STO_POOL |
|
|
|
#elif defined KERNEL_STO_POOL |
|
|
|