Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ea89e968
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ea89e968
编写于
6月 06, 2023
作者:
W
winter-wang
提交者:
GitHub
6月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR] format the use of new ir api (#54356)
上级
2e0c8678
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
95 addition
and
98 deletion
+95
-98
paddle/fluid/ir/dialect/op_gen.py
paddle/fluid/ir/dialect/op_gen.py
+2
-2
paddle/fluid/ir_adaptor/translator/op_translator.cc
paddle/fluid/ir_adaptor/translator/op_translator.cc
+6
-6
paddle/fluid/ir_adaptor/translator/program_translator.cc
paddle/fluid/ir_adaptor/translator/program_translator.cc
+1
-1
paddle/ir/core/block.cc
paddle/ir/core/block.cc
+1
-1
paddle/ir/core/builder.cc
paddle/ir/core/builder.cc
+14
-14
paddle/ir/core/builder.h
paddle/ir/core/builder.h
+10
-10
paddle/ir/core/builtin_op.cc
paddle/ir/core/builtin_op.cc
+5
-6
paddle/ir/core/builtin_op.h
paddle/ir/core/builtin_op.h
+3
-4
paddle/ir/core/operation.cc
paddle/ir/core/operation.cc
+4
-4
paddle/ir/core/operation.h
paddle/ir/core/operation.h
+3
-3
paddle/ir/core/program.cc
paddle/ir/core/program.cc
+2
-2
test/cpp/ir/core/ir_exe_test.cc
test/cpp/ir/core/ir_exe_test.cc
+3
-3
test/cpp/ir/core/ir_infershape_test.cc
test/cpp/ir/core/ir_infershape_test.cc
+1
-1
test/cpp/ir/core/ir_op_test.cc
test/cpp/ir/core/ir_op_test.cc
+9
-9
test/cpp/ir/core/ir_program_test.cc
test/cpp/ir/core/ir_program_test.cc
+18
-19
test/cpp/ir/core/ir_value_test.cc
test/cpp/ir/core/ir_value_test.cc
+8
-8
test/cpp/ir/pass/pass_manager_test.cc
test/cpp/ir/pass/pass_manager_test.cc
+5
-5
未找到文件。
paddle/fluid/ir/dialect/op_gen.py
浏览文件 @
ea89e968
...
...
@@ -647,10 +647,10 @@ def GenBuildInputArgsStr(
for_func_define
=
True
,
):
'''
Example: ir::
Builder &builder, ir::
OperationArgument &argument, ir::OpResult x_, phi::DataType dtype=phi::DataType::UNDEFINED, phi::Place place={}
Example: ir::OperationArgument &argument, ir::OpResult x_, phi::DataType dtype=phi::DataType::UNDEFINED, phi::Place place={}
'''
build_args_str
=
"ir::Builder &builder, ir::OperationArgument &argument"
# add inputs
build_args_str
=
"ir::OperationArgument &argument"
if
len
(
op_input_name_list
)
>
0
:
for
input_name
in
op_input_name_list
:
build_args_str
+=
", ir::OpResult "
+
input_name
+
"_"
...
...
paddle/fluid/ir_adaptor/translator/op_translator.cc
浏览文件 @
ea89e968
...
...
@@ -126,7 +126,7 @@ inline ir::Operation* InsertSliceOperationForTarget(
ir
::
VectorType
src_vec_type
=
defining_info
.
value
.
type
().
dyn_cast
<
ir
::
VectorType
>
();
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
({
defining_info
.
value
},
ir
::
Operation
::
C
reate
({
defining_info
.
value
},
op_attribute_map
,
{
src_vec_type
[
defining_info
.
idx_in_vector
]},
op_info
);
...
...
@@ -153,7 +153,7 @@ inline ir::Operation* InsertCombineOperationForTarget(
}
ir
::
Type
target_vec_type
=
ir
::
VectorType
::
get
(
ctx
,
types_in_vec
);
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
(
src_values
,
{},
{
target_vec_type
},
op_info
);
ir
::
Operation
::
C
reate
(
src_values
,
{},
{
target_vec_type
},
op_info
);
program
->
block
()
->
push_back
(
operation
);
return
operation
;
}
...
...
@@ -165,7 +165,7 @@ inline ir::Operation* InsertConstantOperationForOptionalArg(
ir
::
Type
null_type
=
ir
::
Type
(
nullptr
);
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
({},
{},
{
null_type
},
op_info
);
ir
::
Operation
::
C
reate
({},
{},
{
null_type
},
op_info
);
program
->
block
()
->
push_back
(
operation
);
return
operation
;
}
...
...
@@ -401,7 +401,7 @@ ir::Operation* GeneralOpHandler(ir::IrContext* ctx,
VLOG
(
4
)
<<
"[general op]["
<<
op_desc
.
Type
()
<<
"] preparation end."
;
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
ir
::
Operation
::
C
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
VLOG
(
4
)
<<
"[general op]["
<<
op_desc
.
Type
()
<<
"] opearation creation end."
;
program
->
block
()
->
push_back
(
operation
);
...
...
@@ -436,7 +436,7 @@ ir::Operation* FeedOpHandler(ir::IrContext* ctx,
};
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
ir
::
Operation
::
C
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
program
->
block
()
->
push_back
(
operation
);
RecordOpResultMapping
(
param_map
,
op_desc
,
operation
,
arg_to_idx
);
...
...
@@ -466,7 +466,7 @@ ir::Operation* FetchOpHandler(ir::IrContext* ctx,
};
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
ir
::
Operation
::
C
reate
(
op_inputs
,
attribute_map
,
op_output_types
,
op_info
);
program
->
block
()
->
push_back
(
operation
);
return
operation
;
...
...
paddle/fluid/ir_adaptor/translator/program_translator.cc
浏览文件 @
ea89e968
...
...
@@ -79,7 +79,7 @@ void ProgramTranslator::ExtractParameterFromSingleBlock(
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
var
->
Name
())},
};
ir
::
Type
translated_var_type
=
type_translator
[
var
->
GetType
()](
ctx
,
*
var
);
ir
::
Operation
*
operation
=
ir
::
Operation
::
c
reate
(
ir
::
Operation
*
operation
=
ir
::
Operation
::
C
reate
(
{},
op_attribute_map
,
{
translated_var_type
},
op_info
);
program
->
block
()
->
push_back
(
operation
);
param_map
[
var
->
Name
()]
=
...
...
paddle/ir/core/block.cc
浏览文件 @
ea89e968
...
...
@@ -33,7 +33,7 @@ Block::iterator Block::insert(const_iterator iterator, Operation *op) {
void
Block
::
clear
()
{
while
(
!
empty
())
{
ops_
.
back
()
->
d
estroy
();
ops_
.
back
()
->
D
estroy
();
ops_
.
pop_back
();
}
}
...
...
paddle/ir/core/builder.cc
浏览文件 @
ea89e968
...
...
@@ -17,26 +17,26 @@
#include "paddle/ir/core/value.h"
namespace
ir
{
Operation
*
Builder
::
insert
(
Operation
*
op
)
{
if
(
block_
)
{
block_
->
insert
(
insert_point_
,
op
);
}
else
{
LOG
(
WARNING
)
<<
"Builder's Block is nullptr, insert failed."
;
}
return
op
;
}
/// Create an operation given the fields represented as an OperationState.
Operation
*
Builder
::
create
(
OperationArgument
&&
argument
)
{
return
insert
(
Operation
::
c
reate
(
std
::
move
(
argument
)));
Operation
*
Builder
::
Build
(
OperationArgument
&&
argument
)
{
return
Insert
(
Operation
::
C
reate
(
std
::
move
(
argument
)));
}
/// Creates an operation with the given fields.
Operation
*
Builder
::
create
(
const
std
::
vector
<
OpResult
>
&
inputs
,
Operation
*
Builder
::
Build
(
const
std
::
vector
<
OpResult
>
&
inputs
,
const
AttributeMap
&
attribute
,
const
std
::
vector
<
Type
>
&
output_types
,
OpInfo
op_info
)
{
return
create
(
OperationArgument
(
inputs
,
attribute
,
output_types
,
op_info
));
return
Build
(
OperationArgument
(
inputs
,
attribute
,
output_types
,
op_info
));
}
Operation
*
Builder
::
Insert
(
Operation
*
op
)
{
if
(
block_
)
{
block_
->
insert
(
insert_point_
,
op
);
}
else
{
LOG
(
WARNING
)
<<
"Builder's Block is nullptr, insert failed."
;
}
return
op
;
}
}
// namespace ir
paddle/ir/core/builder.h
浏览文件 @
ea89e968
...
...
@@ -43,27 +43,27 @@ class Builder {
Block
*
block
()
const
{
return
block_
;
}
Operation
*
insert
(
Operation
*
op
);
/// Creates an operation given the fields represented as an OperationState.
Operation
*
create
(
OperationArgument
&&
argument
);
Operation
*
Build
(
OperationArgument
&&
argument
);
/// Creates an operation with the given fields.
Operation
*
create
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
Operation
*
Build
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
const
AttributeMap
&
attribute
,
const
std
::
vector
<
ir
::
Type
>
&
output_types
,
ir
::
OpInfo
op_info
);
/// Create an operation of specific op type at the current insertion point.
template
<
typename
OpTy
,
typename
...
Args
>
OpTy
create
(
Args
&&
...
args
)
{
OpTy
Build
(
Args
&&
...
args
)
{
OperationArgument
argument
(
context_
->
GetRegisteredOpInfo
(
OpTy
::
name
()));
OpTy
::
Build
(
*
this
,
argument
,
std
::
forward
<
Args
>
(
args
)...);
Operation
*
op
=
create
(
std
::
move
(
argument
));
OpTy
::
Build
(
argument
,
std
::
forward
<
Args
>
(
args
)...);
Operation
*
op
=
Build
(
std
::
move
(
argument
));
return
op
->
dyn_cast
<
OpTy
>
();
}
private:
Operation
*
Insert
(
Operation
*
op
);
IrContext
*
context_
;
Block
*
block_
=
nullptr
;
// The insertion point within the list that this builder is inserting before.
...
...
paddle/ir/core/builtin_op.cc
浏览文件 @
ea89e968
...
...
@@ -37,17 +37,17 @@ Block *ModuleOp::block() {
return
operation
()
->
GetRegion
(
0
).
front
();
}
ModuleOp
ModuleOp
::
c
reate
(
IrContext
*
context
,
Program
*
pointer
)
{
ModuleOp
ModuleOp
::
C
reate
(
IrContext
*
context
,
Program
*
pointer
)
{
ir
::
OpInfo
info
=
context
->
GetRegisteredOpInfo
(
name
());
OperationArgument
argument
(
info
);
argument
.
AddRegion
()
->
emplace_back
();
argument
.
AddAttribute
(
"program"
,
PointerAttribute
::
get
(
context
,
pointer
));
return
ModuleOp
(
Operation
::
c
reate
(
std
::
move
(
argument
)));
return
ModuleOp
(
Operation
::
C
reate
(
std
::
move
(
argument
)));
}
void
ModuleOp
::
d
estroy
()
{
void
ModuleOp
::
D
estroy
()
{
if
(
operation
())
{
operation
()
->
d
estroy
();
operation
()
->
D
estroy
();
*
this
=
ModuleOp
(
nullptr
);
}
}
...
...
@@ -216,8 +216,7 @@ void SliceOp::Verify(const std::vector<ir::OpResult> &inputs,
const
char
*
ConstantOp
::
attributes_name
[
attributes_num
]
=
{
"value"
};
void
ConstantOp
::
Build
(
Builder
&
builder
,
OperationArgument
&
argument
,
void
ConstantOp
::
Build
(
OperationArgument
&
argument
,
Attribute
value
,
Type
output_type
)
{
argument
.
AddAttribute
(
"value"
,
value
);
...
...
paddle/ir/core/builtin_op.h
浏览文件 @
ea89e968
...
...
@@ -40,8 +40,8 @@ class ModuleOp : public ir::Op<ModuleOp> {
//
// As the top operation, ModuleOp only support create&destroye through
// below interface: "create"&"destroy".
static
ModuleOp
c
reate
(
IrContext
*
context
,
Program
*
pointer
);
void
d
estroy
();
static
ModuleOp
C
reate
(
IrContext
*
context
,
Program
*
pointer
);
void
D
estroy
();
};
///
...
...
@@ -125,8 +125,7 @@ class ConstantOp : public Op<ConstantOp, ConstantLikeTrait> {
static
constexpr
uint32_t
attributes_num
=
1
;
static
const
char
*
attributes_name
[
attributes_num
];
static
void
Build
(
Builder
&
builder
,
// NOLINT
OperationArgument
&
argument
,
// NOLINT
static
void
Build
(
OperationArgument
&
argument
,
// NOLINT
Attribute
value
,
Type
output_type
);
...
...
paddle/ir/core/operation.cc
浏览文件 @
ea89e968
...
...
@@ -24,8 +24,8 @@
#include "paddle/ir/core/value_impl.h"
namespace
ir
{
Operation
*
Operation
::
c
reate
(
OperationArgument
&&
argument
)
{
Operation
*
op
=
c
reate
(
argument
.
inputs
,
Operation
*
Operation
::
C
reate
(
OperationArgument
&&
argument
)
{
Operation
*
op
=
C
reate
(
argument
.
inputs
,
argument
.
attributes
,
argument
.
output_types
,
argument
.
info
,
...
...
@@ -40,7 +40,7 @@ Operation *Operation::create(OperationArgument &&argument) {
// Allocate the required memory based on the size and number of inputs, outputs,
// and operators, and construct it in the order of: OpOutlineResult,
// OpInlineResult, Operation, Operand.
Operation
*
Operation
::
c
reate
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
Operation
*
Operation
::
C
reate
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
const
AttributeMap
&
attributes
,
const
std
::
vector
<
ir
::
Type
>
&
output_types
,
ir
::
OpInfo
op_info
,
...
...
@@ -104,7 +104,7 @@ Operation *Operation::create(const std::vector<ir::OpResult> &inputs,
// Call destructors for OpResults, Operation, and OpOperands in sequence, and
// finally free memory.
void
Operation
::
d
estroy
()
{
void
Operation
::
D
estroy
()
{
// Deconstruct Regions.
if
(
num_regions_
>
0
)
{
for
(
size_t
idx
=
0
;
idx
<
num_regions_
;
idx
++
)
{
...
...
paddle/ir/core/operation.h
浏览文件 @
ea89e968
...
...
@@ -34,17 +34,17 @@ class alignas(8) Operation final {
/// NOTE: Similar to new and delete, the destroy() and the create() need to be
/// used in conjunction.
///
static
Operation
*
c
reate
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
static
Operation
*
C
reate
(
const
std
::
vector
<
ir
::
OpResult
>
&
inputs
,
const
AttributeMap
&
attributes
,
const
std
::
vector
<
ir
::
Type
>
&
output_types
,
ir
::
OpInfo
op_info
,
size_t
num_regions
=
0
);
static
Operation
*
c
reate
(
OperationArgument
&&
op_argument
);
static
Operation
*
C
reate
(
OperationArgument
&&
op_argument
);
///
/// \brief Destroy the operation objects and free memory by create().
///
void
d
estroy
();
void
D
estroy
();
IrContext
*
ir_context
()
const
;
...
...
paddle/ir/core/program.cc
浏览文件 @
ea89e968
...
...
@@ -18,12 +18,12 @@
namespace
ir
{
Program
::
Program
(
IrContext
*
context
)
{
module_
=
ModuleOp
::
c
reate
(
context
,
this
);
module_
=
ModuleOp
::
C
reate
(
context
,
this
);
}
Program
::~
Program
()
{
if
(
module_
)
{
module_
.
d
estroy
();
module_
.
D
estroy
();
}
}
...
...
test/cpp/ir/core/ir_exe_test.cc
浏览文件 @
ea89e968
...
...
@@ -89,7 +89,7 @@ TEST(program_test, program) {
{
"seed"
,
seed
},
{
"place"
,
uni_place
}};
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
ir
::
Operation
::
C
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
block
->
push_back
(
op1
);
...
...
@@ -99,13 +99,13 @@ TEST(program_test, program) {
ir
::
Attribute
ten2
=
ir
::
Int32_tAttribute
::
get
(
ctx
,
3
);
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op2_attribute
{{
"shape"
,
ten2
}};
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op2_info
);
ir
::
Operation
::
C
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op2_info
);
block
->
push_back
(
op2
);
// (3) Def out = AddOp(a, b)
std
::
string
add_op_name
=
std
::
string
(
paddle
::
dialect
::
AddOp
::
name
());
ir
::
OpInfo
add_op_info
=
ctx
->
GetRegisteredOpInfo
(
add_op_name
);
ir
::
Operation
*
add_op
=
ir
::
Operation
::
c
reate
(
ir
::
Operation
*
add_op
=
ir
::
Operation
::
C
reate
(
{
op1
->
GetResultByIndex
(
0
),
op2
->
GetResultByIndex
(
0
)},
{},
{
dense_tensor_dtype
},
...
...
test/cpp/ir/core/ir_infershape_test.cc
浏览文件 @
ea89e968
...
...
@@ -82,7 +82,7 @@ TEST(infershape_test, infershape_test) {
std
::
vector
<
ir
::
OpResult
>
op_inputs
=
{};
std
::
vector
<
ir
::
Type
>
op_output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
ir
::
Operation
*
op
=
ir
::
Operation
::
c
reate
(
op_inputs
,
{},
op_output_types
,
op_info
);
ir
::
Operation
::
C
reate
(
op_inputs
,
{},
op_output_types
,
op_info
);
InferShapeInterface
interface
=
op
->
dyn_cast
<
InferShapeInterface
>
();
phi
::
InferMetaContext
infer_meta_ctx
;
...
...
test/cpp/ir/core/ir_op_test.cc
浏览文件 @
ea89e968
...
...
@@ -175,7 +175,7 @@ TEST(op_test, op_test) {
std
::
vector
<
ir
::
OpResult
>
op_inputs
=
{};
std
::
vector
<
ir
::
Type
>
op_output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
(
op_inputs
,
ir
::
Operation
::
C
reate
(
op_inputs
,
CreateAttributeMap
({
"op2_attr1"
,
"op2_attr2"
},
{
"op2_attr1"
,
"op2_attr2"
}),
op_output_types
,
...
...
@@ -187,7 +187,7 @@ TEST(op_test, op_test) {
interface
.
InferShape
();
Operation2
Op2
=
op2
->
dyn_cast
<
Operation2
>
();
EXPECT_EQ
(
Op2
.
operation
(),
op2
);
op2
->
d
estroy
();
op2
->
D
estroy
();
}
TEST
(
op_test
,
region_test
)
{
...
...
@@ -201,13 +201,13 @@ TEST(op_test, region_test) {
ir
::
OpInfo
op2_info
=
ctx
->
GetRegisteredOpInfo
(
Operation2
::
name
());
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
({},
ir
::
Operation
::
C
reate
({},
CreateAttributeMap
({
"op1_attr1"
,
"op1_attr2"
},
{
"op1_attr1"
,
"op1_attr2"
}),
{
ir
::
Float32Type
::
get
(
ctx
)},
op1_info
);
ir
::
Operation
*
op1_2
=
ir
::
Operation
::
c
reate
({},
ir
::
Operation
::
C
reate
({},
CreateAttributeMap
({
"op1_attr1"
,
"op1_attr2"
},
{
"op1_attr1"
,
"op1_attr2"
}),
{
ir
::
Float32Type
::
get
(
ctx
)},
...
...
@@ -227,8 +227,8 @@ TEST(op_test, region_test) {
ir
::
Block
*
block
=
region
->
front
();
block
->
push_front
(
op1
);
block
->
insert
(
block
->
begin
(),
op1_2
);
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
(
std
::
move
(
argument
));
op2
->
d
estroy
();
ir
::
Operation
*
op2
=
ir
::
Operation
::
C
reate
(
std
::
move
(
argument
));
op2
->
D
estroy
();
}
TEST
(
op_test
,
module_op_death
)
{
...
...
@@ -240,9 +240,9 @@ TEST(op_test, module_op_death) {
ir
::
AttributeMap
attrs
{{
"program"
,
ir
::
Int32_tAttribute
::
get
(
ctx
,
1
)}};
std
::
vector
<
ir
::
Type
>
output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
EXPECT_THROW
(
ir
::
Operation
::
c
reate
(
inputs
,
{},
{},
op_info
),
const
char
*
);
EXPECT_THROW
(
ir
::
Operation
::
c
reate
({},
attrs
,
{},
op_info
),
const
char
*
);
EXPECT_THROW
(
ir
::
Operation
::
c
reate
({},
{},
output_types
,
op_info
),
EXPECT_THROW
(
ir
::
Operation
::
C
reate
(
inputs
,
{},
{},
op_info
),
const
char
*
);
EXPECT_THROW
(
ir
::
Operation
::
C
reate
({},
attrs
,
{},
op_info
),
const
char
*
);
EXPECT_THROW
(
ir
::
Operation
::
C
reate
({},
{},
output_types
,
op_info
),
const
char
*
);
ir
::
Program
program
(
ctx
);
...
...
test/cpp/ir/core/ir_program_test.cc
浏览文件 @
ea89e968
...
...
@@ -64,10 +64,9 @@ TEST(program_test, program) {
// (3) Create a float32 DenseTensor Parameter and save into Program
ir
::
Type
fp32_dtype
=
ir
::
Float32Type
::
get
(
ctx
);
paddle
::
dialect
::
DenseTensorTypeStorage
::
Dim
dims
=
{
2
,
2
};
paddle
::
dialect
::
DenseTensorTypeStorage
::
DataLayout
data_layout
=
paddle
::
dialect
::
DenseTensorTypeStorage
::
DataLayout
::
NCHW
;
paddle
::
dialect
::
DenseTensorTypeStorage
::
LoD
lod
=
{{
0
,
1
,
2
}};
phi
::
DDim
dims
=
{
2
,
2
};
phi
::
DataLayout
data_layout
=
phi
::
DataLayout
::
NCHW
;
phi
::
LoD
lod
=
{{
0
,
1
,
2
}};
size_t
offset
=
0
;
ir
::
Type
dense_tensor_dtype
=
paddle
::
dialect
::
DenseTensorType
::
get
(
ctx
,
fp32_dtype
,
dims
,
data_layout
,
lod
,
offset
);
...
...
@@ -94,7 +93,7 @@ TEST(program_test, program) {
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op1_attribute
{
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
"a"
)}};
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
ir
::
Operation
::
C
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
ir
::
Block
*
block
=
program
.
block
();
block
->
push_back
(
op1
);
...
...
@@ -132,7 +131,7 @@ TEST(program_test, program) {
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op2_attribute
{
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
"b"
)}};
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
({},
op2_attribute
,
{
dense_tensor_dtype
},
op2_info
);
ir
::
Operation
::
C
reate
({},
op2_attribute
,
{
dense_tensor_dtype
},
op2_info
);
block
->
push_back
(
op2
);
EXPECT_EQ
(
op2
->
GetResultByIndex
(
0
).
type
().
dialect
().
id
(),
...
...
@@ -159,7 +158,7 @@ TEST(program_test, program) {
builtin_dialect
->
name
()
+
"."
+
std
::
string
(
AddOp
::
name
());
ir
::
OpInfo
op3_info
=
ctx
->
GetRegisteredOpInfo
(
op3_name
);
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op3_attribute
;
ir
::
Operation
*
op3
=
ir
::
Operation
::
c
reate
(
ir
::
Operation
*
op3
=
ir
::
Operation
::
C
reate
(
{
op1
->
GetResultByIndex
(
0
),
op2
->
GetResultByIndex
(
0
)},
op3_attribute
,
{
dense_tensor_dtype
},
...
...
@@ -194,7 +193,7 @@ TEST(program_test, program) {
abs_argument
.
AddOperands
(
operands
.
begin
(),
operands
.
end
());
abs_argument
.
AddAttributes
(
abs_op_attribute
.
begin
(),
abs_op_attribute
.
end
());
abs_argument
.
AddTypes
(
output_types
.
begin
(),
output_types
.
end
());
ir
::
Operation
*
abs_op
=
ir
::
Operation
::
c
reate
(
std
::
move
(
abs_argument
));
ir
::
Operation
*
abs_op
=
ir
::
Operation
::
C
reate
(
std
::
move
(
abs_argument
));
paddle
::
dialect
::
OpYamlInfoInterface
interface
=
abs_op
->
dyn_cast
<
paddle
::
dialect
::
OpYamlInfoInterface
>
();
EXPECT_EQ
(
std
::
get
<
0
>
(
interface
.
GetOpInfo
())[
0
].
name
==
"x"
,
true
);
...
...
@@ -209,7 +208,7 @@ TEST(program_test, program) {
ir
::
OperationArgument
op4_argument
(
{
op3
->
GetResultByIndex
(
0
)},
{},
{},
op4_info
);
op4_argument
.
AddAttributes
(
op4_attribute
.
begin
(),
op4_attribute
.
end
());
ir
::
Operation
*
op4
=
ir
::
Operation
::
c
reate
(
std
::
move
(
op4_argument
));
ir
::
Operation
*
op4
=
ir
::
Operation
::
C
reate
(
std
::
move
(
op4_argument
));
block
->
push_back
(
op4
);
EXPECT_EQ
(
op4
->
GetOperandByIndex
(
0
).
source
().
type
().
dialect
().
id
(),
...
...
@@ -256,7 +255,7 @@ TEST(program_test, slice_combine_test) {
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op1_attribute
{
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
"a"
)}};
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
({},
op1_attribute
,
{
fp32_dtype
},
op1_info
);
ir
::
Operation
::
C
reate
({},
op1_attribute
,
{
fp32_dtype
},
op1_info
);
program
.
block
()
->
push_back
(
op1
);
// (5) Def b = Constant("b")
...
...
@@ -266,7 +265,7 @@ TEST(program_test, slice_combine_test) {
attr_map
.
insert
(
std
::
pair
<
std
::
string
,
ir
::
Attribute
>
(
"value"
,
ir
::
FloatAttribute
::
get
(
ctx
,
2.0
)));
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
({},
attr_map
,
{
fp32_dtype
},
op2_info
);
ir
::
Operation
::
C
reate
({},
attr_map
,
{
fp32_dtype
},
op2_info
);
program
.
block
()
->
push_back
(
op2
);
// (6) Def combine_op = CombineOp("a", "b")
...
...
@@ -274,7 +273,7 @@ TEST(program_test, slice_combine_test) {
ir
::
OpInfo
combine_op_info
=
ctx
->
GetRegisteredOpInfo
(
combine_op_name
);
ir
::
Type
output_type
=
ir
::
VectorType
::
get
(
ctx
,
std
::
vector
<
ir
::
Type
>
({
fp32_dtype
,
fp32_dtype
}));
ir
::
Operation
*
combine_op
=
ir
::
Operation
::
c
reate
(
ir
::
Operation
*
combine_op
=
ir
::
Operation
::
C
reate
(
{
op1
->
GetResultByIndex
(
0
),
op2
->
GetResultByIndex
(
0
)},
{},
{
output_type
},
...
...
@@ -286,7 +285,7 @@ TEST(program_test, slice_combine_test) {
ir
::
OpInfo
slice_op_info
=
ctx
->
GetRegisteredOpInfo
(
slice_op_name
);
ir
::
Attribute
index_attr
=
ir
::
Int32_tAttribute
::
get
(
ctx
,
0
);
ir
::
Operation
*
slice_op
=
ir
::
Operation
::
c
reate
({
combine_op
->
GetResultByIndex
(
0
)},
ir
::
Operation
::
C
reate
({
combine_op
->
GetResultByIndex
(
0
)},
{{
"index"
,
index_attr
}},
{
fp32_dtype
},
slice_op_info
);
...
...
@@ -302,14 +301,14 @@ TEST(program_test, builder) {
ir
::
Program
program
(
ctx
);
ir
::
Builder
builder
=
ir
::
Builder
::
AtBlockEnd
(
ctx
,
program
.
block
());
paddle
::
dialect
::
FullOp
full_op
=
builder
.
create
<
paddle
::
dialect
::
FullOp
>
(
paddle
::
dialect
::
FullOp
full_op
=
builder
.
Build
<
paddle
::
dialect
::
FullOp
>
(
std
::
vector
<
int64_t
>
{
2
,
2
},
1.5
,
phi
::
DataType
::
FLOAT32
,
phi
::
CPUPlace
());
ir
::
Type
full_op_output
=
full_op
->
GetResultByIndex
(
0
).
type
();
EXPECT_EQ
(
program
.
block
()
->
size
()
==
1
,
true
);
EXPECT_EQ
(
program
.
block
()
->
size
()
,
1u
);
EXPECT_EQ
(
program
.
block
()
->
back
(),
full_op
.
operation
());
EXPECT_EQ
(
full_op
->
num_operands
()
==
0
,
true
);
EXPECT_EQ
(
full_op
->
num_results
()
==
1
,
true
);
EXPECT_EQ
(
full_op
->
attributes
().
size
()
==
4
,
true
);
EXPECT_EQ
(
full_op
->
num_operands
()
,
0u
);
EXPECT_EQ
(
full_op
->
num_results
()
,
1u
);
EXPECT_EQ
(
full_op
->
attributes
().
size
()
,
4u
);
EXPECT_EQ
(
full_op_output
.
dyn_cast
<
paddle
::
dialect
::
DenseTensorType
>
().
offset
()
==
0
,
true
);
...
...
@@ -319,7 +318,7 @@ TEST(program_test, builder) {
EXPECT_EQ
(
dim
==
2
,
true
);
}
ir
::
ConstantOp
constant
=
builder
.
create
<
ir
::
ConstantOp
>
(
ir
::
ConstantOp
constant
=
builder
.
Build
<
ir
::
ConstantOp
>
(
ir
::
Int32_tAttribute
::
get
(
ctx
,
2
),
ir
::
Int32Type
::
get
(
ctx
));
EXPECT_EQ
(
program
.
block
()
->
size
()
==
2
,
true
);
EXPECT_EQ
(
constant
.
value
().
dyn_cast
<
ir
::
Int32_tAttribute
>
().
data
()
==
2
,
...
...
test/cpp/ir/core/ir_value_test.cc
浏览文件 @
ea89e968
...
...
@@ -39,7 +39,7 @@ TEST(value_test, value_test) {
std
::
vector
<
ir
::
OpResult
>
op1_inputs
=
{};
std
::
vector
<
ir
::
Type
>
op1_output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
(
op1_inputs
,
ir
::
Operation
::
C
reate
(
op1_inputs
,
CreateAttributeMap
(
"op1_name"
,
"op1_attr"
),
op1_output_types
,
nullptr
);
...
...
@@ -48,7 +48,7 @@ TEST(value_test, value_test) {
std
::
vector
<
ir
::
OpResult
>
op2_inputs
=
{};
std
::
vector
<
ir
::
Type
>
op2_output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
(
op2_inputs
,
ir
::
Operation
::
C
reate
(
op2_inputs
,
CreateAttributeMap
(
"op2_name"
,
"op2_attr"
),
op2_output_types
,
nullptr
);
...
...
@@ -58,7 +58,7 @@ TEST(value_test, value_test) {
op2
->
GetResultByIndex
(
0
)};
std
::
vector
<
ir
::
Type
>
op3_output_types
=
{
ir
::
Float32Type
::
get
(
ctx
)};
ir
::
Operation
*
op3
=
ir
::
Operation
::
c
reate
(
op3_inputs
,
ir
::
Operation
::
C
reate
(
op3_inputs
,
CreateAttributeMap
(
"op3_name"
,
"op3_attr"
),
op3_output_types
,
nullptr
);
...
...
@@ -71,7 +71,7 @@ TEST(value_test, value_test) {
op4_output_types
.
push_back
(
ir
::
Float32Type
::
get
(
ctx
));
}
ir
::
Operation
*
op4
=
ir
::
Operation
::
c
reate
(
op4_inputs
,
ir
::
Operation
::
C
reate
(
op4_inputs
,
CreateAttributeMap
(
"op4_name"
,
"op4_attr"
),
op4_output_types
,
nullptr
);
...
...
@@ -101,11 +101,11 @@ TEST(value_test, value_test) {
// destroy
VLOG
(
0
)
<<
op1
->
GetResultByIndex
(
0
).
print_ud_chain
()
<<
std
::
endl
;
op4
->
d
estroy
();
op4
->
D
estroy
();
VLOG
(
0
)
<<
op1
->
GetResultByIndex
(
0
).
print_ud_chain
()
<<
std
::
endl
;
op3
->
d
estroy
();
op3
->
D
estroy
();
VLOG
(
0
)
<<
op1
->
GetResultByIndex
(
0
).
print_ud_chain
()
<<
std
::
endl
;
op2
->
d
estroy
();
op2
->
D
estroy
();
VLOG
(
0
)
<<
op1
->
GetResultByIndex
(
0
).
print_ud_chain
()
<<
std
::
endl
;
op1
->
d
estroy
();
op1
->
D
estroy
();
}
test/cpp/ir/pass/pass_manager_test.cc
浏览文件 @
ea89e968
...
...
@@ -107,7 +107,7 @@ TEST(pass_manager_test, pass_manager) {
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op1_attribute
{
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
"a"
)}};
ir
::
Operation
*
op1
=
ir
::
Operation
::
c
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
ir
::
Operation
::
C
reate
({},
op1_attribute
,
{
dense_tensor_dtype
},
op1_info
);
ir
::
Block
*
block
=
program
.
block
();
block
->
push_back
(
op1
);
...
...
@@ -145,7 +145,7 @@ TEST(pass_manager_test, pass_manager) {
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op2_attribute
{
{
"parameter_name"
,
ir
::
StrAttribute
::
get
(
ctx
,
"b"
)}};
ir
::
Operation
*
op2
=
ir
::
Operation
::
c
reate
({},
op2_attribute
,
{
dense_tensor_dtype
},
op2_info
);
ir
::
Operation
::
C
reate
({},
op2_attribute
,
{
dense_tensor_dtype
},
op2_info
);
block
->
push_back
(
op2
);
EXPECT_EQ
(
op2
->
GetResultByIndex
(
0
).
type
().
dialect
().
id
(),
...
...
@@ -172,7 +172,7 @@ TEST(pass_manager_test, pass_manager) {
builtin_dialect
->
name
()
+
"."
+
std
::
string
(
AddOp
::
name
());
ir
::
OpInfo
op3_info
=
ctx
->
GetRegisteredOpInfo
(
op3_name
);
std
::
unordered_map
<
std
::
string
,
ir
::
Attribute
>
op3_attribute
;
ir
::
Operation
*
op3
=
ir
::
Operation
::
c
reate
(
ir
::
Operation
*
op3
=
ir
::
Operation
::
C
reate
(
{
op1
->
GetResultByIndex
(
0
),
op2
->
GetResultByIndex
(
0
)},
op3_attribute
,
{
dense_tensor_dtype
},
...
...
@@ -207,7 +207,7 @@ TEST(pass_manager_test, pass_manager) {
abs_argument
.
AddOperands
(
operands
.
begin
(),
operands
.
end
());
abs_argument
.
AddAttributes
(
abs_op_attribute
.
begin
(),
abs_op_attribute
.
end
());
abs_argument
.
AddTypes
(
output_types
.
begin
(),
output_types
.
end
());
ir
::
Operation
*
abs_op
=
ir
::
Operation
::
c
reate
(
std
::
move
(
abs_argument
));
ir
::
Operation
*
abs_op
=
ir
::
Operation
::
C
reate
(
std
::
move
(
abs_argument
));
paddle
::
dialect
::
OpYamlInfoInterface
interface
=
abs_op
->
dyn_cast
<
paddle
::
dialect
::
OpYamlInfoInterface
>
();
EXPECT_EQ
(
std
::
get
<
0
>
(
interface
.
GetOpInfo
())[
0
].
name
==
"x"
,
true
);
...
...
@@ -222,7 +222,7 @@ TEST(pass_manager_test, pass_manager) {
ir
::
OperationArgument
op4_argument
(
{
op3
->
GetResultByIndex
(
0
)},
{},
{},
op4_info
);
op4_argument
.
AddAttributes
(
op4_attribute
.
begin
(),
op4_attribute
.
end
());
ir
::
Operation
*
op4
=
ir
::
Operation
::
c
reate
(
std
::
move
(
op4_argument
));
ir
::
Operation
*
op4
=
ir
::
Operation
::
C
reate
(
std
::
move
(
op4_argument
));
block
->
push_back
(
op4
);
EXPECT_EQ
(
op4
->
GetOperandByIndex
(
0
).
source
().
type
().
dialect
().
id
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录