Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
55b17c11
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看板
提交
55b17c11
编写于
12月 26, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add the parsing part for the profiling tool
上级
f266284d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
92 addition
and
1 deletion
+92
-1
paddle/platform/profiler.cc
paddle/platform/profiler.cc
+59
-0
paddle/platform/profiler.h
paddle/platform/profiler.h
+11
-1
paddle/platform/profiler_test.cc
paddle/platform/profiler_test.cc
+22
-0
未找到文件。
paddle/platform/profiler.cc
浏览文件 @
55b17c11
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/platform/profiler.h"
#include <map>
namespace
paddle
{
namespace
platform
{
...
...
@@ -70,5 +71,63 @@ std::vector<std::vector<Event>> DisableProfiler() {
return
result
;
}
void
PushEvent
(
const
std
::
string
name
,
const
platform
::
DeviceContext
*
dev_ctx
)
{
GetEventList
().
Record
(
EventKind
::
kPushRange
,
std
::
move
(
name
),
kThreadId
,
dev_ctx
);
}
void
PopEvent
(
const
std
::
string
name
,
const
platform
::
DeviceContext
*
dev_ctx
)
{
GetEventList
().
Record
(
EventKind
::
kPopRange
,
std
::
move
(
name
),
kThreadId
,
dev_ctx
);
}
void
ParseEvents
(
std
::
vector
<
std
::
vector
<
Event
>>
events
)
{
std
::
map
<
std
::
string
,
std
::
tuple
<
int
,
double
,
double
>>
events_table
;
for
(
size_t
i
=
0
;
i
<
events
.
size
();
i
++
)
{
std
::
list
<
Event
>
pushed_events
;
for
(
size_t
j
=
0
;
j
<
events
[
i
].
size
();
j
++
)
{
if
(
events
[
i
][
j
].
kind
()
==
"push"
)
{
pushed_events
.
push_back
(
events
[
i
][
j
]);
}
if
(
events
[
i
][
j
].
kind
()
==
"pop"
)
{
std
::
list
<
Event
>::
reverse_iterator
rit
=
pushed_events
.
rbegin
();
while
(
rit
->
name
()
!=
events
[
i
][
j
].
name
()
&&
rit
!=
pushed_events
.
rend
())
{
++
rit
;
}
if
(
rit
!=
pushed_events
.
rend
())
{
Event
pushed_event
=
*
rit
;
double
cpu_time
=
rit
->
CpuElapsedUs
(
events
[
i
][
j
]);
double
cuda_time
=
0
;
#ifdef PADDLE_WITH_CUDA
cuda_time
=
rit
->
CudaElapsedUs
(
events
[
i
][
j
]);
#endif
if
(
events_table
.
find
(
rit
->
name
())
==
events_table
.
end
())
{
events_table
[
rit
->
name
()]
=
std
::
make_tuple
(
1
,
cpu_time
,
cuda_time
);
}
else
{
std
::
get
<
0
>
(
events_table
[
rit
->
name
()])
+=
1
;
std
::
get
<
1
>
(
events_table
[
rit
->
name
()])
+=
cpu_time
;
std
::
get
<
2
>
(
events_table
[
rit
->
name
()])
+=
cuda_time
;
}
// remove the start marker from the list
pushed_events
.
erase
((
++
rit
).
base
());
}
else
{
std
::
cout
<<
"Warning: can not find the start marker of event "
<<
events
[
i
][
j
].
name
();
}
}
}
}
// output events table
std
::
cout
<<
"
\n
Events
\t\t
Calls
\t\t
Total CPU time
\t\t
Total GPU time
\n
"
;
for
(
std
::
map
<
std
::
string
,
std
::
tuple
<
int
,
double
,
double
>>::
iterator
it
=
events_table
.
begin
();
it
!=
events_table
.
end
();
++
it
)
{
std
::
cout
<<
it
->
first
<<
"
\t\t
"
<<
std
::
get
<
0
>
(
it
->
second
)
<<
"
\t\t
"
<<
std
::
get
<
1
>
(
it
->
second
)
<<
"
\t\t
"
<<
std
::
get
<
2
>
(
it
->
second
)
<<
std
::
endl
;
}
}
}
// namespace platform
}
// namespace paddle
paddle/platform/profiler.h
浏览文件 @
55b17c11
...
...
@@ -173,25 +173,35 @@ inline void Mark(const std::string name,
GetEventList
().
Record
(
EventKind
::
kMark
,
std
::
move
(
name
),
kThreadId
,
dev_ctx
);
}
void
PushEvent
(
const
std
::
string
name
,
const
platform
::
DeviceContext
*
dev_ctx
=
nullptr
);
void
PopEvent
(
const
std
::
string
name
,
const
platform
::
DeviceContext
*
dev_ctx
=
nullptr
);
struct
RecordEvent
{
explicit
RecordEvent
(
const
std
::
string
name
,
platform
::
DeviceContext
*
dev_ctx
=
nullptr
)
{
if
(
kState
==
ProfilerState
::
kDisabled
)
return
;
dev_ctx_
=
dev_ctx
;
name_
=
name
;
GetEventList
().
Record
(
EventKind
::
kPushRange
,
std
::
move
(
name
),
kThreadId
,
dev_ctx_
);
}
~
RecordEvent
()
{
if
(
kState
==
ProfilerState
::
kDisabled
)
return
;
GetEventList
().
Record
(
EventKind
::
kPopRange
,
std
::
string
(
),
kThreadId
,
GetEventList
().
Record
(
EventKind
::
kPopRange
,
std
::
move
(
name_
),
kThreadId
,
dev_ctx_
);
}
platform
::
DeviceContext
*
dev_ctx_
;
std
::
string
name_
;
};
void
EnableProfiler
(
ProfilerState
state
);
std
::
vector
<
std
::
vector
<
Event
>>
DisableProfiler
();
void
ParseEvents
(
std
::
vector
<
std
::
vector
<
Event
>>
);
}
// namespace platform
}
// namespace paddle
paddle/platform/profiler_test.cc
浏览文件 @
55b17c11
...
...
@@ -67,8 +67,29 @@ TEST(RecordEvent, RecordEvent) {
#endif
EnableProfiler
(
state
);
/* Usage 1:
* PushEvent(evt_name, dev_ctx);
* ...
* code to time
* ...
* PopEvent(evt_name, dev_ctx);
*/
for
(
int
i
=
1
;
i
<
5
;
++
i
)
{
std
::
string
name
=
"op_"
+
std
::
to_string
(
i
);
PushEvent
(
name
,
dev_ctx
);
int
counter
=
1
;
while
(
counter
!=
i
*
1000
)
counter
++
;
PopEvent
(
name
,
dev_ctx
);
}
/* Usage 2:
* {
* RecordEvent record_event(name, dev_ctx);
* ...
* }
*/
for
(
int
i
=
1
;
i
<
5
;
++
i
)
{
std
::
string
name
=
"evs_op_"
+
std
::
to_string
(
i
);
RecordEvent
record_event
(
name
,
dev_ctx
);
int
counter
=
1
;
while
(
counter
!=
i
*
1000
)
counter
++
;
...
...
@@ -77,6 +98,7 @@ TEST(RecordEvent, RecordEvent) {
int
cuda_startup_count
=
0
;
int
start_profiler_count
=
0
;
int
stop_profiler_count
=
0
;
ParseEvents
(
events
);
for
(
size_t
i
=
0
;
i
<
events
.
size
();
++
i
)
{
for
(
size_t
j
=
0
;
j
<
events
[
i
].
size
();
++
j
)
{
if
(
events
[
i
][
j
].
name
()
==
"_cuda_startup_"
)
++
cuda_startup_count
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录