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

[IR] Add test for LegacyKernelOp (#56818)

* add test for legacy_op

* add test for legacy_op

* add test

* change test legacy op : pd.c_concat

* fix codestyle

* add legacy kernel op test

* Update ir_kernel_dialect_pass_test.cc

* Update ir_kernel_dialect_pass_test.cc

* Update ir_kernel_dialect_pass_test.cc
上级 396fd4c0
......@@ -121,7 +121,7 @@ Operation *Operation::Create(const std::vector<ir::OpResult> &inputs,
// Call destructors for Region , OpResults, Operation, and OpOperands in
// sequence, and finally free memory.
void Operation::Destroy() {
VLOG(6) << "Destroy Operation [" << name() << "] ...";
VLOG(10) << "Destroy Operation [" << name() << "] ...";
// 1. Deconstruct Regions.
if (num_regions_ > 0) {
for (size_t idx = 0; idx < num_regions_; idx++) {
......
......@@ -26,6 +26,7 @@
#include "paddle/fluid/ir/dialect/paddle_dialect/utils/utils.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/legacy_kernel_op.h"
#include "paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_adaptor.h"
#include "paddle/fluid/ir/transforms/pd_op_to_kernel_pass.h"
#include "paddle/fluid/platform/init.h"
......@@ -127,3 +128,46 @@ TEST(dialect_attr, attr) {
ss.str() == "<backend:CPU|layout:Undefined(AnyLayout)|dtype:float32>",
true);
}
ir::AttributeMap CreateAttributeMap(std::vector<std::string> attribute_names,
std::vector<std::string> attributes,
std::string attr_name,
phi::KernelKey kernel_key) {
ir::IrContext* ctx = ir::IrContext::Instance();
ir::AttributeMap attr_map;
for (size_t i = 0; i < attribute_names.size(); i++) {
ir::Attribute attr_value = ir::StrAttribute::get(ctx, attributes[i]);
attr_map.insert(
std::pair<std::string, ir::Attribute>(attribute_names[i], attr_value));
}
auto attr = paddle::dialect::KernelAttribute::get(ctx, kernel_key);
attr_map.insert(std::pair<std::string, ir::Attribute>(attr_name, attr));
return attr_map;
}
TEST(kernel_dialect, legacy_op_test) {
// (1) Init environment.
ir::IrContext* ctx = ir::IrContext::Instance();
ir::Program program((ctx));
ctx->GetOrRegisterDialect<paddle::dialect::PaddleDialect>();
phi::KernelKey kernel_key(
phi::Backend::CPU, phi::DataLayout::ALL_LAYOUT, phi::DataType::FLOAT32);
ir::OpInfo kernel_op_info =
ctx->GetRegisteredOpInfo(paddle::dialect::LegacyKernelOp::name());
ir::OperationArgument argument(kernel_op_info);
argument.attributes = CreateAttributeMap({"op_name", "kernel_name"},
{"pd.kernel_op", "kernel_op"},
"kernel_key",
kernel_key);
ir::Operation* op = ir::Operation::Create(std::move(argument));
EXPECT_EQ("pd.kernel_op",
op->dyn_cast<paddle::dialect::LegacyKernelOp>().op_name());
EXPECT_EQ("kernel_op",
op->dyn_cast<paddle::dialect::LegacyKernelOp>().kernel_name());
EXPECT_EQ(kernel_key,
op->dyn_cast<paddle::dialect::LegacyKernelOp>().kernel_key());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册