slice_op.cc 20.8 KB
Newer Older
W
whs 已提交
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/slice_op.h"
16

W
whs 已提交
17
#include <algorithm>
18
#include <memory>
19
#include <string>
W
whs 已提交
20
#include <vector>
21

H
hong 已提交
22
#include "paddle/phi/kernels/funcs/slice_utils.h"
W
whs 已提交
23 24 25 26 27 28 29 30 31 32

namespace paddle {
namespace operators {

using Tensor = framework::Tensor;

class SliceOp : public framework::OperatorWithKernel {
 public:
  using framework::OperatorWithKernel::OperatorWithKernel;

33
  void InferShape(framework::InferShapeContext *ctx) const override {
34 35
    OP_INOUT_CHECK(ctx->HasInput("Input"), "Input", "Input", "slice");
    OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "slice");
36

37
    // Case 1: Special treatment when input is a tensor array.
38 39 40
    auto x_var_type = ctx->GetInputsVarType("Input")[0];
    auto axes = ctx->Attrs().Get<std::vector<int>>("axes");
    if (x_var_type == framework::proto::VarType::LOD_TENSOR_ARRAY) {
41 42
      PADDLE_ENFORCE_EQ(axes.size(),
                        1,
43 44 45 46 47 48 49 50 51 52
                        platform::errors::InvalidArgument(
                            "The size of axes must be 1 when the Input of "
                            "SliceOp is LoDTensorArray, "
                            "but received %d.",
                            axes.size()));
      if (ctx->IsRuntime()) {
        // If the var type of input is LOD_TENSOR_ARRAY,
        // the output shape is determined by SliceKernel:Compute in runtime.
        return;
      } else {
L
liym27 已提交
53 54
        // NOTE(liym27): A better way is needed to get accurate dims of tensor
        // array.
55 56 57 58 59 60
        // The resulted dim of GetInputDim("Input") is the dim of the
        // last item written into TensorArray "Input". Maybe it's a bug to fix.
        ctx->SetOutputDim("Out", ctx->GetInputDim("Input"));
        return;
      }
    }
61 62

    // Case 2: input is a tensor.
W
whs 已提交
63
    auto in_dims = ctx->GetInputDim("Input");
64 65
    PADDLE_ENFORCE_LT(in_dims.size(),
                      7,
T
Thunderbrook 已提交
66 67
                      platform::errors::InvalidArgument(
                          "The rank of input should be less than 7."));
W
whs 已提交
68
    framework::DDim out_dims(in_dims);
69

W
whs 已提交
70 71
    auto starts = ctx->Attrs().Get<std::vector<int>>("starts");
    auto ends = ctx->Attrs().Get<std::vector<int>>("ends");
H
Hongyu Liu 已提交
72
    auto decrease_axis = ctx->Attrs().Get<std::vector<int>>("decrease_axis");
73
    auto infer_flags = ctx->Attrs().Get<std::vector<int>>("infer_flags");
74 75 76 77 78 79
    if (infer_flags.empty()) {
      // Initialize infer_flags with 1.
      // To be compatible with other op tests in which infer_flags is not set.
      infer_flags = std::vector<int>(axes.size(), 1);
    }

80 81 82 83
    // 2.1 Check attrs.
    auto starts_size = starts.size();
    auto ends_size = ends.size();

84
    if (ctx->HasInputs("StartsTensorList")) {
85
      starts_size = ctx->Inputs("StartsTensorList").size();
86 87
      PADDLE_ENFORCE_GT(starts_size,
                        0,
T
Thunderbrook 已提交
88 89
                        platform::errors::InvalidArgument(
                            "StartsTensorList size can't be zero"));
90 91
    }
    if (ctx->HasInputs("EndsTensorList")) {
92
      ends_size = ctx->Inputs("EndsTensorList").size();
93 94
      PADDLE_ENFORCE_GT(ends_size,
                        0,
95 96
                        platform::errors::InvalidArgument(
                            "EndsTensorList size can't be zero"));
97 98
    }

99
    if (!ctx->HasInput("StartsTensor")) {
100
      PADDLE_ENFORCE_EQ(
101 102
          starts_size,
          axes.size(),
T
Thunderbrook 已提交
103 104
          platform::errors::InvalidArgument(
              "The size of starts must be equal to the size of axes."));
105
    }
106
    if (!ctx->HasInput("EndsTensor")) {
T
Thunderbrook 已提交
107
      PADDLE_ENFORCE_EQ(
108 109
          ends_size,
          axes.size(),
T
Thunderbrook 已提交
110 111
          platform::errors::InvalidArgument(
              "The size of ends must be equal to the size of axes."));
112
    }
113 114 115 116 117
    for (auto &axis : axes) {
      if (axis < 0) {
        axis = std::max(0, axis + in_dims.size());
      }
    }
118 119
    phi::funcs::CheckAndUpdateSliceAttrs<int>(
        in_dims, axes, &starts, &ends, nullptr, &infer_flags);
H
Hongyu Liu 已提交
120

121 122
    auto slice_dims = phi::funcs::GetSliceDims<int>(
        in_dims, axes, starts, ends, nullptr, &infer_flags);
123
    if (ctx->IsRuntime()) {
124 125
      out_dims = phi::funcs::GetDecreasedDims<int>(
          slice_dims, decrease_axis, &infer_flags);
126
    } else {
H
hong 已提交
127 128
      out_dims =
          phi::funcs::GetDecreasedDims<int>(slice_dims, decrease_axis, nullptr);
H
Hongyu Liu 已提交
129
    }
130

W
whs 已提交
131
    ctx->SetOutputDim("Out", out_dims);
132
    if (axes.size() > 0 && axes[0] != 0) {
J
jerrywgz 已提交
133 134
      ctx->ShareLoD("Input", /*->*/ "Out");
    }
W
whs 已提交
135 136 137 138
  }

