未验证 提交 ded10442 编写于 作者: C chen2016013 提交者: GitHub

[IR] Rigister LegacyKernelOp into KernelDialect (#56680)

* Register LegacyKernelDialect & Rigister LegacyKernelOp

* fix code style

* delete LegacyKernelDialect ,register LegacyKernelOp into PaddleKernelDialect

* fix bug

* change as reviewed comments

* bug fix

* bug fix

* try to restart coverage CI

* pass legacy op to kernel pass

* fix code style

* fix code style

* fix code style
上级 e457c298
......@@ -42,6 +42,11 @@
#include "paddle/fluid/framework/new_executor/instruction/legacy_kernel_instruction.h"
#include "paddle/fluid/framework/new_executor/instruction/phi_kernel_instruction.h"
#include "paddle/fluid/ir/dialect/paddle_dialect/utils/utils.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_attribute.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_dialect.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_op.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_type.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/legacy_kernel_op.h"
#include "paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_util.h"
#include "paddle/ir/core/builtin_attribute.h"
......@@ -517,7 +522,7 @@ void NewIRInterpreter::BuildInstruction() {
}
VLOG(6) << "process " << op_name;
if (dialect::IsLegacyOp(op_name)) {
if (op->name().compare(paddle::dialect::LegacyKernelOp::name()) == 0) {
vec_instruction_base_.emplace_back(
std::make_unique<LegacyKernelInstruction>(op_idx++,
place_,
......
......@@ -16,6 +16,7 @@
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_attribute.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_op.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_type.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/legacy_kernel_op.h"
#include "paddle/fluid/platform/init_phi.h"
#include "paddle/phi/common/place.h"
#include "paddle/phi/core/ddim.h"
......@@ -32,9 +33,9 @@ PaddleKernelDialect::PaddleKernelDialect(ir::IrContext *context)
void PaddleKernelDialect::initialize() {
RegisterTypes<paddle::dialect::AllocatedDenseTensorType>();
RegisterTypes<paddle::dialect::AllocatedSelectedRowsType>();
RegisterOps<dialect::PhiKernelOp>();
RegisterTypes<paddle::dialect::AllocatedDenseTensorType,
paddle::dialect::AllocatedSelectedRowsType>();
RegisterOps<dialect::PhiKernelOp, dialect::LegacyKernelOp>();
RegisterAttributes<paddle::dialect::KernelAttribute>();
}
......
......@@ -24,7 +24,7 @@ namespace dialect {
class PhiKernelOp : public ir::Op<PhiKernelOp> {
public:
using Op::Op;
static const char *name() { return "phi.kernel"; }
static const char *name() { return "pd_kernel.phi_kernel"; }
static constexpr uint32_t attributes_num = 3;
static const char *attributes_name[attributes_num];
std::string op_name();
......
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/legacy_kernel_op.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_attribute.h"
#include "paddle/ir/core/builtin_attribute.h"
#include "paddle/phi/core/enforce.h"
namespace paddle {
namespace dialect {
const char* LegacyKernelOp::attributes_name[attributes_num] = { // NOLINT
"op_name",
"kernel_name",
"kernel_key"};
void LegacyKernelOp::Verify() {
VLOG(4) << "Verifying inputs, outputs and attributes for: LegacyKernelOp.";
auto& attributes = this->attributes();
PADDLE_ENFORCE(attributes.count("op_name") > 0 &&
attributes.at("op_name").isa<ir::StrAttribute>(),
phi::errors::PreconditionNotMet(
"Type of attribute: op_name is not right."));
PADDLE_ENFORCE(attributes.count("kernel_name") > 0 &&
attributes.at("kernel_name").isa<ir::StrAttribute>(),
phi::errors::PreconditionNotMet(
"Type of attribute: kernel_name is not right."));
PADDLE_ENFORCE(attributes.count("kernel_key") > 0 &&
attributes.at("kernel_key").isa<KernelAttribute>(),
phi::errors::PreconditionNotMet(
"Type of attribute: kernel_key is not right."));
}
std::string LegacyKernelOp::op_name() {
return attributes().at("op_name").dyn_cast<ir::StrAttribute>().AsString();
}
std::string LegacyKernelOp::kernel_name() {
return attributes().at("kernel_name").dyn_cast<ir::StrAttribute>().AsString();
}
phi::KernelKey LegacyKernelOp::kernel_key() {
return attributes().at("kernel_key").dyn_cast<KernelAttribute>().data();
}
} // namespace dialect
} // namespace paddle
IR_DEFINE_EXPLICIT_TYPE_ID(paddle::dialect::LegacyKernelOp)
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/ir/core/builder.h"
#include "paddle/ir/core/op_base.h"
#include "paddle/phi/core/kernel_factory.h"
namespace paddle {
namespace dialect {
class LegacyKernelOp : public ir::Op<LegacyKernelOp> {
public:
using Op::Op;
static const char *name() { return "pd_kernel.legacy_kernel"; }
static constexpr uint32_t attributes_num = 3;
static const char *attributes_name[attributes_num];
std::string op_name();
std::string kernel_name();
phi::KernelKey kernel_key();
void Verify();
};
} // namespace dialect
} // namespace paddle
IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::LegacyKernelOp)
......@@ -27,6 +27,7 @@
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_dialect.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_op.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/kernel_type.h"
#include "paddle/fluid/ir/dialect/paddle_kernel_dialect/ir/legacy_kernel_op.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/api/lib/data_transform.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
......@@ -507,6 +508,10 @@ std::unique_ptr<ir::Program> PdOpLowerToKernelPass(ir::Program* prog,
std::string phi_kernel_op_name = paddle::dialect::PhiKernelOp::name();
ir::OpInfo phi_kernel_op_info = ctx->GetRegisteredOpInfo(phi_kernel_op_name);
std::string legacy_kernel_op_name = paddle::dialect::LegacyKernelOp::name();
ir::OpInfo legacy_kernel_op_info =
ctx->GetRegisteredOpInfo(legacy_kernel_op_name);
auto skip_feed_names = GetSkipFeedNames(block);
for (auto op_item : *block) {
......@@ -1008,7 +1013,6 @@ std::unique_ptr<ir::Program> PdOpLowerToKernelPass(ir::Program* prog,
{"op_name", ir::StrAttribute::get(ctx, op_item->name())},
{"kernel_name", ir::StrAttribute::get(ctx, kernel_fn_str)},
{"kernel_key", dialect::KernelAttribute::get(ctx, kernel_key)}};
auto op_attr_map = op_item->attributes();
for (auto& map_item : op_attr_map) {
......@@ -1019,8 +1023,14 @@ std::unique_ptr<ir::Program> PdOpLowerToKernelPass(ir::Program* prog,
op_attribute.emplace("is_inplace", ir::BoolAttribute::get(ctx, true));
}
ir::Operation* op = ir::Operation::Create(
vec_inputs, op_attribute, op_output_types, phi_kernel_op_info);
ir::Operation* op;
if (dialect::IsLegacyOp(op_item->name())) {
op = ir::Operation::Create(
vec_inputs, op_attribute, op_output_types, legacy_kernel_op_info);
} else {
op = ir::Operation::Create(
vec_inputs, op_attribute, op_output_types, phi_kernel_op_info);
}
map_op_pair[op_item] = op;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册