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
61566cb1
Commit
61566cb1
authored
Feb 01, 2019
by
Shucai Xiao
Browse files
add more test examples and found an issue with simplify_reshape(so disabled simplify_reshape.
parent
f13b32f2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
245 additions
and
17 deletions
+245
-17
src/rewrite_rnn.cpp
src/rewrite_rnn.cpp
+4
-7
src/simplify_reshapes.cpp
src/simplify_reshapes.cpp
+2
-1
src/targets/gpu/gemm.cpp
src/targets/gpu/gemm.cpp
+1
-0
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+3
-3
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+235
-6
No files found.
src/rewrite_rnn.cpp
View file @
61566cb1
...
...
@@ -26,8 +26,8 @@ void rewrite_rnn::apply(program& prog) const
std
::
size_t
hidden_size
=
args
[
1
]
->
get_shape
().
lens
()[
1
];
std
::
size_t
batch_size
=
seq_shape
.
lens
()[
1
];
shape
::
type_t
type
=
seq_shape
.
type
();
migraphx
::
shape
ih_shape
{
type
,
{
batch_size
,
hidden_size
}};
std
::
vector
<
char
>
data
(
ih_shape
.
byte
s
(),
0
);
migraphx
::
shape
ih_shape
{
type
,
{
1
,
batch_size
,
hidden_size
}};
std
::
vector
<
float
>
data
(
ih_shape
.
element
s
(),
0
);
auto
rnn_op
=
any_cast
<
op
::
rnn
>
(
ins
->
get_operator
());
op
::
rnn
::
rnn_direction_t
dicrt
=
rnn_op
.
direction
;
...
...
@@ -207,6 +207,7 @@ std::vector<instruction_ref> rewrite_rnn::rnn_cell(bool is_forward,
}
instruction_ref
hidden_out
=
prog
.
end
(),
last_out
;
last_out
=
prog
.
insert_instruction
(
ins
,
op
::
unsqueeze
{{
0
,
1
}},
sih
);
std
::
size_t
seq_len
=
input
->
get_shape
().
lens
()[
0
];
for
(
std
::
size_t
i
=
0
;
i
<
seq_len
;
i
++
)
{
...
...
@@ -256,11 +257,7 @@ std::vector<instruction_ref> rewrite_rnn::rnn_cell(bool is_forward,
}
}
std
::
vector
<
instruction_ref
>
out_args
;
out_args
.
push_back
(
hidden_out
);
out_args
.
push_back
(
last_out
);
return
out_args
;
return
{
hidden_out
,
last_out
};
}
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/simplify_reshapes.cpp
View file @
61566cb1
...
...
@@ -14,7 +14,8 @@ bool is_nonstandard_reshaper(instruction_ref ins)
{
// clang-format off
static
const
std
::
unordered_set
<
std
::
string
>
names
=
{
"reshape"
"reshape"
,
"contiguous"
};
// clang-format on
return
contains
(
names
,
ins
->
name
())
and
ins
->
inputs
().
front
()
->
name
()
==
"contiguous"
;
...
...
src/targets/gpu/gemm.cpp
View file @
61566cb1
...
...
@@ -107,6 +107,7 @@ argument miopen_gemm::compute(context& ctx,
ldc
);
});
return
args
[
2
];
}
...
...
src/targets/gpu/target.cpp
View file @
61566cb1
...
...
@@ -32,16 +32,16 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
dead_code_elimination
{},
fwd_conv_batchnorm_rewrite
{},
dead_code_elimination
{},
common_subexpression_elimination
{},
dead_code_elimination
{},
rewrite_rnn
{},
dead_code_elimination
{},
common_subexpression_elimination
{},
dead_code_elimination
{},
simplify_algebra
{},
dead_code_elimination
{},
constant_propagate
{},
dead_code_elimination
{},
auto_contiguous
{},
simplify_reshapes
{},
//
simplify_reshapes{},
dead_code_elimination
{},
lowering
{
ctx
},
eliminate_concat
{
concat_gpu_optimization
{}},
...
...
test/gpu/miopen.cpp
View file @
61566cb1
...
...
@@ -1054,7 +1054,7 @@ struct test_rnn_forward
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
2
;
std
::
size_t
seq_len
=
1
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
...
...
@@ -1062,16 +1062,56 @@ struct test_rnn_forward
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
auto
output
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
forward
,
clip
},
seq
,
w
,
r
,
bias
,
ih
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
output
);
return
p
;
}
};
struct
test_rnn_forward10
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
10
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
auto
output
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
...
...
@@ -1094,7 +1134,7 @@ struct test_rnn_reverse
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
2
;
std
::
size_t
seq_len
=
1
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
...
...
@@ -1102,16 +1142,54 @@ struct test_rnn_reverse
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
reverse
,
clip
},
seq
,
w
,
r
,
bias
,
ih
);
return
p
;
}
};
struct
test_rnn_reverse2
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
2
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
...
...
@@ -1127,12 +1205,116 @@ struct test_rnn_reverse
}
};
struct
test_rnn_3args
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
1
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
reverse
,
clip
},
seq
,
w
,
r
);
return
p
;
}
};
struct
test_rnn_4args
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
5
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
reverse
,
clip
},
seq
,
w
,
r
,
bias
);
return
p
;
}
};
struct
test_rnn_5args
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
10
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
output
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
forward
,
clip
},
seq
,
w
,
r
,
bias
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
output
);
return
p
;
}
};
struct
test_rnn_bidirectional
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
2
;
std
::
size_t
seq_len
=
1
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
2
;
...
...
@@ -1140,16 +1322,56 @@ struct test_rnn_bidirectional
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
auto
output
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn
::
bidirectional
,
clip
},
seq
,
w
,
r
,
bias
,
ih
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
output
);
return
p
;
}
};
struct
test_rnn_bidirectional10
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
10
;
std
::
size_t
hidden_size
=
4
;
std
::
size_t
input_size
=
3
;
std
::
size_t
num_dirct
=
2
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
seq_len
,
batch_size
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
2
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
batch_size
,
hidden_size
}};
auto
seq
=
p
.
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
p
.
add_parameter
(
"ih"
,
ih_shape
);
auto
output
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hidden_size
,
...
...
@@ -1227,6 +1449,13 @@ int main()
verify_program
<
test_gather
>
();
verify_program
<
test_gather_neg_axis
>
();
verify_program
<
test_rnn_forward
>
();
verify_program
<
test_rnn_forward10
>
();
verify_program
<
test_rnn_reverse
>
();
verify_program
<
test_rnn_reverse2
>
();
verify_program
<
test_rnn_3args
>
();
verify_program
<
test_rnn_4args
>
();
verify_program
<
test_rnn_5args
>
();
verify_program
<
test_rnn_bidirectional
>
();
verify_program
<
test_rnn_bidirectional10
>
();
}
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