未验证 提交 a38fc5e1 编写于 作者: Z zhangyikun02 提交者: GitHub

conv2d_transpose and deformable_conv unrestricted some limit for xpu2, test=kunlun (#47837)

上级 cdd8c8ab
......@@ -10,7 +10,7 @@ set(XPU_RT_LIB_NAME "libxpurt.so")
if(NOT DEFINED XPU_BASE_URL)
set(XPU_BASE_URL_WITHOUT_DATE
"https://baidu-kunlun-product.su.bcebos.com/KL-SDK/klsdk-dev")
set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20221104")
set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20221110")
else()
set(XPU_BASE_URL "${XPU_BASE_URL}")
endif()
......@@ -19,7 +19,7 @@ endif()
if(NOT DEFINED XPU_XDNN_BASE_URL)
set(XPU_XDNN_BASE_URL_WITHOUT_DATE
"https://klx-sdk-release-public.su.bcebos.com/xdnn/dev")
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20221103")
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20221109")
else()
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL}")
endif()
......
......@@ -72,52 +72,30 @@ void Conv2dTransposeKernel(const Context& ctx,
const int batch_size = static_cast<int>(x.dims()[0]);
const int img_yc = static_cast<int>(x.dims()[1]);
const int img_yh = static_cast<int>(x.dims()[2]);
const int img_yw = static_cast<int>(x.dims()[3]);
const int img_xc = static_cast<int>(out->dims()[1]);
const int img_xh = static_cast<int>(out->dims()[2]);
const int img_xw = static_cast<int>(out->dims()[3]);
{
std::vector<int> ksize_check = vector_extend(ksize, 2);
std::vector<int> stride_check = vector_extend(strides, 2);
std::vector<int> pad_check = vector_extend(paddings_, 4);
std::vector<int> dilation_check = vector_extend(dilations_, 2);
int xh_check = (img_yh - 1) * stride_check[0] - pad_check[0] -
pad_check[1] +
(dilation_check[0] * (ksize_check[0] - 1) + 1);
int xw_check = (img_yw - 1) * stride_check[1] - pad_check[2] -
pad_check[3] +
(dilation_check[1] * (ksize_check[1] - 1) + 1);
PADDLE_ENFORCE_EQ(
xh_check == img_xh && xw_check == img_xw,
true,
errors::InvalidArgument(
("XPU output size check error in conv_transpose op.")));
}
int r =
xpu::conv2d_transpose<float, float, float, int16_t>(ctx.x_context(),
x.data<float>(),
filter_.data<float>(),
out->data<float>(),
batch_size,
img_yc,
img_yh,
img_yw,
img_xc,
ksize,
strides,
paddings_,
dilations_,
groups,
nullptr,
nullptr,
nullptr,
true);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "conv2d_transpose");
int r = xpu::conv2d_transpose_v2<float, float, float, int16_t>(
ctx.x_context(),
x.data<float>(),
filter_.data<float>(),
out->data<float>(),
batch_size,
img_yc,
img_xh,
img_xw,
img_xc,
ksize,
strides,
paddings_,
dilations_,
groups,
nullptr,
nullptr,
nullptr,
true);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "conv2d_transpose_v2");
}
} // namespace phi
......
......@@ -54,21 +54,24 @@ void DeformableConvGradKernel(const Context& dev_ctx,
dmask_data = dev_ctx.template Alloc<T>(mask_grad);
}
PADDLE_ENFORCE_EQ(
deformable_groups == 1,
true,
errors::InvalidArgument(
("XPU only support deformable_groups == 1 in deformable_conv op.")));
if (phi::backends::xpu::get_xpu_version(dev_ctx.GetPlace().GetDeviceId()) ==
phi::backends::xpu::XPUVersion::XPU1) {
PADDLE_ENFORCE_EQ(
deformable_groups == 1,
true,
errors::InvalidArgument(("XPU1 only support deformable_groups == 1 in "
"deformable_conv_grad op.")));
}
PADDLE_ENFORCE_EQ(
groups == 1,
true,
errors::InvalidArgument(
("XPU only support groups == 1 in deformable_conv op.")));
("XPU only support groups == 1 in deformable_conv_grad op.")));
PADDLE_ENFORCE_EQ(filter.dims()[2] <= 8 && filter.dims()[3] <= 8,
true,
errors::InvalidArgument(
"Filter high and weight should less than 8 on xpu "
"in deformable_conv op."));
"in deformable_conv_grad op."));
const int batch_size = static_cast<int>(x.dims()[0]);
std::vector<int64_t> output_shape_vec(phi::vectorize(out_grad.dims()));
......
......@@ -34,16 +34,19 @@ void DeformableConvKernel(const Context& dev_ctx,
DenseTensor* out) {
dev_ctx.template Alloc<T>(out);
PADDLE_ENFORCE_EQ(
deformable_groups == 1,
true,
errors::InvalidArgument(
("XPU only support deformable_groups == 1 in deformable_conv op.")));
PADDLE_ENFORCE_EQ(
groups == 1,
true,
errors::InvalidArgument(
("XPU only support groups == 1 in deformable_conv op.")));
if (phi::backends::xpu::get_xpu_version(dev_ctx.GetPlace().GetDeviceId()) ==
phi::backends::xpu::XPUVersion::XPU1) {
PADDLE_ENFORCE_EQ(
deformable_groups == 1,
true,
errors::InvalidArgument(("XPU1 only support deformable_groups == 1 in "
"deformable_conv op.")));
PADDLE_ENFORCE_EQ(
groups == 1,
true,
errors::InvalidArgument(
("XPU1 only support groups == 1 in deformable_conv op.")));
}
PADDLE_ENFORCE_EQ(filter.dims()[2] <= 8 && filter.dims()[3] <= 8,
true,
errors::InvalidArgument(
......
......@@ -280,6 +280,17 @@ class XPUTestConv2DTransposeOp(XPUOpTestWrapper):
f_c = self.input_size[1]
self.filter_size = [f_c, 6, 3, 3]
class TestWithEvenUpsample(TestConv2DTransposeOp):
def init_test_case(self):
self.pad = [2, 2]
self.stride = [2, 2]
self.groups = 1
self.dilations = [1, 1]
self.output_size = [14, 14]
self.input_size = [2, 3, 7, 7] # NCHW
f_c = self.input_size[1]
self.filter_size = [f_c, 6, 5, 5]
support_types = get_xpu_op_support_types('conv2d_transpose')
for stype in support_types:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册