From e73ddd6c15d5f5fc39c696d93c4ad3f2fd9e35d4 Mon Sep 17 00:00:00 2001 From: zhangbo9674 <82555433+zhangbo9674@users.noreply.github.com> Date: Mon, 12 Jun 2023 09:57:35 +0800 Subject: [PATCH] refine attribute name (#54516) --- paddle/fluid/ir/dialect/op_gen.py | 18 +++++++++--------- paddle/fluid/ir/dialect/pd_attribute.cc | 8 ++++---- paddle/fluid/ir/dialect/pd_attribute.h | 4 ++-- paddle/fluid/ir/dialect/utils.h | 4 ++-- .../translator/attribute_translator.cc | 6 +++--- .../ir_adaptor/translator/op_translator.cc | 10 +++++----- paddle/ir/core/builtin_attribute.cc | 4 ++-- paddle/ir/core/builtin_attribute.h | 8 ++++---- paddle/ir/core/builtin_attribute_storage.h | 4 ++-- paddle/ir/core/builtin_dialect.cc | 4 ++-- paddle/ir/core/builtin_op.cc | 4 ++-- paddle/ir/core/ir_printer.cc | 4 ++-- test/cpp/ir/core/ir_op_test.cc | 2 +- test/cpp/ir/core/ir_program_test.cc | 7 +++---- test/cpp/ir/core/op_info_test.cc | 2 +- test/cpp/ir/core/phi_kernel_adaptor.h | 5 ++--- test/cpp/ir/core/scalar_attribute_test.cc | 4 ++-- 17 files changed, 48 insertions(+), 50 deletions(-) diff --git a/paddle/fluid/ir/dialect/op_gen.py b/paddle/fluid/ir/dialect/op_gen.py index ab8354f1fb8..cc4ca4a2cd7 100644 --- a/paddle/fluid/ir/dialect/op_gen.py +++ b/paddle/fluid/ir/dialect/op_gen.py @@ -251,8 +251,8 @@ def to_phi_and_fluid_op_name(op_item): scalar_type_maps = { - 'int': 'ir::Int32_tAttribute', - 'int64_t': 'ir::Int64_tAttribute', + 'int': 'ir::Int32Attribute', + 'int64_t': 'ir::Int64Attribute', 'float': 'ir::FloatAttribute', 'dobule': 'ir::DoubleAttribute', 'bool': 'ir::BoolAttribute', @@ -309,17 +309,17 @@ class OpInfoParser: self.attr_types_map = { 'IntArray': ['paddle::dialect::IntArrayAttribute', 'IntArray'], 'Scalar': ['paddle::dialect::ScalarAttribute', 'Scalar'], - 'Scalar(int)': ['ir::Int32_tAttribute', 'int'], - 'Scalar(int64_t)': ['ir::Int64_tAttribute', 'int64_t'], + 'Scalar(int)': ['ir::Int32Attribute', 'int'], + 'Scalar(int64_t)': ['ir::Int64Attribute', 'int64_t'], 'Scalar(float)': ['ir::FloatAttribute', 'float'], 'Scalar(dobule)': ['ir::DoubleAttribute', 'dobule'], 'Scalar[]': [ 'ir::ArrayAttribute', 'const std::vector&', ], - 'int': ['ir::Int32_tAttribute', 'int'], - 'int32_t': ['ir::Int32_tAttribute', 'int32_t'], - 'int64_t': ['ir::Int64_tAttribute', 'int64_t'], + 'int': ['ir::Int32Attribute', 'int'], + 'int32_t': ['ir::Int32Attribute', 'int32_t'], + 'int64_t': ['ir::Int64Attribute', 'int64_t'], 'long': ['ir::LongAttribute', 'long'], 'size_t': ['ir::Size_tAttribute', 'size_t'], 'float': ['ir::FloatAttribute', 'float'], @@ -345,11 +345,11 @@ class OpInfoParser: ], 'DataType': ['paddle::dialect::DataTypeAttribute', 'DataType'], 'int64_t[]': [ - 'ir::ArrayAttribute', + 'ir::ArrayAttribute', 'const std::vector&', ], 'int[]': [ - 'ir::ArrayAttribute', + 'ir::ArrayAttribute', 'const std::vector&', ], } diff --git a/paddle/fluid/ir/dialect/pd_attribute.cc b/paddle/fluid/ir/dialect/pd_attribute.cc index 0bb42226d49..08f552683d1 100644 --- a/paddle/fluid/ir/dialect/pd_attribute.cc +++ b/paddle/fluid/ir/dialect/pd_attribute.cc @@ -31,10 +31,10 @@ phi::Scalar ScalarAttribute::data() { return phi::Scalar(dyn_cast().data()); } else if (isa()) { return phi::Scalar(dyn_cast().data()); - } else if (isa()) { - return phi::Scalar(dyn_cast().data()); - } else if (isa()) { - return phi::Scalar(dyn_cast().data()); + } else if (isa()) { + return phi::Scalar(dyn_cast().data()); + } else if (isa()) { + return phi::Scalar(dyn_cast().data()); } else if (isa()) { return phi::Scalar(dyn_cast().data()); } else { diff --git a/paddle/fluid/ir/dialect/pd_attribute.h b/paddle/fluid/ir/dialect/pd_attribute.h index 1cc1c90950d..c95dbe248ca 100644 --- a/paddle/fluid/ir/dialect/pd_attribute.h +++ b/paddle/fluid/ir/dialect/pd_attribute.h @@ -44,8 +44,8 @@ class ScalarAttribute : public ir::Attribute { return (val.type_id() == ir::BoolAttribute::type_id()) || (val.type_id() == ir::FloatAttribute::type_id()) || (val.type_id() == ir::DoubleAttribute::type_id()) || - (val.type_id() == ir::Int32_tAttribute::type_id()) || - (val.type_id() == ir::Int64_tAttribute::type_id()); + (val.type_id() == ir::Int32Attribute::type_id()) || + (val.type_id() == ir::Int64Attribute::type_id()); } phi::Scalar data(); diff --git a/paddle/fluid/ir/dialect/utils.h b/paddle/fluid/ir/dialect/utils.h index 14f83d81809..46724c0c773 100644 --- a/paddle/fluid/ir/dialect/utils.h +++ b/paddle/fluid/ir/dialect/utils.h @@ -83,9 +83,9 @@ static inline ir::Attribute TransToIrAttribute(phi::Scalar scalar, case phi::DataType::FLOAT64: return ir::DoubleAttribute::get(ctx, scalar.to()); case phi::DataType::INT32: - return ir::Int32_tAttribute::get(ctx, scalar.to()); + return ir::Int32Attribute::get(ctx, scalar.to()); case phi::DataType::INT64: - return ir::Int64_tAttribute::get(ctx, scalar.to()); + return ir::Int64Attribute::get(ctx, scalar.to()); case phi::DataType::BOOL: return ir::BoolAttribute::get(ctx, scalar.to()); default: diff --git a/paddle/fluid/ir_adaptor/translator/attribute_translator.cc b/paddle/fluid/ir_adaptor/translator/attribute_translator.cc index f2da12c6643..95e61d849f2 100644 --- a/paddle/fluid/ir_adaptor/translator/attribute_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/attribute_translator.cc @@ -38,7 +38,7 @@ class AttributeVisitor { public: virtual ir::Attribute operator()(int i) { VLOG(10) << "translating int"; - return ir::Int32_tAttribute::get(ctx, i); + return ir::Int32Attribute::get(ctx, i); } virtual ir::Attribute operator()(float f) { @@ -91,7 +91,7 @@ class AttributeVisitor { std::vector attrs; attrs.reserve(is.size()); for (const auto& v : is) { - attrs.push_back(ir::Int32_tAttribute::get(ctx, v)); + attrs.push_back(ir::Int32Attribute::get(ctx, v)); } return ir::ArrayAttribute::get(ctx, attrs); } @@ -111,7 +111,7 @@ class AttributeVisitor { std::vector attrs; attrs.reserve(i64s.size()); for (const auto& v : i64s) { - attrs.push_back(ir::Int64_tAttribute::get(ctx, v)); + attrs.push_back(ir::Int64Attribute::get(ctx, v)); } return ir::ArrayAttribute::get(ctx, attrs); } diff --git a/paddle/fluid/ir_adaptor/translator/op_translator.cc b/paddle/fluid/ir_adaptor/translator/op_translator.cc index 3e2c8117897..9bd8c7452cd 100644 --- a/paddle/fluid/ir_adaptor/translator/op_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/op_translator.cc @@ -131,7 +131,7 @@ inline ir::Operation* InsertSliceOperationForTarget( std::string slice_op_name(ir::SliceOp::name()); ir::OpInfo op_info = ctx->GetRegisteredOpInfo(slice_op_name); std::unordered_map op_attribute_map = { - {"index", ir::Int32_tAttribute::get(ctx, defining_info.idx_in_vector)}, + {"index", ir::Int32Attribute::get(ctx, defining_info.idx_in_vector)}, }; ir::VectorType src_vec_type = defining_info.value.type().dyn_cast(); @@ -179,11 +179,11 @@ inline ir::Operation* InsertFullOperationForAttributeInput(ir::IrContext* ctx, } else if (attr.isa()) { data = static_cast(attr.dyn_cast().data()); dtype = phi::DataType::FLOAT64; - } else if (attr.isa()) { - data = static_cast(attr.dyn_cast().data()); + } else if (attr.isa()) { + data = static_cast(attr.dyn_cast().data()); dtype = phi::DataType::INT32; - } else if (attr.isa()) { - data = static_cast(attr.dyn_cast().data()); + } else if (attr.isa()) { + data = static_cast(attr.dyn_cast().data()); dtype = phi::DataType::INT64; } else if (attr.isa()) { data = static_cast(attr.dyn_cast().data()); diff --git a/paddle/ir/core/builtin_attribute.cc b/paddle/ir/core/builtin_attribute.cc index 76cc50d3de4..d9f4798ccab 100644 --- a/paddle/ir/core/builtin_attribute.cc +++ b/paddle/ir/core/builtin_attribute.cc @@ -25,9 +25,9 @@ float FloatAttribute::data() const { return storage()->GetAsKey(); } double DoubleAttribute::data() const { return storage()->GetAsKey(); } -int32_t Int32_tAttribute::data() const { return storage()->GetAsKey(); } +int32_t Int32Attribute::data() const { return storage()->GetAsKey(); } -int64_t Int64_tAttribute::data() const { return storage()->GetAsKey(); } +int64_t Int64Attribute::data() const { return storage()->GetAsKey(); } std::vector ArrayAttribute::data() const { return storage()->GetAsKey(); diff --git a/paddle/ir/core/builtin_attribute.h b/paddle/ir/core/builtin_attribute.h index cc4741dc3a7..ba013af6ff2 100644 --- a/paddle/ir/core/builtin_attribute.h +++ b/paddle/ir/core/builtin_attribute.h @@ -61,20 +61,20 @@ class DoubleAttribute : public Attribute { double data() const; }; -class Int32_tAttribute : public Attribute { +class Int32Attribute : public Attribute { public: using Attribute::Attribute; - DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int32_tAttribute, Int32_tAttributeStorage); + DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int32Attribute, Int32AttributeStorage); int32_t data() const; }; -class Int64_tAttribute : public Attribute { +class Int64Attribute : public Attribute { public: using Attribute::Attribute; - DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int64_tAttribute, Int64_tAttributeStorage); + DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int64Attribute, Int64AttributeStorage); int64_t data() const; }; diff --git a/paddle/ir/core/builtin_attribute_storage.h b/paddle/ir/core/builtin_attribute_storage.h index 40b833fe9c7..bf68dc387cb 100644 --- a/paddle/ir/core/builtin_attribute_storage.h +++ b/paddle/ir/core/builtin_attribute_storage.h @@ -81,8 +81,8 @@ struct StrAttributeStorage : public AttributeStorage { DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(BoolAttributeStorage, bool); DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(FloatAttributeStorage, float); DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(DoubleAttributeStorage, double); -DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(Int32_tAttributeStorage, int32_t); -DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(Int64_tAttributeStorage, int64_t); +DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(Int32AttributeStorage, int32_t); +DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(Int64AttributeStorage, int64_t); DECLARE_BASE_TYPE_ATTRIBUTE_STORAGE(PointerAttributeStorage, void *); struct ArrayAttributeStorage : public AttributeStorage { diff --git a/paddle/ir/core/builtin_dialect.cc b/paddle/ir/core/builtin_dialect.cc index f3a5183cd6c..0be2bc1a2e3 100644 --- a/paddle/ir/core/builtin_dialect.cc +++ b/paddle/ir/core/builtin_dialect.cc @@ -41,8 +41,8 @@ void BuiltinDialect::initialize() { FloatAttribute, DoubleAttribute, PointerAttribute, - Int32_tAttribute, - Int64_tAttribute, + Int32Attribute, + Int64Attribute, ArrayAttribute>(); RegisterOps &inputs, IR_ENFORCE(attributes.count("index") != 0, "The attributes must contains index."); const ir::Attribute &attr = attributes.at("index"); - IR_ENFORCE(attr.isa(), + IR_ENFORCE(attr.isa(), "The attribute index must be INT32."); - auto index = attr.dyn_cast().data(); + auto index = attr.dyn_cast().data(); // index >= 0 and < inputs[0].size() IR_ENFORCE( diff --git a/paddle/ir/core/ir_printer.cc b/paddle/ir/core/ir_printer.cc index fd0a41fbdae..900a6a14775 100644 --- a/paddle/ir/core/ir_printer.cc +++ b/paddle/ir/core/ir_printer.cc @@ -83,9 +83,9 @@ class BasicIRPrinter { os << f.data(); } else if (auto d = attr.dyn_cast()) { os << d.data(); - } else if (auto i = attr.dyn_cast()) { + } else if (auto i = attr.dyn_cast()) { os << i.data(); - } else if (auto i = attr.dyn_cast()) { + } else if (auto i = attr.dyn_cast()) { os << i.data(); } else if (auto arr = attr.dyn_cast()) { const auto& vec = arr.data(); diff --git a/test/cpp/ir/core/ir_op_test.cc b/test/cpp/ir/core/ir_op_test.cc index c071a0d45df..6d9524634c7 100644 --- a/test/cpp/ir/core/ir_op_test.cc +++ b/test/cpp/ir/core/ir_op_test.cc @@ -238,7 +238,7 @@ TEST(op_test, module_op_death) { // (3) Test uses for op. std::vector inputs{ir::OpResult()}; - ir::AttributeMap attrs{{"program", ir::Int32_tAttribute::get(ctx, 1)}}; + ir::AttributeMap attrs{{"program", ir::Int32Attribute::get(ctx, 1)}}; std::vector output_types = {ir::Float32Type::get(ctx)}; EXPECT_THROW(ir::Operation::Create(inputs, {}, {}, op_info), diff --git a/test/cpp/ir/core/ir_program_test.cc b/test/cpp/ir/core/ir_program_test.cc index 2388752a87b..b67fe6d4d89 100644 --- a/test/cpp/ir/core/ir_program_test.cc +++ b/test/cpp/ir/core/ir_program_test.cc @@ -283,7 +283,7 @@ TEST(program_test, slice_combine_test) { // (7) Def slice_op = SliceOp(combine_op, 0) std::string slice_op_name = std::string(ir::SliceOp::name()); ir::OpInfo slice_op_info = ctx->GetRegisteredOpInfo(slice_op_name); - ir::Attribute index_attr = ir::Int32_tAttribute::get(ctx, 0); + ir::Attribute index_attr = ir::Int32Attribute::get(ctx, 0); ir::Operation *slice_op = ir::Operation::Create({combine_op->GetResultByIndex(0)}, {{"index", index_attr}}, @@ -319,8 +319,7 @@ TEST(program_test, builder) { } ir::ConstantOp constant = builder.Build( - ir::Int32_tAttribute::get(ctx, 2), ir::Int32Type::get(ctx)); + ir::Int32Attribute::get(ctx, 2), ir::Int32Type::get(ctx)); EXPECT_EQ(program.block()->size() == 2, true); - EXPECT_EQ(constant.value().dyn_cast().data() == 2, - true); + EXPECT_EQ(constant.value().dyn_cast().data() == 2, true); } diff --git a/test/cpp/ir/core/op_info_test.cc b/test/cpp/ir/core/op_info_test.cc index da3142dfe5f..c869328af34 100644 --- a/test/cpp/ir/core/op_info_test.cc +++ b/test/cpp/ir/core/op_info_test.cc @@ -28,7 +28,7 @@ TEST(ir_op_info_test, op_op_info_test) { ir::Block* block = program.block(); ir::Builder builder(context, block); - builder.Build(ir::Int32_tAttribute::get(context, 5), + builder.Build(ir::Int32Attribute::get(context, 5), ir::Int32Type::get(context)); ir::Operation* op = block->back(); diff --git a/test/cpp/ir/core/phi_kernel_adaptor.h b/test/cpp/ir/core/phi_kernel_adaptor.h index 2e44ff55848..e9a6ed5bddd 100644 --- a/test/cpp/ir/core/phi_kernel_adaptor.h +++ b/test/cpp/ir/core/phi_kernel_adaptor.h @@ -164,9 +164,8 @@ void build_context(ir::Operation* op, } else if (type_name == "paddle::dialect::DataTypeAttribute") { ctx->EmplaceBackAttr( attr_map[t].dyn_cast().data()); - } else if (type_name == "ir::Int32_tAttribute") { - ctx->EmplaceBackAttr( - attr_map[t].dyn_cast().data()); + } else if (type_name == "ir::Int32Attribute") { + ctx->EmplaceBackAttr(attr_map[t].dyn_cast().data()); } else if (type_name == "paddle::dialect::PlaceAttribute") { ctx->EmplaceBackAttr( attr_map[t].dyn_cast().data()); diff --git a/test/cpp/ir/core/scalar_attribute_test.cc b/test/cpp/ir/core/scalar_attribute_test.cc index c2292357f41..8dc3f8314ad 100644 --- a/test/cpp/ir/core/scalar_attribute_test.cc +++ b/test/cpp/ir/core/scalar_attribute_test.cc @@ -47,9 +47,9 @@ TEST(ScalarTest, test_classof) { ir::Attribute double_scalar = ir::DoubleAttribute::get(ctx, 1.0); EXPECT_TRUE(double_scalar.isa()); - ir::Attribute int32_scalar = ir::Int32_tAttribute::get(ctx, 1); + ir::Attribute int32_scalar = ir::Int32Attribute::get(ctx, 1); EXPECT_TRUE(int32_scalar.isa()); - ir::Attribute int64_scalar = ir::Int64_tAttribute::get(ctx, 1l); + ir::Attribute int64_scalar = ir::Int64Attribute::get(ctx, 1l); EXPECT_TRUE(int64_scalar.isa()); } -- GitLab