var_conv_2d_op.cc 19.7 KB
Newer Older
K
Kevin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

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

    http://www.apache.org/licenses/LICENSE-2.0

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. */

#include "paddle/fluid/operators/var_conv_2d_op.h"
16

17
#include <memory>
K
Kevin 已提交
18
#include <vector>
19

K
Kevin 已提交
20
#include "paddle/fluid/platform/dynload/mklml.h"
21 22
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/funcs/math_function.h"
K
Kevin 已提交
23 24 25 26 27 28 29 30

namespace paddle {
namespace operators {

using LoD = framework::LoD;

void VarConv2dOpMaker::Make() {
  AddInput("X",
31 32
           "X (phi::DenseTensor, default phi::DenseTensor<float>) Input "
           "variable which "
K
Kevin 已提交
33
           "should contain lod information.");
34 35
  AddInput("ROW",
           "(phi::DenseTensor) the row variable provides lod information");
K
Kevin 已提交
36
  AddInput("COLUMN",
37
           "(phi::DenseTensor) the column variable provides lod information");
38
  AddInput("W", "W (phi::DenseTensor), the filter.");
K
Kevin 已提交
39 40 41 42 43 44 45
  AddAttr<int>("InputChannel", "the input filter num").SetDefault(1);
  AddAttr<int>("OutputChannel", "the output filter num").SetDefault(1);
  AddAttr<int>("StrideH", "the height of Stride").SetDefault(1);
  AddAttr<int>("StrideW", "the width of Stride").SetDefault(1);
  AddAttr<int>("KernelH", "the height of Kernel").SetDefault(1);
  AddAttr<int>("KernelW", "the width of Kernel").SetDefault(1);

46 47 48
  AddOutput(
      "Out",
      "(phi::DenseTensor, default phi::DenseTensor<float>) Output variable");
K
Kevin 已提交
49
  AddOutput("Col",
50 51
            "(phi::DenseTensor, default phi::DenseTensor<float>) the "
            "intermediate result "
K
Kevin 已提交
52 53 54 55 56
            "variable");

  AddComment(R"DOC(
    Var Size Conv Operator

57
    This operator calculate Out = \sigma \left ( W * X + b \right ),
K
Kevin 已提交
58
    only support 2-D for X.
59

K
Kevin 已提交
60 61 62 63 64 65
    NOTE: only support 'float32' data type now.

  )DOC");
}

void VarConv2dOP::InferShape(framework::InferShapeContext* ctx) const {
66
  PADDLE_ENFORCE_EQ(
67 68
      ctx->HasInput("X"),
      true,
69 70
      platform::errors::NotFound("X(Input) of VarConv2dOP is not found."));
  PADDLE_ENFORCE_EQ(
71 72
      ctx->HasInput("W"),
      true,
73 74
      platform::errors::NotFound("W(Input) of VarConv2dOP is not found."));
  PADDLE_ENFORCE_EQ(
75 76
      ctx->HasInput("ROW"),
      true,
77 78
      platform::errors::NotFound("Input(ROW) of VarConv2dOP is not found."));
  PADDLE_ENFORCE_EQ(
79 80
      ctx->HasInput("COLUMN"),
      true,
81 82
      platform::errors::NotFound("Input(COLUMN) of VarConv2dOP is not found."));
  PADDLE_ENFORCE_EQ(
83 84
      ctx->HasOutput("Out"),
      true,
85 86
      platform::errors::NotFound("Out(Output) of VarConv2dOP is not found."));
  PADDLE_ENFORCE_EQ(
87 88
      ctx->HasOutput("Col"),
      true,
89
      platform::errors::NotFound("Col(Output) of VarConv2dOP is not found."));
K
Kevin 已提交
90 91

  auto x_dims = ctx->GetInputDim("X");
92
  PADDLE_ENFORCE_EQ(
93 94
      x_dims.size(),
      2,
95 96 97
      platform::errors::InvalidArgument(
          "The rank of X(Input) can't be less than 2, but received rank is %u.",
          x_dims.size()));
K
Kevin 已提交
98 99 100

  auto w_dims = ctx->GetInputDim("W");

101
  PADDLE_ENFORCE_EQ(
102 103
      w_dims.size(),
      2,
104 105 106
      platform::errors::InvalidArgument(
          "Input W should be a 2-D tensor, but its actual dimension is %u.",
          w_dims.size()));
K
Kevin 已提交
107 108 109 110
  int output_channel = ctx->Attrs().Get<int>("OutputChannel");
  int input_channel = ctx->Attrs().Get<int>("InputChannel");
  int kernel_h = ctx->Attrs().Get<int>("KernelH");
  int kernel_w = ctx->Attrs().Get<int>("KernelW");
111
  PADDLE_ENFORCE_EQ(
112 113
      w_dims[0],
      output_channel,
114 115 116
      platform::errors::InvalidArgument(
          "Input W's dimension[0] should be equal to OutputChannel, the "
          "dimension[0] is %d, OutputChannel is %d.",
117 118
          w_dims[0],
          output_channel));
K
Kevin 已提交
119
  PADDLE_ENFORCE_EQ(
120 121
      w_dims[1],
      input_channel * kernel_h * kernel_w,
122 123 124
      platform::errors::InvalidArgument(
          "Input W's dimension[1] should be equal to InputChannel * StrideH * "
          "StrideW, the dimension[1] is %d, expected value is %d.",
125 126
          w_dims[1],
          input_channel * kernel_h * kernel_w));
K
Kevin 已提交
127 128 129

  if (ctx->IsRuntime()) {
    framework::Variable* x_var =
R
Ruibiao Chen 已提交
130
        PADDLE_GET(framework::Variable*, ctx->GetInputVarPtrs("X")[0]);
131
    const auto& x_lod = x_var->Get<phi::DenseTensor>().lod();
132 133 134 135 136
    PADDLE_ENFORCE_EQ(!x_lod.empty(),
                      true,
                      platform::errors::InvalidArgument(
                          "The Input(X) phi::DenseTensor of VarConv2dOP "
                          "does not contain LoD information."));
K
Kevin 已提交
137

138 139
    PADDLE_ENFORCE_GE(x_lod.size(),
                      1,
140 141
                      platform::errors::InvalidArgument(
                          "The Input(X)'s lod info is corrupted."));
142 143
    PADDLE_ENFORCE_EQ(x_dims[0],
                      static_cast<int64_t>(x_lod[0].back()),
144 145 146
                      platform::errors::InvalidArgument(
                          "The Input(X)'s lod info mismatches the actual "
                          "tensor shape, input lod is %s, tensor shape is %s.",
147 148
                          x_lod,
                          x_dims));
K
Kevin 已提交
149 150

    framework::Variable* row_var =
R
Ruibiao Chen 已提交
151
        PADDLE_GET(framework::Variable*, ctx->GetInputVarPtrs("ROW")[0]);
152
    const auto& row_lod = row_var->Get<phi::DenseTensor>().lod();
153 154 155 156 157 158
    PADDLE_ENFORCE_EQ(
        !row_lod.empty(),
        true,
        platform::errors::InvalidArgument(
            "The Input(ROW) phi::DenseTensor of VarConv2dOP does not "
            "contain LoD information."));
K
Kevin 已提交
159 160

    framework::Variable* col_var =
R
Ruibiao Chen 已提交
161
        PADDLE_GET(framework::Variable*, ctx->GetInputVarPtrs("COLUMN")[0]);
162
    const auto& col_lod = col_var->Get<phi::DenseTensor>().lod();
163 164 165 166 167 168
    PADDLE_ENFORCE_EQ(
        !col_lod.empty(),
        true,
        platform::errors::InvalidArgument(
            "The Input(COLUMN) phi::DenseTensor of VarConv2dOP does not "
            "contain LoD information."));
K
Kevin 已提交
169 170 171 172 173
  } else {
    std::vector<int64_t> out_dims_vec{-1};
    out_dims_vec.push_back(1);
    std::vector<int64_t> col_dims_vec{-1};
    col_dims_vec.push_back(1);
174 175
    ctx->SetOutputDim("Out", phi::make_ddim(out_dims_vec));
    ctx->SetOutputDim("Col", phi::make_ddim(col_dims_vec));
K
Kevin 已提交
176 177 178 179 180 181
  }
}

template <typename DeviceContext, typename T>
class CPUVarConv2dOPKernel : public framework::OpKernel<T> {
 public:
182
  void Im2Col(const framework::ExecutionContext& ctx,
183 184
              const phi::DenseTensor& input,
              phi::DenseTensor* col) const {
K
Kevin 已提交
185
    int input_channel = ctx.Attr<int>("InputChannel");
186 187
    auto* in_row = ctx.Input<phi::DenseTensor>("ROW");
    auto* in_col = ctx.Input<phi::DenseTensor>("COLUMN");
K
Kevin 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    int kernel_h = ctx.Attr<int>("KernelH");
    int kernel_w = ctx.Attr<int>("KernelW");
    int stride_h = ctx.Attr<int>("StrideH");
    int stride_w = ctx.Attr<int>("StrideW");

    int batch = input.lod()[0].size() - 1;
    const auto& bottom_offset = input.lod()[0];
    // 2-D lod info.
    const auto& offset_x = in_col->lod()[0];
    const auto& offset_y = in_row->lod()[0];

    // top offset is the whole size of each data sample
    std::vector<size_t> top_offset;
    int top_size = 0;
    top_offset.push_back(top_size);
    for (int b = 0; b < batch; ++b) {
      int width = offset_x[b + 1] - offset_x[b];
      int height = offset_y[b + 1] - offset_y[b];
      int top_im_x = 0;
      if (width == 0) {
        top_im_x = 0;
      } else {
        top_im_x = (width - 1) / stride_w + 1;
      }
      int top_im_y = 0;
      if (height == 0) {
        top_im_y = 0;
      } else {
        top_im_y = (height - 1) / stride_h + 1;
      }
      int top_x = top_im_y * top_im_x;
      int top_y = input_channel * kernel_h * kernel_w;
      top_size += top_y * top_x;
      top_offset.push_back(top_size);
    }
    framework::LoD col_lod;
    col_lod.push_back(top_offset);
    col->set_lod(col_lod);
    std::vector<int64_t> col_dims_vec{top_size};
    col_dims_vec.push_back(1);
228
    auto* top_data =
229
        col->mutable_data<T>(phi::make_ddim(col_dims_vec), ctx.GetPlace());
K
Kevin 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    auto* bottom_data = input.data<T>();

    int kernel_win_size = kernel_h * kernel_w;
    int half_kernel_h = kernel_h / 2;
    int half_kernel_w = kernel_w / 2;
    for (int b = 0; b < batch; ++b) {
      int t_offset = top_offset[b];
      int b_offset = bottom_offset[b];
      int width = offset_x[b + 1] - offset_x[b];
      int height = offset_y[b + 1] - offset_y[b];
      if (width == 0 || height == 0) {
        continue;
      }
      int top_im_x = (width - 1) / stride_w + 1;
      int top_im_y = (height - 1) / stride_h + 1;
      int top_x = top_im_y * top_im_x;
      for (int z = 0; z < input_channel; ++z) {
        int row_offset = kernel_win_size * z;
        int im_offset = z * width * height;
        for (int y = 0; y < height; y += stride_h) {
          for (int x = 0; x < width; x += stride_w) {
            int col_offset = x / stride_w + y / stride_h * top_im_x;
            for (int ky = 0; ky < kernel_h; ++ky) {
              for (int kx = 0; kx < kernel_w; ++kx) {
                int im_y = y + ky - half_kernel_h;
                int im_x = x + kx - half_kernel_w;
                if (im_x >= 0 && im_x < width && im_y >= 0 && im_y < height) {
                  top_data[t_offset +
                           (row_offset + ky * kernel_w + kx) * top_x +
                           col_offset] =
                      bottom_data[b_offset + im_offset + im_y * width + im_x];
                } else {
                  top_data[t_offset +
                           (row_offset + ky * kernel_w + kx) * top_x +
                           col_offset] = 0;
                }
              }
            }
          }
        }
      }
    }
  }

