conv_transpose_op.cc 23.9 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
C
chengduoZH 已提交
2

L
Luo Tao 已提交
3 4 5
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
C
chengduoZH 已提交
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
C
chengduoZH 已提交
8

L
Luo Tao 已提交
9 10 11 12 13
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
C
chengduoZH 已提交
14

Y
Yi Wang 已提交
15
#include "paddle/fluid/operators/conv_transpose_op.h"
F
From00 已提交
16

S
Siddharth Goyal 已提交
17 18
#include <string>
#include <vector>
19

20
#include "paddle/fluid/framework/data_layout.h"
F
From00 已提交
21 22
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
23
#include "paddle/fluid/framework/op_version_registry.h"
24
#include "paddle/fluid/platform/cudnn_workspace_helper.h"
F
From00 已提交
25 26 27
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/infermeta/binary.h"
J
Jacek Czaja 已提交
28 29 30 31
#ifdef PADDLE_WITH_MKLDNN
#include "paddle/fluid/platform/mkldnn_helper.h"
#endif

C
chengduoZH 已提交
32 33 34
namespace paddle {
namespace operators {

35 36
using DataLayout = framework::DataLayout;

37 38
framework::OpKernelType ConvTransposeOp::GetExpectedKernelType(
    const framework::ExecutionContext& ctx) const {
J
Jacek Czaja 已提交
39
  framework::LibraryType library_{framework::LibraryType::kPlain};
40
  framework::DataLayout layout_ = framework::DataLayout::kAnyLayout;
41 42
  bool use_cudnn =
      ctx.HasAttr("use_cudnn") ? ctx.Attr<bool>("use_cudnn") : false;
C
chengduoZH 已提交
43
  use_cudnn &= platform::is_gpu_place(ctx.GetPlace());
44
  auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "Input");
45
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
C
chengduoZH 已提交
46 47 48
  if (platform::is_gpu_place(ctx.GetPlace())) {
    auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>();
    use_cudnn &= dev_ctx.cudnn_handle() != nullptr;
J
Jacek Czaja 已提交
49 50 51
    if (use_cudnn) {
      library_ = framework::LibraryType::kCUDNN;
    }
C
chengduoZH 已提交
52 53
  }
#endif
J
Jacek Czaja 已提交
54 55
#ifdef PADDLE_WITH_MKLDNN
  if (library_ == framework::LibraryType::kPlain &&
56
      this->CanMKLDNNBeUsed(ctx, data_type)) {
J
Jacek Czaja 已提交
57 58
    library_ = framework::LibraryType::kMKLDNN;
    layout_ = framework::DataLayout::kMKLDNN;
59
  }
J
Jacek Czaja 已提交
60
#endif
61

62
  return framework::OpKernelType(data_type, ctx.GetPlace(), layout_, library_);
63 64
}

65
framework::OpKernelType ConvTransposeOp::GetKernelTypeForVar(
66 67
    const std::string& var_name,
    const framework::Tensor& tensor,
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    const framework::OpKernelType& expected_kernel_type) const {
#ifdef PADDLE_WITH_MKLDNN
  // Only input require reshaping, weights and
  // bias are having shape in NCHW order
  if ((var_name == "Input") &&
      (expected_kernel_type.data_layout_ == framework::DataLayout::kMKLDNN) &&
      (tensor.layout() != framework::DataLayout::kMKLDNN)) {
    auto attrs = Attrs();
    auto ar = paddle::framework::AttrReader(attrs);
    const std::string data_format = ar.Get<std::string>("data_format");
    auto dl = framework::StringToDataLayout(data_format);
    // Some models may have intentionally set "AnyLayout" for pool
    // op. Treat this as NCHW (default data_format value)
    if (dl != framework::DataLayout::kAnyLayout) {
      return framework::OpKernelType(
83 84
          expected_kernel_type.data_type_,
          tensor.place(),
85 86 87 88
          framework::StringToDataLayout(data_format));
    }
  }
#endif
89 90
  return framework::OpKernelType(
      expected_kernel_type.data_type_, tensor.place(), tensor.layout());
91 92
}

Y
Yu Yang 已提交
93
void Conv2DTransposeOpMaker::Make() {
J
Jacek Czaja 已提交
94 95 96
  AddAttr<bool>("is_test",
                "(bool, default false) Set to true for inference only, false "
                "for training. Some layers may run faster when this is true.")
97 98
      .SetDefault(false)
      .AsExtra();
99 100 101 102 103
  AddInput("Input",
           "(Tensor) The input tensor of convolution transpose operator. "
           "The format of input tensor is NCHW or NHWC. Where N is batch size, "
           "C is the number of input channels, H is the height of the feature, "
           "and W is the width of the feature.");
C
chengduoZH 已提交
104 105 106 107 108 109 110 111
  AddInput(
      "Filter",
      "(Tensor) The filter tensor of convolution transpose operator. "
      "The format of the filter tensor is MCHW, where M is the number of "
      "input feature channels, C is the number of "
      "output feature channels,"
      "H is the height of the filter, and W is the width of the filter. "
      "We enforce groups number == 1 in the convolution transpose scenario.");
112 113 114 115
  AddInput("Bias",
           "(Tensor) Bias to be added to each output of filter application."
           "The format of output tensor is X (one-dimensional) of size equal"
           "to the number of output channels. Only used with MKL-DNN.")
116 117
      .AsDispensable()
      .AsExtra();
C
chengduoZH 已提交
118
  AddOutput("Output",
C
chengduoZH 已提交
119
            "(Tensor) The output tensor of convolution transpose operator. "
120
            "The format of output tensor is the same as input tensor.");
L
LielinJiang 已提交
121 122 123 124 125
  AddAttr<std::vector<int>>("output_padding",
                            "(vector<int> default: []), Additional size added "
                            "to one side of each dimension in the output "
                            "shape")
      .SetDefault({});
126 127 128 129
  AddAttr<std::vector<int>>("output_size",
                            "(vector<int> default: []), the "
                            "size of the output tensor")
      .SetDefault({});
Y
Yibing Liu 已提交
130 131 132 133
  AddAttr<int>("groups",
               "(int default:1), the groups number of the convolution "
               "transpose operator. ")
      .SetDefault(1);
C
chengduoZH 已提交
134 135 136 137 138
  AddAttr<std::vector<int>>("dilations",
                            "(vector<int> default:{1, 1}), the "
                            "dilations(h_dilation, w_dilation) of convolution "
                            "transpose operator.")
      .SetDefault({1, 1});
C
chengduoZH 已提交
139 140
  AddAttr<std::vector<int>>(
      "strides",
C
chengduoZH 已提交
141
      "(vector<int> default:{1, 1}), the strides(h_stride, w_stride) of "
142
      "convolution transpose operator.")
C
chengduoZH 已提交
143
      .SetDefault({1, 1});
C
chengduoZH 已提交
144 145
  AddAttr<std::vector<int>>(
      "paddings",
C
chengduoZH 已提交
146
      "(vector<int> default:{0, 0}), the paddings(h_pad, w_pad) of convolution "
C
chengduoZH 已提交
147
      "transpose operator.")
C
chengduoZH 已提交
148
      .SetDefault({0, 0});
149 150 151
  AddAttr<bool>(
      "use_cudnn",
      "(bool, default false) Only used in cudnn kernel, need install cudnn")
152 153
      .SetDefault(false)
      .AsExtra();
J
Jacek Czaja 已提交
154 155
  AddAttr<bool>("use_mkldnn",
                "(bool, default false) Only used in mkldnn kernel")
156 157
      .SetDefault(false)
      .AsExtra();
158 159 160
  AddAttr<bool>("force_fp32_output",
                "(bool, default false) Force BF16 kernel output FP32, only "
                "used in MKL-DNN BF16")
161 162
      .SetDefault(false)
      .AsExtra();
163 164 165 166
  AddAttr<std::string>(
      "mkldnn_data_type",
      "(string, default \"float32\"). Data type of mkldnn kernel")
      .SetDefault("float32")
167 168
      .InEnum({"float32", "bfloat16"})
      .AsExtra();
J
Jacek Czaja 已提交
169
  AddAttr<bool>("fuse_relu", "(bool, default false) Only used in mkldnn kernel")
170 171
      .SetDefault(false)
      .AsExtra();
172 173
  AddAttr<std::string>("fuse_activation",
                       "(string, default \"\") Only used in mkldnn kernel")
174 175
      .SetDefault("")
      .AsExtra();
176 177
  AddAttr<float>("fuse_alpha",
                 "(float, default 0.0) Only used in mkldnn kernel")
178 179
      .SetDefault(0.0f)
      .AsExtra();
180
  AddAttr<float>("fuse_beta", "(float, default 0.0) Only used in mkldnn kernel")
181 182
      .SetDefault(0.0f)
      .AsExtra();
183 184 185 186
  AddAttr<std::string>(
      "data_format",
      "(string, default NCHW) Only used in "
      "An optional string from: \"NHWC\", \"NCHW\". "
187 188 189 190 191 192 193 194 195
      "Specify that the data format of the input and output data is "
      "channel_first or channel_last.")
      .SetDefault("NCHW");
  AddAttr<std::string>(
      "padding_algorithm",
      "(string, default \"EXPLICIT\") An optional string from: \"EXPLICIT\","
      "\"SAME\",\"VALID\". Set to \"EXPLICIT\" for explicit padding. "
      "Set to \"SAME\" or \"VALID\" for algorithm of padding. ")
      .SetDefault("EXPLICIT");
196 197 198 199 200
  AddAttr<int>("workspace_size_MB",
               "Used in cudnn kernel only. workspace size for cudnn, in MB, "
               "workspace is a section of GPU memory which will be "
               "allocated/freed each time the operator runs, larger "
               "workspace size can increase performance but also requires "
T
tianshuo78520a 已提交
201
               "better hardward. This size should be carefully set.")
202 203
      .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB())
      .AsExtra();
C
chengduoZH 已提交
204
  AddComment(R"DOC(
C
chengduoZH 已提交
205 206
Convolution2D Transpose Operator.

C
chengduoZH 已提交
207
The convolution transpose operation calculates the output based on the input, filter
C
chengduoZH 已提交
208
and dilations, strides, paddings, groups parameters. The size of each dimension of the
C
chengduoZH 已提交
209
parameters is checked in the infer-shape.
210
Input(Input) and output(Output) are in NCHW or NHWC format. Where N is batchsize, C is the
C
chengduoZH 已提交
211 212 213 214 215 216
number of channels, H is the height of the feature, and W is the width of the feature.
Filter(Input) is in MCHW format. Where M is the number of input feature channels,
C is the number of output feature channels, H is the height of the filter,
and W is the width of the filter.
Parameters(strides, paddings) are two elements. These two elements represent height
and width, respectively.
C
chengduoZH 已提交
217
The input(X) size and output(Out) size may be different.
C
chengduoZH 已提交
218

Y
update  
yi.wu 已提交
219
For an example:
C
chengduoZH 已提交
220
  Input:
C
chengduoZH 已提交
221 222
       Input shape: $(N, C_{in}, H_{in}, W_{in})$
       Filter shape: $(C_{in}, C_{out}, H_f, W_f)$
C
chengduoZH 已提交
223
  Output:
C
chengduoZH 已提交
224 225 226
       Output shape: $(N, C_{out}, H_{out}, W_{out})$
  Where
  $$
227 228
       H_{out} = (H_{in} - 1) * strides[0] - pad_height_top - pad_height_bottom  + dilations[0] * (H_f - 1) + 1 \\
       W_{out} = (W_{in} - 1) * strides[1] - pad_width_left  - pad_width_right + dilations[1] * (W_f - 1) + 1
C
chengduoZH 已提交
229
  $$
C
chengduoZH 已提交
230 231 232
)DOC");
}

