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
68c8601a
Unverified
Commit
68c8601a
authored
Apr 26, 2019
by
Paul Fultz II
Committed by
GitHub
Apr 26, 2019
Browse files
Merge branch 'develop' into scalar_parsing
parents
8c393998
849f7d92
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
11 deletions
+84
-11
src/include/migraphx/program.hpp
src/include/migraphx/program.hpp
+1
-0
src/include/migraphx/ranges.hpp
src/include/migraphx/ranges.hpp
+1
-1
src/program.cpp
src/program.cpp
+41
-10
test/print_graph_test.cpp
test/print_graph_test.cpp
+41
-0
No files found.
src/include/migraphx/program.hpp
View file @
68c8601a
...
@@ -108,6 +108,7 @@ struct program
...
@@ -108,6 +108,7 @@ struct program
void
debug_print
()
const
;
void
debug_print
()
const
;
void
debug_print
(
instruction_ref
ins
)
const
;
void
debug_print
(
instruction_ref
ins
)
const
;
void
debug_print
(
const
std
::
vector
<
instruction_ref
>&
inss
)
const
;
void
debug_print
(
const
std
::
vector
<
instruction_ref
>&
inss
)
const
;
void
print_graph
(
std
::
ostream
&
os
)
const
;
void
dry_run
(
parameter_map
params
)
const
;
void
dry_run
(
parameter_map
params
)
const
;
...
...
src/include/migraphx/ranges.hpp
View file @
68c8601a
...
@@ -12,7 +12,7 @@ inline namespace MIGRAPHX_INLINE_NS {
...
@@ -12,7 +12,7 @@ inline namespace MIGRAPHX_INLINE_NS {
namespace
detail
{
namespace
detail
{
template
<
class
String
,
class
T
>
template
<
class
String
,
class
T
>
auto
generic_find_impl
(
rank
<
2
>
,
String
&&
s
,
const
T
&
x
)
->
decltype
(
s
.
begin
()
+
s
.
find
(
x
)
,
s
.
npos
)
auto
generic_find_impl
(
rank
<
2
>
,
String
&&
s
,
const
T
&
x
)
->
decltype
(
s
.
npos
,
s
.
begin
()
+
s
.
find
(
x
))
{
{
auto
index
=
s
.
find
(
x
);
auto
index
=
s
.
find
(
x
);
if
(
index
==
s
.
npos
)
if
(
index
==
s
.
npos
)
...
...
src/program.cpp
View file @
68c8601a
...
@@ -56,7 +56,7 @@ static void print_instruction(std::ostream& os,
...
@@ -56,7 +56,7 @@ static void print_instruction(std::ostream& os,
}
}
template
<
class
F
>
template
<
class
F
>
static
void
print_program
(
std
::
ostream
&
os
,
const
program
&
p
,
F
annonate
)
static
void
print_program
(
const
program
&
p
,
F
print_func
)
{
{
std
::
unordered_map
<
instruction_ref
,
std
::
string
>
names
;
std
::
unordered_map
<
instruction_ref
,
std
::
string
>
names
;
int
count
=
0
;
int
count
=
0
;
...
@@ -77,11 +77,7 @@ static void print_program(std::ostream& os, const program& p, F annonate)
...
@@ -77,11 +77,7 @@ static void print_program(std::ostream& os, const program& p, F annonate)
(
void
)
arg
;
(
void
)
arg
;
}
}
print_instruction
(
os
,
ins
,
names
);
print_func
(
ins
,
names
);
annonate
(
ins
,
names
);
os
<<
std
::
endl
;
count
++
;
count
++
;
}
}
...
@@ -460,10 +456,12 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
...
@@ -460,10 +456,12 @@ void program::perf_report(std::ostream& os, std::size_t n, parameter_map params)
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
&&
)
{
print_program
(
*
this
,
[
&
](
auto
ins
,
const
auto
&
names
)
{
print_instruction
(
std
::
cout
,
ins
,
names
);
double
avg
=
common_average
(
ins_vec
[
ins
]);
double
avg
=
common_average
(
ins_vec
[
ins
]);
double
percent
=
std
::
ceil
(
100.0
*
avg
/
total_instruction_time
);
double
percent
=
std
::
ceil
(
100.0
*
avg
/
total_instruction_time
);
os
<<
": "
<<
avg
<<
"ms, "
<<
percent
<<
"%"
;
os
<<
": "
<<
avg
<<
"ms, "
<<
percent
<<
"%"
;
os
<<
std
::
endl
;
});
});
os
<<
std
::
endl
;
os
<<
std
::
endl
;
...
@@ -501,7 +499,7 @@ void program::debug_print(instruction_ref ins) const
...
@@ -501,7 +499,7 @@ void program::debug_print(instruction_ref ins) const
return
;
return
;
}
}
std
::
stringstream
ss
;
std
::
stringstream
ss
;
print_program
(
ss
,
*
this
,
[
&
](
auto
x
,
auto
&
&
names
)
{
print_program
(
*
this
,
[
&
](
auto
x
,
const
auto
&
names
)
{
if
(
x
==
ins
)
if
(
x
==
ins
)
{
{
print_instruction
(
std
::
cout
,
x
,
names
);
print_instruction
(
std
::
cout
,
x
,
names
);
...
@@ -516,6 +514,32 @@ void program::debug_print(const std::vector<instruction_ref>& inss) const
...
@@ -516,6 +514,32 @@ void program::debug_print(const std::vector<instruction_ref>& inss) const
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
static
std
::
string
enclose_name
(
const
std
::
string
&
name
)
{
return
'"'
+
replace_string
(
name
,
"
\"
"
,
"
\\\"
"
)
+
'"'
;
}
void
program
::
print_graph
(
std
::
ostream
&
os
)
const
{
os
<<
"digraph {"
<<
std
::
endl
;
os
<<
"
\t
rankdir=LR;"
<<
std
::
endl
;
print_program
(
*
this
,
[
&
](
auto
ins
,
const
auto
&
names
)
{
os
<<
"
\t
"
<<
enclose_name
(
names
.
at
(
ins
))
<<
"[label="
<<
enclose_name
(
to_string
(
ins
->
get_operator
()))
<<
"];"
;
os
<<
std
::
endl
;
if
(
!
ins
->
inputs
().
empty
())
{
for
(
auto
&&
arg
:
ins
->
inputs
())
{
os
<<
"
\t
"
<<
enclose_name
(
names
.
at
(
arg
))
<<
" -> "
<<
enclose_name
(
names
.
at
(
ins
));
os
<<
"[label="
<<
enclose_name
(
to_string
(
ins
->
get_shape
()))
<<
"];"
;
os
<<
std
::
endl
;
}
}
});
os
<<
"}"
<<
std
::
endl
;
}
void
program
::
dry_run
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
void
program
::
dry_run
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
{
{
auto
&
ctx
=
this
->
impl
->
ctx
;
auto
&
ctx
=
this
->
impl
->
ctx
;
...
@@ -524,14 +548,21 @@ void program::dry_run(std::unordered_map<std::string, argument> params) const
...
@@ -524,14 +548,21 @@ void program::dry_run(std::unordered_map<std::string, argument> params) const
void
program
::
annotate
(
std
::
ostream
&
os
,
std
::
function
<
void
(
instruction_ref
)
>
a
)
const
void
program
::
annotate
(
std
::
ostream
&
os
,
std
::
function
<
void
(
instruction_ref
)
>
a
)
const
{
{
print_program
(
os
,
*
this
,
[
&
](
auto
ins
,
auto
&&
)
{
a
(
ins
);
});
print_program
(
*
this
,
[
&
](
auto
ins
,
const
auto
&
names
)
{
print_instruction
(
os
,
ins
,
names
);
a
(
ins
);
os
<<
std
::
endl
;
});
}
}
bool
operator
==
(
const
program
&
x
,
const
program
&
y
)
{
return
to_string
(
x
)
==
to_string
(
y
);
}
bool
operator
==
(
const
program
&
x
,
const
program
&
y
)
{
return
to_string
(
x
)
==
to_string
(
y
);
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
program
&
p
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
program
&
p
)
{
{
print_program
(
os
,
p
,
[](
auto
&&
...)
{});
print_program
(
p
,
[
&
](
auto
ins
,
const
auto
&
names
)
{
print_instruction
(
os
,
ins
,
names
);
os
<<
std
::
endl
;
});
return
os
;
return
os
;
}
}
...
...
test/print_graph_test.cpp
0 → 100644
View file @
68c8601a
#include <migraphx/program.hpp>
#include <migraphx/ranges.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>
migraphx
::
program
create_program
()
{
migraphx
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int64_type
});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int64_type
});
auto
sum
=
p
.
add_instruction
(
sum_op
{},
x
,
y
);
auto
one
=
p
.
add_literal
(
1
);
p
.
add_instruction
(
sum_op
{},
sum
,
one
);
return
p
;
}
TEST_CASE
(
basic_graph_test
)
{
migraphx
::
program
p
=
create_program
();
std
::
stringstream
ss
;
p
.
print_graph
(
ss
);
std
::
string
test
=
ss
.
str
();
EXPECT
(
migraphx
::
contains
(
test
,
"digraph"
));
EXPECT
(
migraphx
::
contains
(
test
,
"rankdir=LR"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
@0
\"
[label=
\"
@literal
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
[label=
\"
@param:y
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
[label=
\"
@param:x
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
@3
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
@4
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
->
\"
@3
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
->
\"
@3
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
@3
\"
->
\"
@4
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
@0
\"
->
\"
@4
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"[label=
\"
int64_type, {1}, {0}
\"
]"
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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