Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
41c745da
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
41c745da
编写于
6月 03, 2020
作者:
-
--get
提交者:
jackzhang235
6月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(feat): add int64 to int32 pass
上级
ce7548d9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
192 addition
and
0 deletion
+192
-0
lite/api/paddle_use_passes.h
lite/api/paddle_use_passes.h
+2
-0
lite/core/mir/CMakeLists.txt
lite/core/mir/CMakeLists.txt
+1
-0
lite/core/mir/int64_to_int32_pass.cc
lite/core/mir/int64_to_int32_pass.cc
+149
-0
lite/core/mir/int64_to_int32_pass.h
lite/core/mir/int64_to_int32_pass.h
+38
-0
lite/core/optimizer.h
lite/core/optimizer.h
+2
-0
未找到文件。
lite/api/paddle_use_passes.h
浏览文件 @
41c745da
...
@@ -46,6 +46,8 @@ USE_MIR_PASS(multi_stream_analysis_pass);
...
@@ -46,6 +46,8 @@ USE_MIR_PASS(multi_stream_analysis_pass);
USE_MIR_PASS
(
elementwise_mul_constant_eliminate_pass
)
USE_MIR_PASS
(
elementwise_mul_constant_eliminate_pass
)
USE_MIR_PASS
(
npu_subgraph_pass
);
USE_MIR_PASS
(
npu_subgraph_pass
);
USE_MIR_PASS
(
xpu_subgraph_pass
);
USE_MIR_PASS
(
xpu_subgraph_pass
);
USE_MIR_PASS
(
int64_to_int32_pass
);
// USE_MIR_PASS(identity_cast_eliminate_pass);
USE_MIR_PASS
(
mlu_subgraph_pass
);
USE_MIR_PASS
(
mlu_subgraph_pass
);
USE_MIR_PASS
(
mlu_postprocess_pass
);
USE_MIR_PASS
(
mlu_postprocess_pass
);
USE_MIR_PASS
(
weight_quantization_preprocess_pass
);
USE_MIR_PASS
(
weight_quantization_preprocess_pass
);
...
...
lite/core/mir/CMakeLists.txt
浏览文件 @
41c745da
...
@@ -35,6 +35,7 @@ lite_cc_library(mir_passes
...
@@ -35,6 +35,7 @@ lite_cc_library(mir_passes
generate_program_pass.cc
generate_program_pass.cc
argument_type_display_pass.cc
argument_type_display_pass.cc
demo_pass.cc
demo_pass.cc
int64_to_int32_pass.cc
runtime_context_assign_pass.cc
runtime_context_assign_pass.cc
memory_optimize_pass.cc
memory_optimize_pass.cc
multi_stream_analysis_pass.cc
multi_stream_analysis_pass.cc
...
...
lite/core/mir/int64_to_int32_pass.cc
0 → 100644
浏览文件 @
41c745da
// Copyright (c) 2019 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 "lite/core/mir/int64_to_int32_pass.h"
#include <list>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "lite/core/mir/graph_visualize_pass.h"
#include "lite/core/mir/pass_registry.h"
#include "lite/operators/subgraph_op.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
void
Int64ToInt32Pass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
std
::
list
<
Node
*>
nodes
;
for
(
auto
&
node
:
graph
->
StmtTopologicalOrder
())
{
nodes
.
push_back
(
node
);
}
for
(
auto
&
node
:
nodes
)
{
if
(
!
node
->
IsStmt
()
||
node
->
AsStmt
().
op_type
()
==
"while"
)
continue
;
if
(
!
node
->
IsStmt
()
||
node
->
AsStmt
().
op_type
()
==
"feed"
)
continue
;
if
(
!
node
->
IsStmt
()
||
node
->
AsStmt
().
op_type
()
==
"fetch"
)
continue
;
auto
inlinks
=
node
->
inlinks
;
ChangeInt64ToInt32IfNeeded
(
node
);
}
}
/*
some op decide data type beside input or output tensor from op_param:
3. fillconstant
4. FillConstantBatchSiz
5. uniformrandom
int64 input or output from arm kernels
1. argmax:
2. beam_search
3. gather
4. lookup_table
5. read_from_arry
6. topk
7. write_to_arry
8. feed
9. compare
10. ctc
may support int64
1. cast
2. concat
*/
void
Int64ToInt32Pass
::
ChangeInt64ToInt32IfNeeded
(
Node
*
inst_node
)
{
CHECK
(
inst_node
->
IsStmt
());
auto
&
inst
=
inst_node
->
AsStmt
();
std
::
string
op_type
=
inst
.
op_info
()
->
Type
();
// TODO(zhaoying): support more op
if
(
op_type
==
"cast"
)
{
auto
in_dtype
=
inst
.
op_info
()
->
GetAttr
<
int
>
(
"in_dtype"
);
auto
out_dtype
=
inst
.
op_info
()
->
GetAttr
<
int
>
(
"out_dtype"
);
VLOG
(
6
)
<<
"in_dtype : "
<<
in_dtype
;
VLOG
(
6
)
<<
"out_dtype : "
<<
out_dtype
;
// BOOL = 0;INT16 = 1;INT32 = 2;INT64 = 3;FP16 = 4;FP32 = 5;FP64 = 6;
// SIZE_T = 19;UINT8 = 20;INT8 = 21;
cpp
::
OpDesc
*
cast_opdesc
=
const_cast
<
OpInfo
*>
(
inst
.
op_info
());
cast_opdesc
->
SetAttr
<
int
>
(
"out_dtype"
,
2
);
cast_opdesc
->
SetAttr
<
int
>
(
"in_dtype"
,
2
);
}
if
(
op_type
==
"fill_constant"
)
{
CHECK
(
0
)
<<
"int64_to_int32 pass do not expect fill_constant op for now"
;
}
else
if
(
op_type
==
"uniform_random"
)
{
CHECK
(
0
)
<<
"int64_to_int32 pass do not expect uniform_random op for now"
;
// auto dtype = opdesc.GetAttr<int>("dtype");
// if (dtype == static_cast<int32_t>(lite::core::FluidType::INT64)) {
// opdesc.SetAttr<int>("dtype",static_cast<int32_t>(lite::core::FluidType::INT32);
// }
}
else
if
(
op_type
==
"fill_constant_batch_size_like"
)
{
CHECK
(
0
)
<<
"int64_to_int32 pass do not expect "
"fill_constant_batch_size_like op for now"
;
}
for
(
auto
*
in
:
inst_node
->
inlinks
)
{
CHECK
(
in
->
IsRoleSet
());
CHECK
(
in
->
IsArg
());
CHECK
(
in
->
AsArg
().
type
);
auto
in_arg_name
=
in
->
AsArg
().
name
;
std
::
string
tmp
;
CHECK
(
inst
.
op_info
()
->
GetInputArgname
(
in_arg_name
,
&
tmp
));
auto
rt_precision
=
in
->
AsArg
().
type
->
precision
();
// ================== DEBUG INFO ===================
VLOG
(
6
)
<<
"op :"
<<
op_type
;
VLOG
(
6
)
<<
"arg name :"
<<
in_arg_name
;
VLOG
(
6
)
<<
"arg :"
<<
tmp
;
VLOG
(
6
)
<<
"runtime precision :"
<<
PrecisionToStr
(
rt_precision
);
// ================== DEBUG END ===================
if
(
rt_precision
==
PRECISION
(
kInt64
))
{
VLOG
(
6
)
<<
"change precison from int64 to int32"
;
in
->
AsArg
().
type
=
const_cast
<
Type
*>
(
Type
::
GetTensorTy
(
in
->
AsArg
().
type
->
target
(),
PRECISION
(
kInt32
),
in
->
AsArg
().
type
->
layout
()));
}
}
for
(
auto
*
out
:
inst_node
->
outlinks
)
{
CHECK
(
out
->
IsRoleSet
());
CHECK
(
out
->
IsArg
());
CHECK
(
out
->
AsArg
().
type
);
auto
out_arg_name
=
out
->
AsArg
().
name
;
std
::
string
tmp
;
CHECK
(
inst
.
op_info
()
->
GetOutputArgname
(
out_arg_name
,
&
tmp
));
auto
rt_precision
=
out
->
AsArg
().
type
->
precision
();
// ================== DEBUG INFO ===================
VLOG
(
6
)
<<
"op :"
<<
op_type
;
VLOG
(
6
)
<<
"arg name :"
<<
out_arg_name
;
VLOG
(
6
)
<<
"arg :"
<<
tmp
;
VLOG
(
6
)
<<
"runtime precision :"
<<
PrecisionToStr
(
rt_precision
);
// ================== DEBUG END ===================
if
(
rt_precision
==
PRECISION
(
kInt64
))
{
VLOG
(
6
)
<<
"change precison from int64 to int32"
;
out
->
AsArg
().
type
=
const_cast
<
Type
*>
(
Type
::
GetTensorTy
(
out
->
AsArg
().
type
->
target
(),
PRECISION
(
kInt32
),
out
->
AsArg
().
type
->
layout
()));
}
}
}
}
// namespace mir
}
// namespace lite
}
// namespace paddle
REGISTER_MIR_PASS
(
int64_to_int32_pass
,
paddle
::
lite
::
mir
::
Int64ToInt32Pass
)
.
BindTargets
({
TARGET
(
kMLU
)});
lite/core/mir/int64_to_int32_pass.h
0 → 100644
浏览文件 @
41c745da
// Copyright (c) 2019 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 <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/pass.h"
#include "lite/core/op_registry.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
class
Int64ToInt32Pass
:
public
ProgramPass
{
public:
void
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
override
;
void
ChangeInt64ToInt32IfNeeded
(
Node
*
inst_node
);
};
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/optimizer.h
浏览文件 @
41c745da
...
@@ -90,6 +90,8 @@ class Optimizer {
...
@@ -90,6 +90,8 @@ class Optimizer {
"xpu_subgraph_pass"
,
"xpu_subgraph_pass"
,
"bm_subgraph_pass"
,
"bm_subgraph_pass"
,
"rknpu_subgraph_pass"
,
"rknpu_subgraph_pass"
,
"int64_to_int32_pass"
,
// "identity_cast_eliminate_pass",
"mlu_subgraph_pass"
,
"mlu_subgraph_pass"
,
"static_kernel_pick_pass"
,
// pick original kernel from graph
"static_kernel_pick_pass"
,
// pick original kernel from graph
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录