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
7c453f85
Commit
7c453f85
authored
Oct 22, 2018
by
Khalique
Browse files
added leaky_relu.onnx file, added test for parsing onnx
parent
ade3a03c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
4 deletions
+57
-4
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+14
-0
src/targets/gpu/leaky_relu.cpp
src/targets/gpu/leaky_relu.cpp
+2
-2
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+2
-2
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+12
-0
test/onnx/leaky_relu.onnx
test/onnx/leaky_relu.onnx
+14
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+13
-0
No files found.
src/onnx/onnx.cpp
View file @
7c453f85
...
...
@@ -56,6 +56,7 @@ struct onnx_parser
add_generic_op
(
"Sub"
,
op
::
sub
{});
add_generic_op
(
"Sum"
,
op
::
add
{});
add_mem_op
(
"LeakyRelu"
,
&
onnx_parser
::
parse_leaky_relu
);
add_mem_op
(
"Constant"
,
&
onnx_parser
::
parse_constant
);
add_mem_op
(
"Conv"
,
&
onnx_parser
::
parse_conv
);
add_mem_op
(
"MaxPool"
,
&
onnx_parser
::
parse_pooling
);
...
...
@@ -260,6 +261,19 @@ struct onnx_parser
return
prog
.
add_instruction
(
op
,
std
::
move
(
args
));
}
instruction_ref
parse_leaky_relu
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
float
alpha
=
0.01
;
if
(
contains
(
attributes
,
"alpha"
))
{
alpha
=
parse_value
(
attributes
.
at
(
"alpha"
)).
at
<
float
>
();
}
op
::
leaky_relu
op
{
alpha
};
return
prog
.
add_instruction
(
op
,
args
.
front
());
}
void
parse_from
(
std
::
istream
&
is
)
{
onnx
::
ModelProto
model
;
...
...
src/targets/gpu/leaky_relu.cpp
View file @
7c453f85
...
...
@@ -14,8 +14,8 @@ shape miopen_leaky_relu::compute_shape(const std::vector<shape>& inputs) const
}
argument
miopen_leaky_relu
::
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
float
alpha
=
1
,
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
...
...
src/targets/gpu/lowering.cpp
View file @
7c453f85
...
...
@@ -129,12 +129,12 @@ struct miopen_apply
}
return
ins
;
}
instruction_ref
apply_leaky_relu
(
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
leaky_relu
>
(
ins
->
get_operator
());
auto
ad
=
make_leaky_relu
(
op
.
alpha
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_leaky_relu
{
std
::
move
(
ad
)},
ins
->
inputs
().
at
(
0
),
output
);
...
...
test/gpu/miopen.cpp
View file @
7c453f85
...
...
@@ -368,6 +368,17 @@ struct test_add_relu
}
};
struct
test_leaky_relu
{
migraph
::
program
create_program
()
const
{
migraph
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
p
.
add_instruction
(
migraph
::
op
::
leaky_relu
{
0.01
},
x
);
return
p
;
}
};
struct
test_conv_pooling
{
migraph
::
program
create_program
()
const
...
...
@@ -619,6 +630,7 @@ int main()
verify_program
<
test_conv2
>
();
verify_program
<
test_conv_relu
>
();
verify_program
<
test_add_relu
>
();
verify_program
<
test_leaky_relu
>
();
verify_program
<
test_conv_pooling
>
();
verify_program
<
test_gemm
>
();
// verify_program<test_gemm_ld>();
...
...
test/onnx/leaky_relu.onnx
0 → 100644
View file @
7c453f85
leaky_relu-example:R
"
01" LeakyRelu*
alpha
#<
test-modelZ
0
b
1
B
\ No newline at end of file
test/onnx/onnx_test.cpp
View file @
7c453f85
...
...
@@ -88,10 +88,23 @@ void pytorch_conv_relu_maxpool_x2()
EXPECT
(
p
==
prog
);
}
void
leaky_relu_test
()
{
migraph
::
program
p
;
float
alpha
=
0.01
f
;
auto
l0
=
p
.
add_parameter
(
"0"
,
{
migraph
::
shape
::
float_type
,
{
3
}});
p
.
add_instruction
(
migraph
::
op
::
leaky_relu
{
alpha
},
l0
);
auto
prog
=
migraph
::
parse_onnx
(
"leaky_relu.onnx"
);
EXPECT
(
p
==
prog
);
}
int
main
()
{
pytorch_conv_bias_test
();
pytorch_conv_relu_maxpool
();
pytorch_conv_bn_relu_maxpool
();
pytorch_conv_relu_maxpool_x2
();
leaky_relu_test
();
}
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