提交 be8b6e0c 编写于 作者: W Wilber 提交者: GitHub

add eltwise_mul kernel for x86. test=develop (#3627)

上级 e3677727
......@@ -35,3 +35,14 @@ REGISTER_LITE_KERNEL(elementwise_add,
.BindInput("Y", {LiteType::GetTensorTy(TARGET(kX86))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kX86))})
.Finalize();
REGISTER_LITE_KERNEL(elementwise_mul,
kX86,
kFloat,
kNCHW,
paddle::lite::kernels::x86::ElementwiseMulCompute<float>,
def)
.BindInput("X", {LiteType::GetTensorTy(TARGET(kX86))})
.BindInput("Y", {LiteType::GetTensorTy(TARGET(kX86))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kX86))})
.Finalize();
......@@ -33,6 +33,11 @@ struct AddFunctor {
inline HOSTDEVICE T operator()(T a, T b) const { return a + b; }
};
template <typename T>
struct MulFunctor {
inline HOSTDEVICE T operator()(T a, T b) const { return a * b; }
};
template <typename T>
class ElementwiseSubCompute
: public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
......@@ -71,6 +76,24 @@ class ElementwiseAddCompute
virtual ~ElementwiseAddCompute() = default;
};
template <typename T>
class ElementwiseMulCompute
: public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
public:
using param_t = operators::ElementwiseParam;
void Run() override {
auto& param = *param_.get_mutable<param_t>();
auto& context = ctx_->As<X86Context>();
param.Out->template mutable_data<T>();
paddle::lite::kernels::x86::ElementwiseComputeEx<MulFunctor<T>,
lite::TargetType::kX86,
T>(
context, param.X, param.Y, param.axis, MulFunctor<T>(), param.Out);
}
virtual ~ElementwiseMulCompute() = default;
};
} // namespace x86
} // namespace kernels
} // namespace lite
......
......@@ -324,7 +324,7 @@ void ElementwiseComputeEx(const lite::Context<Target> &ctx,
}
axis = (axis == -1 ? x_dims.size() - y_dims_untrimed.size() : axis);
PADDLE_ENFORCE(axis >= 0 && axis < x_dims.size(),
PADDLE_ENFORCE(axis >= 0 && axis < static_cast<int>(x_dims.size()),
"Axis should be in range [0, x_dims)");
auto y_dims = trim_trailing_singular_dims(y_dims_untrimed);
axis = (y_dims.size() == 0) ? x_dims.size() : axis;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册