未验证 提交 55e63763 编写于 作者: J Jacek Czaja 提交者: GitHub

[oneDNN] adaptive pool support (#27747)

上级 6335e6a0
......@@ -126,6 +126,9 @@ class PoolMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
UpdatePadding(&paddings, global_pooling, 0, padding_algorithm, data_dims,
strides, ksize);
platform::PoolingMKLDNNHandler<T>::ComputeAdaptivePoolParameters(
ctx, paddle::framework::vectorize(in_x->dims()), ksize, strides);
auto& dev_ctx =
ctx.template device_context<platform::MKLDNNDeviceContext>();
......
......@@ -853,6 +853,9 @@ class PoolingMKLDNNHandler : public MKLDNNHandlerT<T, mkldnn::pooling_forward,
CorrectOutputSize(src_tz, dst_tz, ksize, paddings, strides,
mkldnn_paddings[1]);
}
ComputeAdaptivePoolParameters(ctx, src_tz, ksize, strides);
this->AcquireForwardPrimitiveDescriptor(
is_test ? mkldnn::prop_kind::forward_inference
: mkldnn::prop_kind::forward_training,
......@@ -919,6 +922,27 @@ class PoolingMKLDNNHandler : public MKLDNNHandlerT<T, mkldnn::pooling_forward,
return mem_p;
}
static void ComputeAdaptivePoolParameters(
const paddle::framework::ExecutionContext& ctx,
const std::vector<int64_t>& src_tz, std::vector<int64_t>& ksize,
std::vector<int64_t>& strides) {
if (ctx.Attr<bool>("adaptive")) {
// (jczaja): oneDNN is supporting only unchangable in size pool window
PADDLE_ENFORCE_EQ(
src_tz[src_tz.size() - 1] % ksize[1], 0,
platform::errors::Unimplemented(
"Input dim must be divisible by corressponding ksize dim."));
PADDLE_ENFORCE_EQ(
src_tz[src_tz.size() - 2] % ksize[0], 0,
platform::errors::Unimplemented(
"Input dim must be divisible by corressponding ksize dim."));
ksize[0] = src_tz[src_tz.size() - 2] / ksize[0];
ksize[1] = src_tz[src_tz.size() - 1] / ksize[1];
strides[0] = ksize[0];
strides[1] = ksize[1];
}
}
private:
static inline int ComputeCeiledOutput(int input_size, int kernel_size,
int padding, int stride) {
......
......@@ -61,6 +61,37 @@ create_test_mkldnn_class(TestCase4)
create_test_mkldnn_class(TestCase5)
class TestAvgPoolAdaptive(TestPool2D_Op):
def init_adaptive(self):
self.adaptive = True
def init_pool_type(self):
self.pool_type = "avg"
self.pool2D_forward_naive = avg_pool2D_forward_naive
def init_kernel_type(self):
self.use_mkldnn = True
def init_test_case(self):
self.ksize = [1, 1]
self.strides = [1, 1]
def init_data_type(self):
self.dtype = np.float32
def init_global_pool(self):
self.global_pool = False
class TestAvgPoolAdaptive2(TestAvgPoolAdaptive):
def init_test_case(self):
self.ksize = [2, 3]
self.strides = [1, 1]
def init_shape(self):
self.shape = [2, 3, 6, 6]
class TestAsymPad(TestPool2D_Op):
def init_test_case(self):
self.ksize = [3, 3]
......@@ -160,4 +191,6 @@ class TestAsymPadValidNHWC(TestAsymPadValid):
if __name__ == '__main__':
from paddle import enable_static
enable_static()
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册