Y
Yu Yang 已提交
233
void Conv3DTransposeOpMaker::Make() {
234 235 236 237 238 239
  AddInput(
      "Input",
      "(Tensor) The input tensor of convolution transpose operator."
      "The format of input tensor is NCDHW or NDHWC. Where N is batch "
      "size, C is the number of channels, D is the depth of the feature, "
      "H is the height of the feature, and W is the width of the feature.");
C
chengduoZH 已提交
240 241
  AddInput("Filter",
           "(Tensor) The filter tensor of convolution transpose operator."
C
chengduoZH 已提交
242 243 244
           "The format of the filter tensor is MCDHW, where M is the number of "
           "input feature channels, C is the number of "
           "output feature channels, D "
C
chengduoZH 已提交
245 246
           "is the depth of the filter, H is the height of the filter, and "
           "W is the width of the filter."
C
chengduoZH 已提交
247
           "We enforce groups number == 1 and padding == 0 in "
C
chengduoZH 已提交
248
           "the convolution3d transpose scenario.");
C
chengduoZH 已提交
249 250
  AddOutput("Output",
            "(Tensor) The output tensor of convolution transpose operator."
251
            "The format of output tensor is the same as input tensor."
C
chengduoZH 已提交
252
            "Where N is batch size, C is "
C
chengduoZH 已提交
253 254
            "the number of channels, D is the depth of the feature, H is the "
            "height of the feature, and W is the width of the feature.");
L
LielinJiang 已提交
255 256 257 258 259
  AddAttr<std::vector<int>>("output_padding",
                            "(vector<int> default: []), Additional size added "
                            "to one side of each dimension in the output "
                            "shape")
      .SetDefault({});
260 261 262 263
  AddAttr<std::vector<int>>("output_size",
                            "(vector<int> default: []), the "
                            "size of the output tensor")
      .SetDefault({});
C
chengduoZH 已提交
264 265 266 267 268 269
  AddAttr<std::vector<int>>(
      "dilations",
      "(vector<int> default:{1, 1, 1}), the "
      "dilations(d_dilation,h_dilation, w_dilation) of convolution "
      "transpose operator.")
      .SetDefault({1, 1, 1});
C
chengduoZH 已提交
270
  AddAttr<std::vector<int>>("strides",
C
chengduoZH 已提交
271
                            "(vector<int> default:{1, 1, 1}), the "
272
                            "strides{d_stride, h_stride, w_stride} of "
C
chengduoZH 已提交
273
                            "convolution transpose operator.")
C
chengduoZH 已提交
274
      .SetDefault({1, 1, 1});
C
chengduoZH 已提交
275
  AddAttr<std::vector<int>>("paddings",
C
chengduoZH 已提交
276
                            "(vector<int> default:{0, 0, 0}), paddings(d_pad, "
C
chengduoZH 已提交
277
                            "h_pad, w_pad) of convolution transpose operator.")
C
chengduoZH 已提交
278
      .SetDefault({0, 0, 0});
279 280 281 282
  AddAttr<int>("groups",
               "(int default:1), the groups number of the convolution3d "
               "transpose operator. ")
      .SetDefault(1);
283 284 285
  AddAttr<bool>(
      "use_cudnn",
      "(bool, default false) Only used in cudnn kernel, need install cudnn")
286 287
      .SetDefault(false)
      .AsExtra();
288 289
  AddAttr<bool>("use_mkldnn",
                "(bool, default false) Only used in mkldnn kernel")
290 291
      .SetDefault(false)
      .AsExtra();
292 293 294 295
  AddAttr<std::string>(
      "data_format",
      "(string, default NCHW) Only used in "
      "An optional string from: \"NHWC\", \"NCHW\". "
296 297 298 299 300 301 302 303 304
      "Specify that the data format of the input and output data is "
      "channel_first or channel_last.")
      .SetDefault("NCHW");
  AddAttr<std::string>(
      "padding_algorithm",
      "(string, default \"EXPLICIT\") An optional string from: \"EXPLICIT\","
      "\"SAME\",\"VALID\". Set to \"EXPLICIT\" for explicit padding. "
      "Set to \"SAME\" or \"VALID\" for algorithm of padding. ")
      .SetDefault("EXPLICIT");
305 306 307 308 309
  AddAttr<int>("workspace_size_MB",
               "Used in cudnn kernel only. workspace size for cudnn, in MB, "
               "workspace is a section of GPU memory which will be "
               "allocated/freed each time the operator runs, larger "
               "workspace size can increase performance but also requires "
T
tianshuo78520a 已提交
310
               "better hardward. This size should be carefully set.")
311 312
      .SetDefault(platform::GetDefaultConvWorkspaceSizeLimitMB())
      .AsExtra();
C
chengduoZH 已提交
313
  AddComment(R"DOC(
C
chengduoZH 已提交
314 315
Convolution3D Transpose Operator.

C
chengduoZH 已提交
316
The convolution transpose operation calculates the output based on the input, filter
C
chengduoZH 已提交
317
and dilations, strides, paddings, groups parameters. The size of each dimension of the
C
chengduoZH 已提交
318
parameters is checked in the infer-shape.
319
Input(Input) and output(Output) are in NCDHW or NDHWC format. Where N is batch size, C is the
C
chengduoZH 已提交
320 321 322 323 324 325 326
number of channels, D is the depth of the feature, H is the height of the feature,
and W is the width of the feature.
Filter(Input) is in MCDHW format. Where M is the number of input feature channels,
C is the number of output feature channels, D is the depth of the filter,H is the
height of the filter, and W is the width of the filter.
Parameters(strides, paddings) are three elements. These three elements represent
depth, height and width, respectively.
C
chengduoZH 已提交
327
The input(X) size and output(Out) size may be different.
C
chengduoZH 已提交
328

329
Example:
C
chengduoZH 已提交
330
  Input:
C
chengduoZH 已提交
331 332
       Input shape: $(N, C_{in}, D_{in}, H_{in}, W_{in})$
       Filter shape: $(C_{in}, C_{out}, D_f, H_f, W_f)$
C
chengduoZH 已提交
333
  Output:
C
chengduoZH 已提交
334 335 336
       Output shape: $(N, C_{out}, D_{out}, H_{out}, W_{out})$
  Where
  $$
337 338 339
       D_{out} = (D_{in} - 1) * strides[0] - pad_depth_front - pad_depth_back + dilations[0] * (D_f - 1) + 1 \\
       H_{out} = (H_{in} - 1) * strides[1] - pad_height_top  - pad_height_bottom + dilations[1] * (H_f - 1) + 1 \\
       W_{out} = (W_{in} - 1) * strides[2] - pad_width_left - pad_width_right + dilations[2] * (W_f - 1) + 1
C
chengduoZH 已提交
340
  $$
C
chengduoZH 已提交
341 342 343
)DOC");
}

