-
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
[NewIR] Add parser to deserialize #55695
Conversation
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.
关于文件结构,可以把parser相关的文件在 ir/core路径下单独建一个子文件夹如ir/core/parser
处理,把token.h/lexer.h/lexer.cc/ir_parser.cc放在里面,就留ir_parser.h在外面吧
记得顺便更改下ir/core/CMakeLists
Sorry to inform you that 17baf61's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
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.
@xingmingyyj 麻烦完善下PR描述,结合这里的单测说明下新加入的parser模块的用法,如果有的话,可以把文档里面写好的部分粘贴过来,没有的话麻烦补充下。
test/cpp/ir/core/ir_parser_test.cc
Outdated
// limitations under the License. | ||
|
||
#include "paddle/ir/core/ir_parser.h" | ||
#include <gtest/gtest.h> |
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.
#include <gtest/gtest.h> | |
#include <fstream> | |
#include <iostream> | |
#include <gtest/gtest.h> |
这个顺序更合适些
Co-authored-by: kangguangli <kangguangli@hotmail.com>
已添加 |
Co-authored-by: kangguangli <kangguangli@hotmail.com>
Co-authored-by: kangguangli <kangguangli@hotmail.com>
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.
Good job!
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
gtest | ||
pd_dialect | ||
ir) | ||
|
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.
建议将cc_test_old改为cc_test,link静态库会导致可执行文件比较大,会在连接的时候占用更多的内存,可能导致内存打满,coverage编译挂掉,鉴于此PR编译出来的单测可执行文件小与500M,可提前approve,建议合入之后,改为cc_test,或者使用cc_test_old依赖libpaddle.so
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.
好的👌
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
@xingmingyyj 恭喜PR合入了,可以先解决下上面提到的cc_test_old的问题,替换成cc_test试试,看看有没有什么问题 |
好的好的👌 |
* add parser * add parser * add parser * add parser * add parser * add parser * add parser * Update test/cpp/ir/core/ir_parser_test.cc Co-authored-by: kangguangli <kangguangli@hotmail.com> * add parser * add parser * add parser * Update test/cpp/ir/core/program_translator_test.cc Co-authored-by: kangguangli <kangguangli@hotmail.com> * Update test/cpp/ir/core/program_translator_test.cc Co-authored-by: kangguangli <kangguangli@hotmail.com> * Update dialect.h * add parser * add parser * Update CMakeLists.txt * add parser --------- Co-authored-by: kangguangli <kangguangli@hotmail.com>
PR types
Others
PR changes
Others
Description
该PR为Paddle增加Parser模块,该模块可以完成将文本文件分序列化为计算图的功能。Parser主要支持
Attribute
、Type
和Program
的反序列化。设计文档
Parser设计文档
如何反序列化Program
参考代码如下:
ir::IrContext *ctx = ir::IrContext::Instance(); ctx->GetOrRegisterDialect<PaddleDialect>(); std::ifstream program_text(file_path); std::unique_ptr<ir::Program> program = ir::Program::Parse(program_text,ctx); std::cout << *program << std::endl;
可以参考
test/cpp/ir/core/program_translator_test.cc
的IrParserTest
,提供了例子。如何反序列化Type/Attribute
Type
和Attribute
的Parse方式和Program类似,如下:可以参考
test/cpp/ir/core/ir_parser_test.cc
和test/cpp/ir/core/TestParserText.txt
。如果新定义了一个dialect,如何为它自定义parser?
在定义dialect时,需要重载下面几个方法:
可以参考
test/cpp/ir/core/add_dialect_parser_test.cc
。