coalesce_tensor_op.cc 22.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2019 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.

15
#include <sstream>
16
#include <vector>
17

18
#include "paddle/fluid/framework/op_registry.h"
19
#include "paddle/fluid/framework/op_version_registry.h"
20 21
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/var_type.h"
22
#include "paddle/fluid/platform/device_memory_aligment.h"
23
#include "paddle/phi/kernels/funcs/math_function.h"
24
#ifdef PADDLE_WITH_ASCEND_CL
25
#include "paddle/fluid/platform/device/npu/npu_op_runner.h"
26
#endif
27
#include "paddle/fluid/framework/convert_utils.h"
28 29 30
#ifdef PADDLE_WITH_MLU
#include "paddle/fluid/operators/mlu/mlu_baseop.h"
#endif
31 32 33 34

namespace paddle {
namespace operators {

35 36 37
template <typename DeviceContext>
struct FillConstantVisitor {
  FillConstantVisitor(const DeviceContext &dev_ctx,
38 39 40 41 42 43 44 45
                      framework::LoDTensor *tensor, const float value,
                      framework::proto::VarType::Type dtype,
                      const framework::ExecutionContext &context)
      : dev_ctx_(dev_ctx),
        tensor_(tensor),
        value_(value),
        dtype_(dtype),
        context_(context) {}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

  template <typename T>
  void apply(typename std::enable_if<std::is_same<T, int8_t>::value ||
                                     std::is_same<T, int16_t>::value>::type * =
                 nullptr) const {
    PADDLE_THROW(platform::errors::InvalidArgument(
        "Not support data type for set_constant attr"));
  }

  template <typename T>
  void apply(typename std::enable_if<!(std::is_same<T, int8_t>::value ||
                                       std::is_same<T, int16_t>::value)>::type
                 * = nullptr) const {
#ifdef PADDLE_WITH_ASCEND_CL
    if (platform::is_npu_place(dev_ctx_.GetPlace())) {
61
      Tensor tensor_tmp(framework::TransToPhiDataType(dtype_));
62 63 64 65 66
      tensor_tmp.mutable_data<T>({1}, context_.GetPlace());
      FillNpuTensorWithConstant<T>(&tensor_tmp, static_cast<T>(value_));

      const auto &runner =
          NpuOpRunner("FillD", {tensor_tmp}, {*tensor_},
67
                      {{"dims", phi::vectorize(tensor_->dims())}});
68 69 70 71
      auto stream =
          context_.template device_context<paddle::platform::NPUDeviceContext>()
              .stream();
      runner.Run(stream);
72
    } else {
73
      phi::funcs::SetConstant<DeviceContext, T> set_constant;
74 75
      set_constant(dev_ctx_, tensor_, static_cast<T>(value_));
    }
76 77 78 79 80 81 82
#elif defined(PADDLE_WITH_MLU)
    if (platform::is_mlu_place(context_.GetPlace())) {
      FillMLUTensorWithHostValue<T>(context_, static_cast<T>(value_), tensor_);
    } else {
      phi::funcs::SetConstant<DeviceContext, T> set_constant;
      set_constant(dev_ctx_, tensor_, static_cast<T>(value_));
    }
83
#else
84
    phi::funcs::SetConstant<DeviceContext, T> set_constant;
85 86 87 88 89 90 91
    set_constant(dev_ctx_, tensor_, static_cast<T>(value_));
#endif
  }