344 345
framework::OpKernelType ConvTransposeOpGrad::GetExpectedKernelType(
    const framework::ExecutionContext& ctx) const {
346 347
  bool use_cudnn =
      ctx.HasAttr("use_cudnn") ? ctx.Attr<bool>("use_cudnn") : false;
348
  use_cudnn &= platform::is_gpu_place(ctx.GetPlace());
349
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
C
chengduoZH 已提交
350 351 352 353 354
  if (platform::is_gpu_place(ctx.GetPlace())) {
    auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>();
    use_cudnn &= dev_ctx.cudnn_handle() != nullptr;
  }
#endif
355 356 357 358 359 360 361
  framework::LibraryType library_;
  if (use_cudnn) {
    library_ = framework::LibraryType::kCUDNN;
  } else {
    library_ = framework::LibraryType::kPlain;
  }

362
  framework::DataLayout layout_ = framework::DataLayout::kAnyLayout;
363
  return framework::OpKernelType(
364 365 366 367
      OperatorWithKernel::IndicateVarDataType(ctx, "Input"),
      ctx.GetPlace(),
      layout_,
      library_);
368 369
}

H
hong 已提交
370 371
template <typename T>
class ConvTransposeGradOpMaker : public framework::SingleGradOpMaker<T> {
S
sneaxiy 已提交
372
 public:
H
hong 已提交
373
  using framework::SingleGradOpMaker<T>::SingleGradOpMaker;
S
sneaxiy 已提交
374 375

