Commit 5caf6244 authored by Li, Peng's avatar Li, Peng Committed by Alexander Alekhin

Merge pull request #10922 from pengli:dnn

* ave pooling ocl fix

support the padded area control in ave pooling
Signed-off-by: 's avatarLi Peng <peng.li@intel.com>

* warning fix: ununitialized field
parent eaaba646
...@@ -145,9 +145,6 @@ public: ...@@ -145,9 +145,6 @@ public:
inps.getUMatVector(inputs); inps.getUMatVector(inputs);
outs.getUMatVector(outputs); outs.getUMatVector(outputs);
if (type == AVE && padMode == "SAME")
return false;
if (poolOp.empty()) if (poolOp.empty())
{ {
OCL4DNNPoolConfig config; OCL4DNNPoolConfig config;
...@@ -161,6 +158,7 @@ public: ...@@ -161,6 +158,7 @@ public:
config.pool_method = type == MAX ? LIBDNN_POOLING_METHOD_MAX : config.pool_method = type == MAX ? LIBDNN_POOLING_METHOD_MAX :
(type == AVE ? LIBDNN_POOLING_METHOD_AVE : (type == AVE ? LIBDNN_POOLING_METHOD_AVE :
LIBDNN_POOLING_METHOD_STO); LIBDNN_POOLING_METHOD_STO);
config.avePoolPaddedArea = avePoolPaddedArea;
poolOp = Ptr<OCL4DNNPool<float> >(new OCL4DNNPool<float>(config)); poolOp = Ptr<OCL4DNNPool<float> >(new OCL4DNNPool<float>(config));
} }
......
...@@ -344,7 +344,8 @@ struct OCL4DNNPoolConfig ...@@ -344,7 +344,8 @@ struct OCL4DNNPoolConfig
dilation(1, 1), dilation(1, 1),
channels(0), channels(0),
pool_method(LIBDNN_POOLING_METHOD_MAX), pool_method(LIBDNN_POOLING_METHOD_MAX),
global_pooling(false) global_pooling(false),
avePoolPaddedArea(false)
{} {}
MatShape in_shape; MatShape in_shape;
MatShape out_shape; MatShape out_shape;
...@@ -356,6 +357,7 @@ struct OCL4DNNPoolConfig ...@@ -356,6 +357,7 @@ struct OCL4DNNPoolConfig
int channels; int channels;
ocl4dnnPoolingMethod_t pool_method; // = LIBDNN_POOLING_METHOD_MAX; ocl4dnnPoolingMethod_t pool_method; // = LIBDNN_POOLING_METHOD_MAX;
bool global_pooling; // = false; bool global_pooling; // = false;
bool avePoolPaddedArea;
}; };
template<typename Dtype> template<typename Dtype>
...@@ -388,6 +390,7 @@ class OCL4DNNPool ...@@ -388,6 +390,7 @@ class OCL4DNNPool
int32_t width_; int32_t width_;
int32_t pooled_height_; int32_t pooled_height_;
int32_t pooled_width_; int32_t pooled_width_;
bool avePoolPaddedArea;
}; };
struct OCL4DNNInnerProductConfig struct OCL4DNNInnerProductConfig
......
...@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config) ...@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config)
channels_ = config.channels; channels_ = config.channels;
pool_method_ = config.pool_method; pool_method_ = config.pool_method;
avePoolPaddedArea = config.avePoolPaddedArea;
for (int i = 0; i < spatial_dims; ++i) for (int i = 0; i < spatial_dims; ++i)
{ {
...@@ -143,10 +144,11 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom, ...@@ -143,10 +144,11 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
ocl::dnn::ocl4dnn_pooling_oclsrc, ocl::dnn::ocl4dnn_pooling_oclsrc,
format("-D KERNEL_AVE_POOL=1 -D KERNEL_W=%d -D KERNEL_H=%d" format("-D KERNEL_AVE_POOL=1 -D KERNEL_W=%d -D KERNEL_H=%d"
" -D STRIDE_W=%d -D STRIDE_H=%d" " -D STRIDE_W=%d -D STRIDE_H=%d"
" -D PAD_W=%d -D PAD_H=%d", " -D PAD_W=%d -D PAD_H=%d%s",
kernel_w_, kernel_h_, kernel_w_, kernel_h_,
stride_w_, stride_h_, stride_w_, stride_h_,
pad_w_, pad_h_ pad_w_, pad_h_,
avePoolPaddedArea ? " -D AVE_POOL_PADDING_AREA" : ""
)); ));
if (oclk_ave_pool_forward.empty()) if (oclk_ave_pool_forward.empty())
......
...@@ -114,11 +114,20 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)( ...@@ -114,11 +114,20 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
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);
const int pool_size = (hend - hstart) * (wend - wstart); int pool_size;
#ifdef AVE_POOL_PADDING_AREA
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
hstart = max(hstart, (int)0);
wstart = max(wstart, (int)0);
hend = min(hend, height);
wend = min(wend, width);
pool_size = (hend - hstart) * (wend - wstart);
#endif
Dtype aveval = 0; Dtype aveval = 0;
__global const Dtype* bottom_slice = bottom_data __global const Dtype* bottom_slice = bottom_data
+ (n * channels + c) * height * width; + (n * channels + c) * height * width;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment