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
20b6c15c
Unverified
Commit
20b6c15c
authored
Aug 26, 2019
by
mvermeulen
Committed by
GitHub
Aug 26, 2019
Browse files
Merge branch 'develop' into multiply-add
parents
6bc31506
62cb3441
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
221 additions
and
35 deletions
+221
-35
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+30
-7
src/quantization.cpp
src/quantization.cpp
+2
-1
src/tf/tf.cpp
src/tf/tf.cpp
+89
-12
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+27
-0
test/onnx/transpose_gather.onnx
test/onnx/transpose_gather.onnx
+0
-0
test/tf/assert_less_equal_test.pb
test/tf/assert_less_equal_test.pb
+0
-0
test/tf/onehot_test.pb
test/tf/onehot_test.pb
+0
-0
test/tf/stridedslice_masks_test.pb
test/tf/stridedslice_masks_test.pb
+0
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+73
-15
No files found.
src/onnx/onnx.cpp
View file @
20b6c15c
...
@@ -206,6 +206,16 @@ struct onnx_parser
...
@@ -206,6 +206,16 @@ struct onnx_parser
return
out_lens
;
return
out_lens
;
}
}
instruction_ref
make_contiguous
(
instruction_ref
ins
)
{
if
(
ins
->
get_shape
().
standard
())
{
return
ins
;
}
return
prog
.
add_instruction
(
op
::
contiguous
{},
ins
);
}
template
<
class
T
>
template
<
class
T
>
instruction_ref
add_broadcastable_binary_op
(
instruction_ref
arg0
,
instruction_ref
arg1
,
T
x
)
instruction_ref
add_broadcastable_binary_op
(
instruction_ref
arg0
,
instruction_ref
arg1
,
T
x
)
{
{
...
@@ -437,12 +447,7 @@ struct onnx_parser
...
@@ -437,12 +447,7 @@ struct onnx_parser
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
dims
));
});
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
dims
));
});
}
}
if
(
!
args
[
0
]
->
get_shape
().
standard
())
return
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]));
{
args
[
0
]
=
prog
.
add_instruction
(
op
::
contiguous
{},
args
[
0
]);
}
return
prog
.
add_instruction
(
op
,
args
[
0
]);
}
}
instruction_ref
instruction_ref
...
@@ -490,23 +495,41 @@ struct onnx_parser
...
@@ -490,23 +495,41 @@ struct onnx_parser
{
{
axis
=
parse_value
(
attributes
.
at
(
"axis"
)).
at
<
int
>
();
axis
=
parse_value
(
attributes
.
at
(
"axis"
)).
at
<
int
>
();
}
}
op
::
gather
op
{
axis
};
op
::
gather
op
{
axis
};
return
prog
.
add_instruction
(
op
,
std
::
move
(
args
));
return
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]),
make_contiguous
(
args
[
1
]
));
}
}
instruction_ref
instruction_ref
parse_slice
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
parse_slice
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
{
op
::
slice
op
;
op
::
slice
op
;
std
::
vector
<
size_t
>
dims
=
args
[
0
]
->
get_shape
().
lens
();
size_t
num_dims
=
dims
.
size
();
if
(
contains
(
attributes
,
"axes"
))
if
(
contains
(
attributes
,
"axes"
))
{
{
literal
s
=
parse_value
(
attributes
.
at
(
"axes"
));
literal
s
=
parse_value
(
attributes
.
at
(
"axes"
));
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
axes
));
});
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
axes
));
});
}
}
else
{
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_dims
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
}
if
(
contains
(
attributes
,
"ends"
))
{
{
literal
s
=
parse_value
(
attributes
.
at
(
"ends"
));
literal
s
=
parse_value
(
attributes
.
at
(
"ends"
));
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
ends
));
});
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
ends
));
});
for
(
size_t
i
=
0
;
i
<
num_dims
;
i
++
)
{
if
(
static_cast
<
size_t
>
(
op
.
ends
[
i
])
>
dims
[
i
])
{
op
.
ends
[
i
]
=
dims
[
i
];
}
}
}
}
if
(
contains
(
attributes
,
"starts"
))
{
{
literal
s
=
parse_value
(
attributes
.
at
(
"starts"
));
literal
s
=
parse_value
(
attributes
.
at
(
"starts"
));
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
starts
));
});
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
starts
));
});
...
...
src/quantization.cpp
View file @
20b6c15c
...
@@ -74,7 +74,8 @@ void quantize(program& prog, const std::vector<std::string>& ins_names)
...
@@ -74,7 +74,8 @@ void quantize(program& prog, const std::vector<std::string>& ins_names)
// if the input is a convert operator, uses its input
// if the input is a convert operator, uses its input
// as its current input
// as its current input
instruction_ref
input_fp16
{};
instruction_ref
input_fp16
{};
if
(
input
->
name
()
==
"convert"
)
if
(
input
->
name
()
==
"convert"
and
input
->
inputs
().
front
()
->
get_shape
().
type
()
==
shape
::
half_type
)
{
{
input_fp16
=
input
->
inputs
().
front
();
input_fp16
=
input
->
inputs
().
front
();
}
}
...
...
src/tf/tf.cpp
View file @
20b6c15c
...
@@ -26,7 +26,6 @@ struct tf_parser
...
@@ -26,7 +26,6 @@ struct tf_parser
{
{
using
attribute_map
=
std
::
unordered_map
<
std
::
string
,
tensorflow
::
AttrValue
>
;
using
attribute_map
=
std
::
unordered_map
<
std
::
string
,
tensorflow
::
AttrValue
>
;
using
node_map
=
std
::
map
<
std
::
string
,
tensorflow
::
NodeDef
>
;
using
node_map
=
std
::
map
<
std
::
string
,
tensorflow
::
NodeDef
>
;
// using input_node_map = std::unordered_map<std::string, std::unordered_set<std::string>>;
using
op_func
=
std
::
function
<
instruction_ref
(
attribute_map
,
std
::
vector
<
instruction_ref
>
)
>
;
using
op_func
=
std
::
function
<
instruction_ref
(
attribute_map
,
std
::
vector
<
instruction_ref
>
)
>
;
node_map
nodes
;
node_map
nodes
;
...
@@ -149,9 +148,26 @@ struct tf_parser
...
@@ -149,9 +148,26 @@ struct tf_parser
return
axes
;
return
axes
;
}
}
std
::
vector
<
int64_t
>
get_axes_from_mask
(
const
size_t
num_axes
,
const
uint32_t
mask
)
{
uint32_t
bitwise_compare
=
1
;
std
::
vector
<
int64_t
>
axes
;
for
(
size_t
i
=
0
;
i
<
num_axes
;
i
++
)
{
// the LSB corresponds to axis 0 when determining which axes to begin
if
(((
mask
>>
i
)
&
bitwise_compare
)
==
1
)
axes
.
push_back
(
1
);
else
axes
.
push_back
(
0
);
}
return
axes
;
}
tf_parser
()
tf_parser
()
{
{
add_generic_op
(
"All"
,
op
::
identity
{});
add_generic_op
(
"Identity"
,
op
::
identity
{});
add_generic_op
(
"Identity"
,
op
::
identity
{});
add_generic_op
(
"LessEqual"
,
op
::
identity
{});
add_generic_op
(
"Relu"
,
op
::
relu
{});
add_generic_op
(
"Relu"
,
op
::
relu
{});
add_generic_op
(
"Relu6"
,
op
::
clip
{
6.0
,
0.0
});
add_generic_op
(
"Relu6"
,
op
::
clip
{
6.0
,
0.0
});
add_generic_op
(
"Rsqrt"
,
op
::
rsqrt
{});
add_generic_op
(
"Rsqrt"
,
op
::
rsqrt
{});
...
@@ -166,6 +182,7 @@ struct tf_parser
...
@@ -166,6 +182,7 @@ struct tf_parser
add_mem_op
(
"AvgPool"
,
&
tf_parser
::
parse_pooling
);
add_mem_op
(
"AvgPool"
,
&
tf_parser
::
parse_pooling
);
add_mem_op
(
"BatchMatMul"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"BatchMatMul"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"BatchMatMulV2"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"BiasAdd"
,
&
tf_parser
::
parse_biasadd
);
add_mem_op
(
"BiasAdd"
,
&
tf_parser
::
parse_biasadd
);
add_mem_op
(
"Cast"
,
&
tf_parser
::
parse_cast
,
false
);
add_mem_op
(
"Cast"
,
&
tf_parser
::
parse_cast
,
false
);
add_mem_op
(
"ConcatV2"
,
&
tf_parser
::
parse_concat
,
false
);
add_mem_op
(
"ConcatV2"
,
&
tf_parser
::
parse_concat
,
false
);
...
@@ -177,14 +194,15 @@ struct tf_parser
...
@@ -177,14 +194,15 @@ struct tf_parser
add_mem_op
(
"GatherV2"
,
&
tf_parser
::
parse_gather
,
false
);
add_mem_op
(
"GatherV2"
,
&
tf_parser
::
parse_gather
,
false
);
add_mem_op
(
"MatMul"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"MatMul"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"MaxPool"
,
&
tf_parser
::
parse_pooling
);
add_mem_op
(
"MaxPool"
,
&
tf_parser
::
parse_pooling
);
add_mem_op
(
"Mean"
,
&
tf_parser
::
parse_mean
);
add_mem_op
(
"Mean"
,
&
tf_parser
::
parse_mean
,
false
);
add_mem_op
(
"OneHot"
,
&
tf_parser
::
parse_onehot
,
false
);
add_mem_op
(
"Pack"
,
&
tf_parser
::
parse_pack
,
false
);
add_mem_op
(
"Pack"
,
&
tf_parser
::
parse_pack
,
false
);
add_mem_op
(
"Pad"
,
&
tf_parser
::
parse_pad
);
add_mem_op
(
"Pad"
,
&
tf_parser
::
parse_pad
);
add_mem_op
(
"Reshape"
,
&
tf_parser
::
parse_reshape
,
false
);
add_mem_op
(
"Reshape"
,
&
tf_parser
::
parse_reshape
,
false
);
add_mem_op
(
"Slice"
,
&
tf_parser
::
parse_slice
,
false
);
add_mem_op
(
"Slice"
,
&
tf_parser
::
parse_slice
,
false
);
add_mem_op
(
"Softmax"
,
&
tf_parser
::
parse_softmax
<
op
::
softmax
>
);
add_mem_op
(
"Softmax"
,
&
tf_parser
::
parse_softmax
<
op
::
softmax
>
,
false
);
add_mem_op
(
"Squeeze"
,
&
tf_parser
::
parse_squeeze
,
false
);
add_mem_op
(
"Squeeze"
,
&
tf_parser
::
parse_squeeze
,
false
);
add_mem_op
(
"StridedSlice"
,
&
tf_parser
::
parse_stridedslice
);
add_mem_op
(
"StridedSlice"
,
&
tf_parser
::
parse_stridedslice
,
false
);
add_mem_op
(
"Transpose"
,
&
tf_parser
::
parse_transpose
,
false
);
add_mem_op
(
"Transpose"
,
&
tf_parser
::
parse_transpose
,
false
);
}
}
...
@@ -547,7 +565,7 @@ struct tf_parser
...
@@ -547,7 +565,7 @@ struct tf_parser
}
}
if
(
contains
(
attributes
,
"transpose_b"
))
if
(
contains
(
attributes
,
"transpose_b"
))
{
{
transb
=
attributes
.
at
(
"transpose_
a
"
).
b
();
transb
=
attributes
.
at
(
"transpose_
b
"
).
b
();
}
}
if
(
contains
(
attributes
,
"adj_x"
))
if
(
contains
(
attributes
,
"adj_x"
))
...
@@ -574,8 +592,7 @@ struct tf_parser
...
@@ -574,8 +592,7 @@ struct tf_parser
parse_mean
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
parse_mean
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
{
bool
keep_dims
=
attributes
.
at
(
"keep_dims"
).
b
();
bool
keep_dims
=
attributes
.
at
(
"keep_dims"
).
b
();
auto
lens
=
args
[
0
]
->
get_shape
().
lens
();
auto
axes
=
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
<
int64_t
>
();
auto
axes
=
parse_axes
(
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
<
int64_t
>
(),
lens
.
size
());
if
(
keep_dims
)
if
(
keep_dims
)
{
{
...
@@ -588,6 +605,32 @@ struct tf_parser
...
@@ -588,6 +605,32 @@ struct tf_parser
}
}
}
}
instruction_ref
parse_onehot
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
size_t
depth
=
static_cast
<
size_t
>
(
args
[
1
]
->
eval
().
at
<
int32_t
>
());
int64_t
axis
=
-
1
;
float
on_value
=
args
[
2
]
->
eval
().
at
<
float
>
();
float
off_value
=
args
[
3
]
->
eval
().
at
<
float
>
();
std
::
vector
<
float
>
depth_input
(
depth
*
depth
,
off_value
);
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
{
depth_input
[
depth
*
i
+
i
]
=
on_value
;
}
if
(
contains
(
attributes
,
"axis"
))
axis
=
attributes
.
at
(
"axis"
).
i
();
if
(
axis
==
-
1
)
{
shape
s
{
shape
::
float_type
,
{
depth
,
depth
}};
auto
l0
=
prog
.
add_literal
({
s
,
depth_input
});
return
prog
.
add_instruction
(
op
::
gather
{
0
},
{
l0
,
args
[
0
]});
}
MIGRAPHX_THROW
(
"MIGraphX does not support axis != -1"
);
}
instruction_ref
parse_pack
(
const
std
::
string
&
,
instruction_ref
parse_pack
(
const
std
::
string
&
,
const
attribute_map
&
attributes
,
const
attribute_map
&
attributes
,
std
::
vector
<
instruction_ref
>
args
)
std
::
vector
<
instruction_ref
>
args
)
...
@@ -799,21 +842,50 @@ struct tf_parser
...
@@ -799,21 +842,50 @@ struct tf_parser
std
::
vector
<
instruction_ref
>
args
)
std
::
vector
<
instruction_ref
>
args
)
{
{
op
::
slice
op
;
op
::
slice
op
;
auto
starts
=
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
auto
starts
=
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
auto
ends
=
args
[
2
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
auto
ends
=
args
[
2
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
size_t
num_axes
=
args
[
0
]
->
get_shape
().
lens
().
size
();
auto
l0
=
args
[
0
];
size_t
num_axes
=
l0
->
get_shape
().
lens
().
size
();
std
::
vector
<
size_t
>
axes
=
l0
->
get_shape
().
lens
();
op
.
starts
=
std
::
vector
<
int64_t
>
(
starts
.
begin
(),
starts
.
end
());
op
.
starts
=
std
::
vector
<
int64_t
>
(
starts
.
begin
(),
starts
.
end
());
op
.
ends
=
std
::
vector
<
int64_t
>
(
ends
.
begin
(),
ends
.
end
());
op
.
ends
=
std
::
vector
<
int64_t
>
(
ends
.
begin
(),
ends
.
end
());
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
uint32_t
begin_mask
=
0
;
uint32_t
end_mask
=
0
;
uint32_t
shrink_axis_mask
=
0
;
uint32_t
shrink_axis_mask
=
0
;
uint32_t
bitwise_compare
=
1
;
uint32_t
bitwise_compare
=
1
;
std
::
vector
<
int64_t
>
squeeze_axes
;
std
::
vector
<
int64_t
>
squeeze_axes
;
if
(
contains
(
attributes
,
"begin_mask"
))
begin_mask
=
static_cast
<
uint32_t
>
(
attributes
.
at
(
"begin_mask"
).
i
());
if
(
contains
(
attributes
,
"end_mask"
))
end_mask
=
static_cast
<
uint32_t
>
(
attributes
.
at
(
"end_mask"
).
i
());
if
(
contains
(
attributes
,
"shrink_axis_mask"
))
if
(
contains
(
attributes
,
"shrink_axis_mask"
))
shrink_axis_mask
=
static_cast
<
uint32_t
>
(
attributes
.
at
(
"shrink_axis_mask"
).
i
());
shrink_axis_mask
=
static_cast
<
uint32_t
>
(
attributes
.
at
(
"shrink_axis_mask"
).
i
());
std
::
vector
<
int64_t
>
begin_axes
=
get_axes_from_mask
(
num_axes
,
begin_mask
);
std
::
vector
<
int64_t
>
end_axes
=
get_axes_from_mask
(
num_axes
,
end_mask
);
for
(
size_t
i
=
0
;
i
<
num_axes
;
i
++
)
{
if
(
begin_axes
.
at
(
i
)
==
1
)
{
op
.
starts
.
at
(
i
)
=
0
;
}
if
(
end_axes
.
at
(
i
)
==
1
)
{
op
.
ends
.
at
(
i
)
=
axes
.
at
(
i
);
}
}
auto
l1
=
prog
.
add_instruction
(
op
,
l0
);
if
(
shrink_axis_mask
==
0
)
return
l1
;
for
(
size_t
i
=
0
;
i
<
num_axes
;
i
++
)
for
(
size_t
i
=
0
;
i
<
num_axes
;
i
++
)
{
{
// the LSB corresponds to axis 0 when determining which axes to squeeze
// the LSB corresponds to axis 0 when determining which axes to squeeze
...
@@ -821,8 +893,7 @@ struct tf_parser
...
@@ -821,8 +893,7 @@ struct tf_parser
squeeze_axes
.
push_back
(
i
);
squeeze_axes
.
push_back
(
i
);
}
}
auto
l0
=
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]));
return
prog
.
add_instruction
(
op
::
squeeze
{
squeeze_axes
},
l1
);
return
to_nhwc
(
prog
.
add_instruction
(
op
::
squeeze
{
squeeze_axes
},
l0
));
}
}
instruction_ref
instruction_ref
...
@@ -862,10 +933,16 @@ struct tf_parser
...
@@ -862,10 +933,16 @@ struct tf_parser
if
(
instructions
.
count
(
name
)
==
0
)
if
(
instructions
.
count
(
name
)
==
0
)
{
{
auto
&&
node
=
nodes
.
at
(
name
);
auto
&&
node
=
nodes
.
at
(
name
);
// assert ops ignored
if
(
node
.
op
()
==
"Assert"
or
contains
(
name
,
"Assert"
))
return
;
std
::
vector
<
instruction_ref
>
args
;
std
::
vector
<
instruction_ref
>
args
;
for
(
auto
&&
input
:
node
.
input
())
for
(
auto
&&
input
:
node
.
input
())
{
{
// control dependencies (signified by ^ before the name) are ignored
if
(
contains
(
input
,
"^"
))
continue
;
if
(
nodes
.
count
(
input
)
>
0
)
if
(
nodes
.
count
(
input
)
>
0
)
{
{
auto
&&
iname
=
get_name
(
nodes
.
at
(
input
));
auto
&&
iname
=
get_name
(
nodes
.
at
(
input
));
...
...
test/onnx/onnx_test.cpp
View file @
20b6c15c
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include <migraphx/operators.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/program.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/instruction_ref.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/onnx.hpp>
#include "test.hpp"
#include "test.hpp"
...
@@ -509,6 +510,32 @@ TEST_CASE(shape_gather_test)
...
@@ -509,6 +510,32 @@ TEST_CASE(shape_gather_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
transpose_gather_test
)
{
migraphx
::
program
p
;
auto
make_contiguous
=
[
&
p
](
migraphx
::
instruction_ref
ins
)
{
if
(
ins
->
get_shape
().
standard
())
{
return
ins
;
}
return
p
.
add_instruction
(
migraphx
::
op
::
contiguous
{},
ins
);
};
auto
data
=
p
.
add_parameter
(
"data"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
5
,
4
,
6
}});
auto
ind
=
p
.
add_parameter
(
"indices"
,
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
2
,
4
,
3
,
5
}});
auto
tr_data
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
1
,
3
}},
data
);
auto
tr_ind
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
1
,
3
}},
ind
);
int
axis
=
1
;
p
.
add_instruction
(
migraphx
::
op
::
gather
{
axis
},
make_contiguous
(
tr_data
),
make_contiguous
(
tr_ind
));
auto
prog
=
migraphx
::
parse_onnx
(
"transpose_gather.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
flatten_test
)
TEST_CASE
(
flatten_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/onnx/transpose_gather.onnx
0 → 100644
View file @
20b6c15c
File added
test/tf/assert_less_equal_test.pb
0 → 100644
View file @
20b6c15c
File added
test/tf/onehot_test.pb
0 → 100644
View file @
20b6c15c
File added
test/tf/stridedslice_masks_test.pb
0 → 100644
View file @
20b6c15c
File added
test/tf/tf_test.cpp
View file @
20b6c15c
...
@@ -48,6 +48,22 @@ TEST_CASE(add_bcast_test)
...
@@ -48,6 +48,22 @@ TEST_CASE(add_bcast_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
assert_less_equal_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
l0
=
p
.
add_parameter
(
"0"
,
s0
);
auto
l1
=
p
.
add_parameter
(
"1"
,
s0
);
migraphx
::
literal
l
{
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
2
}},
{
0
,
1
}};
auto
l2
=
p
.
add_literal
(
l
);
p
.
add_instruction
(
migraphx
::
op
::
add
{},
l0
,
l1
);
auto
l3
=
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
l0
,
l1
);
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
l3
,
l2
);
auto
prog
=
optimize_tf
(
"assert_less_equal_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
batchmatmul_test
)
TEST_CASE
(
batchmatmul_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
@@ -100,6 +116,16 @@ TEST_CASE(biasadd_test)
...
@@ -100,6 +116,16 @@ TEST_CASE(biasadd_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
cast_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}});
p
.
add_instruction
(
migraphx
::
op
::
convert
{
migraphx
::
shape
::
int32_type
},
l0
);
auto
prog
=
optimize_tf
(
"cast_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
concat_test
)
TEST_CASE
(
concat_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
@@ -118,16 +144,6 @@ TEST_CASE(concat_test)
...
@@ -118,16 +144,6 @@ TEST_CASE(concat_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
cast_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}});
p
.
add_instruction
(
migraphx
::
op
::
convert
{
migraphx
::
shape
::
int32_type
},
l0
);
auto
prog
=
optimize_tf
(
"cast_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
const_test
)
TEST_CASE
(
const_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
@@ -271,9 +287,10 @@ TEST_CASE(mean_test_nhwc)
...
@@ -271,9 +287,10 @@ TEST_CASE(mean_test_nhwc)
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
literal
l
{
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
2
}},
{
1
,
2
}};
migraphx
::
literal
l
{
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
2
}},
{
1
,
2
}};
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}});
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}});
migraphx
::
op
::
reduce_mean
op
{{
2
,
3
}};
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
3
,
1
}},
l0
);
auto
l3
=
p
.
add_instruction
(
op
,
l0
);
migraphx
::
op
::
reduce_mean
op
{{
1
,
2
}};
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
2
,
3
}},
l3
);
auto
l2
=
p
.
add_instruction
(
op
,
l1
);
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
1
,
2
}},
l2
);
auto
prog
=
optimize_tf
(
"mean_test_nhwc.pb"
,
true
);
auto
prog
=
optimize_tf
(
"mean_test_nhwc.pb"
,
true
);
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
...
@@ -291,6 +308,23 @@ TEST_CASE(mul_test)
...
@@ -291,6 +308,23 @@ TEST_CASE(mul_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
onehot_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
5
}},
{
1
,
1
,
1
,
1
,
1
}});
p
.
add_literal
(
2
);
p
.
add_literal
(
1.0
f
);
p
.
add_literal
(
0.0
f
);
auto
l1
=
p
.
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}},
{
1
,
0
,
0
,
1
}});
int
axis
=
0
;
p
.
add_instruction
(
migraphx
::
op
::
gather
{
axis
},
l1
,
l0
);
auto
prog
=
optimize_tf
(
"onehot_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
pack_test
)
TEST_CASE
(
pack_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
@@ -475,20 +509,44 @@ TEST_CASE(stridedslice_test)
...
@@ -475,20 +509,44 @@ TEST_CASE(stridedslice_test)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
10
,
1
,
1
}});
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
10
,
1
,
1
}});
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
3
,
1
}},
l0
);
std
::
size_t
num_axes
=
4
;
std
::
size_t
num_axes
=
4
;
migraphx
::
op
::
slice
op
;
migraphx
::
op
::
slice
op
;
op
.
starts
=
{
0
,
0
,
0
,
0
};
op
.
starts
=
{
0
,
0
,
0
,
0
};
op
.
ends
=
{
1
,
1
,
1
,
5
};
op
.
ends
=
{
1
,
1
,
1
,
5
};
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
auto
l
1
=
p
.
add_instruction
(
op
,
l
0
);
auto
l
2
=
p
.
add_instruction
(
op
,
l
1
);
auto
shrink_axis
=
1
;
auto
shrink_axis
=
1
;
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
shrink_axis
}},
l
1
);
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
shrink_axis
}},
l
2
);
auto
prog
=
optimize_tf
(
"stridedslice_test.pb"
,
true
);
auto
prog
=
optimize_tf
(
"stridedslice_test.pb"
,
true
);
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
stridedslice_masks_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
10
,
3
,
3
}});
std
::
size_t
num_axes
=
4
;
migraphx
::
op
::
slice
op
;
op
.
starts
=
{
0
,
1
,
1
,
0
};
op
.
ends
=
{
1
,
3
,
3
,
10
};
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
// add literals for starts, ends, and strides in tf (NHWC format)
p
.
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
4
}},
std
::
vector
<
int
>
{
0
,
1
,
1
,
0
});
p
.
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
4
}},
std
::
vector
<
int
>
{
0
,
0
,
0
,
0
});
p
.
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
4
}},
std
::
vector
<
int
>
{
1
,
1
,
1
,
1
});
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
3
,
1
}},
l0
);
auto
l2
=
p
.
add_instruction
(
op
,
l1
);
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
3
,
1
,
2
}},
l2
);
auto
prog
=
migraphx
::
parse_tf
(
"stridedslice_masks_test.pb"
,
true
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
sub_test
)
TEST_CASE
(
sub_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
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