 protected:
376
  void Apply(GradOpPtr<T> op) const override {
H
hong 已提交
377 378 379 380 381 382 383 384
    op->SetType(this->ForwardOpType() + "_grad");
    op->SetInput("Input", this->Input("Input"));
    op->SetInput("Filter", this->Input("Filter"));
    op->SetOutput(framework::GradVarName("Input"), this->InputGrad("Input"));
    op->SetOutput(framework::GradVarName("Filter"), this->InputGrad("Filter"));
    if (this->HasInput("Bias")) {
      op->SetInput("Bias", this->Input("Bias"));
      op->SetOutput(framework::GradVarName("Bias"), this->InputGrad("Bias"));
S
sneaxiy 已提交
385
    }
H
hong 已提交
386 387
    op->SetInput(framework::GradVarName("Output"), this->OutputGrad("Output"));
    op->SetAttrMap(this->Attrs());
S
sneaxiy 已提交
388 389 390
  }
};

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
/*
 * Inputs:  I, W, dO, ddI, ddW
 * Outputs: ddO, dW, dI
 */
template <typename T>
class ConvTransposeDoubleGradMaker : public framework::SingleGradOpMaker<T> {
 public:
  using framework::SingleGradOpMaker<T>::SingleGradOpMaker;

  void Apply(GradOpPtr<T> op) const override {
    op->SetType(this->ForwardOpType() + "_grad");
    // I, W, dO, ddI, ddW
    op->SetInput("Input", this->Input("Input"));
    op->SetInput("Filter", this->Input("Filter"));
    op->SetInput("DOutput", this->Input(framework::GradVarName("Output")));
    op->SetInput("DDInput", this->OutputGrad(framework::GradVarName("Input")));
    op->SetInput("DDFilter",
                 this->OutputGrad(framework::GradVarName("Filter")));

    // ddO, dI, dW
    // Unlike grad op, double grad op does not use name@GRAD@GRAD
    // as key of ops' inputs and outputs.
    auto ddx = this->OutputGrad(framework::GradVarName("Input"));
    auto ddw = this->OutputGrad(framework::GradVarName("Filter"));

    op->SetOutput("DDOutput",
                  ddx.empty()
                      ? this->EmptyInputGrad()
                      : this->InputGrad(framework::GradVarName("Output")));
420 421 422 423 424 425
    op->SetOutput(
        "DFilter",
        ddx.empty() ? this->EmptyInputGrad() : this->InputGrad("Filter"));
    op->SetOutput(
        "DInput",
        ddw.empty() ? this->EmptyInputGrad() : this->InputGrad("Input"));
426 427 428 429 430 431 432

    op->SetAttrMap(this->Attrs());
  }
};

