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
32815c2e
Commit
32815c2e
authored
Jul 05, 2019
by
Shucai Xiao
Browse files
add test cases for operator in the bert model
parent
24a6fec2
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
162 additions
and
11 deletions
+162
-11
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+31
-9
src/targets/gpu/device/pow.cpp
src/targets/gpu/device/pow.cpp
+2
-2
src/targets/gpu/device/reduce_sum.cpp
src/targets/gpu/device/reduce_sum.cpp
+1
-0
test/onnx/cast_test.onnx
test/onnx/cast_test.onnx
+15
-0
test/onnx/const_of_shape1.onnx
test/onnx/const_of_shape1.onnx
+0
-0
test/onnx/const_of_shape2.onnx
test/onnx/const_of_shape2.onnx
+12
-0
test/onnx/const_of_shape3.onnx
test/onnx/const_of_shape3.onnx
+10
-0
test/onnx/const_of_shape4.onnx
test/onnx/const_of_shape4.onnx
+0
-0
test/onnx/expand_test.onnx
test/onnx/expand_test.onnx
+17
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+74
-0
No files found.
src/onnx/onnx.cpp
View file @
32815c2e
...
...
@@ -545,6 +545,12 @@ struct onnx_parser
const
std
::
vector
<
instruction_ref
>&
)
{
literal
v
=
parse_value
(
attributes
.
at
(
"value"
));
// return empty literal
if
(
v
.
get_shape
().
elements
()
==
0
)
{
return
prog
.
add_literal
(
literal
{});
}
auto
dim_size
=
attributes
.
at
(
"value"
).
t
().
dims_size
();
// if dim_size is 0, it is a scalar
if
(
dim_size
==
0
)
...
...
@@ -923,21 +929,31 @@ struct onnx_parser
// input is empty, output is a scalar
auto
type
=
l_val
.
get_shape
().
type
();
if
(
args
.
size
()
==
0
)
{
return
prog
.
add_literal
(
literal
({
type
,
{
1
},
{
0
}},
l_val
.
data
()));
MIGRAPHX_THROW
(
"Parse ConstantOfShape : must have 1 input!"
);
}
else
{
migraphx
::
shape
s
;
// empty input tensor, output is a scalar
if
(
args
[
0
]
->
get_shape
().
elements
()
==
0
)
{
s
=
migraphx
::
shape
{
type
,
{
1
},
{
0
}};
}
else
{
migraphx
::
argument
in
=
args
[
0
]
->
eval
();
if
(
in
.
empty
())
{
MIGRAPHX_THROW
(
"ConstantOfShape: cannot handle dynamic shape as input"
);
MIGRAPHX_THROW
(
"
Parse
ConstantOfShape: cannot handle dynamic shape as input"
);
}
std
::
vector
<
std
::
size_t
>
dims
;
in
.
visit
([
&
](
auto
input
)
{
dims
.
assign
(
input
.
begin
(),
input
.
end
());
});
migraphx
::
shape
s
(
type
,
dims
);
s
=
migraphx
::
shape
{
type
,
dims
};
}
literal
l_out
;
l_val
.
visit
([
&
](
auto
val
)
{
...
...
@@ -955,8 +971,14 @@ struct onnx_parser
parse_expand
(
const
std
::
string
&
,
attribute_map
,
std
::
vector
<
instruction_ref
>
args
)
{
auto
in_lens
=
args
[
0
]
->
get_shape
().
lens
();
auto
ex_lens
=
args
[
1
]
->
get_shape
().
lens
();
auto
out_lens
=
compute_broadcasted_lens
(
in_lens
,
ex_lens
);
migraphx
::
argument
arg_s
=
args
[
1
]
->
eval
();
if
(
arg_s
.
empty
())
{
MIGRAPHX_THROW
(
"Parse Expand: cannot handle dynamic shape as input"
);
}
std
::
vector
<
std
::
size_t
>
dims
;
arg_s
.
visit
([
&
](
auto
input
)
{
dims
.
assign
(
input
.
begin
(),
input
.
end
());
});
auto
out_lens
=
compute_broadcasted_lens
(
in_lens
,
dims
);
return
prog
.
add_instruction
(
op
::
multibroadcast
{
out_lens
},
std
::
move
(
args
[
0
]));
}
...
...
src/targets/gpu/device/pow.cpp
View file @
32815c2e
...
...
@@ -6,10 +6,10 @@ inline namespace MIGRAPHX_INLINE_NS {
namespace
gpu
{
namespace
device
{
void
pow
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
2
,
const
argument
&
arg
1
)
void
pow
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
1
,
const
argument
&
arg
2
)
{
nary
(
stream
,
result
,
arg1
,
arg2
)(
[](
auto
x
,
auto
y
)
{
return
::
pow
(
to_hip_type
(
x
),
to_hip_type
(
y
));
});
[](
auto
e
,
auto
b
)
{
return
::
pow
(
to_hip_type
(
b
),
to_hip_type
(
e
));
});
}
}
// namespace device
...
...
src/targets/gpu/device/reduce_sum.cpp
View file @
32815c2e
...
...
@@ -8,6 +8,7 @@ namespace device {
void
reduce_sum
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
)
{
reduce
(
stream
,
result
,
arg
,
sum
{},
0
,
id
{},
id
{});
}
...
...
test/onnx/cast_test.onnx
0 → 100644
View file @
32815c2e
cast-example:F
xy"Cast*
to test_castZ
x
b
y
B
test/onnx/const_of_shape1.onnx
0 → 100644
View file @
32815c2e
File added
test/onnx/const_of_shape2.onnx
0 → 100644
View file @
32815c2e
constant-of-shape:
6shape"Constant*#
value**Bshape_tensor
7
shapey"ConstantOfShape*
value*:
Bvalue constant_of_shapeb
y
B
test/onnx/const_of_shape3.onnx
0 → 100644
View file @
32815c2e
constant-of-shape:
6shape"Constant*#
value**Bshape_tensor
shapey"ConstantOfShapeconstant_of_shapeb
y
B
test/onnx/const_of_shape4.onnx
0 → 100644
View file @
32815c2e
File added
test/onnx/expand_test.onnx
0 → 100644
View file @
32815c2e
expand:
7shape"Constant*$
value**Bshape_tensor
x
shapey"ExpandexpandZ
x
b
y
B
test/onnx/onnx_test.cpp
View file @
32815c2e
...
...
@@ -884,4 +884,78 @@ TEST_CASE(pow_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
cast_test
)
{
migraphx
::
program
p
;
auto
l
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
half_type
,
{
10
}});
p
.
add_instruction
(
migraphx
::
op
::
convert
{
migraphx
::
shape
::
float_type
},
l
);
auto
prog
=
migraphx
::
parse_onnx
(
"cast_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
const_of_shape1
)
{
migraphx
::
program
p
;
migraphx
::
shape
ss
(
migraphx
::
shape
::
int32_type
,
{
3
});
p
.
add_literal
(
migraphx
::
literal
(
ss
,
{
2
,
3
,
4
}));
migraphx
::
shape
s
(
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
});
std
::
vector
<
float
>
vec
(
s
.
elements
(),
10.0
f
);
p
.
add_literal
(
migraphx
::
literal
(
s
,
vec
));
auto
prog
=
migraphx
::
parse_onnx
(
"const_of_shape1.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
const_of_shape2
)
{
migraphx
::
program
p
;
migraphx
::
shape
ss
(
migraphx
::
shape
::
int32_type
,
{
3
});
p
.
add_literal
(
migraphx
::
literal
(
ss
,
{
2
,
3
,
4
}));
migraphx
::
shape
s
(
migraphx
::
shape
::
int64_type
,
{
2
,
3
,
4
});
std
::
vector
<
int64_t
>
vec
(
s
.
elements
(),
10.0
f
);
p
.
add_literal
(
migraphx
::
literal
(
s
,
vec
));
auto
prog
=
migraphx
::
parse_onnx
(
"const_of_shape2.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
const_of_shape3
)
{
migraphx
::
program
p
;
migraphx
::
shape
ss
(
migraphx
::
shape
::
int32_type
,
{
3
});
p
.
add_literal
(
migraphx
::
literal
(
ss
,
{
2
,
3
,
4
}));
migraphx
::
shape
s
(
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
});
std
::
vector
<
float
>
vec
(
s
.
elements
(),
0.0
f
);
p
.
add_literal
(
migraphx
::
literal
(
s
,
vec
));
auto
prog
=
migraphx
::
parse_onnx
(
"const_of_shape3.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
const_of_shape4
)
{
migraphx
::
program
p
;
p
.
add_literal
(
migraphx
::
literal
());
migraphx
::
shape
s
(
migraphx
::
shape
::
int64_type
,
{
1
},
{
0
});
std
::
vector
<
int64_t
>
vec
(
s
.
elements
(),
10
);
p
.
add_literal
(
migraphx
::
literal
(
s
,
vec
));
auto
prog
=
migraphx
::
parse_onnx
(
"const_of_shape4.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
expand_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
(
migraphx
::
shape
::
float_type
,
{
3
,
1
,
1
});
auto
param
=
p
.
add_parameter
(
"x"
,
s
);
migraphx
::
shape
ss
(
migraphx
::
shape
::
int32_type
,
{
4
});
p
.
add_literal
(
migraphx
::
literal
(
ss
,
{
2
,
3
,
4
,
5
}));
p
.
add_instruction
(
migraphx
::
op
::
multibroadcast
{{
2
,
3
,
4
,
5
}},
param
);
auto
prog
=
migraphx
::
parse_onnx
(
"expand_test.onnx"
);
EXPECT
(
p
==
prog
);
}
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