 protected:
  framework::OpKernelType GetExpectedKernelType(
139
      const framework::ExecutionContext &ctx) const override {
140 141 142 143
    auto *in_var = ctx.InputVar("Input");
    if (in_var->IsType<framework::LoDTensor>()) {
      auto &in_tensor = in_var->Get<framework::LoDTensor>();
      PADDLE_ENFORCE_EQ(
144 145
          in_tensor.IsInitialized(),
          true,
146 147
          platform::errors::InvalidArgument(
              "The tensor Input (Input) of Slice op is not initialized."));
148 149
      // NOTE: cuda pinned tensor need to copy its data to target place
      if (platform::is_cuda_pinned_place(in_tensor.place())) {
150 151 152
        return framework::OpKernelType(
            framework::TransToProtoVarType(in_tensor.dtype()),
            ctx.device_context());
153
      }
154 155 156 157 158 159 160 161 162 163 164

#ifdef PADDLE_WITH_MKLDNN
      auto input_data_type =
          framework::OperatorWithKernel::IndicateVarDataType(ctx, "Input");

      if (this->CanMKLDNNBeUsed(ctx, input_data_type)) {
        // OneDNN uses blocking format, which cannot be always supported with
        // reorders, because if blocked dimension is not divisible by 8 or
        // 16(depending on which blocking format is used) submemory cannot be
        // created, so in that scenario a fallback is needed
        auto tmp_md = dnnl::memory::desc(
165
            phi::vectorize(ctx.Input<Tensor>("Input")->dims()),
166 167
            dnnl::memory::data_type::f32,
            ctx.Input<Tensor>("Input")->format());
168
        if (tmp_md.data.format_desc.blocking.inner_nblks == 0)
169 170
          return framework::OpKernelType(input_data_type,
                                         ctx.GetPlace(),
171 172 173 174 175
                                         framework::DataLayout::kMKLDNN,
                                         framework::LibraryType::kMKLDNN);
      }
#endif

176 177
      return framework::OpKernelType(
          framework::TransToProtoVarType(in_tensor.dtype()), in_tensor.place());
178
    }
179
    return framework::OpKernelType(
180
        OperatorWithKernel::IndicateVarDataType(ctx, "Input"), ctx.GetPlace());
181
  }
182

183
  framework::OpKernelType GetKernelTypeForVar(
184 185
      const std::string &var_name,
      const Tensor &tensor,
186 187 188 189 190 191 192
      const framework::OpKernelType &expected_kernel_type) const override {
    if (var_name == "StartsTensor" || var_name == "EndsTensor") {
      return expected_kernel_type;
    }
    if (var_name == "StartsTensorList" || var_name == "EndsTensorList") {
      return expected_kernel_type;
    }
193 194
    return framework::OpKernelType(
        expected_kernel_type.data_type_, tensor.place(), tensor.layout());
W
whs 已提交
195 196 197
  }
};

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
class SliceOpVarTypeInference : public framework::VarTypeInference {
 public:
  void operator()(framework::InferVarTypeContext *ctx) const override {
    auto x_name = "Input";
    auto out_name = "Out";
    auto decrease_axis = ctx->GetAttr("decrease_axis");
    auto not_decrease = boost::get<std::vector<int>>(decrease_axis).size() == 0;
    if (not_decrease) {
      // The default type of out is LoDTensor.
      // However, if no axis is decreased and the type of input is not
      // LoDTensor, the type of out should be the same as input.
      // For example, input is a LoDTensorArray and no axis is decreased, the
      // output should be a LoDTensorArray.
      ctx->SetOutputType(out_name, ctx->GetInputType(x_name));
      ctx->SetOutputDataType(out_name, ctx->GetInputDataType(x_name));
    }
  }
};

W
whs 已提交
217 218 219
class SliceOpMaker : public framework::OpProtoAndCheckerMaker {
 public:
  void Make() override {
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
    AddInput("Input", "(Tensor) Tensor of data to extract slices from.");
    AddInput("StartsTensor",
             "(Tensor<int32>, optional) If provided, slice will use this."
             "It has the highest priority of StartsTensor, StartsTensorList "
             "and attr(starts).")
        .AsDispensable();
    AddInput("EndsTensor",
             "(Tensor<int32>, optional) If provided, slice will use this."
             "It has the highest priority of EndsTensor, EndsTensorList and "
             "attr(ends).")
        .AsDispensable();
    AddInput(
        "StartsTensorList",
        "(vector<Tensor<int32>>, optional) If provided, slice will use this."
        "The shape of the tensor in vector MUST BE [1]."
        "It has higher priority compare with attr(starts).")
        .AsDuplicable()
        .AsDispensable();
    AddInput(
        "EndsTensorList",
        "(vector<Tensor<int32>>, optional) If provided, slice will use this."
        "The shape of the tensor in vector MUST BE [1]."
        "It has higher priority compare with attr(ends).")
        .AsDuplicable()
        .AsDispensable();
W
whs 已提交
245 246 247 248 249 250 251
    AddOutput("Out", "Sliced data tensor.");
    AddAttr<std::vector<int>>(
        "axes",
        "(list<int>) Axes that `starts` and `ends` apply to. It's optional."
        "If not present, will be treated as [0, 1, ..., len(`starts`) - 1].");
    AddAttr<std::vector<int>>(
        "starts",
252 253 254 255 256
        "(list<int>) Starting indices of corresponding axis in `axes`")
        .SetDefault({});
    AddAttr<std::vector<int>>(
        "ends", "(list<int>) Ending indices of corresponding axis in `axes`.")
        .SetDefault({});
W
whs 已提交
257
    AddAttr<std::vector<int>>(
258 259
        "infer_flags", "(list<int>) Flags of inferring dims in attributes.")
        .SetDefault({});
H
Hongyu Liu 已提交
260 261
    AddAttr<std::vector<int>>("decrease_axis", "(list<int>) decrease_axis")
        .SetDefault({});
262 263
    AddAttr<bool>("use_mkldnn",
                  "(bool, default false) Only used in mkldnn kernel")
264 265
        .SetDefault(false)
        .AsExtra();
266 267 268 269
    AddAttr<std::string>(
        "mkldnn_data_type",
        "(string, default \"float32\"). Data type of mkldnn kernel")
        .SetDefault("float32")
Z
Zuza 已提交
270
        .InEnum({"float32", "int8", "bfloat16"})
271
        .AsExtra();
W
whs 已提交
272 273 274 275 276
    AddComment(R"DOC(
Slice Operator.

Produces a slice of the input tensor along multiple axes. Similar to numpy:
https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
277
Slice uses `axes`, `starts` and `ends` attributes to specify the start and
W
whs 已提交
278
end dimension for each axis in the list of axes, it uses this information
279 280
to slice the input data tensor. If a negative value is passed for any of
the start or end indices, it represents number of elements before the end
W
whs 已提交
281
of that dimension. If the value passed to start or end is larger than
282 283
the n (the number of elements in this dimension), it represents n.
For slicing to the end of a dimension with unknown size, it is recommended
284
to pass in INT_MAX. The size of axes must be equal to starts\' and ends\'.
285 286
Following examples will explain how slice works:

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
.. code-block:: text

    Case1:
        Given:
            data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
            axes = [0, 1]
            starts = [1, 0]
            ends = [2, 3]
        Then:
            result = [ [5, 6, 7], ]

    Case2:
        Given:
            data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
            starts = [0, 1]
            ends = [-1, 1000]
        Then:
            result = [ [2, 3, 4], ]
W
whs 已提交
305 306 307 308
)DOC");
  }
};

309 310 311 312
class SliceOpGrad : public framework::OperatorWithKernel {
 public:
  using framework::OperatorWithKernel::OperatorWithKernel;

313
  void InferShape(framework::InferShapeContext *ctx) const override {
T
Thunderbrook 已提交
314
    PADDLE_ENFORCE_EQ(
315 316
        ctx->HasInput("Input"),
        true,
T
Thunderbrook 已提交
317
        platform::errors::InvalidArgument("Input should not be null"));
318 319
    PADDLE_ENFORCE_EQ(ctx->HasInput(framework::GradVarName("Out")),
                      true,
T
Thunderbrook 已提交
320 321
                      platform::errors::InvalidArgument(
                          "Input(Out@GRAD) should not be null"));
322 323 324 325 326 327 328 329
    auto x_var_type = ctx->GetInputsVarType("Input")[0];
    if (x_var_type == framework::proto::VarType::LOD_TENSOR_ARRAY) {
      // If the var type of input is LOD_TENSOR_ARRAY,
      // the output shape is determined by SliceGradKernel:Compute in runtime.
      if (ctx->IsRuntime()) {
        return;
      }
    }
330 331 332 333 334 335
    auto x_dims = ctx->GetInputDim("Input");
    auto x_grad_name = framework::GradVarName("Input");
    if (ctx->HasOutput(x_grad_name)) {
      ctx->SetOutputDim(x_grad_name, x_dims);
    }
  }
336

337
  framework::OpKernelType GetExpectedKernelType(
338
      const framework::ExecutionContext &ctx) const override {
339 340 341 342 343 344 345 346 347 348
    auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(
        ctx, framework::GradVarName("Out"));

#ifdef PADDLE_WITH_MKLDNN
    if (this->CanMKLDNNBeUsed(ctx, input_data_type)) {
      // OneDNN uses blocking format, which cannot be always supported with
      // reorders, because if blocked dimension is not divisible by 8 or
      // 16(depending on which blocking format is used) submemory cannot be
      // created, so in that scenario a fallback is needed
      auto tmp_md = dnnl::memory::desc(
349
          phi::vectorize(
350 351 352 353
              ctx.Input<Tensor>(framework::GradVarName("Out"))->dims()),
          dnnl::memory::data_type::f32,
          ctx.Input<Tensor>(framework::GradVarName("Out"))->format());
      if (tmp_md.data.format_desc.blocking.inner_nblks == 0)
354 355
        return framework::OpKernelType(input_data_type,
                                       ctx.GetPlace(),
356 357 358 359 360
                                       framework::DataLayout::kMKLDNN,
                                       framework::LibraryType::kMKLDNN);
    }
#endif
    return framework::OpKernelType(input_data_type, ctx.GetPlace());
361
  }
362

363
  framework::OpKernelType GetKernelTypeForVar(
364 365
      const std::string &var_name,
      const Tensor &tensor,
366 367 368 369 370 371 372
      const framework::OpKernelType &expected_kernel_type) const override {
    if (var_name == "StartsTensor" || var_name == "EndsTensor") {
      return expected_kernel_type;
    }
    if (var_name == "StartsTensorList" || var_name == "EndsTensorList") {
      return expected_kernel_type;
    }
373 374
    return framework::OpKernelType(
        expected_kernel_type.data_type_, tensor.place(), tensor.layout());
375
  }
376 377
};

378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
class SliceOpGradVarTypeInference : public framework::VarTypeInference {
 public:
  void operator()(framework::InferVarTypeContext *ctx) const override {
    auto x = "Input";
    auto d_out = framework::GradVarName("Out");
    auto out = framework::GradVarName("Input");
    // The types of grad_input and input should always be the same.
    // The default type of out is LoDTensor, but the type of input can be
    // LoDTensor or LoDTensorArray,
    // so set the type of both to be the same.
    ctx->SetOutputType(out, ctx->GetInputType(x));
    ctx->SetOutputDataType(out, ctx->GetInputDataType(d_out));
  }
};

H
hong 已提交
393 394
template <typename T>
class SliceOpGradMaker : public framework::SingleGradOpMaker<T> {
395
 public:
H
hong 已提交
396
  using framework::SingleGradOpMaker<T>::SingleGradOpMaker;
397 398