framework::OpKernelType ConvTransposeOpDoubleGrad::GetExpectedKernelType(
    const framework::ExecutionContext& ctx) const {
433 434
  bool use_cudnn =
      ctx.HasAttr("use_cudnn") ? ctx.Attr<bool>("use_cudnn") : false;
435
  use_cudnn &= platform::is_gpu_place(ctx.GetPlace());
436
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
437 438 439 440 441 442 443 444 445 446 447 448 449 450
  if (platform::is_gpu_place(ctx.GetPlace())) {
    auto& dev_ctx = ctx.template device_context<platform::CUDADeviceContext>();
    use_cudnn &= dev_ctx.cudnn_handle() != nullptr;
  }
#endif
  framework::LibraryType library_;
  if (use_cudnn) {
    library_ = framework::LibraryType::kCUDNN;
  } else {
    library_ = framework::LibraryType::kPlain;
  }

  framework::DataLayout layout_ = framework::DataLayout::kAnyLayout;
  return framework::OpKernelType(
451 452 453 454
      OperatorWithKernel::IndicateVarDataType(ctx, "Input"),
      ctx.GetPlace(),
      layout_,
      library_);
455 456
}

C
chengduoZH 已提交
457 458 459 460
}  // namespace operators
}  // namespace paddle

namespace ops = paddle::operators;
C
chengduoZH 已提交
461

