-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PTen] Unify InferMeta(Shape) Function in pten and fluid op #38976
[PTen] Unify InferMeta(Shape) Function in pten and fluid op #38976
Conversation
… pten/upgrade_infermeta_design
Thanks for your contribution! |
… pten/upgrade_infermeta_design
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2bcf72d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Function optimization
PR changes
Others
Describe
[PTen] Upgrade InferMeta and ArgumentMapping design
一、解决之前pten迁移InferMeta函数没有和原先Op的InferShape统一维护一份实现的问题
以sign为例,sign的InferMeta方法为
UnchangedInferMeta
,升级前后的写法分别为此处的
MetaConfig
,用来存储一些InferShape需要的状态变量,类似Context,但是相比Context来讲,非常轻量,在内部函数复用时一般也用不到(可能放到末尾会更自然)PT_KERNEL
宏,这里命名为PT_INFER_META
然后将
PT_INFER_META(UnchangedInferMetaNew)
包装到一个functor中,functor中先将InferShapeContext转换为InferMetaContext,再调用相应InferMeta函数,可以通过一个宏整理代码然后将该functor在Op注册时维护到相应OpInfo中即可,同时删除原先Op的InferShape实现,示例如下
像这样,原Op的InferShape函数迁移至pten InferMeta之后,可以重新注册回fluid中被调用,从而实现InferShape的函数化复用与全局统一。
二、新增OpUtilsMap,用于注册Op对应ApiName和ArgumentMappingFn,以兼容原fluid以及infrt
ArgumentMappingFn注册,通过在cc文件中注册对应函数,编译时自动生成对应编译对象,实现注册