 protected:
399
  void Apply(GradOpPtr<T> bind) const override {
H
hong 已提交
400
    bind->SetInput("Input", this->Input("Input"));
H
hong 已提交
401 402 403 404 405 406 407 408 409 410 411 412
    if (this->HasInput("StartsTensor")) {
      bind->SetInput("StartsTensor", this->Input("StartsTensor"));
    }
    if (this->HasInput("EndsTensor")) {
      bind->SetInput("EndsTensor", this->Input("EndsTensor"));
    }
    if (this->HasInput("StartsTensorList")) {
      bind->SetInput("StartsTensorList", this->Input("StartsTensorList"));
    }
    if (this->HasInput("EndsTensorList")) {
      bind->SetInput("EndsTensorList", this->Input("EndsTensorList"));
    }
H
hong 已提交
413 414 415
    bind->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out"));
    bind->SetOutput(framework::GradVarName("Input"), this->InputGrad("Input"));
    bind->SetAttrMap(this->Attrs());
416 417 418 419
    bind->SetType("slice_grad");
  }
};

420 421 422 423 424 425
template <typename T>
class SliceDoubleOpGradMaker : public framework::SingleGradOpMaker<T> {
 public:
  using framework::SingleGradOpMaker<T>::SingleGradOpMaker;

 protected:
426
  void Apply(GradOpPtr<T> bind) const override {
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    if (this->HasInput("StartsTensor")) {
      bind->SetInput("StartsTensor", this->Input("StartsTensor"));
    }
    if (this->HasInput("EndsTensor")) {
      bind->SetInput("EndsTensor", this->Input("EndsTensor"));
    }
    if (this->HasInput("StartsTensorList")) {
      bind->SetInput("StartsTensorList", this->Input("StartsTensorList"));
    }
    if (this->HasInput("EndsTensorList")) {
      bind->SetInput("EndsTensorList", this->Input("EndsTensorList"));
    }
    bind->SetInput("Input", this->OutputGrad(framework::GradVarName("Input")));
    bind->SetOutput("Out", this->InputGrad(framework::GradVarName("Out")));
    bind->SetAttrMap(this->Attrs());
    bind->SetType("slice");
  }
};

446
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SliceOpGradNoNeedBufferVarsInferer,
Z
Zeng Jinle 已提交
447
                                    "Input");
