Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
05b3196e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
提交
05b3196e
编写于
5月 13, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clang-format
上级
d8c8f419
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
38 deletion
+26
-38
paddle/majel/place.cpp
paddle/majel/place.cpp
+16
-28
paddle/majel/test/place_test.cpp
paddle/majel/test/place_test.cpp
+8
-8
paddle/majel/test/test_framework.cpp
paddle/majel/test/test_framework.cpp
+2
-2
未找到文件。
paddle/majel/place.cpp
浏览文件 @
05b3196e
...
...
@@ -4,58 +4,46 @@ namespace majel {
namespace
detail
{
class
PlacePrinter
:
public
boost
::
static_visitor
<>
{
class
PlacePrinter
:
public
boost
::
static_visitor
<>
{
private:
std
::
ostream
&
os_
;
std
::
ostream
&
os_
;
public:
PlacePrinter
(
std
::
ostream
&
os
)
:
os_
(
os
)
{}
PlacePrinter
(
std
::
ostream
&
os
)
:
os_
(
os
)
{}
void
operator
()(
const
CpuPlace
&
)
{
os_
<<
"CpuPlace"
;
}
void
operator
()(
const
CpuPlace
&
)
{
os_
<<
"CpuPlace"
;
}
void
operator
()(
const
GpuPlace
&
p
)
{
os_
<<
"GpuPlace("
<<
p
.
device
<<
")"
;
}
void
operator
()(
const
GpuPlace
&
p
)
{
os_
<<
"GpuPlace("
<<
p
.
device
<<
")"
;
}
};
}
// namespace majel
static
Place
the_default_place
;
void
set_place
(
const
Place
&
place
)
{
the_default_place
=
place
;
}
void
set_place
(
const
Place
&
place
)
{
the_default_place
=
place
;
}
const
Place
&
get_place
()
{
return
the_default_place
;
}
const
Place
&
get_place
()
{
return
the_default_place
;
}
const
GpuPlace
default_gpu
()
{
return
GpuPlace
(
0
);
}
const
GpuPlace
default_gpu
()
{
return
GpuPlace
(
0
);
}
const
CpuPlace
default_cpu
()
{
return
CpuPlace
();
}
const
CpuPlace
default_cpu
()
{
return
CpuPlace
();
}
bool
is_gpu_place
(
const
Place
&
p
)
{
return
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
return
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
}
bool
is_cpu_place
(
const
Place
&
p
)
{
return
!
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
return
!
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
}
bool
places_are_same_class
(
const
Place
&
p1
,
const
Place
&
p2
)
{
return
is_gpu_place
(
p1
)
==
is_gpu_place
(
p2
);
return
is_gpu_place
(
p1
)
==
is_gpu_place
(
p2
);
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
majel
::
Place
&
p
)
{
majel
::
detail
::
PlacePrinter
printer
(
os
);
boost
::
apply_visitor
(
printer
,
p
);
return
os
;
majel
::
detail
::
PlacePrinter
printer
(
os
);
boost
::
apply_visitor
(
printer
,
p
);
return
os
;
}
}
// namespace majel
paddle/majel/test/place_test.cpp
浏览文件 @
05b3196e
#include "gtest/gtest.h"
#include "majel/place.h"
#include <sstream>
#include "gtest/gtest.h"
TEST
(
Place
,
Equality
)
{
majel
::
CpuPlace
cpu
;
...
...
@@ -18,12 +18,12 @@ TEST(Place, Equality) {
}
TEST
(
Place
,
Default
)
{
EXPECT_TRUE
(
majel
::
is_gpu_place
(
majel
::
get_place
()));
EXPECT_TRUE
(
majel
::
is_gpu_place
(
majel
::
default_gpu
()));
EXPECT_TRUE
(
majel
::
is_cpu_place
(
majel
::
default_cpu
()));
EXPECT_TRUE
(
majel
::
is_gpu_place
(
majel
::
get_place
()));
EXPECT_TRUE
(
majel
::
is_gpu_place
(
majel
::
default_gpu
()));
EXPECT_TRUE
(
majel
::
is_cpu_place
(
majel
::
default_cpu
()));
majel
::
set_place
(
majel
::
CpuPlace
());
EXPECT_TRUE
(
majel
::
is_cpu_place
(
majel
::
get_place
()));
EXPECT_TRUE
(
majel
::
is_cpu_place
(
majel
::
get_place
()));
}
TEST
(
Place
,
Print
)
{
...
...
@@ -33,8 +33,8 @@ TEST(Place, Print) {
EXPECT_EQ
(
"GpuPlace(1)"
,
ss
.
str
());
}
{
std
::
stringstream
ss
;
ss
<<
majel
::
CpuPlace
();
EXPECT_EQ
(
"CpuPlace"
,
ss
.
str
());
std
::
stringstream
ss
;
ss
<<
majel
::
CpuPlace
();
EXPECT_EQ
(
"CpuPlace"
,
ss
.
str
());
}
}
paddle/majel/test/test_framework.cpp
浏览文件 @
05b3196e
#include "gtest/gtest.h"
int
main
(
int
argc
,
char
**
argv
)
{
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录