462
// conv2d_transpose
463 464
DECLARE_INFER_SHAPE_FUNCTOR(conv2d_transpose,
                            Conv2dTranposeInferShapeFunctor,
F
From00 已提交
465 466 467 468 469
                            PD_INFER_META(phi::ConvTransposeInferMeta));
DECLARE_INFER_SHAPE_FUNCTOR(conv2d_transpose_grad,
                            Conv2dTranposeGradInferShapeFunctor,
                            PD_INFER_META(phi::ConvTransposeGradInferMeta));
DECLARE_INFER_SHAPE_FUNCTOR(
470 471
    conv2d_transpose_grad_grad,
    Conv2dTranposeDoubleGradInferShapeFunctor,
F
From00 已提交
472 473
    PD_INFER_META(phi::Conv2dTransposeDoubleGradInferMeta));

474 475
REGISTER_OPERATOR(conv2d_transpose,
                  ops::ConvTransposeOp,
Y
Yang Yang 已提交
476
                  ops::Conv2DTransposeOpMaker,
H
hong 已提交
477
                  ops::ConvTransposeGradOpMaker<paddle::framework::OpDesc>,
F
From00 已提交
478 479
                  ops::ConvTransposeGradOpMaker<paddle::imperative::OpBase>,
                  Conv2dTranposeInferShapeFunctor);
