Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ed38d79b
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
ed38d79b
编写于
10月 14, 2019
作者:
Z
Zhaolong Xing
提交者:
GitHub
10月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
align yolov3 cuda int8 (#2183)
test=develop
上级
1cd077dc
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
47 deletion
+42
-47
lite/backends/cuda/math/cudnn_conv.cc
lite/backends/cuda/math/cudnn_conv.cc
+10
-10
lite/core/mir/type_layout_cast_pass.cc
lite/core/mir/type_layout_cast_pass.cc
+20
-20
lite/core/mir/type_precision_cast_pass.cc
lite/core/mir/type_precision_cast_pass.cc
+5
-5
lite/core/mir/type_target_cast_pass.cc
lite/core/mir/type_target_cast_pass.cc
+5
-5
lite/kernels/cuda/calib_compute.cu
lite/kernels/cuda/calib_compute.cu
+2
-7
未找到文件。
lite/backends/cuda/math/cudnn_conv.cc
浏览文件 @
ed38d79b
...
...
@@ -537,16 +537,16 @@ bool CudnnConv2DInt8<Ptype_out>::run(const operators::ConvParam& param) {
static_cast
<
const
void
*>
(
scale
),
this
->
stream_
);
}
else
{
bias_int8_nhwc
<
int8_
t
>
(
num
,
static_cast
<
const
void
*>
(
temp_out
),
static_cast
<
const
void
*>
(
b_data
),
static_cast
<
void
*>
(
temp_out
),
n
,
c
,
h
,
w
,
static_cast
<
const
void
*>
(
scale
),
this
->
stream_
);
bias_int8_nhwc
<
floa
t
>
(
num
,
static_cast
<
const
void
*>
(
temp_out
),
static_cast
<
const
void
*>
(
b_data
),
static_cast
<
void
*>
(
temp_out
),
n
,
c
,
h
,
w
,
static_cast
<
const
void
*>
(
scale
),
this
->
stream_
);
}
return
true
;
}
...
...
lite/core/mir/type_layout_cast_pass.cc
浏览文件 @
ed38d79b
...
...
@@ -30,17 +30,17 @@ void TypeLayoutTransformPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
// Start from inputs of the graph, those should have place set.
VLOG
(
4
)
<<
"
\n
"
<<
Visualize
(
graph
.
get
());
std
::
list
<
Node
*>
nodes
;
for
(
auto
&
node
:
graph
->
mutable_nodes
())
{
nodes
.
push_back
(
&
node
);
for
(
auto
&
node
:
graph
->
StmtTopologicalOrder
())
{
nodes
.
push_back
(
node
);
}
LOG
(
INFO
)
<<
"nodes.size():"
<<
nodes
.
size
();
VLOG
(
4
)
<<
"nodes.size():"
<<
nodes
.
size
();
for
(
auto
&
node
:
nodes
)
{
LOG
(
INFO
)
<<
"!node->IsStmt():"
<<
!
node
->
IsStmt
();
VLOG
(
4
)
<<
"!node->IsStmt():"
<<
!
node
->
IsStmt
();
if
(
!
node
->
IsStmt
())
continue
;
auto
inlinks
=
node
->
inlinks
;
LOG
(
INFO
)
<<
"node->AsStmt().desc:"
<<
node
->
AsStmt
().
desc
<<
" inlinks.size():"
<<
inlinks
.
size
();
VLOG
(
4
)
<<
"node->AsStmt().desc:"
<<
node
->
AsStmt
().
desc
<<
" inlinks.size():"
<<
inlinks
.
size
();
for
(
auto
*
in
:
inlinks
)
{
ComplementInputs
(
graph
.
get
(),
node
,
in
);
}
...
...
@@ -58,7 +58,7 @@ void TypeLayoutTransformPass::ComplementInputs(SSAGraph* graph,
CHECK
(
inst_node
->
IsStmt
());
auto
&
inst
=
inst_node
->
AsStmt
();
LOG
(
INFO
)
<<
"found Target tensor: "
<<
in
->
AsArg
().
name
;
VLOG
(
4
)
<<
"found Target tensor: "
<<
in
->
AsArg
().
name
;
CHECK
(
in
->
IsRoleSet
());
CHECK
(
in
->
IsArg
());
auto
in_arg_name
=
in
->
AsArg
().
name
;
...
...
@@ -66,15 +66,15 @@ void TypeLayoutTransformPass::ComplementInputs(SSAGraph* graph,
CHECK
(
inst
.
op_info
()
->
GetInputArgname
(
in_arg_name
,
&
tmp
));
auto
decl_arg_type
=
inst
.
picked_kernel
().
GetInputDeclType
(
tmp
);
CHECK
(
in
->
AsArg
().
type
);
LOG
(
INFO
)
<<
"
\n
tmp:"
<<
tmp
<<
"
\n
in->AsArg().name:"
<<
in
->
AsArg
().
name
<<
"
\n
*in->AsArg().type:"
<<
*
in
->
AsArg
().
type
<<
"
\n
*decl_arg_type:"
<<
*
decl_arg_type
<<
"
\n
inst.op()->DebugString():"
<<
inst
.
op
()
->
DebugString
();
VLOG
(
4
)
<<
"
\n
tmp:"
<<
tmp
<<
"
\n
in->AsArg().name:"
<<
in
->
AsArg
().
name
<<
"
\n
*in->AsArg().type:"
<<
*
in
->
AsArg
().
type
<<
"
\n
*decl_arg_type:"
<<
*
decl_arg_type
<<
"
\n
inst.op()->DebugString():"
<<
inst
.
op
()
->
DebugString
();
if
(
!
DataLayoutCompatible
(
*
in
->
AsArg
().
type
,
*
decl_arg_type
))
{
LOG
(
INFO
)
<<
"found Layout unmatched tensor: "
<<
in
->
AsArg
().
name
<<
" for kernel "
<<
inst
.
op
()
->
DebugString
()
<<
" "
<<
*
in
->
AsArg
().
type
<<
" -> "
<<
*
decl_arg_type
;
VLOG
(
4
)
<<
"found Layout unmatched tensor: "
<<
in
->
AsArg
().
name
<<
" for kernel "
<<
inst
.
op
()
->
DebugString
()
<<
" "
<<
*
in
->
AsArg
().
type
<<
" -> "
<<
*
decl_arg_type
;
AddLayoutInst
(
*
in
->
AsArg
().
type
,
*
decl_arg_type
,
in
,
...
...
@@ -94,9 +94,9 @@ void TypeLayoutTransformPass::AddLayoutInst(
CHECK
(
!
valid_places
.
empty
())
<<
"valid_place should be set"
;
CHECK
(
in
->
IsArg
());
auto
node_id
=
[
&
]
{
return
graph
->
nodes
().
size
();
};
//
auto node_id = [&] { return graph->nodes().size(); };
auto
layout_output_name
=
string_format
(
"%s/layout_trans
/%d"
,
in
->
AsArg
().
name
.
c_str
(),
node_id
());
string_format
(
"%s/layout_trans
"
,
in
->
AsArg
().
name
.
c_str
());
auto
*
layout_output_arg
=
graph
->
NewArgumentNode
(
layout_output_name
);
layout_output_arg
->
AsArg
().
type
=
LiteType
::
GetTensorTy
(
from
.
target
(),
from
.
precision
(),
to
.
layout
());
...
...
@@ -145,10 +145,10 @@ void TypeLayoutTransformPass::AddLayoutInst(
CHECK
(
is_found
)
<<
"Can't find a layout kernel for layout op: "
<<
from
<<
":"
<<
in
->
AsArg
().
name
<<
"->"
<<
to
<<
":"
<<
inst_node
->
AsStmt
().
op_info
()
->
Type
();
LOG
(
INFO
)
<<
"========= final picked kernel [info]:"
<<
layout_inst
->
AsStmt
().
picked_kernel
().
name
()
<<
" [summary]:"
<<
layout_inst
->
AsStmt
().
picked_kernel
().
summary
()
<<
"
\n
"
;
VLOG
(
4
)
<<
"========= final picked kernel [info]:"
<<
layout_inst
->
AsStmt
().
picked_kernel
().
name
()
<<
" [summary]:"
<<
layout_inst
->
AsStmt
().
picked_kernel
().
summary
()
<<
"
\n
"
;
// Remove the old link
RemoveDirectedLink
(
in
,
inst_node
);
...
...
lite/core/mir/type_precision_cast_pass.cc
浏览文件 @
ed38d79b
...
...
@@ -28,8 +28,8 @@ namespace mir {
void
PrecisionCastPass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
// Start from inputs of the graph, those should have place set.
std
::
list
<
Node
*>
nodes
;
for
(
auto
&
node
:
graph
->
mutable_nodes
())
{
nodes
.
push_back
(
&
node
);
for
(
auto
&
node
:
graph
->
StmtTopologicalOrder
())
{
nodes
.
push_back
(
node
);
}
for
(
auto
&
node
:
nodes
)
{
...
...
@@ -86,9 +86,9 @@ void PrecisionCastPass::AddCastInst(const Type& from,
// var -> new_transform_op -> new_var -> inst
// So there will be a new Argument node and a new Cast Statement Node.
CHECK
(
in
->
IsArg
());
auto
node_id
=
[
&
]
{
return
graph
->
nodes
().
size
();
};
auto
cast_op_output_name
=
in
->
AsArg
().
name
+
"/precision_trans/"
+
std
::
to_string
(
node_id
());
//
auto node_id = [&] { return graph->nodes().size(); };
auto
cast_op_output_name
=
in
->
AsArg
().
name
+
"/precision_trans"
;
//
in->AsArg().name + "/precision_trans/" + std::to_string(node_id());
auto
*
cast_op_output_arg
=
graph
->
NewArgumentNode
(
cast_op_output_name
);
cast_op_output_arg
->
AsArg
().
type
=
LiteType
::
GetTensorTy
(
from
.
target
(),
to
.
precision
(),
from
.
layout
());
...
...
lite/core/mir/type_target_cast_pass.cc
浏览文件 @
ed38d79b
...
...
@@ -29,8 +29,8 @@ namespace mir {
void
TypeTargetTransformPass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
// Start from inputs of the graph, those should have place set.
std
::
list
<
Node
*>
nodes
;
for
(
auto
&
node
:
graph
->
mutable_nodes
())
{
nodes
.
push_back
(
&
node
);
for
(
auto
&
node
:
graph
->
StmtTopologicalOrder
())
{
nodes
.
push_back
(
node
);
}
CHECK
(
!
valid_places_
.
empty
());
...
...
@@ -60,7 +60,6 @@ void TypeTargetTransformPass::ComplementInputs(SSAGraph* graph,
auto
in_arg_name
=
in
->
AsArg
().
name
;
std
::
string
tmp
;
CHECK
(
inst
.
op_info
()
->
GetInputArgname
(
in_arg_name
,
&
tmp
));
LOG
(
INFO
)
<<
"tmp:"
<<
tmp
;
auto
decl_arg_type
=
inst
.
picked_kernel
().
GetInputDeclType
(
tmp
);
CHECK
(
in
->
AsArg
().
type
);
if
(
!
TargetCompatibleTo
(
*
in
->
AsArg
().
type
,
*
decl_arg_type
))
{
...
...
@@ -85,9 +84,10 @@ void TypeTargetTransformPass::AddIoCopyInst(
// So there will be a new Argument node and a new IoCopy Statement Node.
CHECK
(
in
->
IsArg
());
auto
node_id
=
[
&
]
{
return
graph
->
nodes
().
size
();
};
//
auto node_id = [&] { return graph->nodes().size(); };
auto
io_copy_output_name
=
string_format
(
"%s/target_trans/%d"
,
in
->
AsArg
().
name
.
c_str
(),
node_id
());
string_format
(
"%s/target_trans"
,
in
->
AsArg
().
name
.
c_str
());
// string_format("%s/target_trans/%d", in->AsArg().name.c_str(), node_id());
// TODO(MyPandaShaoxiang) should set same place with input?
auto
*
io_copy_output_arg
=
graph
->
NewArgumentNode
(
io_copy_output_name
);
// Set the place for io_copy_output_arg node, the target should be equal to
...
...
lite/kernels/cuda/calib_compute.cu
浏览文件 @
ed38d79b
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include <vector>
#include "lite/backends/cuda/math/utils.h"
#include "lite/core/op_registry.h"
#include "lite/core/type_system.h"
#include "lite/kernels/cuda/calib_compute.h"
...
...
@@ -22,19 +23,13 @@ namespace lite {
namespace
kernels
{
namespace
cuda
{
__device__
__forceinline__
int8_t
float2int8
(
float
x
)
{
x
=
fmaxf
(
x
,
INT8_MIN
);
x
=
fminf
(
x
,
INT8_MAX
);
return
__float2int_rn
(
x
);
}
__global__
void
Fp32ToInt8Kernel
(
const
int
num
,
const
float
scale
,
const
float
*
input
,
int8_t
*
output
)
{
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
if
(
index
<
num
)
{
output
[
index
]
=
float2int8
(
input
[
index
]
/
scale
);
output
[
index
]
=
lite
::
cuda
::
math
::
from_float
<
int8_t
>
(
input
[
index
]
/
scale
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录