448

W
whs 已提交
449 450 451 452
}  // namespace operators
}  // namespace paddle

namespace ops = paddle::operators;
453 454 455
REGISTER_OPERATOR(slice,
                  ops::SliceOp,
                  ops::SliceOpMaker,
H
hong 已提交
456
                  ops::SliceOpGradMaker<paddle::framework::OpDesc>,
457 458
                  ops::SliceOpGradMaker<paddle::imperative::OpBase>,
                  ops::SliceOpVarTypeInference);
459 460
REGISTER_OPERATOR(slice_grad,
                  ops::SliceOpGrad,
461 462
                  ops::SliceDoubleOpGradMaker<paddle::framework::OpDesc>,
                  ops::SliceDoubleOpGradMaker<paddle::imperative::OpBase>,
463
                  ops::SliceOpGradNoNeedBufferVarsInferer,
464
                  ops::SliceOpGradVarTypeInference);
W
whs 已提交
465 466

REGISTER_OP_CPU_KERNEL(
467 468
    slice,
    ops::SliceKernel<paddle::platform::CPUDeviceContext, bool>,
W
WeiXin 已提交
469
    ops::SliceKernel<paddle::platform::CPUDeviceContext, int>,
W
whs 已提交
470 471
    ops::SliceKernel<paddle::platform::CPUDeviceContext, int64_t>,
    ops::SliceKernel<paddle::platform::CPUDeviceContext, float>,
472 473
    ops::SliceKernel<paddle::platform::CPUDeviceContext, double>,
    ops::SliceKernel<paddle::platform::CPUDeviceContext,
474
                     paddle::platform::complex<float>>,
475
    ops::SliceKernel<paddle::platform::CPUDeviceContext,
476 477 478
                     paddle::platform::complex<double>>,
    ops::SliceKernel<paddle::platform::CPUDeviceContext,
                     paddle::platform::bfloat16>);