  void Compute(const framework::ExecutionContext& ctx) const override {
275 276 277
    auto* bottom = ctx.Input<phi::DenseTensor>("X");
    auto* in_row = ctx.Input<phi::DenseTensor>("ROW");
    auto* in_col = ctx.Input<phi::DenseTensor>("COLUMN");
278
    auto* w = ctx.Input<phi::DenseTensor>("W");
279 280
    auto* top = ctx.Output<phi::DenseTensor>("Out");
    auto* col = ctx.Output<phi::DenseTensor>("Col");
K
Kevin 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322

    int output_channel = ctx.Attr<int>("OutputChannel");
    int input_channel = ctx.Attr<int>("InputChannel");
    int kernel_h = ctx.Attr<int>("KernelH");
    int kernel_w = ctx.Attr<int>("KernelW");
    int stride_h = ctx.Attr<int>("StrideH");
    int stride_w = ctx.Attr<int>("StrideW");

    Im2Col(ctx, *bottom, col);
    int batch = bottom->lod()[0].size() - 1;
    const auto& col_offset = col->lod()[0];
    const auto& offset_x = in_col->lod()[0];
    const auto& offset_y = in_row->lod()[0];
    std::vector<size_t> top_offset;
    int top_size = 0;
    top_offset.push_back(top_size);
    for (int b = 0; b < batch; ++b) {
      int width = offset_x[b + 1] - offset_x[b];
      int height = offset_y[b + 1] - offset_y[b];
      int top_im_x = 0;
      if (width == 0) {
        top_im_x = 0;
      } else {
        top_im_x = (width - 1) / stride_w + 1;
      }
      int top_im_y = 0;
      if (height == 0) {
        top_im_y = 0;
      } else {
        top_im_y = (height - 1) / stride_h + 1;
      }
      int top_im_size = top_im_y * top_im_x;
      top_size += output_channel * top_im_size;
      top_offset.push_back(top_size);
    }

    framework::LoD top_lod;
    top_lod.push_back(top_offset);

    top->set_lod(top_lod);
    std::vector<int64_t> top_dims_vec{top_size};
    top_dims_vec.push_back(1);
323
    auto* top_data =
324
        top->mutable_data<T>(phi::make_ddim(top_dims_vec), ctx.GetPlace());
K
Kevin 已提交
325 326 327 328

    auto* w_data = w->data<T>();
    auto* col_data = col->data<T>();

329 330
    auto& dev_ctx = ctx.template device_context<phi::CPUContext>();
    auto blas = phi::funcs::GetBlas<phi::CPUContext, T>(dev_ctx);
K
Kevin 已提交
331 332 333 334 335 336
    for (int b = 0; b < batch; ++b) {
      int top_im_size = (top_offset[b + 1] - top_offset[b]) / output_channel;
      if (top_im_size == 0) {
        continue;
      }

337 338 339 340 341 342 343 344 345 346
      blas.GEMM(CblasNoTrans,
                CblasNoTrans,
                output_channel,
                top_im_size,
                input_channel * kernel_h * kernel_w,
                1.0,
                w_data,
                col_data + col_offset[b],
                0.0,
                top_data + top_offset[b]);
K
Kevin 已提交
347 348 349 350
    }
  }
};

351 352 353 354 355
template <typename T>
class VarConv2dGradMaker : public framework::SingleGradOpMaker<T> {
 public:
  using framework::SingleGradOpMaker<T>::SingleGradOpMaker;

356
  void Apply(GradOpPtr<T> op) const override {
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    op->SetType(this->ForwardOpType() + "_grad");
    op->SetInput("X", this->Input("X"));
    op->SetInput("W", this->Input("W"));
    op->SetInput("ROW", this->Input("ROW"));
    op->SetInput("COLUMN", this->Input("COLUMN"));
    op->SetInput("Col", this->Output("Col"));
    op->SetInput("Out", this->Output("Out"));
    op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out"));

    op->SetOutput(framework::GradVarName("X"), this->InputGrad("X"));
    op->SetOutput(framework::GradVarName("W"), this->InputGrad("W"));
    op->SetAttrMap(this->Attrs());
  }
};

K
Kevin 已提交
372
void VarConv2dOpGrad::InferShape(framework::InferShapeContext* ctx) const {
373 374
  PADDLE_ENFORCE_EQ(ctx->HasInput("X"),
                    true,
375 376
                    platform::errors::NotFound(
                        "Input(X) of SequencePadGradOp is not found."));
377 378
  PADDLE_ENFORCE_EQ(ctx->HasInput("W"),
                    true,
379 380
                    platform::errors::NotFound(
                        "Input(W) of SequencePadGradOp is not found."));
381 382
  PADDLE_ENFORCE_EQ(ctx->HasInput(framework::GradVarName("Out")),
                    true,
383 384
                    platform::errors::NotFound(
                        "Input(Out@GRAD) of SequencePadGradOp is not found."));
K
Kevin 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398

  if (ctx->HasOutput(framework::GradVarName("X"))) {
    ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("X"));
    ctx->ShareLoD("X", /*->*/ framework::GradVarName("X"));
  }
  if (ctx->HasOutput(framework::GradVarName("W"))) {
    ctx->SetOutputDim(framework::GradVarName("W"), ctx->GetInputDim("W"));
  }
}

template <typename DeviceContext, typename T>
class CPUVarConv2dOPGradKernel : public framework::OpKernel<T> {
 public:
  void Im2ColGrad(const framework::ExecutionContext& ctx, T* top_diff) const {
399 400 401 402
    auto* x = ctx.Input<phi::DenseTensor>("X");
    auto* in_row = ctx.Input<phi::DenseTensor>("ROW");
    auto* in_col = ctx.Input<phi::DenseTensor>("COLUMN");
    auto* col = ctx.Input<phi::DenseTensor>("Col");
K
Kevin 已提交
403 404 405 406 407 408 409

    int input_channel = ctx.Attr<int>("InputChannel");
    int kernel_h = ctx.Attr<int>("KernelH");
    int kernel_w = ctx.Attr<int>("KernelW");
    int stride_h = ctx.Attr<int>("StrideH");
    int stride_w = ctx.Attr<int>("StrideW");

410
    auto* dx = ctx.Output<phi::DenseTensor>(framework::GradVarName("X"));
K
Kevin 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

    auto* dx_data = dx->mutable_data<T>(ctx.GetPlace());
    memset(dx_data, 0.0, x->dims()[0] * x->dims()[1] * sizeof(T));

    const auto& bottom_offset = x->lod()[0];
    const auto& offset_x = in_col->lod()[0];
    const auto& offset_y = in_row->lod()[0];
    const auto& top_offset = col->lod()[0];
    int batch = x->lod()[0].size() - 1;
    int kernel_win_size = kernel_h * kernel_w;
    int half_kernel_h = kernel_h / 2;
    int half_kernel_w = kernel_w / 2;
    for (int b = 0; b < batch; ++b) {
      int t_offset = top_offset[b];
      int b_offset = bottom_offset[b];
      int width = offset_x[b + 1] - offset_x[b];
      int height = offset_y[b + 1] - offset_y[b];
      if (width == 0 || height == 0) {
        continue;
      }
      int top_im_x = (width - 1) / stride_w + 1;
      int top_im_y = (height - 1) / stride_h + 1;
      int top_x = top_im_y * top_im_x;
      for (int z = 0; z < input_channel; ++z) {
        int row_offset = kernel_win_size * z;
        int im_offset = z * width * height;
        for (int y = 0; y < height; y += stride_h) {
          for (int x = 0; x < width; x += stride_w) {
            int col_offset = x / stride_w + y / stride_h * top_im_x;
            for (int ky = 0; ky < kernel_h; ++ky) {
              for (int kx = 0; kx < kernel_w; ++kx) {
                int im_y = y + ky - half_kernel_h;
                int im_x = x + kx - half_kernel_w;
                if (im_x >= 0 && im_x < width && im_y >= 0 && im_y < height) {
                  dx_data[b_offset + im_offset + im_y * width + im_x] +=
                      top_diff[t_offset +
                               (row_offset + ky * kernel_w + kx) * top_x +
                               col_offset];
                }
              }
            }
          }
        }
      }
    }
  }

