Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
87aae57c
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看板
未验证
提交
87aae57c
编写于
12月 25, 2017
作者:
Q
qingqing01
提交者:
GitHub
12月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6715 from qingqing01/cuda_profile
Refine CUDA profiler and delete the test file.
上级
127bc2e0
ba8660a1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
13 addition
and
21 deletion
+13
-21
paddle/platform/cuda_profiler.h
paddle/platform/cuda_profiler.h
+1
-17
python/paddle/v2/fluid/profiler.py
python/paddle/v2/fluid/profiler.py
+8
-3
python/paddle/v2/fluid/tests/test_profiler.py
python/paddle/v2/fluid/tests/test_profiler.py
+4
-1
未找到文件。
paddle/platform/cuda_profiler.h
浏览文件 @
87aae57c
...
...
@@ -22,23 +22,7 @@ namespace paddle {
namespace
platform
{
void
CudaProfilerInit
(
std
::
string
output_file
,
std
::
string
output_mode
,
std
::
vector
<
std
::
string
>
config_flags
)
{
std
::
array
<
char
,
128
>
buf
;
std
::
string
tmpl
=
"/tmp/cuda_profile_config.XXXXXX"
;
PADDLE_ENFORCE_LT
(
tmpl
.
size
(),
buf
.
size
());
memcpy
(
buf
.
data
(),
tmpl
.
data
(),
tmpl
.
size
());
auto
result
=
mktemp
(
buf
.
data
());
PADDLE_ENFORCE
(
strlen
(
result
)
!=
0
);
std
::
string
config_file
=
result
;
{
std
::
ofstream
ofs
(
config_file
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
PADDLE_ENFORCE
(
ofs
.
is_open
(),
"ofstream: "
,
ofs
.
rdstate
());
for
(
const
auto
&
line
:
config_flags
)
{
ofs
<<
line
<<
std
::
endl
;
}
}
std
::
string
config_file
)
{
PADDLE_ENFORCE
(
output_mode
==
"kvp"
||
output_mode
==
"csv"
);
cudaOutputMode_t
mode
=
output_mode
==
"csv"
?
cudaCSV
:
cudaKeyValuePair
;
PADDLE_ENFORCE
(
...
...
python/paddle/v2/fluid/profiler.py
浏览文件 @
87aae57c
import
paddle.v2.fluid.core
as
core
from
contextlib
import
contextmanager
import
os
__all__
=
[
'CudaProfiler'
]
...
...
@@ -30,17 +31,21 @@ def cuda_profiler(output_file, output_mode=None, config=None):
written into this file.
output_mode (string) : The output mode has Key-Value pair format and
Comma separated values format. It should be 'kvp' or 'csv'.
config (
string) : The profiler options and counters can refer to
"Compute Command Line Profiler User Guide".
config (
list of string) : The profiler options and counters can refer
to
"Compute Command Line Profiler User Guide".
"""
if
output_mode
is
None
:
output_mode
=
'csv'
if
output_mode
not
in
[
'kvp'
,
'csv'
]:
raise
ValueError
(
"The output mode must be 'kvp' or 'csv'."
)
config
=
NVPROF_CONFIG
if
config
is
None
else
config
core
.
nvprof_init
(
output_file
,
output_mode
,
config
)
config_file
=
'nvprof_config_file'
with
open
(
config_file
,
'wb'
)
as
fp
:
fp
.
writelines
([
"%s
\n
"
%
item
for
item
in
config
])
core
.
nvprof_init
(
output_file
,
output_mode
,
config_file
)
# Enables profiler collection by the active CUDA profiling tool.
core
.
nvprof_start
()
yield
# Disables profiler collection.
core
.
nvprof_stop
()
os
.
remove
(
config_file
)
python/paddle/v2/fluid/tests/test_profiler.py
浏览文件 @
87aae57c
...
...
@@ -3,6 +3,7 @@ import numpy as np
import
paddle.v2.fluid
as
fluid
import
paddle.v2.fluid.profiler
as
profiler
import
paddle.v2.fluid.layers
as
layers
import
os
class
TestProfiler
(
unittest
.
TestCase
):
...
...
@@ -18,10 +19,12 @@ class TestProfiler(unittest.TestCase):
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
with
profiler
.
cuda_profiler
(
"cuda_profiler.txt"
,
'csv'
)
as
nvprof
:
output_file
=
'cuda_profiler.txt'
with
profiler
.
cuda_profiler
(
output_file
,
'csv'
)
as
nvprof
:
for
i
in
range
(
epoc
):
input
=
np
.
random
.
random
(
dshape
).
astype
(
'float32'
)
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
'data'
:
input
})
os
.
remove
(
output_file
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录