  const DeviceContext &dev_ctx_;
  framework::LoDTensor *tensor_;
  float value_;
92 93
  framework::proto::VarType::Type dtype_;
  const framework::ExecutionContext &context_;
94 95
};

96
template <typename DeviceContext, typename T>
97
class CoalesceTensorOpKernel : public framework::OpKernel<T> {
98 99
 public:
  void Compute(const framework::ExecutionContext &context) const override {
H
hong 已提交
100 101
    auto in_var_names = context.InputNames("Input");
    auto out_var_names = context.OutputNames("Output");
102 103
    const auto &in_tensors = context.MultiInput<framework::LoDTensor>("Input");
    auto out_tensors = context.MultiOutput<framework::LoDTensor>("Output");
104

105
    PADDLE_ENFORCE_GT(in_var_names.size(), static_cast<size_t>(0),
106 107 108 109 110 111 112 113
                      platform::errors::InvalidArgument(
                          "The CoalesceTensor operator has no input."));
    PADDLE_ENFORCE_EQ(in_var_names.size(), out_var_names.size(),
                      platform::errors::InvalidArgument(
                          "The number of CoalesceTensor operator's input and "
                          "output is not match, "
                          "input number is %u, output number is %u.",
                          in_var_names.size(), out_var_names.size()));
114

115
    // Input & Output check: only support LoDTensor
116 117
    bool has_not_init_in_vars = false;
    for (size_t i = 0; i < in_tensors.size(); ++i) {
118
      PADDLE_ENFORCE_NOT_NULL(
119 120
          in_tensors[i], platform::errors::InvalidArgument(
                             "The %d-th input tensor cannot be nullptr.", i));
121
      PADDLE_ENFORCE_NOT_NULL(
122 123 124 125 126 127 128 129 130 131 132 133 134
          out_tensors[i], platform::errors::InvalidArgument(
                              "The %d-th output tensor cannot be nullptr.", i));
      if (!in_tensors[i]->IsInitialized()) {
        has_not_init_in_vars = true;
      }
    }

    if (has_not_init_in_vars) {
      const auto &concated_shapes =
          context.Attr<std::vector<int64_t>>("concated_shapes");
      const auto &concated_ranks =
          context.Attr<std::vector<int64_t>>("concated_ranks");
      PADDLE_ENFORCE_EQ(concated_ranks.size(), out_tensors.size(),
135
                        platform::errors::InvalidArgument(
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
                            "The attribute(concated_ranks) length must be "
                            "equal to the output tensor number."));
      int64_t accumulated_ranks = 0;
      for (size_t i = 0; i < in_tensors.size(); ++i) {
        framework::DDim dims(concated_shapes.data() + accumulated_ranks,
                             concated_ranks[i]);
        if (!in_tensors[i]->IsInitialized()) {
          PADDLE_ENFORCE_EQ(
              in_tensors[i], out_tensors[i],
              platform::errors::InvalidArgument(
                  "The %d-th output tensor and %d-th input tensor when the "
                  "%d-th input tensor is not initialized.",
                  i, i, i));
          out_tensors[i]->Resize(dims);
        } else {
          PADDLE_ENFORCE_EQ(
              in_tensors[i]->dims(), dims,
              platform::errors::InvalidArgument(
                  "The %d-th input tensor shape does not match the "
                  "attribute(concated_shapes) and "
                  "attribute(concated_ranks).",
                  i));
        }
        accumulated_ranks += concated_ranks[i];
        PADDLE_ENFORCE_LE(accumulated_ranks, concated_shapes.size(),
                          platform::errors::InvalidArgument(
                              "The attribute(concated_shapes) and "
                              "attribute(concated_ranks) do not match."));
      }
      PADDLE_ENFORCE_EQ(accumulated_ranks, concated_shapes.size(),
166
                        platform::errors::InvalidArgument(
167 168
                            "The attribute(concated_shapes) and "
                            "attribute(concated_ranks) do not match."));
169 170
    }

171
    bool use_align = context.Attr<bool>("use_align");
172
    auto align_size = context.Attr<int>("align_size");
173
    auto size_of_dtype = context.Attr<int>("user_defined_size_of_dtype");
174 175 176

    if (context.Attr<bool>("check_name")) {
      for (size_t i = 0; i < in_var_names.size(); ++i) {
177 178
        PADDLE_ENFORCE_EQ(
            in_var_names[i], out_var_names[i],
179 180 181 182
            platform::errors::InvalidArgument(
                "The input and output variable of CoalesceTensor operator is "
                "different, %dth input is %s, %dth output is %s.",
                i, in_var_names[i], i, out_var_names[i]));
183 184 185 186
      }
    } else {
      // Init the output as input
      for (size_t i = 0; i < in_tensors.size(); ++i) {
187
        out_tensors[i]->Resize(in_tensors[i]->dims());
188 189 190 191 192 193 194
      }
    }

    auto &dev_ctx = context.template device_context<DeviceContext>();

    // Get numel and dtype
    size_t numel = 0;
195 196
    auto dtype = static_cast<framework::proto::VarType::Type>(
        context.Attr<int>("dtype"));
197 198 199
    if (size_of_dtype == -1) {
      size_of_dtype = framework::SizeOfType(dtype);
    }
200
    GetMemSizeAndDtype(in_tensors, in_var_names, &numel, size_of_dtype,
201
                       context.GetPlace(), use_align, align_size);
202 203 204

    // Alloc the continuous space
    auto fused_tensor = context.Output<framework::LoDTensor>("FusedOutput");
205
    void *fused_tensor_ptr =
206
        fused_tensor->Resize(phi::make_ddim({static_cast<int64_t>(numel)}))
207
            .mutable_data(context.GetPlace(),
208
                          framework::TransToPhiDataType(dtype));
209
    VLOG(10) << "Fused tensor addr " << fused_tensor_ptr;
210 211

    // Init the continuous space
C
chengduo 已提交
212
    size_t offset = 0;
213
    if (context.Attr<bool>("copy_data")) {
214 215 216 217 218 219
#ifdef PADDLE_WITH_ASCEND_CL
      framework::VisitDataType(
          dtype,
          FillConstantVisitor<DeviceContext>(
              dev_ctx, fused_tensor, static_cast<float>(0.0), dtype, context));
#endif
220
      for (size_t i = 0; i < in_var_names.size(); ++i) {
C
chengduo 已提交
221 222 223 224
        size_t len = static_cast<size_t>(in_tensors[i]->numel());
        auto sub_tensor = fused_tensor->Slice(
            static_cast<int64_t>(offset), static_cast<int64_t>(offset + len));
        framework::TensorCopy(*in_tensors[i], context.GetPlace(), dev_ctx,
225
                              &sub_tensor);
C
chengduo 已提交
226

227 228 229 230 231
        offset += use_align
                      ? platform::Alignment(len * size_of_dtype,
                                            context.GetPlace(), align_size) /
                            size_of_dtype
                      : len;
232 233
      }
    } else if (context.Attr<bool>("set_constant")) {
234 235
      framework::VisitDataType(
          dtype, FillConstantVisitor<DeviceContext>(
236 237
                     dev_ctx, fused_tensor, context.Attr<float>("constant"),
                     dtype, context));
238 239 240 241 242 243 244 245 246 247
    } else if (context.Attr<bool>("persist_output")) {
      for (size_t i = 0; i < out_var_names.size(); ++i) {
        size_t len = static_cast<size_t>(out_tensors[i]->numel());
        auto sub_tensor = fused_tensor->Slice(
            static_cast<int64_t>(offset), static_cast<int64_t>(offset + len));
        // some var may not persistable, or persistable var may not init
        if (out_tensors[i]->IsInitialized()) {
          framework::TensorCopy(*out_tensors[i], context.GetPlace(), dev_ctx,
                                &sub_tensor);
        }
248 249 250 251 252
        offset += use_align
                      ? platform::Alignment(len * size_of_dtype,
                                            context.GetPlace(), align_size) /
                            size_of_dtype
                      : len;
253
      }
254 255 256 257
    }

    // Make the outputs point to the continuous space.
    offset = 0;
258 259
    std::stringstream ss;
    ss << "alloc_space_for_vars: ";
260

261
    for (size_t i = 0; i < out_tensors.size(); ++i) {
C
chengduo 已提交
262
      size_t len = static_cast<size_t>(out_tensors[i]->numel());
263
      auto dim = out_tensors[i]->dims();
264
      VLOG(4) << len << " " << dim << " " << offset;
265
      out_tensors[i]
C
chengduo 已提交
266 267
          ->ShareDataWith(fused_tensor->Slice(
              static_cast<int64_t>(offset), static_cast<int64_t>(offset + len)))
268
          .Resize(dim);
269 270 271 272
      len = use_align ? platform::Alignment(len * size_of_dtype,
                                            context.GetPlace(), align_size) /
                            size_of_dtype
                      : len;
273
      ss << "output(" << out_var_names[i] << ")  dim:(" << dim << ")"
274
         << " address: " << out_tensors[i]->data() << " len: " << len << ", ";
275
      offset += len;
276
    }
277 278 279 280 281 282
    PADDLE_ENFORCE_EQ(
        (int64_t)offset, fused_tensor->numel(),
        platform::errors::InvalidArgument(
            "The alloc_space_for_vars's offset: %s is unequal with "
            "fused_tensor's numel: %s.",
            offset, fused_tensor->numel()));
283
    VLOG(10) << ss.str();
284 285
  }

C
chengduo 已提交
286
 private:
287 288 289
  void GetMemSizeAndDtype(
      const std::vector<const framework::LoDTensor *> &lod_tensors,
      const std::vector<std::string> var_names, size_t *numel,
290
      const size_t &size_of_dtype, const platform::Place &place,
291
      const bool use_align = true, const int align_size = -1) const {
292 293 294 295 296 297
    PADDLE_ENFORCE_EQ(
        lod_tensors.size(), var_names.size(),
        platform::errors::InvalidArgument(
            "The number of input tensor and variable does not match, the "
            "number of input tensor is %u, the number of input variable is %u.",
            lod_tensors.size(), var_names.size()));
298
    *numel = 0;
299 300
    std::stringstream ss;
    ss << "alloc_space_for_vars: ";
301 302
    for (size_t i = 0; i < var_names.size(); ++i) {
      auto size = lod_tensors[i]->numel();
303 304 305 306
      PADDLE_ENFORCE_GT(
          size, 0,
          platform::errors::InvalidArgument(
              "The number of tensor `%s`'s elements is 0.", var_names[i]));
307 308 309 310 311
      auto len = use_align ? platform::Alignment(
                                 static_cast<size_t>(size) * size_of_dtype,
                                 place, align_size) /
                                 size_of_dtype
                           : static_cast<size_t>(size);
312 313
      const void *ptr =
          lod_tensors[i]->IsInitialized() ? lod_tensors[i]->data() : nullptr;
314
      VLOG(4) << size << " " << len;
315
      ss << "input(" << var_names[i] << ") dim:(" << lod_tensors[i]->dims()
316
         << ") "
317
         << " addres:" << ptr << " len: " << len << ", ";
318
      *numel += len;
319
    }
320
    VLOG(10) << ss.str();
321 322 323
  }
};

324
class CoalesceTensorOp : public framework::OperatorWithKernel {
325 326 327
 public:
  using framework::OperatorWithKernel::OperatorWithKernel;

328 329 330 331 332 333
  void InferShape(framework::InferShapeContext *ctx) const override {
    if (ctx->IsRuntime()) {
      return;
    }
    auto use_align = ctx->Attrs().Get<bool>("use_align");
    auto align_size = ctx->Attrs().Get<int>("align_size");
334
    auto size_of_dtype = ctx->Attrs().Get<int>("user_defined_size_of_dtype");
335 336 337

    auto dtype = static_cast<framework::proto::VarType::Type>(
        ctx->Attrs().Get<int>("dtype"));
338 339 340
    if (size_of_dtype == -1) {
      size_of_dtype = framework::SizeOfType(dtype);
    }
341 342 343 344 345 346 347 348 349 350 351 352 353 354

    auto alignment = [](size_t size, size_t align_size) {
      size_t remaining = size % align_size;
      auto aligned_size =
          remaining == 0 ? size : size + (align_size - remaining);
      VLOG(4) << remaining << " " << size << " " << align_size << " "
              << aligned_size;
      return aligned_size;
    };
    VLOG(4) << "align_size: " << align_size;
    if (use_align && align_size > 0) {
      int64_t numel = 0;
      auto dims = ctx->GetInputsDim("Input");
      for (const auto &dim : dims) {
355
        auto size = phi::product(dim);
356 357 358 359 360 361 362
        auto len = use_align
                       ? alignment(static_cast<size_t>(size) * size_of_dtype,
                                   align_size) /
                             size_of_dtype
                       : static_cast<size_t>(size);
        numel += len;
      }
363 364
      ctx->SetOutputDim("FusedOutput", phi::make_ddim({numel}));
      VLOG(4) << "FusedOutput size:" << phi::make_ddim({numel});
365 366
    }
  }
367 368

