Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4fed9d11
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4fed9d11
编写于
8月 11, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4207 fix time_profile bugs
Merge pull request !4207 from yeyunpeng2020/master_time_profile
上级
6a5c00ff
03f4ec98
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
25 deletion
+39
-25
mindspore/lite/src/common/file_utils.cc
mindspore/lite/src/common/file_utils.cc
+3
-4
mindspore/lite/src/common/log_adapter.cc
mindspore/lite/src/common/log_adapter.cc
+0
-2
mindspore/lite/tools/time_profile/time_profile.cc
mindspore/lite/tools/time_profile/time_profile.cc
+36
-19
未找到文件。
mindspore/lite/src/common/file_utils.cc
浏览文件 @
4fed9d11
...
@@ -72,13 +72,12 @@ std::string RealPath(const char *path) {
...
@@ -72,13 +72,12 @@ std::string RealPath(const char *path) {
MS_LOG
(
ERROR
)
<<
"new resolvedPath failed"
;
MS_LOG
(
ERROR
)
<<
"new resolvedPath failed"
;
return
""
;
return
""
;
}
}
std
::
string
realP
ath
=
realpath
(
path
,
resolvedPath
.
get
());
char
*
real_p
ath
=
realpath
(
path
,
resolvedPath
.
get
());
if
(
real
Path
.
empty
()
)
{
if
(
real
_path
==
nullptr
||
strlen
(
real_path
)
==
0
)
{
MS_LOG
(
ERROR
)
<<
"Proto file path is
not valid"
;
MS_LOG
(
ERROR
)
<<
"Proto file path is not valid"
;
return
""
;
return
""
;
}
}
std
::
string
res
=
resolvedPath
.
get
();
std
::
string
res
=
resolvedPath
.
get
();
return
res
;
return
res
;
}
}
...
...
mindspore/lite/src/common/log_adapter.cc
浏览文件 @
4fed9d11
...
@@ -47,8 +47,6 @@ bool IsPrint(int level) {
...
@@ -47,8 +47,6 @@ bool IsPrint(int level) {
static
int
ms_level
=
EnvToInt
(
env
);
static
int
ms_level
=
EnvToInt
(
env
);
if
(
ms_level
<
0
)
{
if
(
ms_level
<
0
)
{
ms_level
=
2
;
ms_level
=
2
;
printf
(
"please set env MSLOG DEBUG/INFO/WARNING/ERROR
\n
"
);
printf
(
"the default is WARNING
\n
"
);
}
}
return
level
>=
ms_level
;
return
level
>=
ms_level
;
}
}
...
...
mindspore/lite/tools/time_profile/time_profile.cc
浏览文件 @
4fed9d11
...
@@ -42,12 +42,14 @@ int TimeProfile::GenerateInputData() {
...
@@ -42,12 +42,14 @@ int TimeProfile::GenerateInputData() {
auto
input_data
=
tensor
->
MutableData
();
auto
input_data
=
tensor
->
MutableData
();
if
(
input_data
==
nullptr
)
{
if
(
input_data
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"MallocData for inTensor failed"
;
MS_LOG
(
ERROR
)
<<
"MallocData for inTensor failed"
;
return
RET_ERROR
;
}
}
MS_ASSERT
(
tensor
->
GetData
()
!=
nullptr
);
MS_ASSERT
(
tensor
->
GetData
()
!=
nullptr
);
auto
tensor_byte_size
=
tensor
->
Size
();
auto
tensor_byte_size
=
tensor
->
Size
();
auto
status
=
GenerateRandomData
(
tensor_byte_size
,
input_data
);
auto
status
=
GenerateRandomData
(
tensor_byte_size
,
input_data
);
if
(
status
!=
RET_OK
)
{
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Generate RandomData for inTensor failed %d"
<<
status
;
MS_LOG
(
ERROR
)
<<
"Generate RandomData for inTensor failed "
<<
status
;
return
RET_ERROR
;
}
}
}
}
return
RET_OK
;
return
RET_OK
;
...
@@ -63,10 +65,14 @@ int TimeProfile::ReadInputFile() {
...
@@ -63,10 +65,14 @@ int TimeProfile::ReadInputFile() {
size_t
size
;
size_t
size
;
char
*
bin_buf
=
ReadFile
(
_flags
->
in_data_path_
.
c_str
(),
&
size
);
char
*
bin_buf
=
ReadFile
(
_flags
->
in_data_path_
.
c_str
(),
&
size
);
if
(
bin_buf
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Input data file error, required: "
;
return
RET_ERROR
;
}
auto
tensor_data_size
=
inTensor
->
Size
();
auto
tensor_data_size
=
inTensor
->
Size
();
if
(
size
!=
tensor_data_size
)
{
if
(
size
!=
tensor_data_size
)
{
MS_LOG
(
ERROR
)
<<
"Input binary file size error, required: %zu, in fact: %zu"
<<
tensor_data_size
<<
size
;
MS_LOG
(
ERROR
)
<<
"Input binary file size error, required: "
<<
tensor_data_size
<<
" in fact: %zu"
<<
size
;
return
RET_ERROR
;
}
}
auto
input_data
=
inTensor
->
MutableData
();
auto
input_data
=
inTensor
->
MutableData
();
memcpy
(
input_data
,
bin_buf
,
tensor_data_size
);
memcpy
(
input_data
,
bin_buf
,
tensor_data_size
);
...
@@ -79,11 +85,13 @@ int TimeProfile::LoadInput() {
...
@@ -79,11 +85,13 @@ int TimeProfile::LoadInput() {
auto
status
=
GenerateInputData
();
auto
status
=
GenerateInputData
();
if
(
status
!=
RET_OK
)
{
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Generate input data error "
<<
status
;
MS_LOG
(
ERROR
)
<<
"Generate input data error "
<<
status
;
return
RET_ERROR
;
}
}
}
else
{
}
else
{
auto
status
=
ReadInputFile
();
auto
status
=
ReadInputFile
();
if
(
status
!=
RET_OK
)
{
if
(
status
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"ReadInputFile error, "
<<
status
;
MS_LOG
(
ERROR
)
<<
"ReadInputFile error, "
<<
status
;
return
RET_ERROR
;
}
}
}
}
return
RET_OK
;
return
RET_OK
;
...
@@ -93,7 +101,8 @@ int TimeProfile::InitSession() {
...
@@ -93,7 +101,8 @@ int TimeProfile::InitSession() {
size_t
size
=
0
;
size_t
size
=
0
;
char
*
graph_buf
=
ReadFile
(
_flags
->
model_path_
.
c_str
(),
&
size
);
char
*
graph_buf
=
ReadFile
(
_flags
->
model_path_
.
c_str
(),
&
size
);
if
(
graph_buf
==
nullptr
)
{
if
(
graph_buf
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Load graph failed, path %s"
<<
_flags
->
model_path_
;
MS_LOG
(
ERROR
)
<<
"Load graph failed, path "
<<
_flags
->
model_path_
;
return
RET_ERROR
;
}
}
auto
ctx
=
new
lite
::
Context
;
auto
ctx
=
new
lite
::
Context
;
...
@@ -104,6 +113,7 @@ int TimeProfile::InitSession() {
...
@@ -104,6 +113,7 @@ int TimeProfile::InitSession() {
session_
=
session
::
LiteSession
::
CreateSession
(
ctx
);
session_
=
session
::
LiteSession
::
CreateSession
(
ctx
);
if
(
session_
==
nullptr
)
{
if
(
session_
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"New session failed while running."
;
MS_LOG
(
ERROR
)
<<
"New session failed while running."
;
return
RET_ERROR
;
}
}
return
RET_OK
;
return
RET_OK
;
...
@@ -165,17 +175,31 @@ int TimeProfile::Init() {
...
@@ -165,17 +175,31 @@ int TimeProfile::Init() {
MS_LOG
(
INFO
)
<<
"InDataPath = "
<<
_flags
->
in_data_path_
;
MS_LOG
(
INFO
)
<<
"InDataPath = "
<<
_flags
->
in_data_path_
;
MS_LOG
(
INFO
)
<<
"LoopCount = "
<<
_flags
->
loop_count_
;
MS_LOG
(
INFO
)
<<
"LoopCount = "
<<
_flags
->
loop_count_
;
MS_LOG
(
INFO
)
<<
"NumThreads = "
<<
_flags
->
num_threads_
;
MS_LOG
(
INFO
)
<<
"NumThreads = "
<<
_flags
->
num_threads_
;
if
(
_flags
->
cpu_bind_mode_
==
-
1
)
{
if
(
_flags
->
num_threads_
<
1
)
{
MS_LOG
(
ERROR
)
<<
"NumThreads: "
<<
_flags
->
num_threads_
<<
" must greater than or equal 1"
;
return
RET_ERROR
;
}
if
(
_flags
->
loop_count_
<
1
)
{
MS_LOG
(
ERROR
)
<<
"LoopCount: "
<<
_flags
->
loop_count_
<<
" must greater than or equal 1"
;
return
RET_ERROR
;
}
if
(
_flags
->
cpu_bind_mode_
==
CpuBindMode
::
MID_CPU
)
{
MS_LOG
(
INFO
)
<<
"cpuBindMode = MID_CPU"
;
MS_LOG
(
INFO
)
<<
"cpuBindMode = MID_CPU"
;
}
else
if
(
_flags
->
cpu_bind_mode_
==
1
)
{
}
else
if
(
_flags
->
cpu_bind_mode_
==
CpuBindMode
::
HIGHER_CPU
)
{
MS_LOG
(
INFO
)
<<
"cpuBindMode = HIGHER_CPU"
;
MS_LOG
(
INFO
)
<<
"cpuBindMode = HIGHER_CPU"
;
}
else
{
}
else
if
(
_flags
->
cpu_bind_mode_
==
CpuBindMode
::
NO_BIND
)
{
MS_LOG
(
INFO
)
<<
"cpuBindMode = NO_BIND"
;
MS_LOG
(
INFO
)
<<
"cpuBindMode = NO_BIND"
;
}
else
{
MS_LOG
(
ERROR
)
<<
"cpuBindMode Error"
;
return
RET_ERROR
;
}
}
if
(
_flags
->
model_path_
.
empty
())
{
if
(
_flags
->
model_path_
.
empty
())
{
MS_LOG
(
ERROR
)
<<
"modelPath is required"
;
MS_LOG
(
ERROR
)
<<
"modelPath is required"
;
return
1
;
return
RET_ERROR
;
}
}
auto
status
=
InitSession
();
auto
status
=
InitSession
();
...
@@ -274,7 +298,7 @@ int TimeProfile::RunTimeProfile() {
...
@@ -274,7 +298,7 @@ int TimeProfile::RunTimeProfile() {
char
*
graphBuf
=
ReadFile
(
_flags
->
model_path_
.
c_str
(),
&
size
);
char
*
graphBuf
=
ReadFile
(
_flags
->
model_path_
.
c_str
(),
&
size
);
if
(
graphBuf
==
nullptr
)
{
if
(
graphBuf
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Load graph failed while running %s"
,
modelName
.
c_str
();
MS_LOG
(
ERROR
)
<<
"Load graph failed while running %s"
,
modelName
.
c_str
();
return
1
;
return
RET_ERROR
;
}
}
auto
model
=
lite
::
Model
::
Import
(
graphBuf
,
size
);
auto
model
=
lite
::
Model
::
Import
(
graphBuf
,
size
);
...
@@ -300,6 +324,7 @@ int TimeProfile::RunTimeProfile() {
...
@@ -300,6 +324,7 @@ int TimeProfile::RunTimeProfile() {
ret
=
session_
->
RunGraph
(
before_call_back_
,
after_call_back_
);
ret
=
session_
->
RunGraph
(
before_call_back_
,
after_call_back_
);
if
(
ret
!=
RET_OK
)
{
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Run graph failed."
;
MS_LOG
(
ERROR
)
<<
"Run graph failed."
;
return
RET_ERROR
;
}
}
auto
outputs
=
session_
->
GetOutputs
();
auto
outputs
=
session_
->
GetOutputs
();
...
@@ -307,22 +332,12 @@ int TimeProfile::RunTimeProfile() {
...
@@ -307,22 +332,12 @@ int TimeProfile::RunTimeProfile() {
uint64_t
time
=
run_end
-
run_begin
;
uint64_t
time
=
run_end
-
run_begin
;
time_avg
+=
time
;
time_avg
+=
time
;
session_
->
BindThread
(
false
);
session_
->
BindThread
(
false
);
/*
for(auto &output : outputs) {
for (auto &outputTensor : output.second) {
delete outputTensor;
}
}*/
outputs
.
clear
();
outputs
.
clear
();
}
}
time_avg
/=
_flags
->
loop_count_
;
time_avg
/=
_flags
->
loop_count_
;
float
runCost
=
static_cast
<
float
>
(
time_avg
)
/
1000.0
f
;
float
runCost
=
static_cast
<
float
>
(
time_avg
)
/
1000.0
f
;
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Run session failed."
;
}
const
std
::
vector
<
std
::
string
>
per_op_name
=
{
"opName"
,
"avg(ms)"
,
"percent"
,
"calledTimes"
,
"opTotalTime"
};
const
std
::
vector
<
std
::
string
>
per_op_name
=
{
"opName"
,
"avg(ms)"
,
"percent"
,
"calledTimes"
,
"opTotalTime"
};
const
std
::
vector
<
std
::
string
>
per_op_type
=
{
"opType"
,
"avg(ms)"
,
"percent"
,
"calledTimes"
,
"opTotalTime"
};
const
std
::
vector
<
std
::
string
>
per_op_type
=
{
"opType"
,
"avg(ms)"
,
"percent"
,
"calledTimes"
,
"opTotalTime"
};
PrintResult
(
per_op_name
,
op_times_by_name_
);
PrintResult
(
per_op_name
,
op_times_by_name_
);
...
@@ -360,11 +375,13 @@ int RunTimeProfile(int argc, const char **argv) {
...
@@ -360,11 +375,13 @@ int RunTimeProfile(int argc, const char **argv) {
auto
ret
=
time_profile
.
Init
();
auto
ret
=
time_profile
.
Init
();
if
(
ret
!=
RET_OK
)
{
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Init TimeProfile failed."
;
MS_LOG
(
ERROR
)
<<
"Init TimeProfile failed."
;
return
RET_ERROR
;
}
}
ret
=
time_profile
.
RunTimeProfile
();
ret
=
time_profile
.
RunTimeProfile
();
if
(
ret
!=
RET_OK
)
{
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Run TimeProfile failed."
;
MS_LOG
(
ERROR
)
<<
"Run TimeProfile failed."
;
return
RET_ERROR
;
}
}
return
RET_OK
;
return
RET_OK
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录