  void Compute(const framework::ExecutionContext& ctx) const override {
459
    auto* x = ctx.Input<phi::DenseTensor>("X");
460
    auto* w = ctx.Input<phi::DenseTensor>("W");
461 462
    auto* col = ctx.Input<phi::DenseTensor>("Col");
    auto* out = ctx.Input<phi::DenseTensor>("Out");
K
Kevin 已提交
463 464 465 466 467 468

    int output_channel = ctx.Attr<int>("OutputChannel");
    int input_channel = ctx.Attr<int>("InputChannel");
    int kernel_h = ctx.Attr<int>("KernelH");
    int kernel_w = ctx.Attr<int>("KernelW");

469 470
    auto* d_out = ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"));
    auto* dx = ctx.Output<phi::DenseTensor>(framework::GradVarName("X"));
471
    auto* d_w = ctx.Output<phi::DenseTensor>(framework::GradVarName("W"));
K
Kevin 已提交
472

473
    phi::DenseTensor col_grad;
K
Kevin 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487
    col_grad.Resize(col->dims());
    auto* col_diff = col_grad.mutable_data<T>(ctx.GetPlace());
    auto* dx_data = dx->mutable_data<T>(ctx.GetPlace());
    auto* w_diff = d_w->mutable_data<T>(ctx.GetPlace());

    memset(dx_data, 0.0, x->dims()[0] * x->dims()[1] * sizeof(T));
    memset(w_diff, 0.0, w->dims()[0] * w->dims()[1] * sizeof(T));
    memset(col_diff, 0.0, col->dims()[0] * col->dims()[1] * sizeof(T));
    auto* top_diff = d_out->data<T>();
    auto* w_data = w->data<T>();
    auto* col_data = col->data<T>();
    int batch = x->lod()[0].size() - 1;
    const auto& top_offset = out->lod()[0];
    const auto& col_offset = col->lod()[0];
488 489
    auto& dev_ctx = ctx.template device_context<phi::CPUContext>();
    auto blas = phi::funcs::GetBlas<phi::CPUContext, T>(dev_ctx);
K
Kevin 已提交
490 491 492 493 494 495
    for (int b = 0; b < batch; ++b) {
      int top_im_size = (top_offset[b + 1] - top_offset[b]) / output_channel;
      if (top_im_size == 0) {
        continue;
      }

496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
      blas.GEMM(CblasTrans,
                CblasNoTrans,
                input_channel * kernel_h * kernel_w,
                top_im_size,
                output_channel,
                1.0,
                w_data,
                top_diff + top_offset[b],
                1.0,
                col_diff + col_offset[b]);

      blas.GEMM(CblasNoTrans,
                CblasTrans,
                output_channel,
                input_channel * kernel_h * kernel_w,
                top_im_size,
                1.0,
                top_diff + top_offset[b],
                col_data + col_offset[b],
                1.0,
K
Kevin 已提交
516 517 518 519 520 521 522 523 524 525 526 527
                w_diff);
    }
    Im2ColGrad(ctx, col_diff);
  }
};

}  // namespace operators
}  // namespace paddle

namespace ops = paddle::operators;
namespace plt = paddle::platform;
namespace frm = paddle::framework;
528 529 530
REGISTER_OPERATOR(var_conv_2d,
                  ops::VarConv2dOP,
                  ops::VarConv2dOpMaker,
531 532
                  ops::VarConv2dGradMaker<paddle::framework::OpDesc>,
                  ops::VarConv2dGradMaker<paddle::imperative::OpBase>);
K
Kevin 已提交
533 534 535
REGISTER_OPERATOR(var_conv_2d_grad, ops::VarConv2dOpGrad);

REGISTER_OP_CPU_KERNEL(var_conv_2d,
L
Leo Chen 已提交
536 537
                       ops::CPUVarConv2dOPKernel<phi::CPUContext, float>);
//     ops::CPUVarConv2dOPKernel<phi::CPUContext,
K
Kevin 已提交
538
//                                       double>
L
Leo Chen 已提交
539 540 541
REGISTER_OP_CPU_KERNEL(var_conv_2d_grad,
                       ops::CPUVarConv2dOPGradKernel<phi::CPUContext, float>);
//     ops::CPUVarConv2dOPGradKernel<phi::CPUContext,
K
Kevin 已提交
542
//                                           double>