Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
9b5fb276
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,发现更多精彩内容 >>
提交
9b5fb276
编写于
6月 19, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make place_test buildable and passed.
上级
bb882028
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
61 addition
and
66 deletion
+61
-66
.clang-format
.clang-format
+1
-4
paddle/CMakeLists.txt
paddle/CMakeLists.txt
+7
-5
paddle/platform/place.cc
paddle/platform/place.cc
+18
-21
paddle/platform/place.h
paddle/platform/place.h
+22
-23
paddle/platform/place_test.cc
paddle/platform/place_test.cc
+13
-13
未找到文件。
.clang-format
浏览文件 @
9b5fb276
...
...
@@ -16,10 +16,7 @@
---
Language: Cpp
BasedOnStyle: Google
IndentWidth: 2
TabWidth: 2
ContinuationIndentWidth: 4
AccessModifierOffset: -2 # The private/protected/public has no indent in class
UseTab Never
Standard: Cpp11
AllowAllParametersOfDeclarationOnNextLine: true
BinPackParameters: false
...
...
paddle/CMakeLists.txt
浏览文件 @
9b5fb276
...
...
@@ -17,11 +17,13 @@ add_subdirectory(strings)
find_package
(
Boost QUIET
)
if
(
Boost_FOUND
)
include_directories
(
${
Boost_INCLUDE_DIRS
}
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
)
add_subdirectory
(
majel
)
endif
()
add_subdirectory
(
platform
)
# if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# add_subdirectory(majel)
# endif()
if
(
WITH_C_API
)
add_subdirectory
(
capi
)
...
...
paddle/platform/place.cc
浏览文件 @
9b5fb276
#include "paddle/
majel
/place.h"
#include "paddle/
platform
/place.h"
namespace
majel
{
namespace
paddle
{
namespace
platform
{
namespace
detail
{
class
PlacePrinter
:
public
boost
::
static_visitor
<>
{
private:
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
GpuPlace
&
p
)
{
os_
<<
"GpuPlace("
<<
p
.
device
<<
")"
;
}
void
operator
()(
const
CpuPlace
&
)
{
os_
<<
"CpuPlace"
;
}
void
operator
()(
const
GpuPlace
&
p
)
{
os_
<<
"GpuPlace("
<<
p
.
device
<<
")"
;
}
private:
std
::
ostream
&
os_
;
};
}
// namespace detail
}
// namespace detail
static
Place
the_default_place
;
void
set_place
(
const
Place
&
place
)
{
the_default_place
=
place
;
}
const
Place
&
get_place
()
{
return
the_default_place
;
}
void
set_place
(
const
Place
&
place
)
{
the_default_place
=
place
;
}
const
Place
&
get_place
()
{
return
the_default_place
;
}
const
GpuPlace
default_gpu
()
{
return
GpuPlace
(
0
);
}
const
CpuPlace
default_cpu
()
{
return
CpuPlace
();
}
bool
is_gpu_place
(
const
Place
&
p
)
{
bool
is_gpu_place
(
const
Place
&
p
)
{
return
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
}
bool
is_cpu_place
(
const
Place
&
p
)
{
bool
is_cpu_place
(
const
Place
&
p
)
{
return
!
boost
::
apply_visitor
(
IsGpuPlace
(),
p
);
}
bool
places_are_same_class
(
const
Place
&
p1
,
const
Place
&
p2
)
{
bool
places_are_same_class
(
const
Place
&
p1
,
const
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
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Place
&
p
)
{
detail
::
PlacePrinter
printer
(
os
);
boost
::
apply_visitor
(
printer
,
p
);
return
os
;
}
}
// namespace majel
}
// namespace platform
}
// namespace paddle
paddle/platform/place.h
浏览文件 @
9b5fb276
...
...
@@ -2,49 +2,48 @@
#include <boost/variant.hpp>
#include <iostream>
namespace
majel
{
namespace
paddle
{
namespace
platform
{
struct
CpuPlace
{
CpuPlace
()
{}
// WORKAROUND: for some reason, omitting this constructor
// causes errors with boost 1.59 and OSX
// needed for variant equality comparison
inline
bool
operator
==
(
const
CpuPlace
&
)
const
{
return
true
;
}
// WORKAROUND: for some reason, omitting this constructor
// causes errors with boost 1.59 and OSX
CpuPlace
()
{}
inline
bool
operator
!=
(
const
CpuPlace
&
)
const
{
return
false
;
}
// needed for variant equality comparison
inline
bool
operator
==
(
const
CpuPlace
&
)
const
{
return
true
;
}
inline
bool
operator
!=
(
const
CpuPlace
&
)
const
{
return
false
;
}
};
struct
GpuPlace
{
GpuPlace
()
:
GpuPlace
(
0
)
{}
GpuPlace
(
int
d
)
:
device
(
d
)
{}
// needed for variant equality comparison
inline
bool
operator
==
(
const
GpuPlace
&
o
)
const
{
return
device
==
o
.
device
;
}
inline
bool
operator
!=
(
const
GpuPlace
&
o
)
const
{
return
!
(
*
this
==
o
);
}
inline
bool
operator
==
(
const
GpuPlace
&
o
)
const
{
return
device
==
o
.
device
;
}
inline
bool
operator
!=
(
const
GpuPlace
&
o
)
const
{
return
!
(
*
this
==
o
);
}
GpuPlace
()
:
GpuPlace
(
0
)
{}
int
device
;
};
class
IsGpuPlace
:
public
boost
::
static_visitor
<
bool
>
{
public:
bool
operator
()(
const
CpuPlace
&
)
const
{
return
false
;
}
bool
operator
()(
const
GpuPlace
&
gpu
)
const
{
return
true
;
}
struct
IsGpuPlace
:
public
boost
::
static_visitor
<
bool
>
{
bool
operator
()(
const
CpuPlace
&
)
const
{
return
false
;
}
bool
operator
()(
const
GpuPlace
&
gpu
)
const
{
return
true
;
}
};
typedef
boost
::
variant
<
GpuPlace
,
CpuPlace
>
Place
;
void
set_place
(
const
Place
&
);
const
Place
&
get_place
();
void
set_place
(
const
Place
&
);
const
Place
&
get_place
();
const
GpuPlace
default_gpu
();
const
CpuPlace
default_cpu
();
bool
is_gpu_place
(
const
Place
&
);
bool
is_cpu_place
(
const
Place
&
);
bool
places_are_same_class
(
const
Place
&
,
const
Place
&
);
bool
is_gpu_place
(
const
Place
&
);
bool
is_cpu_place
(
const
Place
&
);
bool
places_are_same_class
(
const
Place
&
,
const
Place
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
majel
::
Place
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Place
&
);
}
// namespace majel
}
// namespace platform
}
// namespace paddle
paddle/platform/place_test.cc
浏览文件 @
9b5fb276
#include "paddle/majel/place.h"
#include <sstream>
#include "paddle/platform/place.h"
#include "gtest/gtest.h"
#include <sstream>
TEST
(
Place
,
Equality
)
{
majel
::
CpuPlace
cpu
;
majel
::
GpuPlace
g0
(
0
),
g1
(
1
),
gg0
(
0
);
paddle
::
platform
::
CpuPlace
cpu
;
paddle
::
platform
::
GpuPlace
g0
(
0
),
g1
(
1
),
gg0
(
0
);
EXPECT_EQ
(
cpu
,
cpu
);
EXPECT_EQ
(
g0
,
g0
);
...
...
@@ -13,28 +13,28 @@ TEST(Place, Equality) {
EXPECT_NE
(
g0
,
g1
);
EXPECT_TRUE
(
majel
::
places_are_same_class
(
g0
,
gg0
));
EXPECT_FALSE
(
majel
::
places_are_same_class
(
g0
,
cpu
));
EXPECT_TRUE
(
paddle
::
platform
::
places_are_same_class
(
g0
,
gg0
));
EXPECT_FALSE
(
paddle
::
platform
::
places_are_same_class
(
g0
,
cpu
));
}
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
(
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
()));
majel
::
set_place
(
majel
::
CpuPlace
());
EXPECT_TRUE
(
majel
::
is_cpu_place
(
majel
::
get_place
()));
paddle
::
platform
::
set_place
(
paddle
::
platform
::
CpuPlace
());
EXPECT_TRUE
(
paddle
::
platform
::
is_cpu_place
(
paddle
::
platform
::
get_place
()));
}
TEST
(
Place
,
Print
)
{
{
std
::
stringstream
ss
;
ss
<<
majel
::
GpuPlace
(
1
);
ss
<<
paddle
::
platform
::
GpuPlace
(
1
);
EXPECT_EQ
(
"GpuPlace(1)"
,
ss
.
str
());
}
{
std
::
stringstream
ss
;
ss
<<
majel
::
CpuPlace
();
ss
<<
paddle
::
platform
::
CpuPlace
();
EXPECT_EQ
(
"CpuPlace"
,
ss
.
str
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录