Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
909cc6f0
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
909cc6f0
编写于
3月 23, 2017
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement paddle::str::to_string instead of calling std::to_string.
上级
6478483f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
6 deletion
+42
-6
paddle/math/Storage.cpp
paddle/math/Storage.cpp
+2
-1
paddle/pserver/ParameterServer2.cpp
paddle/pserver/ParameterServer2.cpp
+3
-1
paddle/utils/StringUtil.h
paddle/utils/StringUtil.h
+31
-0
paddle/utils/tests/test_CustomStackTrace.cpp
paddle/utils/tests/test_CustomStackTrace.cpp
+4
-3
paddle/utils/tests/test_CustomStackTracePrint.cpp
paddle/utils/tests/test_CustomStackTracePrint.cpp
+2
-1
未找到文件。
paddle/math/Storage.cpp
浏览文件 @
909cc6f0
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "Storage.h"
#include "Allocator.h"
#include "paddle/utils/StringUtil.h"
#include "paddle/utils/Util.h"
DEFINE_int32
(
pool_limit_size
,
...
...
@@ -62,7 +63,7 @@ PoolAllocator* StorageEngine::getGpuAllocator(int deviceId) {
}
if
(
gpuAllocator_
[
deviceId
]
==
nullptr
)
{
std
::
string
name
=
"gpu"
+
st
d
::
to_string
(
deviceId
)
+
std
::
string
(
"_pool"
);
"gpu"
+
st
r
::
to_string
(
deviceId
)
+
std
::
string
(
"_pool"
);
gpuAllocator_
[
deviceId
]
=
new
PoolAllocator
(
new
GpuAllocator
(),
FLAGS_pool_limit_size
,
name
);
}
...
...
paddle/pserver/ParameterServer2.cpp
浏览文件 @
909cc6f0
...
...
@@ -29,6 +29,7 @@ limitations under the License. */
#include "paddle/utils/Flags.h"
#include "paddle/utils/GlobalConstants.h"
#include "paddle/utils/Stat.h"
#include "paddle/utils/StringUtil.h"
DEFINE_int32
(
pserver_num_threads
,
1
,
"number of threads for sync op exec"
);
DEFINE_double
(
async_lagged_ratio_min
,
...
...
@@ -218,7 +219,8 @@ void ParameterServer2::setConfig(const SetConfigRequest& request,
callback
(
response
);
/// always defined, barrier slowest node function need it.
statSet_
.
reset
(
new
StatSet
(
"ParameterServer"
+
std
::
to_string
(
serverId_
)));
statSet_
.
reset
(
new
StatSet
(
"ParameterServer"
+
str
::
to_string
(
static_cast
<
int
>
(
serverId_
))));
}
real
bufferSum
(
const
std
::
vector
<
ParameterServer2
::
Buffer
>&
buffers
)
{
...
...
paddle/utils/StringUtil.h
浏览文件 @
909cc6f0
...
...
@@ -54,6 +54,25 @@ inline T toWithStatus(const std::string& s, bool* ok = nullptr) {
return
v
;
}
/**
* Cast type T to string with status.
*
* @param [in] v input value of type T.
* @param [out] ok status, return true if there is no error in casting. Set
* nullptr if user don't care error at all.
* @return result of casting. If error occurred, a empty string will be
* returned.
*/
template
<
class
T
>
inline
std
::
string
toWithStatus
(
const
T
v
,
bool
*
ok
=
nullptr
)
{
std
::
ostringstream
sout
;
sout
<<
v
;
if
(
ok
)
{
*
ok
=
!
sout
.
fail
();
}
return
sout
.
str
();
}
/// Convert string to type T. It makes sure all the characters in s are used.
/// Otherwise it will abort.
///
...
...
@@ -67,6 +86,18 @@ inline T to(const std::string& s) {
return
v
;
}
/// Convert type T to string.
///
/// @tparam T type of input value
/// @param v input value of type T
template
<
class
T
>
std
::
string
to_string
(
T
v
)
{
bool
ok
;
std
::
string
s
=
toWithStatus
<
T
>
(
v
,
&
ok
);
CHECK
(
ok
)
<<
"Cannot convert v("
<<
v
<<
") to type std::string"
;
return
s
;
}
}
// namespace str
#undef DEFINE_STRING_CONVERSION
...
...
paddle/utils/tests/test_CustomStackTrace.cpp
浏览文件 @
909cc6f0
...
...
@@ -19,6 +19,7 @@ limitations under the License. */
#include "paddle/utils/CustomStackTrace.h"
#include "paddle/utils/Locks.h"
#include "paddle/utils/StringUtil.h"
#include "paddle/utils/Util.h"
DEFINE_int32
(
test_thread_num
,
10
,
"testing thread number"
);
...
...
@@ -69,11 +70,11 @@ TEST(CustomStackTrace, normalTrain) {
while
(
countDown
--
>
0
)
{
start
.
wait
();
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
push
(
"layer_"
+
std
::
to_string
(
i
));
tracer
.
push
(
"layer_"
+
paddle
::
str
::
to_string
(
i
));
}
tracer
.
pop
(
""
);
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
pop
(
"layer_"
+
std
::
to_string
(
layerSize
-
1
-
i
));
tracer
.
pop
(
"layer_"
+
paddle
::
str
::
to_string
(
layerSize
-
1
-
i
));
}
finish
.
wait
();
}
...
...
@@ -89,7 +90,7 @@ TEST(CustomStackTrace, normalTest) {
while
(
countDown
--
>
0
)
{
start
.
wait
();
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
push
(
"layer_"
+
std
::
to_string
(
i
));
tracer
.
push
(
"layer_"
+
paddle
::
str
::
to_string
(
i
));
}
tracer
.
clear
();
// in forward test, tracer will clear after forward.
finish
.
wait
();
...
...
paddle/utils/tests/test_CustomStackTracePrint.cpp
浏览文件 @
909cc6f0
...
...
@@ -13,13 +13,14 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/utils/CustomStackTrace.h"
#include "paddle/utils/StringUtil.h"
#include "paddle/utils/Util.h"
int
main
(
int
argc
,
char
**
argv
)
{
paddle
::
initMain
(
argc
,
argv
);
for
(
size_t
i
=
0
;
i
<
1000
;
++
i
)
{
paddle
::
gLayerStackTrace
.
push
(
"layer_"
+
std
::
to_string
(
i
));
paddle
::
gLayerStackTrace
.
push
(
"layer_"
+
paddle
::
str
::
to_string
(
i
));
if
(
i
==
998
)
{
throw
"Unhandle exception"
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录