Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
50fad3ed
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
50fad3ed
编写于
3月 18, 2022
作者:
H
huzhiqiang
提交者:
GitHub
3月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update infrt script (#40670)
上级
34dfb0ec
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
110 addition
and
30 deletion
+110
-30
paddle/infrt/dialect/infrt/common/types.cc
paddle/infrt/dialect/infrt/common/types.cc
+10
-0
paddle/infrt/host_context/paddle_mlir.cc
paddle/infrt/host_context/paddle_mlir.cc
+64
-24
paddle/infrt/host_context/paddle_mlir.h
paddle/infrt/host_context/paddle_mlir.h
+3
-0
paddle/scripts/infrt_build.sh
paddle/scripts/infrt_build.sh
+1
-0
tools/infrt/generate_pd_op_dialect_from_paddle_op_maker.py
tools/infrt/generate_pd_op_dialect_from_paddle_op_maker.py
+30
-5
tools/infrt/generate_phi_kernel_dialect.py
tools/infrt/generate_phi_kernel_dialect.py
+2
-1
未找到文件。
paddle/infrt/dialect/infrt/common/types.cc
浏览文件 @
50fad3ed
...
@@ -30,6 +30,8 @@ llvm::Optional<LayoutType> GetLayoutType(llvm::StringRef key) {
...
@@ -30,6 +30,8 @@ llvm::Optional<LayoutType> GetLayoutType(llvm::StringRef key) {
return
LayoutType
::
NCHW
;
return
LayoutType
::
NCHW
;
else
if
(
key
.
equals_insensitive
(
"NHWC"
))
else
if
(
key
.
equals_insensitive
(
"NHWC"
))
return
LayoutType
::
NHWC
;
return
LayoutType
::
NHWC
;
else
if
(
key
.
equals_insensitive
(
"ANY"
))
return
LayoutType
::
ANY
;
else
else
return
llvm
::
None
;
return
llvm
::
None
;
}
}
...
@@ -39,6 +41,8 @@ llvm::Optional<PrecisionType> GetPrecisionType(llvm::StringRef key) {
...
@@ -39,6 +41,8 @@ llvm::Optional<PrecisionType> GetPrecisionType(llvm::StringRef key) {
return
PrecisionType
::
FLOAT32
;
return
PrecisionType
::
FLOAT32
;
else
if
(
key
.
equals_insensitive
(
"FP16"
))
else
if
(
key
.
equals_insensitive
(
"FP16"
))
return
PrecisionType
::
FLOAT16
;
return
PrecisionType
::
FLOAT16
;
else
if
(
key
.
equals_insensitive
(
"UNK"
))
return
PrecisionType
::
UNK
;
else
else
return
llvm
::
None
;
return
llvm
::
None
;
}
}
...
@@ -67,6 +71,9 @@ llvm::StringRef GetString(LayoutType type) {
...
@@ -67,6 +71,9 @@ llvm::StringRef GetString(LayoutType type) {
case
(
LayoutType
::
NHWC
):
case
(
LayoutType
::
NHWC
):
str
=
"NHWC"
;
str
=
"NHWC"
;
break
;
break
;
case
(
LayoutType
::
ANY
):
str
=
"ANY"
;
break
;
default:
default:
str
=
"Unsupported"
;
str
=
"Unsupported"
;
}
}
...
@@ -82,6 +89,9 @@ llvm::StringRef GetString(PrecisionType type) {
...
@@ -82,6 +89,9 @@ llvm::StringRef GetString(PrecisionType type) {
case
(
PrecisionType
::
FLOAT16
):
case
(
PrecisionType
::
FLOAT16
):
str
=
"FP16"
;
str
=
"FP16"
;
break
;
break
;
case
(
PrecisionType
::
UNK
):
str
=
"UNK"
;
break
;
default:
default:
str
=
"Unsupported"
;
str
=
"Unsupported"
;
}
}
...
...
paddle/infrt/host_context/paddle_mlir.cc
浏览文件 @
50fad3ed
...
@@ -91,11 +91,15 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetModelInputsType(
...
@@ -91,11 +91,15 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetModelInputsType(
if
(
var_desc
.
name
()
==
input_var_name
)
{
if
(
var_desc
.
name
()
==
input_var_name
)
{
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
mlir
::
Type
precision_
;
infrt
::
PrecisionType
precision_
;
ConvertDataType
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
ConvertDataTypeToPhi
(
builder_
,
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
&
precision_
);
&
precision_
);
mlir
::
Type
type_
=
mlir
::
Type
type_
=
mlir
::
RankedTensorType
::
get
(
dims
,
precision_
);
infrt
::
DenseTensorType
::
get
(
context_
,
infrt
::
TargetType
::
CPU
,
precision_
,
infrt
::
LayoutType
::
ANY
);
operandTypes
.
push_back
(
type_
);
operandTypes
.
push_back
(
type_
);
}
}
}
}
...
@@ -117,11 +121,14 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetModelOutputsType(
...
@@ -117,11 +121,14 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetModelOutputsType(
if
(
var_desc
.
name
()
==
input_var_name
)
{
if
(
var_desc
.
name
()
==
input_var_name
)
{
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
mlir
::
Type
precision_
;
infrt
::
PrecisionType
precision_
;
ConvertDataType
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
ConvertDataTypeToPhi
(
builder_
,
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
&
precision_
);
&
precision_
);
mlir
::
Type
type_
=
mlir
::
Type
type_
=
mlir
::
RankedTensorType
::
get
(
dims
,
precision_
);
infrt
::
DenseTensorType
::
get
(
context_
,
infrt
::
TargetType
::
CPU
,
precision_
,
infrt
::
LayoutType
::
ANY
);
resultTypes
.
push_back
(
type_
);
resultTypes
.
push_back
(
type_
);
}
}
}
}
...
@@ -168,15 +175,11 @@ void MLIRModelGenImpl::UpdateModelParams(
...
@@ -168,15 +175,11 @@ void MLIRModelGenImpl::UpdateModelParams(
auto
name
=
builder_
.
getStringAttr
(
var_desc
.
name
());
auto
name
=
builder_
.
getStringAttr
(
var_desc
.
name
());
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
mlir
::
Type
precision_
;
infrt
::
PrecisionType
precision_
;
ConvertDataType
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
ConvertDataTypeToPhi
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
builder_
,
&
precision_
);
&
precision_
);
mlir
::
Type
type_
=
infrt
::
DenseTensorType
::
get
(
mlir
::
Type
type_
=
context_
,
infrt
::
TargetType
::
CPU
,
precision_
,
infrt
::
LayoutType
::
ANY
);
infrt
::
DenseTensorType
::
get
(
context_
,
infrt
::
TargetType
::
CPU
,
infrt
::
PrecisionType
::
FLOAT32
,
infrt
::
LayoutType
::
NCHW
);
auto
op
=
builder_
.
create
<
infrt
::
dt
::
TensorMapGetTensorOp
>
(
auto
op
=
builder_
.
create
<
infrt
::
dt
::
TensorMapGetTensorOp
>
(
mlir
::
UnknownLoc
::
get
(
context_
),
type_
,
map
,
name
);
mlir
::
UnknownLoc
::
get
(
context_
),
type_
,
map
,
name
);
params_map_
.
insert
(
std
::
pair
<
std
::
string
,
mlir
::
Value
>
(
params_map_
.
insert
(
std
::
pair
<
std
::
string
,
mlir
::
Value
>
(
...
@@ -262,11 +265,13 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetOpOutputType(
...
@@ -262,11 +265,13 @@ llvm::SmallVector<mlir::Type, 4> MLIRModelGenImpl::GetOpOutputType(
if
(
var_desc
.
name
()
==
var_name
)
{
if
(
var_desc
.
name
()
==
var_name
)
{
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
std
::
vector
<
int64_t
>
dims
=
RepeatedToVector
<
int64_t
>
(
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
var_desc
.
type
().
lod_tensor
().
tensor
().
dims
());
mlir
::
Type
precision_
;
infrt
::
PrecisionType
precision_
;
ConvertDataType
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
ConvertDataTypeToPhi
(
var_desc
.
type
().
lod_tensor
().
tensor
().
data_type
(),
builder_
,
&
precision_
);
&
precision_
);
mlir
::
Type
type_
=
infrt
::
DenseTensorType
::
get
(
context_
,
mlir
::
Type
type_
=
mlir
::
RankedTensorType
::
get
(
dims
,
precision_
);
infrt
::
TargetType
::
CPU
,
precision_
,
infrt
::
LayoutType
::
ANY
);
resultTypes
.
push_back
(
type_
);
resultTypes
.
push_back
(
type_
);
}
}
}
}
...
@@ -403,3 +408,38 @@ bool ConvertDataType(infrt::paddle::framework_proto::VarType::Type dtype,
...
@@ -403,3 +408,38 @@ bool ConvertDataType(infrt::paddle::framework_proto::VarType::Type dtype,
return
false
;
return
false
;
}
}
}
}
bool
ConvertDataTypeToPhi
(
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
dtype
,
infrt
::
PrecisionType
*
type
)
{
switch
(
dtype
)
{
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_FP16
:
*
type
=
infrt
::
PrecisionType
::
FLOAT16
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_FP32
:
*
type
=
infrt
::
PrecisionType
::
FLOAT32
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_FP64
:
*
type
=
infrt
::
PrecisionType
::
FLOAT64
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_BOOL
:
*
type
=
infrt
::
PrecisionType
::
BOOL
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_INT8
:
*
type
=
infrt
::
PrecisionType
::
INT8
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_INT16
:
*
type
=
infrt
::
PrecisionType
::
INT16
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_INT32
:
*
type
=
infrt
::
PrecisionType
::
INT32
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_INT64
:
*
type
=
infrt
::
PrecisionType
::
INT64
;
return
true
;
case
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
::
VarType_Type_UINT8
:
*
type
=
infrt
::
PrecisionType
::
UINT8
;
return
true
;
default:
return
false
;
}
}
paddle/infrt/host_context/paddle_mlir.h
浏览文件 @
50fad3ed
...
@@ -102,4 +102,7 @@ inline std::vector<T> RepeatedToVector(
...
@@ -102,4 +102,7 @@ inline std::vector<T> RepeatedToVector(
bool
ConvertDataType
(
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
dtype
,
bool
ConvertDataType
(
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
dtype
,
mlir
::
Builder
builder
,
mlir
::
Builder
builder
,
mlir
::
Type
*
type
);
mlir
::
Type
*
type
);
bool
ConvertDataTypeToPhi
(
infrt
::
paddle
::
framework_proto
::
VarType
::
Type
dtype
,
infrt
::
PrecisionType
*
type
);
#endif // PADDLE_INFRT_HOST_CONTEXT_PADDLE_MLIR_H_
#endif // PADDLE_INFRT_HOST_CONTEXT_PADDLE_MLIR_H_
paddle/scripts/infrt_build.sh
浏览文件 @
50fad3ed
...
@@ -45,6 +45,7 @@ function update_pd_ops() {
...
@@ -45,6 +45,7 @@ function update_pd_ops() {
python3 generate_pd_op_dialect_from_paddle_op_maker.py
python3 generate_pd_op_dialect_from_paddle_op_maker.py
python3 generate_phi_kernel_dialect.py
python3 generate_phi_kernel_dialect.py
# generate test model
# generate test model
cd
${
PADDLE_ROOT
}
python3 paddle/infrt/tests/model/abs_model.py
${
PADDLE_ROOT
}
/build/paddle/infrt/tests/abs
python3 paddle/infrt/tests/model/abs_model.py
${
PADDLE_ROOT
}
/build/paddle/infrt/tests/abs
}
}
...
...
tools/infrt/generate_pd_op_dialect_from_paddle_op_maker.py
浏览文件 @
50fad3ed
...
@@ -191,6 +191,21 @@ def generate_all_ops_inputs_outputs_map(op_descs):
...
@@ -191,6 +191,21 @@ def generate_all_ops_inputs_outputs_map(op_descs):
ops_inputs_outputs_head_file
.
write
(
cpp_style_ops_outputs_map_str
)
ops_inputs_outputs_head_file
.
write
(
cpp_style_ops_outputs_map_str
)
def
get_constraint
(
op_type
,
op_proto
):
# 2.3.1 inputs
constraint
=
"NoSideEffect"
optional_input_num_
=
0
for
input_
in
op_proto
[
INPUTS
]:
if
op_proto
[
INPUTS
][
input_
][
EXTRA
]
!=
True
and
op_proto
[
INPUTS
][
input_
][
INTERMEDIATE
]
!=
True
and
op_proto
[
INPUTS
][
input_
][
DISPENSABLE
]
==
True
:
optional_input_num_
+=
1
if
optional_input_num_
>
1
:
constraint
+=
", AttrSizedOperandSegments"
return
constraint
# funtion to generate paddle op dialect file
# funtion to generate paddle op dialect file
def
convert_op_proto_into_mlir
(
op_descs
):
def
convert_op_proto_into_mlir
(
op_descs
):
dst_dialect_file
=
"../../paddle/infrt/dialect/pd/ir/pd_ops.td"
dst_dialect_file
=
"../../paddle/infrt/dialect/pd/ir/pd_ops.td"
...
@@ -237,9 +252,11 @@ def convert_op_proto_into_mlir(op_descs):
...
@@ -237,9 +252,11 @@ def convert_op_proto_into_mlir(op_descs):
if
(
op_type
in
skipped_op_list
)
or
(
op_type
not
in
original_ops_
):
if
(
op_type
in
skipped_op_list
)
or
(
op_type
not
in
original_ops_
):
continue
continue
automatically_generated_op_dialect
.
append
(
op_type
)
automatically_generated_op_dialect
.
append
(
op_type
)
constraint_
=
get_constraint
(
op_type
,
op_proto
)
# 2.1 OpDef
# 2.1 OpDef
HEAD
=
'def PD_{op_type_capitalize}Op : PD_Op<"{op_type}", [
NoSideEffect
]> {left_brace}
\n
'
.
format
(
HEAD
=
'def PD_{op_type_capitalize}Op : PD_Op<"{op_type}", [
{constraint}
]> {left_brace}
\n
'
.
format
(
op_type_capitalize
=
op_type
.
capitalize
(),
op_type_capitalize
=
op_type
.
capitalize
(),
constraint
=
constraint_
,
op_type
=
op_type
,
op_type
=
op_type
,
left_brace
=
"{"
)
left_brace
=
"{"
)
SUMMARY
=
' let summary = "{} op";
\n
'
.
format
(
op_type
)
SUMMARY
=
' let summary = "{} op";
\n
'
.
format
(
op_type
)
...
@@ -256,14 +273,22 @@ def convert_op_proto_into_mlir(op_descs):
...
@@ -256,14 +273,22 @@ def convert_op_proto_into_mlir(op_descs):
ARGUMENTS
=
""
ARGUMENTS
=
""
if
(
len
(
op_proto
[
INPUTS
])
>
0
or
len
(
op_proto
[
ATTRS
])
>
0
):
if
(
len
(
op_proto
[
INPUTS
])
>
0
or
len
(
op_proto
[
ATTRS
])
>
0
):
ARGUMENTS
=
" let arguments = (ins "
ARGUMENTS
=
" let arguments = (ins "
# 2.3.1 inputs
# 2.3.1 inputs
for
input_
in
op_proto
[
INPUTS
]:
for
input_
in
op_proto
[
INPUTS
]:
if
op_proto
[
INPUTS
][
input_
][
EXTRA
]
!=
True
and
op_proto
[
INPUTS
][
if
op_proto
[
INPUTS
][
input_
][
EXTRA
]
!=
True
and
op_proto
[
INPUTS
][
input_
][
INTERMEDIATE
]
!=
True
:
input_
][
INTERMEDIATE
]
!=
True
:
if
op_proto
[
INPUTS
][
input_
][
DUPLICABLE
]
!=
"true"
:
if
op_proto
[
INPUTS
][
input_
][
DISPENSABLE
]
!=
True
:
ARGUMENTS
=
ARGUMENTS
+
" PD_Tensor:$"
+
input_
+
","
if
op_proto
[
INPUTS
][
input_
][
DUPLICABLE
]
!=
True
:
ARGUMENTS
=
ARGUMENTS
+
" PD_Tensor:$"
+
input_
+
","
else
:
ARGUMENTS
=
ARGUMENTS
+
" PD_Tensor_Array:$"
+
input_
+
","
else
:
else
:
ARGUMENTS
=
ARGUMENTS
+
" PD_Tensor_Array:$"
+
input_
+
","
if
op_proto
[
INPUTS
][
input_
][
DUPLICABLE
]
!=
True
:
ARGUMENTS
=
ARGUMENTS
+
" Optional<PD_Tensor>:$"
+
input_
+
","
else
:
ARGUMENTS
=
ARGUMENTS
+
" Optional<PD_Tensor_Array>:$"
+
input_
+
","
# unsupported: BLOCK = 8; BLOCKS = 10;
# unsupported: BLOCK = 8; BLOCKS = 10;
attr_mlir_converter
=
{
attr_mlir_converter
=
{
0
:
'SI32Attr'
,
0
:
'SI32Attr'
,
...
@@ -332,7 +357,7 @@ def convert_op_proto_into_mlir(op_descs):
...
@@ -332,7 +357,7 @@ def convert_op_proto_into_mlir(op_descs):
for
output_
in
op_proto
[
OUTPUTS
]:
for
output_
in
op_proto
[
OUTPUTS
]:
if
op_proto
[
OUTPUTS
][
output_
][
EXTRA
]
!=
True
and
op_proto
[
if
op_proto
[
OUTPUTS
][
output_
][
EXTRA
]
!=
True
and
op_proto
[
OUTPUTS
][
output_
][
INTERMEDIATE
]
!=
True
:
OUTPUTS
][
output_
][
INTERMEDIATE
]
!=
True
:
if
op_proto
[
OUTPUTS
][
output_
][
DUPLICABLE
]
!=
"true"
:
if
op_proto
[
OUTPUTS
][
output_
][
DUPLICABLE
]
!=
True
:
outputs
=
outputs
+
"PD_Tensor:${},"
.
format
(
output_
)
outputs
=
outputs
+
"PD_Tensor:${},"
.
format
(
output_
)
else
:
else
:
outputs
=
outputs
+
"PD_Tensor_Array:${},"
.
format
(
outputs
=
outputs
+
"PD_Tensor_Array:${},"
.
format
(
...
...
tools/infrt/generate_phi_kernel_dialect.py
浏览文件 @
50fad3ed
...
@@ -43,7 +43,8 @@ precision_type_converter = {
...
@@ -43,7 +43,8 @@ precision_type_converter = {
"float64"
:
"FLOAT64"
,
"float64"
:
"FLOAT64"
,
"complex64"
:
"COMPLEX64"
,
"complex64"
:
"COMPLEX64"
,
"complex128"
:
"COMPLEX128"
,
"complex128"
:
"COMPLEX128"
,
"bool"
:
"BOOL"
"bool"
:
"BOOL"
,
"Undefined"
:
"UNK"
}
}
kernel_types_info_file
=
"./kernels.json"
kernel_types_info_file
=
"./kernels.json"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录