Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
19f2ede2
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看板
未验证
提交
19f2ede2
编写于
11月 01, 2019
作者:
L
liu zhengxi
提交者:
GitHub
11月 01, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: BindTargets and ExcludeTargets, test=release/v2.0.0 (#2329)
上级
c18b6ebc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
81 addition
and
42 deletion
+81
-42
lite/api/paddle_place.cc
lite/api/paddle_place.cc
+32
-0
lite/api/paddle_place.h
lite/api/paddle_place.h
+12
-0
lite/core/mir/fusion/conv_bn_fuse_pass.cc
lite/core/mir/fusion/conv_bn_fuse_pass.cc
+2
-1
lite/core/mir/pass.h
lite/core/mir/pass.h
+27
-2
lite/core/mir/pass_registry.h
lite/core/mir/pass_registry.h
+4
-0
lite/core/mir/pass_utils.cc
lite/core/mir/pass_utils.cc
+4
-39
未找到文件。
lite/api/paddle_place.cc
浏览文件 @
19f2ede2
...
...
@@ -113,5 +113,37 @@ const std::string& DataLayoutRepr(DataLayoutType layout) {
return
datalayout2string
[
x
];
}
std
::
set
<
TargetType
>
ExpandValidTargets
(
TargetType
target
)
{
static
const
std
::
set
<
TargetType
>
valid_set
({
TARGET
(
kX86
),
TARGET
(
kCUDA
),
TARGET
(
kARM
),
TARGET
(
kOpenCL
),
TARGET
(
kNPU
),
TARGET
(
kXPU
),
TARGET
(
kFPGA
)});
if
(
target
==
TARGET
(
kAny
))
{
return
valid_set
;
}
return
std
::
set
<
TargetType
>
({
target
});
}
std
::
set
<
PrecisionType
>
ExpandValidPrecisions
(
PrecisionType
precision
)
{
static
const
std
::
set
<
PrecisionType
>
valid_set
(
{
PRECISION
(
kFloat
),
PRECISION
(
kInt8
),
PRECISION
(
kFP16
),
PRECISION
(
kAny
)});
if
(
precision
==
PRECISION
(
kAny
))
{
return
valid_set
;
}
return
std
::
set
<
PrecisionType
>
({
precision
});
}
std
::
set
<
DataLayoutType
>
ExpandValidLayouts
(
DataLayoutType
layout
)
{
static
const
std
::
set
<
DataLayoutType
>
valid_set
(
{
DATALAYOUT
(
kNCHW
),
DATALAYOUT
(
kAny
),
DATALAYOUT
(
kNHWC
)});
if
(
layout
==
DATALAYOUT
(
kAny
))
{
return
valid_set
;
}
return
std
::
set
<
DataLayoutType
>
({
layout
});
}
}
// namespace lite_api
}
// namespace paddle
lite/api/paddle_place.h
浏览文件 @
19f2ede2
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#pragma once
#include <set>
#include <string>
// Generic helper definitions for shared library support
...
...
@@ -124,6 +125,17 @@ const std::string& PrecisionRepr(PrecisionType precision);
const
std
::
string
&
DataLayoutRepr
(
DataLayoutType
layout
);
// Get a set of all the elements represented by the target.
std
::
set
<
TargetType
>
ExpandValidTargets
(
TargetType
target
=
TARGET
(
kAny
));
// Get a set of all the elements represented by the precision.
std
::
set
<
PrecisionType
>
ExpandValidPrecisions
(
PrecisionType
precision
=
PRECISION
(
kAny
));
// Get a set of all the elements represented by the layout.
std
::
set
<
DataLayoutType
>
ExpandValidLayouts
(
DataLayoutType
layout
=
DATALAYOUT
(
kAny
));
/*
* Place specifies the execution context of a Kernel or input/output for a
* kernel. It is used to make the analysis of the MIR more clear and accurate.
...
...
lite/core/mir/fusion/conv_bn_fuse_pass.cc
浏览文件 @
19f2ede2
...
...
@@ -44,4 +44,5 @@ void ConvBNFusePass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
// namespace paddle
REGISTER_MIR_PASS
(
lite_conv_bn_fuse_pass
,
paddle
::
lite
::
mir
::
ConvBNFusePass
)
.
BindTargets
({
TARGET
(
kAny
)});
.
BindTargets
({
TARGET
(
kAny
)})
.
ExcludeTargets
({
TARGET
(
kX86
)});
lite/core/mir/pass.h
浏览文件 @
19f2ede2
...
...
@@ -49,10 +49,35 @@ class Pass {
// Some passes only apply to qualified targets, which need to be explicitly
// declared.
// Bind the target. At runtime, there must be one device in the bound targets.
// Bind targets. At runtime, there must be one device in the bound targets.
void
BindTargets
(
const
std
::
set
<
TargetType
>&
targets
)
{
bound_targets_
=
targets
;
std
::
set
<
TargetType
>
res
;
for
(
const
auto
&
target
:
targets
)
{
const
std
::
set
<
TargetType
>&
universe
=
ExpandValidTargets
(
target
);
std
::
set_union
(
bound_targets_
.
begin
(),
bound_targets_
.
end
(),
universe
.
begin
(),
universe
.
end
(),
std
::
inserter
(
res
,
res
.
begin
()));
}
bound_targets_
=
res
;
}
// Exclude targets. At runtime, there must be one device in the bound targets.
void
ExcludeTargets
(
const
std
::
set
<
TargetType
>&
targets
)
{
std
::
set
<
TargetType
>
res
;
for
(
const
auto
&
target
:
targets
)
{
const
std
::
set
<
TargetType
>&
universe
=
ExpandValidTargets
(
target
);
std
::
set_difference
(
bound_targets_
.
begin
(),
bound_targets_
.
end
(),
universe
.
begin
(),
universe
.
end
(),
std
::
inserter
(
res
,
res
.
begin
()));
}
bound_targets_
=
res
;
}
// Get all bound targets.
const
std
::
set
<
TargetType
>&
Targets
()
const
{
return
bound_targets_
;
}
...
...
lite/core/mir/pass_registry.h
浏览文件 @
19f2ede2
...
...
@@ -34,6 +34,10 @@ class PassRegistry {
pass_
->
BindTargets
(
targets
);
return
*
this
;
}
PassRegistry
&
ExcludeTargets
(
const
std
::
set
<
TargetType
>&
targets
)
{
pass_
->
ExcludeTargets
(
targets
);
return
*
this
;
}
PassRegistry
&
BindKernel
(
const
std
::
string
&
name
,
const
lite_api
::
Place
&
place
)
{
pass_
->
BindKernel
(
name
,
place
);
...
...
lite/core/mir/pass_utils.cc
浏览文件 @
19f2ede2
...
...
@@ -23,52 +23,17 @@ namespace lite {
using
lite_api
::
Place
;
namespace
{
template
<
typename
T
>
class
Types
final
{
public:
explicit
Types
(
const
std
::
set
<
T
>&
types
)
:
types_
(
types
)
{}
~
Types
()
=
default
;
std
::
set
<
T
>
ValidSet
(
const
T
&
element
)
const
;
private:
const
std
::
set
<
T
>
types_
;
};
template
<
typename
T
>
std
::
set
<
T
>
Types
<
T
>::
ValidSet
(
const
T
&
element
)
const
{
if
(
element
==
T
::
kAny
)
{
return
types_
;
}
else
if
(
element
==
T
::
kUnk
)
{
LOG
(
FATAL
)
<<
"The type of the kernel's place is unknown."
;
}
return
std
::
set
<
T
>
({
element
});
}
void
ExpandPlaces
(
std
::
set
<
Place
>*
places
,
const
Place
&
place
)
{
static
const
Types
<
TargetType
>
target_set
({
TARGET
(
kHost
),
TARGET
(
kX86
),
TARGET
(
kCUDA
),
TARGET
(
kARM
),
TARGET
(
kOpenCL
),
TARGET
(
kNPU
),
TARGET
(
kFPGA
)});
static
const
Types
<
PrecisionType
>
precision_set
(
{
PRECISION
(
kFloat
),
PRECISION
(
kInt8
),
PRECISION
(
kFP16
),
PRECISION
(
kAny
)});
static
const
Types
<
DataLayoutType
>
layout_set
(
{
DATALAYOUT
(
kNCHW
),
DATALAYOUT
(
kAny
),
DATALAYOUT
(
kNHWC
)});
for
(
const
auto
&
target
:
target_set
.
ValidSet
(
place
.
target
))
{
for
(
const
auto
&
precision
:
precision_set
.
ValidSet
(
place
.
precision
))
{
for
(
const
auto
&
layout
:
layout_set
.
ValidSet
(
place
.
layout
))
{
for
(
const
auto
&
target
:
lite_api
::
ExpandValidTargets
(
place
.
target
))
{
for
(
const
auto
&
precision
:
lite_api
::
ExpandValidPrecisions
(
place
.
precision
))
{
for
(
const
auto
&
layout
:
lite_api
::
ExpandValidLayouts
(
place
.
layout
))
{
places
->
insert
(
Place
(
target
,
precision
,
layout
));
}
}
}
}
}
// anonymous namespace
bool
KernelRegistered
(
const
std
::
string
name
,
const
Place
&
place
)
{
std
::
set
<
Place
>
places
;
ExpandPlaces
(
&
places
,
place
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录