Skip to content

Commit bce657d

Browse files
committed
asymmetric padding enhancement: automatically use Caffe engine instead of cuDNN to avoid abort.
1 parent 6bf73f6 commit bce657d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/caffe/layer_factory.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ shared_ptr<Layer<Dtype> > GetConvolutionLayer(
122122
use_dilation = true;
123123
}
124124
}
125+
bool asym_pad = false;
126+
if (conv_param.pad_type() != 0) asym_pad = true;
125127
#endif
126128
if (engine == ConvolutionParameter_Engine_DEFAULT) {
127129
engine = ConvolutionParameter_Engine_CAFFE;
128130
#ifdef USE_CUDNN
129-
if (!use_dilation) {
131+
if (!use_dilation && !asym_pad) {
130132
engine = ConvolutionParameter_Engine_CUDNN;
131133
}
134+
if (asym_pad) {
135+
LOG(INFO) << "CuDNN doesn't support the asymmetric padding at Layer "
136+
<< param.name() << ", using Caffe's own convolution layer instead.";
137+
engine = ConvolutionParameter_Engine_CAFFE;
138+
}
132139
#endif
133140
}
134141
if (engine == ConvolutionParameter_Engine_CAFFE) {
@@ -222,7 +229,15 @@ shared_ptr<Layer<Dtype> > GetPoolingLayer(const LayerParameter& param) {
222229
if (engine == PoolingParameter_Engine_DEFAULT) {
223230
engine = PoolingParameter_Engine_CAFFE;
224231
#ifdef USE_CUDNN
225-
engine = PoolingParameter_Engine_CUDNN;
232+
bool asym_pad = false;
233+
if (param.pooling_param().pad_type() != 0) asym_pad = true;
234+
if (!asym_pad)
235+
engine = PoolingParameter_Engine_CUDNN;
236+
else {
237+
LOG(INFO) << "cuDNN does not support the asymmetric padding at Layer "
238+
<< param.name() << " ,using Caffe's own pooling layer instead.";
239+
engine = PoolingParameter_Engine_CAFFE;
240+
}
226241
#endif
227242
}
228243
if (engine == PoolingParameter_Engine_CAFFE) {

0 commit comments

Comments
 (0)