Skip to content
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]refactor pd op to kernel pass #56984

Merged
merged 14 commits into from Sep 12, 2023

Conversation

phlrain
Copy link
Collaborator

@phlrain phlrain commented Sep 5, 2023

PR types

Others

PR changes

Others

Description

对于pd op to kernel pass 做代码结构的调整,进行模块化划分,方便控制流的接入

Pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Sep 5, 2023

你的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.

@paddle-bot
Copy link

paddle-bot bot commented Sep 5, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

@phlrain phlrain changed the title refactor pd op to kernel pass [NewIR]refactor pd op to kernel pass Sep 6, 2023
@@ -255,7 +101,7 @@ bool NeedFallBackCpu(const pir::Operation* op,

phi::Backend GetDstBackend(const std::string& op_name,
phi::Place place,
OpYamlInfoParser* op_yaml_info_parser,
const OpYamlInfoParser* op_yaml_info_parser,
Copy link
Contributor

Choose a reason for hiding this comment

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

phi::Backend GetDstBackend(const std::string& op_name,
                           const phi::Place& place,
                           const OpYamlInfoParser* op_yaml_info_parser,
                           const phi::Backend& kernel_def_backend,
                           size_t input_index) {

对于const的变量,相对于指针类型,我们更推荐引用,应为引用永远是「合法的」。

std::stringstream ss;
prog->Print(ss);
VLOG(2) << "Program after lowering to kernel pass : " << ss.str();
if (op->name() == "pd_op.load_combine") {
Copy link
Contributor

Choose a reason for hiding this comment

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

对于op name 我们更推荐使用 paddle::dialect::LoadCombineOp::name()。其实更好的方式是: op->isa<LoadCombineOp>()

const pir::Value cur_in,
const std::unordered_map<pir::Value, pir::OpResult>& map_value_pair,
const int index,
const std::string op_name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const std::string op_name) {
const std::string& op_name) {

std::unordered_map<pir::Value, pir::OpResult>* map_value_pair) {
std::vector<pir::OpResult> vec_inputs;
std::vector<pir::Type> op_output_types;
if (op_item->name() == "builtin.combine") {
Copy link
Contributor

Choose a reason for hiding this comment

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

同上


if (NeedFallBackFromGPUDNN2GPU(op_item, kernel_key)) {
kernel_key.set_backend(phi::Backend::GPU);
pir::OpInfo op_info = ctx->GetRegisteredOpInfo(op_item->name());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pir::OpInfo op_info = ctx->GetRegisteredOpInfo(op_item->name());
pir::OpInfo& op_info = ctx->GetRegisteredOpInfo(op_item->name());

std::vector<pir::Type> op_output_types;
auto phi_kernel = phi::KernelFactory::Instance().SelectKernelWithGPUDNN(
kernel_fn_str, kernel_key);
auto args_def = phi_kernel.args_def();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto args_def = phi_kernel.args_def();
auto& args_def = phi_kernel.args_def();

auto phi_kernel = phi::KernelFactory::Instance().SelectKernelWithGPUDNN(
kernel_fn_str, kernel_key);
auto args_def = phi_kernel.args_def();
auto output_defs = args_def.output_defs();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto output_defs = args_def.output_defs();
auto& output_defs = args_def.output_defs();

pir::Operation* op_item,
const std::string& kernel_fn_str,
const phi::KernelKey& kernel_key,
const phi::Place place,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const phi::Place place,
const phi::Place& place,


// get input args def type
auto args_def = kernel.args_def();
auto input_defs = args_def.input_defs();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto input_defs = args_def.input_defs();
auto& input_defs = args_def.input_defs();

std::unordered_map<pir::Operation*, pir::Operation*>* map_op_pair,
std::unordered_map<pir::Value, pir::OpResult>* map_value_pair) {
bool feed_op_add_shadow_feed =
(op_item->name() == "pd_op.feed") && platform::is_gpu_place(place);
Copy link
Contributor

Choose a reason for hiding this comment

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

op_item->isa<FeedOp>()

@phlrain phlrain merged commit 772df24 into PaddlePaddle:develop Sep 12, 2023
26 of 27 checks passed
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* refactor pd op to kernel pass

* fix bug

* update

* add code

* fix merge bug

* fix bug

* update

* fix bug

* polish code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants