Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
b858e17b
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b858e17b
编写于
12月 14, 2017
作者:
T
tensor-tang
提交者:
GitHub
12月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6592 from tensor-tang/fluid
add MKLDNNPlace
上级
9956d5f7
bf269d67
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
2 deletion
+39
-2
paddle/operators/math/math_function.cc
paddle/operators/math/math_function.cc
+8
-0
paddle/platform/place.cc
paddle/platform/place.cc
+7
-1
paddle/platform/place.h
paddle/platform/place.h
+18
-1
paddle/platform/place_test.cc
paddle/platform/place_test.cc
+6
-0
未找到文件。
paddle/operators/math/math_function.cc
浏览文件 @
b858e17b
...
...
@@ -277,6 +277,14 @@ void set_constant_with_place<platform::CPUPlace>(
TensorSetConstantCPU
(
tensor
,
value
));
}
template
<
>
void
set_constant_with_place
<
platform
::
MKLDNNPlace
>
(
const
platform
::
DeviceContext
&
context
,
framework
::
Tensor
*
tensor
,
float
value
)
{
framework
::
VisitDataType
(
framework
::
ToDataType
(
tensor
->
type
()),
TensorSetConstantCPU
(
tensor
,
value
));
}
struct
TensorSetConstantWithPlace
:
public
boost
::
static_visitor
<
void
>
{
TensorSetConstantWithPlace
(
const
platform
::
DeviceContext
&
context
,
framework
::
Tensor
*
tensor
,
float
value
)
...
...
paddle/platform/place.cc
浏览文件 @
b858e17b
...
...
@@ -23,6 +23,7 @@ class PlacePrinter : public boost::static_visitor<> {
public:
explicit
PlacePrinter
(
std
::
ostream
&
os
)
:
os_
(
os
)
{}
void
operator
()(
const
CPUPlace
&
)
{
os_
<<
"CPUPlace"
;
}
void
operator
()(
const
MKLDNNPlace
&
)
{
os_
<<
"MKLDNNPlace"
;
}
void
operator
()(
const
GPUPlace
&
p
)
{
os_
<<
"GPUPlace("
<<
p
.
device
<<
")"
;
}
private:
...
...
@@ -38,12 +39,17 @@ const Place &get_place() { return the_default_place; }
const
GPUPlace
default_gpu
()
{
return
GPUPlace
(
0
);
}
const
CPUPlace
default_cpu
()
{
return
CPUPlace
();
}
const
MKLDNNPlace
default_mkldnn
()
{
return
MKLDNNPlace
();
}
bool
is_gpu_place
(
const
Place
&
p
)
{
return
boost
::
apply_visitor
(
IsGPUPlace
(),
p
);
}
bool
is_cpu_place
(
const
Place
&
p
)
{
return
!
boost
::
apply_visitor
(
IsGPUPlace
(),
p
);
return
!
is_gpu_place
(
p
)
&&
!
is_mkldnn_place
(
p
);
}
bool
is_mkldnn_place
(
const
Place
&
p
)
{
return
boost
::
apply_visitor
(
IsMKLDNNPlace
(),
p
);
}
bool
places_are_same_class
(
const
Place
&
p1
,
const
Place
&
p2
)
{
...
...
paddle/platform/place.h
浏览文件 @
b858e17b
...
...
@@ -31,6 +31,14 @@ struct CPUPlace {
inline
bool
operator
!=
(
const
CPUPlace
&
)
const
{
return
false
;
}
};
struct
MKLDNNPlace
{
MKLDNNPlace
()
{}
// needed for variant equality comparison
inline
bool
operator
==
(
const
MKLDNNPlace
&
)
const
{
return
true
;
}
inline
bool
operator
!=
(
const
MKLDNNPlace
&
)
const
{
return
false
;
}
};
struct
GPUPlace
{
GPUPlace
()
:
GPUPlace
(
0
)
{}
explicit
GPUPlace
(
int
d
)
:
device
(
d
)
{}
...
...
@@ -50,14 +58,21 @@ struct CudnnPlace : public GPUPlace {
struct
IsGPUPlace
:
public
boost
::
static_visitor
<
bool
>
{
bool
operator
()(
const
CPUPlace
&
)
const
{
return
false
;
}
bool
operator
()(
const
MKLDNNPlace
&
)
const
{
return
false
;
}
bool
operator
()(
const
GPUPlace
&
gpu
)
const
{
return
true
;
}
};
struct
IsMKLDNNPlace
:
public
boost
::
static_visitor
<
bool
>
{
bool
operator
()(
const
MKLDNNPlace
&
)
const
{
return
true
;
}
bool
operator
()(
const
CPUPlace
&
)
const
{
return
false
;
}
bool
operator
()(
const
GPUPlace
&
)
const
{
return
false
;
}
};
// Define the max number of Place in bit length. i.e., the max number of places
// should be less equal than 2^(NUM_PLACE_TYPE_LIMIT_IN_BIT)
#define NUM_PLACE_TYPE_LIMIT_IN_BIT 4
typedef
boost
::
variant
<
CudnnPlace
,
GPUPlace
,
CPUPlace
>
Place
;
typedef
boost
::
variant
<
CudnnPlace
,
GPUPlace
,
CPUPlace
,
MKLDNNPlace
>
Place
;
// static check number of place types is less equal than
// 2^(NUM_PLACE_TYPE_LIMIT_IN_BIT)
...
...
@@ -70,9 +85,11 @@ const Place &get_place();
const
GPUPlace
default_gpu
();
const
CPUPlace
default_cpu
();
const
MKLDNNPlace
default_mkldnn
();
bool
is_gpu_place
(
const
Place
&
);
bool
is_cpu_place
(
const
Place
&
);
bool
is_mkldnn_place
(
const
Place
&
);
bool
places_are_same_class
(
const
Place
&
,
const
Place
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Place
&
);
...
...
paddle/platform/place_test.cc
浏览文件 @
b858e17b
...
...
@@ -21,9 +21,15 @@ TEST(Place, Default) {
EXPECT_TRUE
(
paddle
::
platform
::
is_gpu_place
(
paddle
::
platform
::
get_place
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_gpu_place
(
paddle
::
platform
::
default_gpu
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
default_cpu
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_mkldnn_place
(
paddle
::
platform
::
default_mkldnn
()));
paddle
::
platform
::
set_place
(
paddle
::
platform
::
CPUPlace
());
EXPECT_TRUE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
get_place
()));
paddle
::
platform
::
set_place
(
paddle
::
platform
::
MKLDNNPlace
());
EXPECT_FALSE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
get_place
()));
EXPECT_TRUE
(
paddle
::
platform
::
is_mkldnn_place
(
paddle
::
platform
::
get_place
()));
}
TEST
(
Place
,
Print
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录