Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit e3d94fc

Browse files
authored
【Hackathon No.56 57 58 59】sparse elementwise add sub mul div (PaddlePaddle#41857)
1 parent 3be36a8 commit e3d94fc

File tree

15 files changed

+1979
-0
lines changed

15 files changed

+1979
-0
lines changed

paddle/phi/kernels/activation_kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ DECLARE_ACTIVATION_KERNEL(Log1p)
7171
DECLARE_ACTIVATION_KERNEL(Round)
7272
DECLARE_ACTIVATION_KERNEL(Floor)
7373
DECLARE_ACTIVATION_KERNEL(Ceil)
74+
DECLARE_ACTIVATION_KERNEL(Negative)
7475

7576
DECLARE_ACTIVATION_KERNEL_WITH_ONE_ATTRS(LeakyRelu, alpha)
7677
DECLARE_ACTIVATION_KERNEL_WITH_ONE_ATTRS(ThresholdedRelu, threshold)

paddle/phi/kernels/cpu/activation_kernel.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ DEFINE_CPU_ACTIVATION_KERNEL(Log1p, Log1pFunctor)
8989
DEFINE_CPU_ACTIVATION_KERNEL(Round, RoundFunctor)
9090
DEFINE_CPU_ACTIVATION_KERNEL(Floor, FloorFunctor)
9191
DEFINE_CPU_ACTIVATION_KERNEL(Ceil, CeilFunctor)
92+
DEFINE_CPU_ACTIVATION_KERNEL(Negative, NegativeFunctor)
9293

9394
DEFINE_CPU_ACT_KERNEL_WITH_ONE_ATTRS(LeakyRelu, LeakyReluFunctor, alpha)
9495
DEFINE_CPU_ACT_KERNEL_WITH_ONE_ATTRS(ThresholdedRelu,
@@ -182,6 +183,15 @@ PD_REGISTER_ACTIVATION_KERNEL(swish, SwishKernel)
182183
PD_REGISTER_ACTIVATION_KERNEL(round, RoundKernel)
183184
PD_REGISTER_ACTIVATION_KERNEL(floor, FloorKernel)
184185
PD_REGISTER_ACTIVATION_KERNEL(ceil, CeilKernel)
186+
PD_REGISTER_KERNEL(negative,
187+
CPU,
188+
ALL_LAYOUT,
189+
phi::NegativeKernel,
190+
float,
191+
double,
192+
int16_t,
193+
int,
194+
int64_t) {}
185195
PD_REGISTER_ACTIVATION_KERNEL(celu, CeluKernel)
186196
PD_REGISTER_KERNEL(
187197
pow, CPU, ALL_LAYOUT, phi::PowKernel, float, double, int, int64_t) {}

paddle/phi/kernels/funcs/activation_functor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,14 @@ struct CeilFunctor : public BaseActivationFunctor<T> {
18141814
}
18151815
};
18161816

1817+
template <typename T>
1818+
struct NegativeFunctor : public BaseActivationFunctor<T> {
1819+
template <typename Device, typename X, typename Out>
1820+
void operator()(Device d, X x, Out out) const {
1821+
out.device(d) = -x;
1822+
}
1823+
};
1824+
18171825
template <typename T>
18181826
struct ZeroGradFunctor : public BaseActivationFunctor<T> {
18191827
template <typename Device,

0 commit comments

Comments
 (0)