 protected:
369 370 371 372 373 374 375
  framework::OpKernelType GetExpectedKernelType(
      const framework::ExecutionContext &context) const override {
    auto dtype = static_cast<framework::proto::VarType::Type>(
        context.Attr<int>("dtype"));
    return framework::OpKernelType(dtype, context.GetPlace());
  }

376 377 378 379 380 381 382
  framework::OpKernelType GetKernelTypeForVar(
      const std::string &var_name, const framework::Tensor &tensor,
      const framework::OpKernelType &expected_kernel_type) const override {
    return framework::OpKernelType(expected_kernel_type.data_type_,
                                   expected_kernel_type.place_,
                                   tensor.layout());
  }
383 384
};

385
class CoalesceTensorOpMaker : public framework::OpProtoAndCheckerMaker {
386 387 388 389
 public:
  void Make() override {
    AddInput("Input",
             "(vector<LoDTensor>) The input tensors of"
390
             " coalesce_tensor operator.")
391 392 393
        .AsDuplicable();
    AddOutput("Output",
              "(vector<LoDTensor>) The output "
394
              "tensors of coalesce_tensor operator. And the address "
395 396 397 398 399
              "of output tensors are continuous, they are sliced from the "
              "tensor of FusedOutput.")
        .AsDuplicable();
    AddOutput("FusedOutput",
              "(LoDTensor) The output tensor "
400
              "of coalesce_tensor operator. And the tensors of"
401
              " Output is sliced from the tensor of FusedOutput.");
402
    AddAttr<int>("dtype", "The output data type.");
403 404 405 406 407
    AddAttr<bool>("copy_data", "Whether to copy the Input value to Output.")
        .SetDefault(false);
    AddAttr<bool>("set_constant",
                  "Whether to set the Output with a constant value.")
        .SetDefault(false);
408 409 410
    AddAttr<bool>("persist_output",
                  "Whether to persist the original Output value.")
        .SetDefault(false);
411 412 413 414 415 416 417 418
    AddAttr<float>("constant",
                   "If set_constant is true, the constant value will be used "
                   "to set the Output.")
        .SetDefault(0.0);
    AddAttr<bool>("check_name",
                  "Whether to check the name of Input and Output to ensure "
                  "they are the same separately.")
        .SetDefault(false);
419 420 421 422
    AddAttr<bool>("use_align",
                  "Whether to consider memory chunk and take alignment into "
                  "account for inputs and outputs.")
        .SetDefault(true);
423 424
    AddAttr<int>("align_size", "The alignment size when use_align is True")
        .SetDefault(-1);
425 426 427 428 429 430 431 432 433
    AddAttr<int>("user_defined_size_of_dtype",
                 "The user defined size of dtype. This is used to coalesce "
                 "grad vars and merged_grad vars at the same time. For some "
                 "strategy, the dtype of fused_grad_vars and the dtype of "
                 "fused_grad_merged_vars are not identical, which will cause "
                 "the shape of these two coalesced vars are different. To "
                 "make sure the shape of these two vars are identical with "
                 "each other, this attr is added.")
        .SetDefault(-1);
434 435 436 437 438 439 440 441 442 443 444 445 446 447
    AddAttr<std::vector<int64_t>>(
        "concated_shapes",
        "The concated shapes of each shape of the input tensors. "
        "If any of the input tensors are not inited, this is used to "
        "init the output tensor shape, together with "
        "attribute(concated_ranks).")
        .SetDefault({});
    AddAttr<std::vector<int64_t>>(
        "concated_ranks",
        "The concated ranks of each rank of the input tensors. "
        "If any of the input tensors are not inited, this is used to "
        "init the output tensor shape, together with "
        "attribute(concated_shapes).")
        .SetDefault({});
448
    AddComment(R"DOC(
449
CoalesceTensor Operator.
450

451
coalesce_tensor is used to make the address of Output
452 453 454 455 456 457 458 459
continuous according to the Input. This Op will alloc a big tensor
according to the tensors of Input, the dtype is the same with those input tensors,
the size is the sum of those input tensors' numel, and the dim of the big
tensor is {sum(numel)}. And the big tensor is stored in FusedOutput.
The tensors of Output are sliced from the tensor of FusedOutput.
Note that, the dtype of Input should be the same, and the dim of Input
and Output should equal.
The tensors of Input and Output could be the same or different. And
460
coalesce_tensor allows copying the value of Input to Output, or
461 462
setting the Output with a constant value, or persist the original Output
value.
463 464 465 466 467 468 469 470

)DOC");
  }
};

}  // namespace operators
}  // namespace paddle

