-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[PIR][1/N] Support register Python function on PIR (IR part) #76935
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
[PIR][1/N] Support register Python function on PIR (IR part) #76935
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
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.
Pull request overview
This PR adds support for registering Python functions on PIR (Paddle Intermediate Representation), which is the IR (Intermediate Representation) part of a multi-part feature addition. The changes introduce a new PythonOperatorDialect and PythonFunctionOp infrastructure to represent Python functions in the PIR system, along with supporting metadata types.
Key Changes
- Added
NativeMetaTensorclass for representing tensor metadata in Python operators - Extended
OpMetaInfoto support Python operator functions and inference metadata functions - Created new dialect classes (
PythonOperatorDialect,PythonFunctionDialect) for Python operations - Changed
OpInfoparameter from pass-by-value to pass-by-const-reference for better performance
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| paddle/pir/src/core/operation.cc | Changed OpInfo parameter to const reference for performance |
| paddle/pir/include/core/operation.h | Updated Create method signature to use const reference for OpInfo |
| paddle/phi/api/lib/op_meta_info.cc | Added Python operator function setters and void* attribute support |
| paddle/phi/api/lib/native_meta_tensor.cc | Implemented NativeMetaTensor class methods |
| paddle/phi/api/lib/CMakeLists.txt | Added native_meta_tensor.cc to build |
| paddle/phi/api/ext/op_meta_info.h | Added Python operator function types and setters to OpMetaInfo |
| paddle/phi/api/ext/native_meta_tensor.h | Defined NativeMetaTensor class for tensor metadata |
| paddle/fluid/pir/dialect/operator/utils/utils.cc | Added void* to attribute type mapping |
| paddle/fluid/pir/dialect/operator/ir/op_dialect.h | Added PythonOperatorDialect class and IsCustomPyOp helper |
| paddle/fluid/pir/dialect/operator/ir/op_dialect.cc | Implemented PythonOperatorDialect registration and info interface |
| paddle/fluid/pir/dialect/kernel/ir/kernel_op.h | Added PythonFunctionOp class declaration |
| paddle/fluid/pir/dialect/kernel/ir/kernel_op.cc | Implemented PythonFunctionOp methods |
| paddle/fluid/pir/dialect/kernel/ir/kernel_dialect.h | Added PythonFunctionDialect class declaration |
| paddle/fluid/pir/dialect/kernel/ir/kernel_dialect.cc | Implemented PythonFunctionDialect with printing methods |
| paddle/fluid/framework/python_operator.h | Added RegisterPythonOperator API |
| paddle/fluid/framework/python_operator.cc | Implemented Python operator registration function |
| paddle/fluid/framework/custom_operator_utils.h | Added GetPythonOperatorInfoByPirName utility and prefix constant |
| paddle/fluid/framework/CMakeLists.txt | Added python_operator.cc to custom_operator library |
| cmake/inference_lib.cmake | Added ddim.h to inference library includes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
| return op_name.find("custom_op") != op_name.npos; | ||
| } | ||
|
|
||
| inline bool IsCustomPyOp(pir::Operation* op) { |
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.
这里的Custom是否要保留?
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.
part2 #76938 会一起改一下
| traits.push_back(pir::TypeId::get<paddle::dialect::InplaceTrait>()); | ||
| } | ||
|
|
||
| char* op_name_c = new char[op_name.size() + 1]; |
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.
这里的 delete part2 加一下
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (1.09%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #76935 +/- ##
==========================================
Coverage ? 1.09%
==========================================
Files ? 10
Lines ? 182
Branches ? 0
==========================================
Hits ? 2
Misses ? 180
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PR Category
Execute Infrastructure
PR Types
New features
Description
支持在 PIR 上表示 Python 函数,以实现 FD 中的 triton、deep gemm 等算子在 IR 上表示,确保整图转静,为 #76888 的拆分与正式化版本,主要由 @DrRyanHuang 开发
IR 命名规范如下:
py_oppy_func(因为 Python 函数并没有 kernel 的概念,从执行层来看,function 是其对应的可执行表示)python function,理由同上PythonFunction#76888 将会作为最后一个 PR 合入