479 480

REGISTER_OP_CPU_KERNEL(
481 482
    slice_grad,
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext, bool>,
W
WeiXin 已提交
483
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext, int>,
484 485
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext, int64_t>,
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext, float>,
486 487
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext, double>,
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext,
488
                         paddle::platform::complex<float>>,
489
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext,
490 491 492
                         paddle::platform::complex<double>>,
    ops::SliceGradKernel<paddle::platform::CPUDeviceContext,
                         paddle::platform::bfloat16>);
493 494

REGISTER_OP_CUDA_KERNEL(
495 496
    slice,
    ops::SliceKernel<paddle::platform::CUDADeviceContext, bool>,
W
WeiXin 已提交
497
    ops::SliceKernel<paddle::platform::CUDADeviceContext, float>,
498 499 500 501 502
    ops::SliceKernel<paddle::platform::CUDADeviceContext, double>,
    ops::SliceKernel<paddle::platform::CUDADeviceContext, int>,
    ops::SliceKernel<paddle::platform::CUDADeviceContext, int64_t>,
    ops::SliceKernel<paddle::platform::CUDADeviceContext,
                     paddle::platform::float16>,
503 504
    ops::SliceKernel<paddle::platform::CUDADeviceContext,
                     paddle::platform::bfloat16>,
505
    ops::SliceKernel<paddle::platform::CUDADeviceContext,
506
                     paddle::platform::complex<float>>,
507
    ops::SliceKernel<paddle::platform::CUDADeviceContext,
508
                     paddle::platform::complex<double>>);
509 510

REGISTER_OP_CUDA_KERNEL(
511 512
    slice_grad,
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext, bool>,
513 514 515 516 517 518
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext, float>,
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext, double>,
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext, int>,
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext, int64_t>,
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext,
                         paddle::platform::float16>,
519 520
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext,
                         paddle::platform::bfloat16>,
521
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext,
522
                         paddle::platform::complex<float>>,
523
    ops::SliceGradKernel<paddle::platform::CUDADeviceContext,
524
                         paddle::platform::complex<double>>);