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
674d0092
Commit
674d0092
authored
Apr 17, 2023
by
Paul
Browse files
Add tracing code
parent
13452c07
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
src/onnx/onnx_parser.cpp
src/onnx/onnx_parser.cpp
+16
-0
src/propagate_constant.cpp
src/propagate_constant.cpp
+15
-0
No files found.
src/onnx/onnx_parser.cpp
View file @
674d0092
...
@@ -270,8 +270,10 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
...
@@ -270,8 +270,10 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
std
::
unordered_map
<
std
::
string
,
instruction_ref
>
mod_insts
;
std
::
unordered_map
<
std
::
string
,
instruction_ref
>
mod_insts
;
for
(
auto
&&
f
:
graph
.
initializer
())
for
(
auto
&&
f
:
graph
.
initializer
())
{
{
// std::cout << "initializer: " << f.name() << std::endl;
// backup instructions in parent mod
// backup instructions in parent mod
mod_insts
[
f
.
name
()]
=
mod
->
add_literal
(
parse_tensor
(
f
));
mod_insts
[
f
.
name
()]
=
mod
->
add_literal
(
parse_tensor
(
f
));
// mod->debug_print(mod_insts[f.name()]);
}
}
for
(
auto
&&
input
:
graph
.
input
())
for
(
auto
&&
input
:
graph
.
input
())
...
@@ -329,6 +331,8 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
...
@@ -329,6 +331,8 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
args
.
push_back
(
instructions
.
at
(
input
));
args
.
push_back
(
instructions
.
at
(
input
));
}
}
std
::
cout
<<
"operator: "
<<
node
.
op_type
()
<<
std
::
endl
;
std
::
vector
<
instruction_ref
>
result
;
std
::
vector
<
instruction_ref
>
result
;
std
::
size_t
output_num
=
static_cast
<
std
::
size_t
>
(
node
.
output
().
size
());
std
::
size_t
output_num
=
static_cast
<
std
::
size_t
>
(
node
.
output
().
size
());
if
(
ops
.
count
(
node
.
op_type
())
==
0
)
if
(
ops
.
count
(
node
.
op_type
())
==
0
)
...
@@ -351,6 +355,18 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
...
@@ -351,6 +355,18 @@ onnx_parser::parse_graph(module* mod, const onnx::GraphProto& graph, bool inlini
result
.
begin
(),
result
.
begin
(),
std
::
inserter
(
instructions
,
instructions
.
end
()),
std
::
inserter
(
instructions
,
instructions
.
end
()),
[](
auto
&&
x
,
auto
&&
y
)
{
return
std
::
make_pair
(
x
,
y
);
});
[](
auto
&&
x
,
auto
&&
y
)
{
return
std
::
make_pair
(
x
,
y
);
});
std
::
vector
<
instruction_ref
>
added_instructions
;
fix
([
&
](
auto
self
,
auto
r
)
{
for
(
auto
ins
:
r
)
{
if
(
contains
(
args
,
ins
))
continue
;
self
(
ins
->
inputs
());
added_instructions
.
push_back
(
ins
);
}
})(
result
);
mod
->
debug_print
(
added_instructions
);
}
}
// Find instructions corresponding to the output
// Find instructions corresponding to the output
...
...
src/propagate_constant.cpp
View file @
674d0092
...
@@ -85,6 +85,21 @@ void propagate_constant::apply(module& m) const
...
@@ -85,6 +85,21 @@ void propagate_constant::apply(module& m) const
{
{
if
(
not
literals
[
i
].
empty
())
if
(
not
literals
[
i
].
empty
())
{
{
std
::
cout
<<
"Const replace: "
<<
std
::
endl
;
std
::
vector
<
instruction_ref
>
inss
;
fix
([
&
](
auto
self
,
auto
ins
)
{
if
(
contains
(
inss
,
ins
))
return
;
for
(
auto
input
:
ins
->
inputs
())
self
(
input
);
inss
.
push_back
(
ins
);
})(
const_instrs_vec
[
i
]);
// for(auto input:const_instrs_vec[i]->inputs()) {
// inss.insert(inss.end(), input->inputs().begin(), input->inputs().end());
// inss.push_back(input);
// }
// inss.push_back(const_instrs_vec[i]);
m
.
debug_print
(
inss
);
assert
(
literals
[
i
].
get_shape
()
==
const_instrs_vec
[
i
]
->
get_shape
());
assert
(
literals
[
i
].
get_shape
()
==
const_instrs_vec
[
i
]
->
get_shape
());
auto
l
=
m
.
add_literal
(
literals
[
i
].
get_shape
(),
literals
[
i
].
data
());
auto
l
=
m
.
add_literal
(
literals
[
i
].
get_shape
(),
literals
[
i
].
data
());
m
.
replace_instruction
(
const_instrs_vec
[
i
],
l
);
m
.
replace_instruction
(
const_instrs_vec
[
i
],
l
);
...
...
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