471 472
REGISTER_OPERATOR(coalesce_tensor, paddle::operators::CoalesceTensorOp,
                  paddle::operators::CoalesceTensorOpMaker);
473
namespace ops = paddle::operators;
474
namespace plat = paddle::platform;
475
REGISTER_OP_CPU_KERNEL(
476
    coalesce_tensor,
477 478 479
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, float>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, double>);
480

481
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
482
REGISTER_OP_CUDA_KERNEL(
483
    coalesce_tensor,
484 485 486 487 488
    ops::CoalesceTensorOpKernel<paddle::platform::CUDADeviceContext,
                                plat::float16>,
    ops::CoalesceTensorOpKernel<paddle::platform::CUDADeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::CUDADeviceContext, float>,
    ops::CoalesceTensorOpKernel<paddle::platform::CUDADeviceContext, double>);
489
#endif
490

491 492 493 494 495 496 497 498 499 500
#if defined(PADDLE_WITH_ASCEND_CL)
REGISTER_OP_CUDA_KERNEL(
    coalesce_tensor,
    ops::CoalesceTensorOpKernel<paddle::platform::NPUDeviceContext,
                                plat::float16>,
    ops::CoalesceTensorOpKernel<paddle::platform::NPUDeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::NPUDeviceContext, float>,
    ops::CoalesceTensorOpKernel<paddle::platform::NPUDeviceContext, double>);
