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

[PIR] dce pass disable custom op #60578

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ PhiKernelInstruction::~PhiKernelInstruction() {
}

void PhiKernelInstruction::Run() {
VLOG(6) << "Begin run op " << phi_op_name_ << " infer meta.";
if (infer_meta_interface_) {
infer_meta_interface_->infer_meta_(&(infer_meta_context_));
}
VLOG(6) << "Run op " << phi_op_name_ << " infer meta.";
VLOG(6) << "End run op " << phi_op_name_ << " infer meta.";
VLOG(6) << "Begin run op " << phi_op_name_ << " kernel.";
(*(phi_kernel_))(&(kernel_context_));
VLOG(6) << "Run op " << phi_op_name_ << " kernel.";
VLOG(6) << "End run op " << phi_op_name_ << " kernel.";
}

} // namespace framework
Expand Down
22 changes: 13 additions & 9 deletions paddle/fluid/pir/transforms/dead_code_elimination_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "paddle/fluid/pir/transforms/dead_code_elimination_pass.h"

#include "paddle/fluid/pir/dialect/operator/ir/op_dialect.h"
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h"
#include "paddle/pir/core/block.h"
#include "paddle/pir/core/builtin_op.h"
Expand All @@ -39,27 +40,30 @@ class DeadCodeEliminationPass : public pir::Pass {
std::vector<pir::Operation*> deleted_ops;
for (auto& op : block) {
if (op.HasTrait<pir::SideEffectTrait>() ||
op.isa<paddle::dialect::DataOp>()) {
op.isa<paddle::dialect::DataOp>() ||
paddle::dialect::IsCustomOp(&op)) {
continue;
}
if (op.use_empty()) {
deleted_ops.push_back(&op);
}
}

for (auto* op : deleted_ops) {
op->Erase();
(*num_erasers)++;
}
for (auto& op : block) {
for (size_t i = 0; i < op.num_regions(); ++i) {
auto& inner_region = op.region(i);
for (auto& inner_block : inner_region) {
EraseOp(inner_block, num_erasers);

if (deleted_ops.empty()) {
for (auto& op : block) {
for (size_t i = 0; i < op.num_regions(); ++i) {
auto& inner_region = op.region(i);
for (auto& inner_block : inner_region) {
EraseOp(inner_block, num_erasers);
}
}
}
}

if (!deleted_ops.empty()) {
} else {
EraseOp(block, num_erasers);
}
}
Expand Down
5 changes: 0 additions & 5 deletions test/ir/pir/fused_pass/test_pir_matmul_scale_fuse_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,5 @@ def test_check_output(self):
self.check_pass_correct()


class TestMatmulScaleFusePatternWtihCpu(TestMatmulScaleFusePattern):
def setUp(self):
self.place_runtime = "cpu"


if __name__ == "__main__":
unittest.main()