Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
696b0253
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
696b0253
编写于
11月 28, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine paddle/v2/fluid/profiler.py.
上级
623f62a7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
58 deletion
+30
-58
paddle/platform/cuda_profiler.h
paddle/platform/cuda_profiler.h
+4
-4
python/paddle/v2/fluid/profiler.py
python/paddle/v2/fluid/profiler.py
+25
-53
python/paddle/v2/fluid/tests/test_profiler.py
python/paddle/v2/fluid/tests/test_profiler.py
+1
-1
未找到文件。
paddle/platform/cuda_profiler.h
浏览文件 @
696b0253
...
@@ -29,10 +29,10 @@ void CudaProfilerInit(std::string output_file, std::string output_mode,
...
@@ -29,10 +29,10 @@ void CudaProfilerInit(std::string output_file, std::string output_mode,
memcpy
(
buf
.
data
(),
tmpl
.
data
(),
tmpl
.
size
());
memcpy
(
buf
.
data
(),
tmpl
.
data
(),
tmpl
.
size
());
auto
result
=
mktemp
(
buf
.
data
());
auto
result
=
mktemp
(
buf
.
data
());
PADDLE_ENFORCE
(
strlen
(
result
)
!=
0
);
PADDLE_ENFORCE
(
strlen
(
result
)
!=
0
);
std
::
string
config
=
result
;
std
::
string
config
_file
=
result
;
{
{
std
::
ofstream
ofs
(
config
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
std
::
ofstream
ofs
(
config
_file
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
PADDLE_ENFORCE
(
ofs
.
is_open
(),
"ofstream: "
,
ofs
.
rdstate
());
PADDLE_ENFORCE
(
ofs
.
is_open
(),
"ofstream: "
,
ofs
.
rdstate
());
for
(
const
auto
&
line
:
config_flags
)
{
for
(
const
auto
&
line
:
config_flags
)
{
ofs
<<
line
<<
std
::
endl
;
ofs
<<
line
<<
std
::
endl
;
...
@@ -42,12 +42,12 @@ void CudaProfilerInit(std::string output_file, std::string output_mode,
...
@@ -42,12 +42,12 @@ void CudaProfilerInit(std::string output_file, std::string output_mode,
PADDLE_ENFORCE
(
output_mode
==
"kvp"
||
output_mode
==
"csv"
);
PADDLE_ENFORCE
(
output_mode
==
"kvp"
||
output_mode
==
"csv"
);
cudaOutputMode_t
mode
=
output_mode
==
"csv"
?
cudaCSV
:
cudaKeyValuePair
;
cudaOutputMode_t
mode
=
output_mode
==
"csv"
?
cudaCSV
:
cudaKeyValuePair
;
PADDLE_ENFORCE
(
PADDLE_ENFORCE
(
cudaProfilerInitialize
(
config
.
c_str
(),
output_file
.
c_str
(),
mode
));
cudaProfilerInitialize
(
config
_file
.
c_str
(),
output_file
.
c_str
(),
mode
));
}
}
void
CudaProfilerStart
()
{
PADDLE_ENFORCE
(
cudaProfilerStart
());
}
void
CudaProfilerStart
()
{
PADDLE_ENFORCE
(
cudaProfilerStart
());
}
void
CudaProfilerStop
()
{
PADDLE_ENFORCE
(
(
cudaProfilerStop
()
));
}
void
CudaProfilerStop
()
{
PADDLE_ENFORCE
(
cudaProfilerStop
(
));
}
}
// namespace platform
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
python/paddle/v2/fluid/profiler.py
浏览文件 @
696b0253
import
paddle.v2.fluid.core
as
core
import
paddle.v2.fluid.core
as
core
import
subprocess
from
contextlib
import
contextmanager
__all__
=
[
'CudaProfiler'
]
__all__
=
[
'CudaProfiler'
]
NV
_FLAGS
=
[
NV
PROF_CONFIG
=
[
"gpustarttimestamp"
,
"gpustarttimestamp"
,
"gpuendtimestamp"
,
"gpuendtimestamp"
,
"gridsize3d"
,
"gridsize3d"
,
...
@@ -14,61 +14,33 @@ NV_FLAGS = [
...
@@ -14,61 +14,33 @@ NV_FLAGS = [
]
]
def
nvporf_init
(
output_file
,
output_mode
=
None
,
flags
=
None
):
@
contextmanager
"""
def
cuda_profiler
(
output_file
,
output_mode
=
None
,
config
=
None
):
Initialize the CUDA profiler.
"""The CUDA profiler.
This methods must be called before nvprof_start.
This fuctions is used to profile CUDA program by CUDA runtime application
programming interface. The profiling result will be written into
:param output_file: The output file name.
`output_file` with Key-Value pair format or Comma separated values format.
:type output_file: string
The user can set the output mode by `output_mode` argument and set the
:param output_mode: The output mode has Key-Value pair format and
counters/options for profiling by `config` argument. The default config
Comma separated values format.
caontains 'gpustarttimestamp', 'gpustarttimestamp', 'gridsize3d',
It should be 'kv' or 'csv'.
'threadblocksize', 'streamid', 'enableonstart 0', 'conckerneltrace'.
:type output_mode: string
Args:
output_file (string) : The output file name, the result will be
written into this file.
output_mode (string) : The output mode has Key-Value pair format and
Comma separated values format. It should be 'kv' or 'csv'.
config (string) : The profiler options and counters can refer to
"Compute Command Line Profiler User Guide".
"""
"""
if
output_mode
is
None
:
if
output_mode
is
None
:
output_mode
=
'csv'
output_mode
=
'csv'
if
output_mode
not
in
[
'kv'
,
'csv'
]:
if
output_mode
not
in
[
'kv'
,
'csv'
]:
raise
ValueError
(
"The output mode must be 'key-value' or 'csv'."
)
raise
ValueError
(
"The output mode must be 'key-value' or 'csv'."
)
flags
=
NV_FLAGS
if
flags
is
None
else
flags
config
=
NVPROF_CONFIG
if
config
is
None
else
config
core
.
nvprof_init
(
output_file
,
output_mode
,
flags
)
core
.
nvprof_init
(
output_file
,
output_mode
,
config
)
# Enables profiler collection by the active CUDA profiling tool.
def
nvporf_start
():
"""
Enables profiler collection by the active CUDA profiling tool.
"""
core
.
nvprof_start
()
core
.
nvprof_start
()
yield
# Disables profiler collection.
def
nvporf_stop
():
"""
Disables profiler collection.
"""
core
.
nvprof_stop
()
core
.
nvprof_stop
()
class
CudaProfiler
(
object
):
def
__init__
(
self
,
output_file
,
output_mode
=
None
,
flags
=
None
,
enabled
=
True
):
self
.
enabled
=
enabled
if
not
self
.
enabled
:
return
self
.
entered
=
False
self
.
out_file
=
output_file
nvporf_init
(
output_file
,
output_mode
,
flags
)
def
__enter__
(
self
):
if
not
self
.
enabled
:
return
if
self
.
entered
:
raise
RuntimeError
(
"The profiler traces are not reentrant"
)
self
.
entered
=
True
nvporf_start
()
return
self
def
__exit__
(
self
,
exc_type
,
exc_value
,
tb
):
if
exc_value
is
not
None
:
raise
exc_value
if
not
self
.
enabled
:
return
nvporf_stop
()
python/paddle/v2/fluid/tests/test_profiler.py
浏览文件 @
696b0253
...
@@ -18,7 +18,7 @@ class TestProfiler(unittest.TestCase):
...
@@ -18,7 +18,7 @@ class TestProfiler(unittest.TestCase):
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
exe
.
run
(
fluid
.
default_startup_program
())
with
profiler
.
CudaP
rofiler
(
"cuda_profiler.txt"
,
'csv'
)
as
nvprof
:
with
profiler
.
cuda_p
rofiler
(
"cuda_profiler.txt"
,
'csv'
)
as
nvprof
:
for
i
in
range
(
epoc
):
for
i
in
range
(
epoc
):
input
=
np
.
random
.
random
(
dshape
).
astype
(
"float32"
)
input
=
np
.
random
.
random
(
dshape
).
astype
(
"float32"
)
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
'data'
:
input
})
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
'data'
:
input
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录