#endif

W
WangXi 已提交
501 502 503 504 505 506 507 508 509 510
#ifdef PADDLE_WITH_XPU
REGISTER_OP_XPU_KERNEL(
    coalesce_tensor,
    ops::CoalesceTensorOpKernel<paddle::platform::XPUDeviceContext,
                                plat::float16>,
    ops::CoalesceTensorOpKernel<paddle::platform::XPUDeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::XPUDeviceContext, float>,
    ops::CoalesceTensorOpKernel<paddle::platform::XPUDeviceContext, double>);
#endif

511 512 513 514 515 516 517 518 519 520
#if defined(PADDLE_WITH_ASCEND_CL)
REGISTER_OP_NPU_KERNEL(
    coalesce_tensor,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, float>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext,
                                plat::float16>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, double>);
#endif

521 522 523 524 525 526 527 528 529
#if defined(PADDLE_WITH_MLU)
REGISTER_OP_MLU_KERNEL(
    coalesce_tensor,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext,
                                plat::float16>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, int>,
    ops::CoalesceTensorOpKernel<paddle::platform::CPUDeviceContext, float>);
#endif

530 531 532 533 534 535 536 537 538
REGISTER_OP_VERSION(coalesce_tensor)
    .AddCheckpoint(
        R"ROC(
              Upgrade coalesce_tensor: add a new attribute [use_align].)ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "use_align",
            "In order to optionally take memory alignment into account when "
            "coalescing tensors. The default value is true to be compatible "
            "with before.",
539 540 541 542 543 544 545 546 547 548 549
            true))
    .AddCheckpoint(
        R"ROC(
                Upgrade coalesce_tensor: add a new attribute [align_size].)ROC",
        paddle::framework::compatible::OpVersionDesc().NewAttr(
            "align_size",
            "In order to optionally take memory alignment into account when "
            "coalescing tensors. The default value is -1 and use the default "
            "align_size "
            "of each place to be compatible with before.",
            -1));