empty_kernel.cc 3.2 KB
Newer Older
1 2
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.

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
6

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

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. */
14
#include "paddle/phi/kernels/empty_kernel.h"
15

16 17
#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/kernel_registry.h"
18

19
#include "paddle/phi/common/complex.h"
20

21
namespace phi {
22

23 24
template <typename T, typename Context>
void EmptyKernel(const Context& dev_ctx,
25
                 const ScalarArray& shape,
26
                 DataType dtype,
27
                 DenseTensor* out) {
28 29
  out->Resize(phi::make_ddim(shape.GetData()));
  dev_ctx.template Alloc<T>(out);
30 31
}

32
template <typename T, typename Context>
33 34 35 36
void EmptyLikeKernel(const Context& dev_ctx,
                     const DenseTensor& x,
                     DataType dtype,
                     DenseTensor* out) {
37
  dev_ctx.template Alloc<T>(out);
38 39
}

40
}  // namespace phi
41

42
PD_REGISTER_KERNEL(empty,
43 44
                   CPU,
                   ALL_LAYOUT,
45
                   phi::EmptyKernel,
46 47 48 49 50 51 52
                   float,
                   double,
                   uint8_t,
                   int16_t,
                   int,
                   int64_t,
                   bool,
53 54 55 56
                   phi::dtype::float16,
                   phi::dtype::bfloat16,
                   phi::dtype::complex<float>,
                   phi::dtype::complex<double>) {}
57

58
PD_REGISTER_KERNEL(empty_like,
59 60
                   CPU,
                   ALL_LAYOUT,
61
                   phi::EmptyLikeKernel,
62 63 64 65 66 67 68
                   float,
                   double,
                   uint8_t,
                   int16_t,
                   int,
                   int64_t,
                   bool,
69 70 71 72
                   phi::dtype::float16,
                   phi::dtype::bfloat16,
                   phi::dtype::complex<float>,
                   phi::dtype::complex<double>) {}
73 74

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
75
PD_REGISTER_KERNEL(empty,
76 77
                   GPU,
                   ALL_LAYOUT,
78
                   phi::EmptyKernel,
79 80 81 82 83 84 85
                   float,
                   double,
                   uint8_t,
                   int16_t,
                   int,
                   int64_t,
                   bool,
86 87 88
                   phi::dtype::float16,
                   phi::dtype::complex<float>,
                   phi::dtype::complex<double>) {}
89

90
PD_REGISTER_KERNEL(empty_like,
91 92
                   GPU,
                   ALL_LAYOUT,
93
                   phi::EmptyLikeKernel,
94 95 96 97 98 99 100
                   float,
                   double,
                   uint8_t,
                   int16_t,
                   int,
                   int64_t,
                   bool,
101 102 103 104
                   phi::dtype::float16,
                   phi::dtype::bfloat16,
                   phi::dtype::complex<float>,
                   phi::dtype::complex<double>) {}
105
#endif