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
  out->ResizeAndAllocate(phi::make_ddim(shape.GetData()));
29 30
}

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

39
}  // namespace phi
40

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

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

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

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