480 481
REGISTER_OPERATOR(conv2d_transpose_grad,
                  ops::ConvTransposeOpGrad,
F
From00 已提交
482 483 484
                  ops::ConvTransposeDoubleGradMaker<paddle::framework::OpDesc>,
                  ops::ConvTransposeDoubleGradMaker<paddle::imperative::OpBase>,
                  Conv2dTranposeGradInferShapeFunctor);
485 486
REGISTER_OPERATOR(conv2d_transpose_grad_grad,
                  ops::ConvTransposeOpDoubleGrad,
F
From00 已提交
487
                  Conv2dTranposeDoubleGradInferShapeFunctor);
C
chengduoZH 已提交
488

489
// conv3d_transpose
490 491
DECLARE_INFER_SHAPE_FUNCTOR(conv3d_transpose,
                            Conv3dTranposeInferShapeFunctor,
F
From00 已提交
492 493 494 495 496
                            PD_INFER_META(phi::ConvTransposeInferMeta));
DECLARE_INFER_SHAPE_FUNCTOR(conv3d_transpose_grad,
                            Conv3dTranposeGradInferShapeFunctor,
                            PD_INFER_META(phi::ConvTransposeGradInferMeta));

497 498
REGISTER_OPERATOR(conv3d_transpose,
                  ops::ConvTransposeOp,
Y
Yang Yang 已提交
499
                  ops::Conv3DTransposeOpMaker,
H
hong 已提交
500
                  ops::ConvTransposeGradOpMaker<paddle::framework::OpDesc>,
F
From00 已提交
501 502
                  ops::ConvTransposeGradOpMaker<paddle::imperative::OpBase>,
                  Conv3dTranposeInferShapeFunctor);
