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
e9885eb3
"src/targets/vscode:/vscode.git/clone" did not exist on "fe91009b73d6fbbd255bef7adeab5b48c9cca54f"
Unverified
Commit
e9885eb3
authored
May 29, 2022
by
Paul Fultz II
Committed by
GitHub
May 29, 2022
Browse files
Merge branch 'develop' into jit-vector-reduce
parents
35579249
d436a723
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
25 deletions
+35
-25
examples/vision/python_yolov4/yolov4_inference.ipynb
examples/vision/python_yolov4/yolov4_inference.ipynb
+3
-3
src/propagate_constant.cpp
src/propagate_constant.cpp
+32
-22
No files found.
examples/vision/python_yolov4/yolov4_inference.ipynb
View file @
e9885eb3
...
...
@@ -24,16 +24,16 @@
"import os.path\n",
"\n",
"if not os.path.exists(\"./utilities/coco.names\"):\n",
" !wget https://github.com/onnx/models/raw/ma
ster
/vision/object_detection_segmentation/yolov4/dependencies/coco.names -P ./utilities/\n",
" !wget https://github.com/onnx/models/raw/ma
in
/vision/object_detection_segmentation/yolov4/dependencies/coco.names -P ./utilities/\n",
"if not os.path.exists(\"./utilities/yolov4_anchors.txt\"):\n",
" !wget https://github.com/onnx/models/raw/ma
ster
/vision/object_detection_segmentation/yolov4/dependencies/yolov4_anchors.txt -P ./utilities/\n",
" !wget https://github.com/onnx/models/raw/ma
in
/vision/object_detection_segmentation/yolov4/dependencies/yolov4_anchors.txt -P ./utilities/\n",
"if not os.path.exists(\"./utilities/input.jpg\"):\n",
" # The image used is from the COCO dataset (https://cocodataset.org/#explore)\n",
" # Other images can be tested by replacing the link below\n",
" image_link = \"https://farm3.staticflickr.com/2009/2306189268_88cc86b30f_z.jpg\"\n",
" !wget -O ./utilities/input.jpg $image_link\n",
"if not os.path.exists(\"./utilities/yolov4.onnx\"):\n",
" !wget https://github.com/onnx/models/raw/ma
ster
/vision/object_detection_segmentation/yolov4/model/yolov4.onnx -P ./utilities/"
" !wget https://github.com/onnx/models/raw/ma
in
/vision/object_detection_segmentation/yolov4/model/yolov4.onnx -P ./utilities/"
]
},
{
...
...
src/propagate_constant.cpp
View file @
e9885eb3
...
...
@@ -3,6 +3,7 @@
#include <migraphx/matcher.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/functional.hpp>
#include <migraphx/par_for.hpp>
#include <unordered_set>
namespace
migraphx
{
...
...
@@ -20,33 +21,42 @@ bool skip_propogate(instruction_ref ins)
return
false
;
}
bool
is_const
(
instruction_ref
ins
)
{
return
ins
->
can_eval
()
and
not
skip_propogate
(
ins
);
}
void
propagate_constant
::
apply
(
module
&
m
)
const
{
std
::
unordered_set
<
instruction_ref
>
const_instrs
;
auto
last
=
std
::
prev
(
m
.
end
());
// Find instructions that can be evaluated to a literal
for
(
auto
i
:
iterator_for
(
m
))
{
if
(
i
->
name
()
!=
"@literal"
)
continue
;
if
(
i
->
outputs
().
empty
())
continue
;
fix
([
&
](
auto
self
,
auto
ins
)
{
std
::
unordered_set
<
instruction_ref
>
children
(
ins
->
outputs
().
begin
(),
ins
->
outputs
().
end
());
for
(
auto
child
:
children
)
{
if
(
child
->
name
()
==
"@literal"
or
skip_propogate
(
child
))
{
self
(
child
);
if
(
is_const
(
i
)
and
i
!=
last
)
continue
;
std
::
copy_if
(
i
->
inputs
().
begin
(),
i
->
inputs
().
end
(),
std
::
inserter
(
const_instrs
,
const_instrs
.
begin
()),
[
&
](
const
instruction_ref
ins
)
{
return
is_const
(
ins
)
and
ins
->
name
()
!=
"@literal"
;
});
}
auto
r
=
child
->
eval
();
if
(
not
r
.
empty
())
// Compute literals in parallel
std
::
vector
<
instruction_ref
>
const_instrs_vec
{
const_instrs
.
begin
(),
const_instrs
.
end
()};
std
::
vector
<
argument
>
literals
(
const_instrs_vec
.
size
());
par_for
(
const_instrs_vec
.
size
(),
1
,
[
&
](
const
auto
i
)
{
literals
[
i
]
=
const_instrs_vec
[
i
]
->
eval
();
});
// Replace instructions in m
for
(
size_t
i
=
0
;
i
<
const_instrs_vec
.
size
();
i
++
)
{
assert
(
r
.
get_shape
()
==
child
->
get_shape
());
auto
l
=
m
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
self
(
m
.
replace_instruction
(
child
,
l
));
}
if
(
not
literals
[
i
].
empty
())
{
assert
(
literals
[
i
].
get_shape
()
==
const_instrs_vec
[
i
]
->
get_shape
());
auto
l
=
m
.
add_literal
(
literals
[
i
].
get_shape
(),
literals
[
i
].
data
());
m
.
replace_instruction
(
const_instrs_vec
[
i
],
l
);
}
})(
i
);
}
}
...
...
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