Skip to content

Conversation

@SigureMo
Copy link
Member

@SigureMo SigureMo commented Dec 16, 2025

PR Category

Execute Infrastructure

PR Types

New features

Description

支持在 PIR 上表示 Python 函数,以实现 FD 中的 triton、deep gemm 等算子在 IR 上表示,确保整图转静,为 #76888 的拆分与正式化版本,主要由 @DrRyanHuang 开发

IR 命名规范如下:

  • op dialect name py_op
  • kernel dialect name py_func(因为 Python 函数并没有 kernel 的概念,从执行层来看,function 是其对应的可执行表示)
  • 执行器 instruction 命名 python function,理由同上
  • 其余 OP 表示层则统一用 PythonFunction

#76888 将会作为最后一个 PR 合入

Copilot AI review requested due to automatic review settings December 16, 2025 11:27
@paddle-bot
Copy link

paddle-bot bot commented Dec 16, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@SigureMo SigureMo changed the title [PIR][1/N] Support register Python function on PIR (IR part) [PIR][1/N]【CINN】 Support register Python function on PIR (IR part) Dec 16, 2025
Copy link
Contributor

Copilot AI left a 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 NativeMetaTensor class for representing tensor metadata in Python operators
  • Extended OpMetaInfo to support Python operator functions and inference metadata functions
  • Created new dialect classes (PythonOperatorDialect, PythonFunctionDialect) for Python operations
  • Changed OpInfo parameter 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.

return op_name.find("custom_op") != op_name.npos;
}

inline bool IsCustomPyOp(pir::Operation* op) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的Custom是否要保留?

Copy link
Member Author

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];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 delete part2 加一下

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 1.09890% with 180 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@f628ff6). Learn more about missing BASE report.

Files with missing lines Patch % Lines
paddle/fluid/pir/dialect/operator/ir/op_dialect.cc 0.00% 82 Missing ⚠️
...ddle/fluid/pir/dialect/kernel/ir/kernel_dialect.cc 0.00% 34 Missing ⚠️
paddle/fluid/framework/custom_operator_utils.h 0.00% 21 Missing ⚠️
paddle/phi/api/lib/op_meta_info.cc 5.55% 17 Missing ⚠️
paddle/fluid/pir/dialect/kernel/ir/kernel_op.cc 0.00% 16 Missing ⚠️
paddle/phi/api/lib/native_meta_tensor.cc 0.00% 4 Missing ⚠️
paddle/fluid/pir/dialect/kernel/ir/kernel_op.h 0.00% 3 Missing ⚠️
...addle/fluid/pir/dialect/kernel/ir/kernel_dialect.h 0.00% 2 Missing ⚠️
paddle/fluid/pir/dialect/operator/ir/op_dialect.h 0.00% 1 Missing ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo SigureMo changed the title [PIR][1/N]【CINN】 Support register Python function on PIR (IR part) [PIR][1/N] Support register Python function on PIR (IR part) Dec 17, 2025
@SigureMo SigureMo merged commit ba313a3 into PaddlePaddle:develop Dec 17, 2025
180 of 212 checks passed
@SigureMo SigureMo deleted the pir/python-op-part-1 branch December 17, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants