Paddle-Lite
Paddle-Lite copied to clipboard
[example] fix using any in kernel base class,test=develop
去除kernel基类中依赖any的example PR: (1) 原有op_lite.h的OpLite基类中和Op子类中都有ParamBase,通过AttachParam()运行时绑定,这里存在重复,通过Op基类定义纯虚函数访问子类实现予以去除; (2) op和kernel中都需要访问OpParam, 每个Op子类通过AttachKernel()把OpParam传递给对应的Kernel子类,这里通过shared_ptr管理需要传递的OpParam,Kernel基类中定义的Any形式的param予以去除,把相应的SetParam()改成纯虚函数(在子类中实现),把基类中的Param()去除挪到子类中实现; // kernel.h [-] template <typename T> [-] void SetParam(T param) { [-] param_.set(param); [-] } [-] template <typename P> [-] P& Param() const { [-] return *param_.get_mutable<P>(); [-] } [+] virtual void SetParam(const std::shared_ptroperators::ParamBase& op_param) = 0; [-] mutable operators::Any param_; ...... // conv_compute.h [+] using param_t = operators::ConvParam; [+] void SetParam (const std::shared_ptroperators::ParamBase& op_param) override { [+] param_ = std::dynamic_pointer_cast<param_t>(op_param); [+] } [+] param_t& Param() { [+] CHECK(param_); [+] return *param_; [+] } ...... // op_lite.h [-] mutable operators::ParamBase *op_param_{nullptr}; [+] virtual operators::ParamBase OpParam() const = 0; ...... // conv_op.h [+] ConvOpLite() { param_ = std::make_shared<param_t>(); } [+] operators::ParamBase OpParam() const override { return param_.get(); } [-] mutable ConvParam param_; [+] std::shared_ptr<param_t> param_;
Thanks for your contribution!
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
Automatically closed by Paddle-bot.