elementwise_kernel.cc 6.9 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.

Y
YuanRisheng 已提交
15
#include "paddle/phi/kernels/elementwise_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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
template <typename T, typename Context>
void MaximumKernel(const Context& dev_ctx,
                   const DenseTensor& x,
                   const DenseTensor& y,
                   DenseTensor* out) {
  int axis = -1;
  MaximumRawKernel<T>(dev_ctx, x, y, axis, out);
}

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

template <typename T, typename Context>
void ModuloKernel(const Context& dev_ctx,
                  const DenseTensor& x,
                  const DenseTensor& y,
                  DenseTensor* out) {
  int axis = -1;
  ModuloRawKernel<T>(dev_ctx, x, y, axis, out);
}
84
}  // namespace phi
85

86 87
using complex64 = ::phi::dtype::complex<float>;
using complex128 = ::phi::dtype::complex<double>;
88

89
PD_REGISTER_KERNEL(add,
90 91
                   CPU,
                   ALL_LAYOUT,
92
                   phi::AddKernel,
93 94
                   float,
                   double,
95
                   int16_t,
96 97 98 99
                   int,
                   int64_t,
                   complex64,
                   complex128) {}
100
PD_REGISTER_KERNEL(subtract,
101 102
                   CPU,
                   ALL_LAYOUT,
103
                   phi::SubtractKernel,
104 105
                   float,
                   double,
106
                   int16_t,
107 108 109
                   int,
                   int64_t,
                   complex64,
110 111
                   complex128,
                   phi::dtype::bfloat16) {}
112
PD_REGISTER_KERNEL(divide,
113 114
                   CPU,
                   ALL_LAYOUT,
115
                   phi::DivideKernel,
116 117 118 119 120 121
                   float,
                   double,
                   int,
                   int64_t,
                   complex64,
                   complex128) {}
122
PD_REGISTER_KERNEL(multiply,
123 124
                   CPU,
                   ALL_LAYOUT,
125
                   phi::MultiplyKernel,
126 127 128 129 130 131
                   float,
                   double,
                   int,
                   int64_t,
                   bool,
                   complex64,
132 133
                   complex128,
                   phi::dtype::bfloat16) {}
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
PD_REGISTER_KERNEL(maximum,
                   CPU,
                   ALL_LAYOUT,
                   phi::MaximumKernel,
                   float,
                   double,
                   int,
                   int64_t,
                   phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(minimum,
                   CPU,
                   ALL_LAYOUT,
                   phi::MinimumKernel,
                   float,
                   double,
                   int,
                   int64_t,
                   phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(
    modulo, CPU, ALL_LAYOUT, phi::ModuloKernel, float, double, int, int64_t) {}
154 155

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

157
PD_REGISTER_KERNEL(add,
158 159
                   GPU,
                   ALL_LAYOUT,
160
                   phi::AddKernel,
161 162
                   float,
                   double,
163
                   int16_t,
164 165
                   int,
                   int64_t,
166
                   phi::dtype::float16,
167
                   phi::dtype::bfloat16,
168 169
                   complex64,
                   complex128) {}
170
PD_REGISTER_KERNEL(subtract,
171 172
                   GPU,
                   ALL_LAYOUT,
173
                   phi::SubtractKernel,
174 175
                   float,
                   double,
176
                   int16_t,
177 178
                   int,
                   int64_t,
179
                   phi::dtype::float16,
180
                   complex64,
181 182
                   complex128,
                   phi::dtype::bfloat16) {}
183
PD_REGISTER_KERNEL(divide,
184 185
                   GPU,
                   ALL_LAYOUT,
186
                   phi::DivideKernel,
187 188 189 190
                   float,
                   double,
                   int,
                   int64_t,
191
                   phi::dtype::float16,
192
                   phi::dtype::bfloat16,
193 194
                   complex64,
                   complex128) {}
195
PD_REGISTER_KERNEL(multiply,
196 197
                   GPU,
                   ALL_LAYOUT,
198
                   phi::MultiplyKernel,
199 200 201 202 203
                   float,
                   double,
                   int,
                   int64_t,
                   bool,
204
                   phi::dtype::float16,
205 206
                   complex64,
                   complex128) {}
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
PD_REGISTER_KERNEL(maximum,
                   GPU,
                   ALL_LAYOUT,
                   phi::MaximumKernel,
                   float,
                   double,
                   int,
                   int64_t,
                   phi::dtype::float16,
                   phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(minimum,
                   GPU,
                   ALL_LAYOUT,
                   phi::MinimumKernel,
                   float,
                   double,
                   int,
                   int64_t,
                   phi::dtype::float16,
                   phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(
    modulo, GPU, ALL_LAYOUT, phi::ModuloKernel, float, double, int, int64_t) {}
229
#endif