assign_kernel.h 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2022 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.

#pragma once

17 18 19
#include <vector>

#include "paddle/phi/common/scalar.h"
20
#include "paddle/phi/core/dense_tensor.h"
21
#include "paddle/phi/core/tensor_array.h"
F
Feiyu Chan 已提交
22
#include "paddle/phi/infermeta/unary.h"
23 24 25

namespace phi {

C
chentianyu03 已提交
26
template <typename Context>
27 28 29
void AssignKernel(const Context& dev_ctx,
                  const DenseTensor& x,
                  DenseTensor* out);
C
chentianyu03 已提交
30

F
Feiyu Chan 已提交
31 32 33 34 35 36 37 38 39 40
template <typename Context>
DenseTensor Assign(const Context& dev_ctx, const DenseTensor& x) {
  DenseTensor out;
  MetaTensor meta_out(&out);
  MetaTensor meta_x(x);
  UnchangedInferMeta(meta_x, &meta_out);
  AssignKernel<Context>(dev_ctx, x, &out);
  return out;
}

41 42 43 44
// In order to be compatible with the `AsDispensable` input in the original
// assign op maker, the input parameter here needs to be dispensable, but
// this looks weird
template <typename Context>
45
void AssignRawKernel(const Context& dev_ctx,
46
                     const paddle::optional<DenseTensor>& x,
47
                     DenseTensor* out);
48 49 50

template <typename Context>
void AssignArrayKernel(const Context& dev_ctx,
51 52
                       const TensorArray& x,
                       TensorArray* out);
53

54 55 56 57 58 59 60
template <typename T, typename Context>
void AssignValueKernel(const Context& dev_ctx,
                       const std::vector<int>& shape,
                       DataType dtype,
                       const std::vector<Scalar>& values,
                       DenseTensor* out);

61
}  // namespace phi