Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
bf794d08
Commit
bf794d08
authored
Aug 17, 2018
by
Paul
Browse files
Calculate a more stable average
parent
46d6a1d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
14 deletions
+29
-14
src/onnx/perf_onnx.cpp
src/onnx/perf_onnx.cpp
+2
-1
src/program.cpp
src/program.cpp
+27
-13
No files found.
src/onnx/perf_onnx.cpp
View file @
bf794d08
...
@@ -24,12 +24,13 @@ int main(int argc, char const* argv[])
...
@@ -24,12 +24,13 @@ int main(int argc, char const* argv[])
if
(
argc
>
1
)
if
(
argc
>
1
)
{
{
std
::
string
file
=
argv
[
1
];
std
::
string
file
=
argv
[
1
];
std
::
size_t
n
=
argc
>
2
?
std
::
stoul
(
argv
[
2
])
:
50
;
auto
p
=
migraph
::
parse_onnx
(
file
);
auto
p
=
migraph
::
parse_onnx
(
file
);
std
::
cout
<<
"Compiling ... "
<<
std
::
endl
;
std
::
cout
<<
"Compiling ... "
<<
std
::
endl
;
p
.
compile
(
migraph
::
gpu
::
target
{});
p
.
compile
(
migraph
::
gpu
::
target
{});
std
::
cout
<<
"Allocating params ... "
<<
std
::
endl
;
std
::
cout
<<
"Allocating params ... "
<<
std
::
endl
;
auto
m
=
create_param_map
(
p
);
auto
m
=
create_param_map
(
p
);
std
::
cout
<<
"Running performance report ... "
<<
std
::
endl
;
std
::
cout
<<
"Running performance report ... "
<<
std
::
endl
;
p
.
perf_report
(
std
::
cout
,
50
,
m
);
p
.
perf_report
(
std
::
cout
,
n
,
m
);
}
}
}
}
src/program.cpp
View file @
bf794d08
...
@@ -320,21 +320,30 @@ argument program::eval(std::unordered_map<std::string, argument> params) const
...
@@ -320,21 +320,30 @@ argument program::eval(std::unordered_map<std::string, argument> params) const
return
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[](
auto
&
,
auto
f
)
{
return
f
();
});
return
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[](
auto
&
,
auto
f
)
{
return
f
();
});
}
}
double
common_average
(
const
std
::
vector
<
double
>&
v
)
{
std
::
size_t
n
=
v
.
size
()
/
4
;
double
total
=
std
::
accumulate
(
v
.
begin
()
+
n
,
v
.
end
()
-
n
,
0.0
);
return
total
/
std
::
distance
(
v
.
begin
()
+
n
,
v
.
end
()
-
n
);
}
void
program
::
perf_report
(
std
::
ostream
&
os
,
std
::
size_t
n
,
parameter_map
params
)
const
void
program
::
perf_report
(
std
::
ostream
&
os
,
std
::
size_t
n
,
parameter_map
params
)
const
{
{
using
milliseconds
=
std
::
chrono
::
duration
<
double
,
std
::
milli
>
;
using
milliseconds
=
std
::
chrono
::
duration
<
double
,
std
::
milli
>
;
// Run once by itself
// Run once by itself
eval
(
params
);
eval
(
params
);
// Run and time entire program
// Run and time entire program
double
total_acc
=
0
;
std
::
vector
<
double
>
total_vec
;
total_vec
.
reserve
(
n
);
for
(
std
::
size_t
i
=
0
;
i
<
n
;
i
++
)
for
(
std
::
size_t
i
=
0
;
i
<
n
;
i
++
)
{
{
total_
acc
+=
time
<
milliseconds
>
([
&
]
{
eval
(
params
);
});
total_
vec
.
push_back
(
time
<
milliseconds
>
([
&
]
{
eval
(
params
);
})
)
;
}
}
std
::
unordered_map
<
instruction_ref
,
double
>
ins_acc
;
std
::
sort
(
total_vec
.
begin
(),
total_vec
.
end
());
std
::
unordered_map
<
instruction_ref
,
std
::
vector
<
double
>>
ins_vec
;
// Fill the map
// Fill the map
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[
&
](
auto
ins
,
auto
)
{
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[
&
](
auto
ins
,
auto
)
{
ins_
ac
c
[
ins
]
=
0
;
ins_
ve
c
[
ins
]
.
reserve
(
n
)
;
return
argument
{};
return
argument
{};
});
});
// Run and time each instruction
// Run and time each instruction
...
@@ -342,30 +351,35 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
...
@@ -342,30 +351,35 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
{
{
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[
&
](
auto
ins
,
auto
f
)
{
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[
&
](
auto
ins
,
auto
f
)
{
argument
result
;
argument
result
;
ins_
ac
c
[
ins
]
+=
time
<
milliseconds
>
([
&
]
{
result
=
f
();
});
ins_
ve
c
[
ins
]
.
push_back
(
time
<
milliseconds
>
([
&
]
{
result
=
f
();
})
)
;
return
result
;
return
result
;
});
});
}
}
for
(
auto
&&
p
:
ins_vec
)
std
::
sort
(
p
.
second
.
begin
(),
p
.
second
.
end
());
// Run and time implicit overhead
// Run and time implicit overhead
double
overhead_acc
=
0
;
std
::
vector
<
double
>
overhead_vec
;
overhead_vec
.
reserve
(
n
);
for
(
std
::
size_t
i
=
0
;
i
<
n
;
i
++
)
for
(
std
::
size_t
i
=
0
;
i
<
n
;
i
++
)
{
{
overhead_
acc
+=
time
<
milliseconds
>
([
&
]
{
overhead_
vec
.
push_back
(
time
<
milliseconds
>
([
&
]
{
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[](
auto
...)
{
return
argument
{};
});
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
params
,
[](
auto
...)
{
return
argument
{};
});
});
})
)
;
}
}
double
total_time
=
total_acc
/
n
;
double
total_time
=
common_average
(
total_vec
);
double
overhead_time
=
overhead_acc
/
n
;
double
rate
=
std
::
ceil
(
1000.0
/
total_time
);
double
overhead_time
=
common_average
(
overhead_vec
);
double
overhead_percent
=
overhead_time
*
100.0
/
total_time
;
double
overhead_percent
=
overhead_time
*
100.0
/
total_time
;
double
total_instruction_time
=
0.0
;
double
total_instruction_time
=
0.0
;
for
(
auto
&&
p
:
ins_
ac
c
)
for
(
auto
&&
p
:
ins_
ve
c
)
total_instruction_time
+=
p
.
second
/
n
;
total_instruction_time
+=
common_average
(
p
.
second
)
;
double
calculate_overhead_time
=
total_time
-
total_instruction_time
;
double
calculate_overhead_time
=
total_time
-
total_instruction_time
;
double
calculate_overhead_percent
=
calculate_overhead_time
*
100.0
/
total_time
;
double
calculate_overhead_percent
=
calculate_overhead_time
*
100.0
/
total_time
;
print_program
(
os
,
*
this
,
[
&
](
auto
ins
,
auto
&&
)
{
os
<<
": "
<<
ins_
ac
c
[
ins
]
/
n
<<
"ms"
;
});
print_program
(
os
,
*
this
,
[
&
](
auto
ins
,
auto
&&
)
{
os
<<
": "
<<
common_average
(
ins_
ve
c
[
ins
]
)
<<
"ms"
;
});
os
<<
"Rate: "
<<
rate
<<
"/sec"
<<
std
::
endl
;
os
<<
"Total time: "
<<
total_time
<<
"ms"
<<
std
::
endl
;
os
<<
"Total time: "
<<
total_time
<<
"ms"
<<
std
::
endl
;
os
<<
"Total instructions time: "
<<
total_instruction_time
<<
"ms"
<<
std
::
endl
;
os
<<
"Total instructions time: "
<<
total_instruction_time
<<
"ms"
<<
std
::
endl
;
os
<<
"Overhead time: "
<<
overhead_time
<<
"ms"
os
<<
"Overhead time: "
<<
overhead_time
<<
"ms"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment