math_kernel.cc 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//   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.

15
#include "paddle/phi/kernels/math_kernel.h"
16

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

20
namespace phi {
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

template <typename T, typename Context>
void AddKernel(const Context& dev_ctx,
               const DenseTensor& x,
               const DenseTensor& y,
               DenseTensor* out) {
  int axis = -1;
  AddRawKernel<T>(dev_ctx, x, y, axis, out);
}

template <typename T, typename Context>
void SubtractKernel(const Context& dev_ctx,
                    const DenseTensor& x,
                    const DenseTensor& y,
                    DenseTensor* out) {
  int axis = -1;
  SubtractRawKernel<T>(dev_ctx, x, y, axis, out);
}

template <typename T, typename Context>
void DivideKernel(const Context& dev_ctx,
                  const DenseTensor& x,
                  const DenseTensor& y,
                  DenseTensor* out) {
  int axis = -1;
  DivideRawKernel<T>(dev_ctx, x, y, axis, out);
}

template <typename T, typename Context>
void MultiplyKernel(const Context& dev_ctx,
                    const DenseTensor& x,
                    const DenseTensor& y,
                    DenseTensor* out) {
  int axis = -1;
  MultiplyRawKernel<T>(dev_ctx, x, y, axis, out);
}

58
}  // namespace phi
59

60 61
using complex64 = ::phi::dtype::complex<float>;
using complex128 = ::phi::dtype::complex<double>;
62

63
PD_REGISTER_KERNEL(add,
64 65
                   CPU,
                   ALL_LAYOUT,
66
                   phi::AddKernel,
67 68
                   float,
                   double,
69
                   int16_t,
70 71 72 73
                   int,
                   int64_t,
                   complex64,
                   complex128) {}
74
PD_REGISTER_KERNEL(subtract,
75 76
                   CPU,
                   ALL_LAYOUT,
77
                   phi::SubtractKernel,
78 79
                   float,
                   double,
80
                   int16_t,
81 82 83
                   int,
                   int64_t,
                   complex64,
84 85
                   complex128,
                   phi::dtype::bfloat16) {}
86
PD_REGISTER_KERNEL(divide,
87 88
                   CPU,
                   ALL_LAYOUT,
89
                   phi::DivideKernel,
90 91 92 93 94 95
                   float,
                   double,
                   int,
                   int64_t,
                   complex64,
                   complex128) {}
96
PD_REGISTER_KERNEL(multiply,
97 98
                   CPU,
                   ALL_LAYOUT,
99
                   phi::MultiplyKernel,
100 101 102 103 104 105
                   float,
                   double,
                   int,
                   int64_t,
                   bool,
                   complex64,
106 107
                   complex128,
                   phi::dtype::bfloat16) {}
108 109

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
110

111
PD_REGISTER_KERNEL(add,
112 113
                   GPU,
                   ALL_LAYOUT,
114
                   phi::AddKernel,
115 116
                   float,
                   double,
117
                   int16_t,
118 119
                   int,
                   int64_t,
120
                   phi::dtype::float16,
121
                   phi::dtype::bfloat16,
122 123
                   complex64,
                   complex128) {}
124
PD_REGISTER_KERNEL(subtract,
125 126
                   GPU,
                   ALL_LAYOUT,
127
                   phi::SubtractKernel,
128 129
                   float,
                   double,
130
                   int16_t,
131 132
                   int,
                   int64_t,
133
                   phi::dtype::float16,
134
                   complex64,
135 136
                   complex128,
                   phi::dtype::bfloat16) {}
137
PD_REGISTER_KERNEL(divide,
138 139
                   GPU,
                   ALL_LAYOUT,
140
                   phi::DivideKernel,
141 142 143 144
                   float,
                   double,
                   int,
                   int64_t,
145
                   phi::dtype::float16,
146
                   phi::dtype::bfloat16,
147 148
                   complex64,
                   complex128) {}
149
PD_REGISTER_KERNEL(multiply,
150 151
                   GPU,
                   ALL_LAYOUT,
152
                   phi::MultiplyKernel,
153 154 155 156 157
                   float,
                   double,
                   int,
                   int64_t,
                   bool,
158
                   phi::dtype::float16,
159 160 161
                   complex64,
                   complex128) {}
#endif