Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
6cf2dcbc
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看板
提交
6cf2dcbc
编写于
11月 27, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add cuda profiler tools.
上级
1f6002ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
151 addition
and
0 deletion
+151
-0
paddle/platform/cuda_profiler.h
paddle/platform/cuda_profiler.h
+70
-0
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+5
-0
python/paddle/v2/fluid/profiler.py
python/paddle/v2/fluid/profiler.py
+59
-0
python/paddle/v2/fluid/tests/test_profiler.py
python/paddle/v2/fluid/tests/test_profiler.py
+17
-0
未找到文件。
paddle/platform/cuda_profiler.h
0 → 100644
浏览文件 @
6cf2dcbc
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <cuda_profiler_api.h>
#include <stdlib.h>
#include <string.h>
namespace
paddle
{
namespace
platform
{
static
std
::
vector
<
std
::
string
>
kCudaProfileConfiguration
=
{
"gpustarttimestamp"
,
"gpuendtimestamp"
,
"gridsize3d"
,
"threadblocksize"
,
"dynsmemperblock"
,
"stasmemperblock"
,
"regperthread"
,
"memtransfersize"
,
"memtransferdir"
,
"memtransferhostmemtype"
,
"streamid"
,
"cacheconfigrequested"
,
"cacheconfigexecuted"
,
"countermodeaggregate"
,
"enableonstart 0"
,
"active_warps"
,
"active_cycles"
,
};
void
CudaProfilerInit
(
std
::
string
output_file
,
std
::
string
output_mode
)
{
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
=
result
;
{
std
::
ofstream
ofs
(
config
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
PADDLE_ENFORCE
(
ofs
.
is_open
(),
"ofstream: "
,
ofs
.
rdstate
());
for
(
const
auto
&
line
:
kCudaProfileConfiguration
)
{
ofs
<<
line
<<
std
::
endl
;
}
}
PADDLE_ENFORCE
(
output_mode
==
"key_value"
||
output_mode
==
"csv"
);
cudaOutputMode_t
mode
=
output_mode
==
"csv"
?
cudaCSV
:
cudaKeyValuePair
;
PADDLE_ENFORCE
(
cudaProfilerInitialize
(
config
.
c_str
(),
output_file
.
c_str
(),
mode
));
}
void
CudaProfilerStart
()
{
PADDLE_ENFORCE
(
cudaProfilerStart
());
}
void
CudaProfilerStop
()
{
PADDLE_ENFORCE
((
cudaProfilerStop
()));
}
}
}
paddle/pybind/pybind.cc
浏览文件 @
6cf2dcbc
...
...
@@ -37,6 +37,7 @@ limitations under the License. */
#ifdef PADDLE_WITH_CUDA
#include "paddle/operators/nccl/nccl_gpu_common.h"
#include "paddle/platform/cuda_profiler.h"
#include "paddle/platform/gpu_info.h"
#endif
...
...
@@ -460,6 +461,10 @@ All parameter, weight, gradient are variables in Paddle.
m
.
def
(
"op_support_gpu"
,
OpSupportGPU
);
#ifdef PADDLE_WITH_CUDA
m
.
def
(
"get_cuda_device_count"
,
platform
::
GetCUDADeviceCount
);
m
.
def
(
"nvprof_init"
,
platform
::
CudaProfilerInit
);
m
.
def
(
"nvprof_start"
,
platform
::
CudaProfilerStart
);
m
.
def
(
"nvprof_stop"
,
platform
::
CudaProfilerStop
);
#endif
return
m
.
ptr
();
...
...
python/paddle/v2/fluid/profiler.py
0 → 100644
浏览文件 @
6cf2dcbc
import
paddle.v2.fluid.core
as
core
def
nvporf_init
(
output_file
,
output_mode
=
None
):
"""
Initialize the CUDA profiler.
This methods must be called before nvprof_start.
:param output_file: The output file name.
:type output_file: string
:param output_mode: The output mode has Key-Value pair format and
Comma separated values format.
It should be 'key-value' or 'csv'.
:type output_mode: string
"""
if
output_mode
is
None
:
output_mode
=
'csv'
if
output_mode
!=
'key-value'
or
output_mode
!=
'csv'
:
raise
ValueError
(
"The output mode must be 'key-value' or 'csv'."
)
core
.
nvprof_init
(
output_file
,
output_mode
)
def
nvporf_start
():
"""
Enables profiler collection by the active CUDA profiling tool.
"""
core
.
nvprof_start
()
def
nvporf_stop
():
"""
Disables profiler collection.
"""
core
.
nvprof_stop
()
class
profiler
(
object
):
def
__init__
(
self
,
output_file
,
output_mode
=
None
,
enabled
=
True
):
self
.
enabled
=
enabled
if
not
self
.
enabled
:
return
self
.
entered
=
False
nvporf_init
(
output_file
,
output_mode
)
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
0 → 100644
浏览文件 @
6cf2dcbc
import
paddle.v2.fluid.profiler
as
profiler
import
paddle.v2.fluid.layers
as
layers
import
numpy
as
np
place
=
core
.
GPUPlace
(
0
)
exe
=
Executor
(
place
)
epoc
=
8
dshape
=
[
4
,
3
,
28
,
28
]
data
=
layers
.
data
(
name
=
'data'
,
shape
=
dshape
,
dtype
=
'float32'
)
conv
=
layers
.
conv2d
(
data
,
20
,
3
,
stride
=
[
1
,
1
],
padding
=
[
1
,
1
])
input
=
core
.
LoDTensor
()
with
profiler
(
"cuda_profiler.txt"
)
as
nvprof
:
for
i
in
range
(
epoc
):
input
.
set
(
np
.
random
.
random
(
dshape
).
astype
(
"float32"
),
place
)
exe
.
run
(
framework
.
default_main_program
(),
feed
=
{
'data'
:
data
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录