@@ -25,103 +25,100 @@ void ReluCompute::Run() {
25
25
auto & param = this ->Param <param_t >();
26
26
auto & ctx = this ->ctx_ ->As <XPUContext>();
27
27
28
- int r = xdnn::activation_forward (
29
- ctx.GetRawContext (), /* context */
30
- xdnn::Activation_t::RELU, /* type */
31
- param.X ->numel (), /* len */
32
- param.X ->data <float >(), /* x */
33
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
28
+ int r = xdnn::relu (ctx.GetRawContext (),
29
+ param.X ->data <float >(),
30
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
31
+ param.X ->numel ());
32
+ CHECK_EQ (r, 0 );
33
+ }
34
+
35
+ void Relu6Compute::Run () {
36
+ auto & param = this ->Param <param_t >();
37
+ auto & ctx = this ->ctx_ ->As <XPUContext>();
38
+
39
+ int r = xdnn::relu6 (ctx.GetRawContext (),
40
+ param.X ->data <float >(),
41
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
42
+ param.X ->numel ());
34
43
CHECK_EQ (r, 0 );
35
44
}
36
45
37
46
void TanhCompute::Run () {
38
47
auto & param = this ->Param <param_t >();
39
48
auto & ctx = this ->ctx_ ->As <XPUContext>();
40
49
41
- int r = xdnn::activation_forward (
42
- ctx.GetRawContext (), /* context */
43
- xdnn::Activation_t::TANH, /* type */
44
- param.X ->numel (), /* len */
45
- param.X ->data <float >(), /* x */
46
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
50
+ int r = xdnn::tanh (ctx.GetRawContext (),
51
+ param.X ->data <float >(),
52
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
53
+ param.X ->numel ());
47
54
CHECK_EQ (r, 0 );
48
55
}
49
56
50
57
void SigmoidCompute::Run () {
51
58
auto & param = this ->Param <param_t >();
52
59
auto & ctx = this ->ctx_ ->As <XPUContext>();
53
60
54
- int r = xdnn::activation_forward (
55
- ctx.GetRawContext (), /* context */
56
- xdnn::Activation_t::SIGMOID, /* type */
57
- param.X ->numel (), /* len */
58
- param.X ->data <float >(), /* x */
59
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
61
+ int r = xdnn::sigmoid (ctx.GetRawContext (),
62
+ param.X ->data <float >(),
63
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
64
+ param.X ->numel ());
60
65
CHECK_EQ (r, 0 );
61
66
}
62
67
63
68
void AbsCompute::Run () {
64
69
auto & param = this ->Param <param_t >();
65
70
auto & ctx = this ->ctx_ ->As <XPUContext>();
66
71
67
- int r = xdnn::activation_forward (
68
- ctx.GetRawContext (), /* context */
69
- xdnn::Activation_t::ABS, /* type */
70
- param.X ->numel (), /* len */
71
- param.X ->data <float >(), /* x */
72
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
72
+ int r = xdnn::abs (ctx.GetRawContext (),
73
+ param.X ->data <float >(),
74
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
75
+ param.X ->numel ());
73
76
CHECK_EQ (r, 0 );
74
77
}
75
78
76
79
void ExpCompute::Run () {
77
80
auto & param = this ->Param <param_t >();
78
81
auto & ctx = this ->ctx_ ->As <XPUContext>();
79
82
80
- int r = xdnn::activation_forward (
81
- ctx.GetRawContext (), /* context */
82
- xdnn::Activation_t::EXP, /* type */
83
- param.X ->numel (), /* len */
84
- param.X ->data <float >(), /* x */
85
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
83
+ int r = xdnn::exp (ctx.GetRawContext (),
84
+ param.X ->data <float >(),
85
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
86
+ param.X ->numel ());
86
87
CHECK_EQ (r, 0 );
87
88
}
88
89
89
90
void SquareCompute::Run () {
90
91
auto & param = this ->Param <param_t >();
91
92
auto & ctx = this ->ctx_ ->As <XPUContext>();
92
93
93
- int r = xdnn::activation_forward (
94
- ctx.GetRawContext (), /* context */
95
- xdnn::Activation_t::SQUARE, /* type */
96
- param.X ->numel (), /* len */
97
- param.X ->data <float >(), /* x */
98
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
94
+ int r = xdnn::square (ctx.GetRawContext (),
95
+ param.X ->data <float >(),
96
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
97
+ param.X ->numel ());
99
98
CHECK_EQ (r, 0 );
100
99
}
101
100
102
101
void ReciprocalCompute::Run () {
103
102
auto & param = this ->Param <param_t >();
104
103
auto & ctx = this ->ctx_ ->As <XPUContext>();
105
104
106
- int r = xdnn::activation_forward (
107
- ctx.GetRawContext (), /* context */
108
- xdnn::Activation_t::RECIPROCAL, /* type */
109
- param. X -> numel (), /* len */
110
- param.X ->data <float >(), /* x */
111
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
105
+ int r =
106
+ xdnn::activation_forward ( ctx.GetRawContext (),
107
+ xdnn::Activation_t::RECIPROCAL,
108
+ param. X -> numel (),
109
+ param.X ->data <float >(),
110
+ param.Out ->mutable_data <float >(TARGET (kXPU )));
112
111
CHECK_EQ (r, 0 );
113
112
}
114
113
115
114
void SqrtCompute::Run () {
116
115
auto & param = this ->Param <param_t >();
117
116
auto & ctx = this ->ctx_ ->As <XPUContext>();
118
117
119
- int r = xdnn::activation_forward (
120
- ctx.GetRawContext (), /* context */
121
- xdnn::Activation_t::SQRT, /* type */
122
- param.X ->numel (), /* len */
123
- param.X ->data <float >(), /* x */
124
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
118
+ int r = xdnn::sqrt (ctx.GetRawContext (),
119
+ param.X ->data <float >(),
120
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
121
+ param.X ->numel ());
125
122
CHECK_EQ (r, 0 );
126
123
}
127
124
@@ -132,25 +129,71 @@ void PowCompute::Run() {
132
129
xdnn::Activation_t act_type (xdnn::Activation_t::ACT_POW);
133
130
act_type.pow_factor = param.factor ;
134
131
135
- int r = xdnn::activation_forward (
136
- ctx.GetRawContext (), /* context */
137
- act_type, /* type */
138
- param. X -> numel (), /* len */
139
- param.X ->data <float >(), /* x */
140
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
132
+ int r =
133
+ xdnn::activation_forward ( ctx.GetRawContext (),
134
+ act_type,
135
+ param. X -> numel (),
136
+ param.X ->data <float >(),
137
+ param.Out ->mutable_data <float >(TARGET (kXPU )));
141
138
CHECK_EQ (r, 0 );
142
139
}
143
140
144
141
void SignCompute::Run () {
145
142
auto & param = this ->Param <param_t >();
146
143
auto & ctx = this ->ctx_ ->As <XPUContext>();
147
144
148
- int r = xdnn::activation_forward (
149
- ctx.GetRawContext (), /* context */
150
- xdnn::Activation_t::SIGN, /* type */
151
- param.X ->numel (), /* len */
152
- param.X ->data <float >(), /* x */
153
- param.Out ->mutable_data <float >(TARGET (kXPU )) /* y */ );
145
+ int r =
146
+ xdnn::activation_forward (ctx.GetRawContext (),
147
+ xdnn::Activation_t::SIGN,
148
+ param.X ->numel (),
149
+ param.X ->data <float >(),
150
+ param.Out ->mutable_data <float >(TARGET (kXPU )));
151
+ CHECK_EQ (r, 0 );
152
+ }
153
+
154
+ void HardSwishCompute::Run () {
155
+ auto & param = this ->Param <param_t >();
156
+ auto & ctx = this ->ctx_ ->As <XPUContext>();
157
+
158
+ int r = xdnn::hard_swish (ctx.GetRawContext (),
159
+ param.X ->data <float >(),
160
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
161
+ param.X ->numel ());
162
+ CHECK_EQ (r, 0 );
163
+ }
164
+
165
+ void HardSigmoidCompute::Run () {
166
+ auto & param = this ->Param <param_t >();
167
+ auto & ctx = this ->ctx_ ->As <XPUContext>();
168
+
169
+ int r = xdnn::hard_sigmoid (ctx.GetRawContext (),
170
+ param.X ->data <float >(),
171
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
172
+ param.X ->numel (),
173
+ param.hard_sigmoid_slope );
174
+ CHECK_EQ (r, 0 );
175
+ }
176
+
177
+ void LeakyReluCompute::Run () {
178
+ auto & param = this ->Param <param_t >();
179
+ auto & ctx = this ->ctx_ ->As <XPUContext>();
180
+
181
+ int r = xdnn::leaky_relu (ctx.GetRawContext (),
182
+ param.X ->data <float >(),
183
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
184
+ param.X ->numel (),
185
+ param.Leaky_relu_alpha );
186
+ CHECK_EQ (r, 0 );
187
+ }
188
+
189
+ void SoftsignCompute::Run () {
190
+ auto & param = this ->Param <param_t >();
191
+ auto & ctx = this ->ctx_ ->As <XPUContext>();
192
+
193
+ int r = xdnn::softsign (ctx.GetRawContext (),
194
+ param.X ->data <float >(),
195
+ param.Out ->mutable_data <float >(TARGET (kXPU )),
196
+ param.X ->numel ());
154
197
CHECK_EQ (r, 0 );
155
198
}
156
199
@@ -165,6 +208,12 @@ REGISTER_LITE_KERNEL(
165
208
.BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
166
209
.Finalize();
167
210
211
+ REGISTER_LITE_KERNEL (
212
+ relu6, kXPU , kFloat , kNCHW , paddle::lite::kernels::xpu::Relu6Compute, def)
213
+ .BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
214
+ .BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
215
+ .Finalize();
216
+
168
217
REGISTER_LITE_KERNEL (
169
218
tanh, kXPU , kFloat , kNCHW , paddle::lite::kernels::xpu::TanhCompute, def)
170
219
.BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
@@ -226,3 +275,43 @@ REGISTER_LITE_KERNEL(reciprocal,
226
275
.BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
227
276
.BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
228
277
.Finalize();
278
+
279
+ REGISTER_LITE_KERNEL (hard_sigmoid,
280
+ kXPU ,
281
+ kFloat ,
282
+ kNCHW ,
283
+ paddle::lite::kernels::xpu::HardSigmoidCompute,
284
+ def)
285
+ .BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
286
+ .BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
287
+ .Finalize();
288
+
289
+ REGISTER_LITE_KERNEL (hard_swish,
290
+ kXPU ,
291
+ kFloat ,
292
+ kNCHW ,
293
+ paddle::lite::kernels::xpu::HardSwishCompute,
294
+ def)
295
+ .BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
296
+ .BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
297
+ .Finalize();
298
+
299
+ REGISTER_LITE_KERNEL (leaky_relu,
300
+ kXPU ,
301
+ kFloat ,
302
+ kNCHW ,
303
+ paddle::lite::kernels::xpu::LeakyReluCompute,
304
+ def)
305
+ .BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
306
+ .BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
307
+ .Finalize();
308
+
309
+ REGISTER_LITE_KERNEL (softsign,
310
+ kXPU ,
311
+ kFloat ,
312
+ kNCHW ,
313
+ paddle::lite::kernels::xpu::SoftsignCompute,
314
+ def)
315
+ .BindInput(" X" , {LiteType::GetTensorTy (TARGET (kXPU ))})
316
+ .BindOutput(" Out" , {LiteType::GetTensorTy (TARGET (kXPU ))})
317
+ .Finalize();
0 commit comments