Skip to content

Commit be1019d

Browse files
committed
improve
1 parent 6faabd5 commit be1019d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

paddle/phi/kernels/gpu/p_norm_kernel.cu

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "paddle/phi/kernels/funcs/reduce_function.h"
2323
#include "paddle/phi/kernels/gpu/reduce.h"
2424

25-
#include "paddle/fluid/framework/tensor_util.h"
2625
#include "paddle/phi/kernels/activation_kernel.h"
2726

2827
namespace phi {
@@ -135,6 +134,7 @@ void PNormKernel(const Context& dev_ctx,
135134
// fast 1-norm
136135
phi::funcs::ReduceKernel<T, T, kps::AddFunctor, FabsFunctor<T>>(
137136
dev_ctx, *in_x, out_norm, FabsFunctor<T>(), reduce_axis);
137+
return;
138138
} else if (porder == 2.0) {
139139
// fast 2-norm
140140
using MT = typename phi::dtype::MPTypeTrait<T>::Type;
@@ -154,7 +154,6 @@ void PNormKernel(const Context& dev_ctx,
154154
phi::SqrtKernel<MT>(dev_ctx, temp_sum_of_squares_hp, &temp_norm_hp);
155155
phi::CastKernel<MT>(dev_ctx, temp_norm_hp, out_norm->dtype(), out_norm);
156156
return;
157-
158157
} else if (porder == 3.0) {
159158
// fast 3-norm
160159
phi::funcs::ReduceKernel<T, MT, kps::AddFunctor, FabsCubicFunctor<MT>>(
@@ -168,14 +167,11 @@ void PNormKernel(const Context& dev_ctx,
168167
UnsignedPowFunctor<MT>(porder),
169168
reduce_axis);
170169
}
171-
172-
if (porder != 1.0) {
173-
std::vector<const DenseTensor*> ins = {&out_temp};
174-
std::vector<DenseTensor*> outs = {out_norm};
175-
MT p_order_ = static_cast<MT>(1.f / porder);
176-
phi::funcs::ElementwiseKernel<T>(
177-
dev_ctx, ins, &outs, UnsignedPowFunctor<MT>(p_order_));
178-
}
170+
std::vector<const DenseTensor*> ins = {&out_temp};
171+
std::vector<DenseTensor*> outs = {out_norm};
172+
MT p_order_ = static_cast<MT>(1.f / porder);
173+
phi::funcs::ElementwiseKernel<T>(
174+
dev_ctx, ins, &outs, UnsignedPowFunctor<MT>(p_order_));
179175
#endif
180176
}
181177
}

0 commit comments

Comments
 (0)