503 504
REGISTER_OPERATOR(conv3d_transpose_grad,
                  ops::ConvTransposeOpGrad,
F
From00 已提交
505
                  Conv3dTranposeGradInferShapeFunctor);
506 507

// depthwise conv2d_transpose
F
From00 已提交
508 509 510 511 512 513 514
DECLARE_INFER_SHAPE_FUNCTOR(depthwise_conv2d_transpose,
                            DepthWiseConv2dTranposeInferShapeFunctor,
                            PD_INFER_META(phi::ConvTransposeInferMeta));
DECLARE_INFER_SHAPE_FUNCTOR(depthwise_conv2d_transpose_grad,
                            DepthWiseConv2dTranposeGradInferShapeFunctor,
                            PD_INFER_META(phi::ConvTransposeGradInferMeta));

515 516
REGISTER_OPERATOR(depthwise_conv2d_transpose,
                  ops::ConvTransposeOp,
517
                  ops::Conv2DTransposeOpMaker,
H
hong 已提交
518
                  ops::ConvTransposeGradOpMaker<paddle::framework::OpDesc>,
F
From00 已提交
519 520
                  ops::ConvTransposeGradOpMaker<paddle::imperative::OpBase>,
                  DepthWiseConv2dTranposeInferShapeFunctor);
521 522
REGISTER_OPERATOR(depthwise_conv2d_transpose_grad,
                  ops::ConvTransposeOpGrad,
F
From00 已提交
523
                  DepthWiseConv2dTranposeGradInferShapeFunctor);
524 525 526 527 528 529 530 531 532 533

REGISTER_OP_VERSION(conv_transpose)
    .AddCheckpoint(
        R"ROC(
      Upgrade convtranspose add a new attribute [output_padding].
    )ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "output_padding",
            "In order to add additional size to one side of each dimension "
            "in the output",
534
            std::vector<int>{}));
535 536 537 538 539 540 541 542 543 544

REGISTER_OP_VERSION(conv2d_transpose)
    .AddCheckpoint(
        R"ROC(
      Upgrade conv2d transpose to add a new attribute [output_padding].
    )ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "output_padding",
            "In order to add additional size to one side of each dimension "
            "in the output",
545 546 547 548 549 550 551 552 553
            std::vector<int>{}))
    .AddCheckpoint(
        R"ROC(
      Upgrade conv2d transpose to add a new attributes [force_fp32_output, mkldnn_data_type].
    )ROC",
        paddle::framework::compatible::OpVersionDesc()
            .NewAttr("force_fp32_output",
                     "Force BF16 kernel output FP32, only used in MKL-DNN BF16",
                     false)
554 555
            .NewAttr("mkldnn_data_type",
                     "Data type of mkldnn kernel",
556
                     "float32"));
557 558 559 560 561 562 563 564 565 566

REGISTER_OP_VERSION(conv3d_transpose)
    .AddCheckpoint(
        R"ROC(
      Upgrade conv3d transpose to add a new attribute [output_padding].
    )ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "output_padding",
            "In order to add additional size to one side of each dimension "
            "in the output",
567
            std::vector<int>{}));
568 569 570 571 572 573 574 575 576 577

REGISTER_OP_VERSION(depthwise_conv2d_transpose)
    .AddCheckpoint(
        R"ROC(
      Upgrade depthwise conv2d transpose to add a new attribute [output_padding].
    )ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "output_padding",
            "In order to add additional size to one side of each dimension "
            "in the output",
578
            std::vector<int>{}));