From 5f31737bd0e742673440a246a80d24eb723c4bf6 Mon Sep 17 00:00:00 2001 From: xiaoting <31891223+tink2123@users.noreply.github.com> Date: Mon, 13 Sep 2021 16:22:12 +0800 Subject: [PATCH] fix interpolate launch error (#35577) * fix interpolate launch error, test=develop * fix area mode for interp, test=develop --- paddle/fluid/operators/interpolate_v2_op.cu | 52 ++++++++++----------- python/paddle/nn/functional/common.py | 20 ++++---- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/paddle/fluid/operators/interpolate_v2_op.cu b/paddle/fluid/operators/interpolate_v2_op.cu index d335e1a2f9d..6f8b89ce645 100644 --- a/paddle/fluid/operators/interpolate_v2_op.cu +++ b/paddle/fluid/operators/interpolate_v2_op.cu @@ -1035,9 +1035,9 @@ static void Interpolate1DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_cw = c * in_w; - int out_cw = c * out_w; - int pixelNum = n * out_cw; + int64_t in_cw = c * in_w; + int64_t out_cw = c * out_w; + auto pixelNum = n * out_cw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1169,12 +1169,12 @@ static void Interpolate2DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_hw = in_h * in_w; - int out_hw = out_h * out_w; - int in_chw = c * in_hw; - int out_chw = c * out_hw; + int64_t in_hw = in_h * in_w; + int64_t out_hw = out_h * out_w; + int64_t in_chw = c * in_hw; + int64_t out_chw = c * out_hw; - int pixelNum = n * out_chw; + auto pixelNum = n * out_chw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1355,12 +1355,12 @@ static void Interpolate3DCUDAFwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_dhw = in_d * in_h * in_w; - int out_dhw = out_d * out_h * out_w; - int in_cdhw = c * in_dhw; - int out_cdhw = c * out_dhw; + int64_t in_dhw = in_d * in_h * in_w; + int64_t out_dhw = out_d * out_h * out_w; + int64_t in_cdhw = c * in_dhw; + int64_t out_cdhw = c * out_dhw; - int pixelNum = n * out_cdhw; + auto pixelNum = n * out_cdhw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1456,9 +1456,9 @@ static void Interpolate1DCUDABwd(const framework::ExecutionContext& ctx, ratio_w = (align_corners) ? static_cast(in_w - 1) / (out_w - 1) : static_cast(new_scale_w); } - int in_cw = c * in_w; - int out_cw = c * out_w; - int pixelNum = n * out_cw; + int64_t in_cw = c * in_w; + int64_t out_cw = c * out_w; + auto pixelNum = n * out_cw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1587,11 +1587,11 @@ static void Interpolate2DCUDABwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_hw = in_h * in_w; - int out_hw = out_h * out_w; - int in_chw = c * in_hw; - int out_chw = c * out_hw; - int pixelNum = n * out_chw; + int64_t in_hw = in_h * in_w; + int64_t out_hw = out_h * out_w; + int64_t in_chw = c * in_hw; + int64_t out_chw = c * out_hw; + auto pixelNum = n * out_chw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); @@ -1773,12 +1773,12 @@ static void Interpolate3DCUDABwd(const framework::ExecutionContext& ctx, : static_cast(new_scale_w); } - int in_dhw = in_d * in_h * in_w; - int out_dhw = out_d * out_h * out_w; - int in_cdhw = c * in_dhw; - int out_cdhw = c * out_dhw; + int64_t in_dhw = in_d * in_h * in_w; + int64_t out_dhw = out_d * out_h * out_w; + int64_t in_cdhw = c * in_dhw; + int64_t out_cdhw = c * out_dhw; - int pixelNum = n * out_cdhw; + auto pixelNum = n * out_cdhw; platform::GpuLaunchConfig config = platform::GetGpuLaunchConfig1D(ctx.cuda_device_context(), pixelNum); diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 7cda9a90ff0..323a8af52bc 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -295,13 +295,16 @@ def interpolate(x, "align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear" ) - if resample == 'AREA' and len(x.shape) == 3: - return paddle.nn.functional.adaptive_avg_pool1d(x, size) - - if resample == 'AREA' and len(x.shape) == 4: - return paddle.nn.functional.adaptive_avg_pool2d(x, size) - if resample == 'AREA' and len(x.shape) == 5: - return paddle.nn.functional.adaptive_avg_pool3d(x, size) + if resample == 'AREA': + if isinstance(size, list) or isinstance(size, tuple): + if len(size) == 0: + raise ValueError("output size can not be empty") + if len(x.shape) == 3: + return paddle.nn.functional.adaptive_avg_pool1d(x, size) + elif len(x.shape) == 4: + return paddle.nn.functional.adaptive_avg_pool2d(x, size) + elif len(x.shape) == 5: + return paddle.nn.functional.adaptive_avg_pool3d(x, size) helper = LayerHelper('{}_interp_v2'.format(resample_type), **locals()) dtype = helper.input_dtype(input_param_name='x') @@ -342,14 +345,13 @@ def interpolate(x, out_shape = size scale = scale_factor + if out_shape is not None and scale is not None: raise ValueError("Only one of size or scale_factor should be defined.") if out_shape is not None: - if isinstance(out_shape, Variable) and not in_dygraph_mode(): out_shape.stop_gradient = True inputs['OutSize'] = out_shape - else: if in_dygraph_mode(): if isinstance(out_shape, Variable): -- GitLab