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
08ac24cf
Commit
08ac24cf
authored
Feb 07, 2022
by
Khalique Ahmed
Browse files
Merge branch 'develop' of
https://github.com/ROCmSoftwarePlatform/AMDMIGraphX
into rocblas_api_opt
parents
96c82f21
b20e3d4d
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
318 additions
and
232 deletions
+318
-232
.github/workflows/ci.yaml
.github/workflows/ci.yaml
+4
-2
src/include/migraphx/iota_iterator.hpp
src/include/migraphx/iota_iterator.hpp
+7
-0
src/onnx/parse_resize.cpp
src/onnx/parse_resize.cpp
+11
-7
src/onnx/parse_upsample.cpp
src/onnx/parse_upsample.cpp
+0
-86
src/program.cpp
src/program.cpp
+72
-2
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+19
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+14
-1
test/onnx/upsample_linear_test.onnx
test/onnx/upsample_linear_test.onnx
+0
-0
tools/api.py
tools/api.py
+182
-132
tools/generate.sh
tools/generate.sh
+9
-2
No files found.
.github/workflows/ci.yaml
View file @
08ac24cf
...
@@ -142,10 +142,12 @@ jobs:
...
@@ -142,10 +142,12 @@ jobs:
with
:
with
:
python-version
:
3.6
python-version
:
3.6
-
name
:
Install pyflakes
-
name
:
Install pyflakes
run
:
pip install pyflakes==2.3.1
run
:
pip install pyflakes==2.3.1
mypy==0.931
-
name
:
Run pyflakes
-
name
:
Run pyflakes
run
:
pyflakes examples/ tools/ src/ test/ doc/
run
:
|
pyflakes examples/ tools/ src/ test/ doc/
mypy tools/api.py
linux
:
linux
:
...
...
src/include/migraphx/iota_iterator.hpp
View file @
08ac24cf
...
@@ -89,6 +89,13 @@ inline std::ptrdiff_t operator-(basic_iota_iterator<F, Iterator> x,
...
@@ -89,6 +89,13 @@ inline std::ptrdiff_t operator-(basic_iota_iterator<F, Iterator> x,
return
x
.
index
-
y
.
index
;
return
x
.
index
-
y
.
index
;
}
}
template
<
class
F
,
class
Iterator
>
inline
basic_iota_iterator
<
F
,
Iterator
>
operator
-
(
basic_iota_iterator
<
F
,
Iterator
>
x
,
std
::
ptrdiff_t
y
)
{
return
x
-=
y
;
}
template
<
class
F
,
class
Iterator
>
template
<
class
F
,
class
Iterator
>
inline
bool
operator
==
(
basic_iota_iterator
<
F
,
Iterator
>
x
,
basic_iota_iterator
<
F
,
Iterator
>
y
)
inline
bool
operator
==
(
basic_iota_iterator
<
F
,
Iterator
>
x
,
basic_iota_iterator
<
F
,
Iterator
>
y
)
{
{
...
...
src/onnx/parse_resize.cpp
View file @
08ac24cf
...
@@ -163,9 +163,9 @@ static std::string get_nearest_mode(const onnx_parser::attribute_map& attr)
...
@@ -163,9 +163,9 @@ static std::string get_nearest_mode(const onnx_parser::attribute_map& attr)
struct
parse_resize
:
op_parser
<
parse_resize
>
struct
parse_resize
:
op_parser
<
parse_resize
>
{
{
std
::
vector
<
op_desc
>
operators
()
const
{
return
{{
"Resize"
}};
}
std
::
vector
<
op_desc
>
operators
()
const
{
return
{{
"Resize"
}
,
{
"Upsample"
}
};
}
instruction_ref
parse
(
const
op_desc
&
/*
opd
*/
,
instruction_ref
parse
(
const
op_desc
&
opd
,
const
onnx_parser
&
/*parser*/
,
const
onnx_parser
&
/*parser*/
,
onnx_parser
::
node_info
info
,
onnx_parser
::
node_info
info
,
std
::
vector
<
instruction_ref
>
args
)
const
std
::
vector
<
instruction_ref
>
args
)
const
...
@@ -183,7 +183,7 @@ struct parse_resize : op_parser<parse_resize>
...
@@ -183,7 +183,7 @@ struct parse_resize : op_parser<parse_resize>
if
(
contains
(
info
.
attributes
,
"exclude_outside"
)
and
if
(
contains
(
info
.
attributes
,
"exclude_outside"
)
and
info
.
attributes
.
at
(
"exclude_outside"
).
i
()
==
1
)
info
.
attributes
.
at
(
"exclude_outside"
).
i
()
==
1
)
{
{
MIGRAPHX_THROW
(
"PARSE_
RESIZE
: exclude_outside 1 is not supported!"
);
MIGRAPHX_THROW
(
"PARSE_
"
+
opd
.
op_name
+
"
: exclude_outside 1 is not supported!"
);
}
}
// input data shape info
// input data shape info
...
@@ -215,12 +215,14 @@ struct parse_resize : op_parser<parse_resize>
...
@@ -215,12 +215,14 @@ struct parse_resize : op_parser<parse_resize>
if
(
type
==
shape
::
int64_type
)
if
(
type
==
shape
::
int64_type
)
{
{
auto
arg_out_s
=
arg
->
eval
();
auto
arg_out_s
=
arg
->
eval
();
check_arg_empty
(
arg_out_s
,
"PARSE_RESIZE: dynamic output size is not supported!"
);
check_arg_empty
(
arg_out_s
,
"PARSE_"
+
opd
.
op_name
+
": dynamic output size is not supported!"
);
arg_out_s
.
visit
([
&
](
auto
ol
)
{
out_lens
.
assign
(
ol
.
begin
(),
ol
.
end
());
});
arg_out_s
.
visit
([
&
](
auto
ol
)
{
out_lens
.
assign
(
ol
.
begin
(),
ol
.
end
());
});
if
(
out_lens
.
size
()
!=
in_lens
.
size
())
if
(
out_lens
.
size
()
!=
in_lens
.
size
())
{
{
MIGRAPHX_THROW
(
"PARSE_RESIZE: specified output size does not match input size"
);
MIGRAPHX_THROW
(
"PARSE_"
+
opd
.
op_name
+
": specified output size does not match input size"
);
}
}
// compute the scale
// compute the scale
...
@@ -239,12 +241,14 @@ struct parse_resize : op_parser<parse_resize>
...
@@ -239,12 +241,14 @@ struct parse_resize : op_parser<parse_resize>
{
{
auto
arg_scale
=
arg
->
eval
();
auto
arg_scale
=
arg
->
eval
();
check_arg_empty
(
arg_scale
,
check_arg_empty
(
arg_scale
,
"PARSE_RESIZE: dynamic input scale is not supported!"
);
"PARSE_"
+
opd
.
op_name
+
": dynamic input scale is not supported!"
);
arg_scale
.
visit
([
&
](
auto
v
)
{
vec_scale
.
assign
(
v
.
begin
(),
v
.
end
());
});
arg_scale
.
visit
([
&
](
auto
v
)
{
vec_scale
.
assign
(
v
.
begin
(),
v
.
end
());
});
if
(
in_lens
.
size
()
!=
vec_scale
.
size
())
if
(
in_lens
.
size
()
!=
vec_scale
.
size
())
{
{
MIGRAPHX_THROW
(
"PARSE_RESIZE: ranks of input and scale are different!"
);
MIGRAPHX_THROW
(
"PARSE_"
+
opd
.
op_name
+
": ranks of input and scale are different!"
);
}
}
std
::
transform
(
in_lens
.
begin
(),
std
::
transform
(
in_lens
.
begin
(),
...
...
src/onnx/parse_upsample.cpp
deleted
100644 → 0
View file @
96c82f21
#include <migraphx/onnx/op_parser.hpp>
#include <migraphx/onnx/checks.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/make_op.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
onnx
{
struct
parse_upsample
:
op_parser
<
parse_upsample
>
{
std
::
vector
<
op_desc
>
operators
()
const
{
return
{{
"Upsample"
}};
}
instruction_ref
parse
(
const
op_desc
&
/*opd*/
,
const
onnx_parser
&
/*parser*/
,
onnx_parser
::
node_info
info
,
std
::
vector
<
instruction_ref
>
args
)
const
{
if
(
contains
(
info
.
attributes
,
"mode"
))
{
auto
mode
=
info
.
attributes
.
at
(
"mode"
).
s
();
if
(
mode
!=
"nearest"
)
{
MIGRAPHX_THROW
(
"PARSE_UPSAMPLE: only nearest mode is supported!"
);
}
}
auto
arg_scale
=
args
[
1
]
->
eval
();
check_arg_empty
(
arg_scale
,
"PARSE_UPSAMPLE: only constant scale is supported!"
);
std
::
vector
<
float
>
vec_scale
;
arg_scale
.
visit
([
&
](
auto
v
)
{
vec_scale
.
assign
(
v
.
begin
(),
v
.
end
());
});
auto
in_s
=
args
[
0
]
->
get_shape
();
auto
in_lens
=
in_s
.
lens
();
if
(
in_lens
.
size
()
!=
vec_scale
.
size
())
{
MIGRAPHX_THROW
(
"PARSE_UPSAMPLE: ranks of input and scale are different!"
);
}
std
::
vector
<
std
::
size_t
>
out_lens
(
in_lens
.
size
());
std
::
transform
(
in_lens
.
begin
(),
in_lens
.
end
(),
vec_scale
.
begin
(),
out_lens
.
begin
(),
[
&
](
auto
idx
,
auto
scale
)
{
return
static_cast
<
std
::
size_t
>
(
idx
*
scale
);
});
std
::
vector
<
float
>
idx_scale
(
in_lens
.
size
());
std
::
transform
(
out_lens
.
begin
(),
out_lens
.
end
(),
in_lens
.
begin
(),
idx_scale
.
begin
(),
[](
auto
od
,
auto
id
)
{
return
(
od
==
id
)
?
1.0
f
:
(
id
-
1.0
f
)
/
(
od
-
1.0
f
);
});
shape
out_s
{
in_s
.
type
(),
out_lens
};
std
::
vector
<
int
>
ind
(
out_s
.
elements
());
// map out_idx to in_idx
shape_for_each
(
out_s
,
[
&
](
auto
idx
)
{
auto
in_idx
=
idx
;
std
::
transform
(
idx
.
begin
(),
idx
.
end
(),
idx_scale
.
begin
(),
in_idx
.
begin
(),
// nearest mode
[](
auto
index
,
auto
scale
)
{
return
static_cast
<
std
::
size_t
>
(
std
::
round
(
index
*
scale
));
});
ind
[
out_s
.
index
(
idx
)]
=
static_cast
<
int64_t
>
(
in_s
.
index
(
in_idx
));
});
// reshape input to one-dimension
std
::
vector
<
int64_t
>
rsp_lens
=
{
static_cast
<
int64_t
>
(
in_s
.
elements
())};
shape
ind_s
{
shape
::
int32_type
,
out_lens
};
auto
rsp
=
info
.
add_instruction
(
make_op
(
"reshape"
,
{{
"dims"
,
rsp_lens
}}),
args
[
0
]);
auto
ins_ind
=
info
.
add_literal
(
literal
(
ind_s
,
ind
));
return
info
.
add_instruction
(
make_op
(
"gather"
,
{{
"axis"
,
0
}}),
rsp
,
ins_ind
);
}
};
}
// namespace onnx
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/program.cpp
View file @
08ac24cf
...
@@ -180,6 +180,63 @@ void program::finalize()
...
@@ -180,6 +180,63 @@ void program::finalize()
mm
->
finalize
(
this
->
impl
->
ctx
);
mm
->
finalize
(
this
->
impl
->
ctx
);
}
}
template
<
class
T
>
std
::
string
classify
(
T
x
)
{
switch
(
std
::
fpclassify
(
x
))
{
case
FP_INFINITE
:
return
"inf"
;
case
FP_NAN
:
return
"nan"
;
case
FP_NORMAL
:
return
"normal"
;
case
FP_SUBNORMAL
:
return
"subnormal"
;
case
FP_ZERO
:
return
"zero"
;
default:
return
"unknown"
;
}
}
std
::
unordered_set
<
std
::
string
>
classify_argument
(
const
argument
&
a
)
{
std
::
unordered_set
<
std
::
string
>
result
;
a
.
visit
(
[
&
](
auto
t
)
{
for
(
const
auto
&
x
:
t
)
result
.
insert
(
classify
(
x
));
},
[
&
](
const
auto
&
xs
)
{
for
(
const
auto
&
x
:
xs
)
{
auto
r
=
classify_argument
(
x
);
result
.
insert
(
r
.
begin
(),
r
.
end
());
}
});
return
result
;
}
void
preview_argument
(
std
::
ostream
&
os
,
const
argument
&
a
)
{
a
.
visit
(
[
&
](
auto
t
)
{
if
(
t
.
size
()
<=
10
)
{
os
<<
t
;
}
else
{
os
<<
to_string_range
(
t
.
begin
(),
t
.
begin
()
+
5
);
os
<<
", ..., "
;
os
<<
to_string_range
(
t
.
end
()
-
5
,
t
.
end
());
}
},
[
&
](
const
auto
&
xs
)
{
for
(
const
auto
&
x
:
xs
)
{
os
<<
'{'
;
preview_argument
(
os
,
x
);
os
<<
'}'
;
}
});
}
template
<
class
F
>
template
<
class
F
>
std
::
vector
<
argument
>
generic_eval
(
const
module
*
mod
,
std
::
vector
<
argument
>
generic_eval
(
const
module
*
mod
,
context
&
ctx
,
context
&
ctx
,
...
@@ -313,7 +370,20 @@ std::vector<argument> program::eval(parameter_map params) const
...
@@ -313,7 +370,20 @@ std::vector<argument> program::eval(parameter_map params) const
ins
->
name
()
!=
"load"
and
not
result
.
empty
())
ins
->
name
()
!=
"load"
and
not
result
.
empty
())
{
{
target
tgt
=
make_target
(
this
->
impl
->
target_name
);
target
tgt
=
make_target
(
this
->
impl
->
target_name
);
std
::
cout
<<
"Output: "
<<
tgt
.
copy_from
(
result
)
<<
std
::
endl
;
auto
buffer
=
tgt
.
copy_from
(
result
);
if
(
trace_level
==
2
)
{
std
::
cout
<<
"Output has "
<<
to_string_range
(
classify_argument
(
buffer
))
<<
std
::
endl
;
std
::
cout
<<
"Output: "
;
preview_argument
(
std
::
cout
,
buffer
);
std
::
cout
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Output: "
<<
buffer
<<
std
::
endl
;
}
}
}
return
result
;
return
result
;
}));
}));
...
...
test/onnx/gen_onnx.py
View file @
08ac24cf
...
@@ -5074,6 +5074,25 @@ def unknown_aten_test():
...
@@ -5074,6 +5074,25 @@ def unknown_aten_test():
return
([
node
],
[
x
,
y
],
[
a
])
return
([
node
],
[
x
,
y
],
[
a
])
@
onnx_test
def
upsample_linear_test
():
scales
=
np
.
array
([
1.0
,
1.0
,
2.0
,
2.0
],
dtype
=
np
.
float32
)
scales_tensor
=
helper
.
make_tensor
(
name
=
'scales'
,
data_type
=
TensorProto
.
FLOAT
,
dims
=
scales
.
shape
,
vals
=
scales
.
flatten
().
astype
(
np
.
float32
))
X
=
helper
.
make_tensor_value_info
(
'X'
,
TensorProto
.
FLOAT
,
[
1
,
1
,
2
,
2
])
Y
=
helper
.
make_tensor_value_info
(
'Y'
,
TensorProto
.
FLOAT
,
[])
node
=
onnx
.
helper
.
make_node
(
'Upsample'
,
inputs
=
[
'X'
,
''
,
'scales'
],
outputs
=
[
'Y'
],
mode
=
'linear'
)
return
([
node
],
[
X
],
[
Y
],
[
scales_tensor
])
@
onnx_test
@
onnx_test
def
upsample_test
():
def
upsample_test
():
scales
=
np
.
array
([
1.0
,
1.0
,
2.0
,
3.0
],
dtype
=
np
.
float32
)
scales
=
np
.
array
([
1.0
,
1.0
,
2.0
,
3.0
],
dtype
=
np
.
float32
)
...
...
test/onnx/onnx_test.cpp
View file @
08ac24cf
...
@@ -3643,7 +3643,7 @@ TEST_CASE(resize_nonstd_input_test)
...
@@ -3643,7 +3643,7 @@ TEST_CASE(resize_nonstd_input_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
resiz
e_upsample_linear_
ac_test
)
static
auto
creat
e_upsample_linear_
prog
(
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
...
@@ -3734,6 +3734,12 @@ TEST_CASE(resize_upsample_linear_ac_test)
...
@@ -3734,6 +3734,12 @@ TEST_CASE(resize_upsample_linear_ac_test)
auto
add1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
mul1
,
slc10
);
auto
add1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
mul1
,
slc10
);
mm
->
add_return
({
add1
});
mm
->
add_return
({
add1
});
return
p
;
}
TEST_CASE
(
resize_upsample_linear_ac_test
)
{
auto
p
=
create_upsample_linear_prog
();
auto
prog
=
migraphx
::
parse_onnx
(
"resize_upsample_linear_ac_test.onnx"
);
auto
prog
=
migraphx
::
parse_onnx
(
"resize_upsample_linear_ac_test.onnx"
);
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
...
@@ -4753,6 +4759,13 @@ TEST_CASE(unknown_test_throw)
...
@@ -4753,6 +4759,13 @@ TEST_CASE(unknown_test_throw)
EXPECT
(
test
::
throws
([
&
]
{
migraphx
::
parse_onnx
(
"unknown_test.onnx"
);
}));
EXPECT
(
test
::
throws
([
&
]
{
migraphx
::
parse_onnx
(
"unknown_test.onnx"
);
}));
}
}
TEST_CASE
(
upsample_linear_test
)
{
auto
p
=
create_upsample_linear_prog
();
auto
prog
=
migraphx
::
parse_onnx
(
"upsample_linear_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
upsample_test
)
TEST_CASE
(
upsample_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/onnx/upsample_linear_test.onnx
0 → 100644
View file @
08ac24cf
File added
tools/api.py
View file @
08ac24cf
This diff is collapsed.
Click to expand it.
tools/generate.sh
View file @
08ac24cf
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
SRC_DIR
=
$DIR
/../src
SRC_DIR
=
$DIR
/../src
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"python3.6
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$SRC_DIR
/include/migraphx/{}"
PYTHON
=
python3
if
type
-p
python3.6
>
/dev/null
;
then
PYTHON
=
python3.6
fi
if
type
-p
python3.8
>
/dev/null
;
then
PYTHON
=
python3.8
fi
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"
$PYTHON
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$SRC_DIR
/include/migraphx/{}"
function
api
{
function
api
{
python3.6
$DIR
/api.py
$SRC_DIR
/api/migraphx.py
$1
| clang-format-5.0
-style
=
file
>
$2
$PYTHON
$DIR
/api.py
$SRC_DIR
/api/migraphx.py
$1
| clang-format-5.0
-style
=
file
>
$2
}
}
api
$DIR
/api/migraphx.h
$SRC_DIR
/api/include/migraphx/migraphx.h
api
$DIR
/api/migraphx.h
$SRC_DIR
/api/include/migraphx/migraphx.h
...
...
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