Skip to content

Commit 3f2b499

Browse files
Cwndmiaozhupengyang
authored andcommitted
[cherry-pick][LITE][XPU] Add xpu softsign kernel (#4860)
test=develop, test=xpu
1 parent 9b9a318 commit 3f2b499

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lite/kernels/xpu/activation_compute.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ void SignCompute::Run() {
154154
CHECK_EQ(r, 0);
155155
}
156156

157+
void SoftsignCompute::Run() {
158+
auto& param = this->Param<param_t>();
159+
auto& ctx = this->ctx_->As<XPUContext>();
160+
161+
int r = xdnn::softsign(ctx.GetRawContext(),
162+
param.X->data<float>(),
163+
param.Out->mutable_data<float>(TARGET(kXPU)),
164+
param.X->numel());
165+
CHECK_EQ(r, 0);
166+
}
167+
157168
} // namespace xpu
158169
} // namespace kernels
159170
} // namespace lite
@@ -226,3 +237,13 @@ REGISTER_LITE_KERNEL(reciprocal,
226237
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU))})
227238
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU))})
228239
.Finalize();
240+
241+
REGISTER_LITE_KERNEL(softsign,
242+
kXPU,
243+
kFloat,
244+
kNCHW,
245+
paddle::lite::kernels::xpu::SoftsignCompute,
246+
def)
247+
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU))})
248+
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU))})
249+
.Finalize();

lite/kernels/xpu/activation_compute.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ class SignCompute : public KernelLite<TARGET(kXPU), PRECISION(kFloat)> {
110110
virtual ~SignCompute() = default;
111111
};
112112

113+
class SoftsignCompute : public KernelLite<TARGET(kXPU), PRECISION(kFloat)> {
114+
public:
115+
using param_t = operators::ActivationParam;
116+
117+
virtual void Run();
118+
119+
virtual ~SoftsignCompute() = default;
120+
};
121+
113122
} // namespace xpu
114123
} // namespace kernels
115124
} // namespace lite

0 commit comments

Comments
 (0)