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
a3aacad6
Commit
a3aacad6
authored
Jul 11, 2019
by
Shucai Xiao
Browse files
merge changes from develop branch
parents
b47ca14f
53355978
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
115 additions
and
16 deletions
+115
-16
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+2
-2
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+2
-2
src/tf/tf.cpp
src/tf/tf.cpp
+35
-12
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+15
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+13
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+10
-0
test/onnx/sqrt_test.onnx
test/onnx/sqrt_test.onnx
+13
-0
test/tf/expanddims_neg_test.pb
test/tf/expanddims_neg_test.pb
+0
-0
test/tf/expanddims_test.pb
test/tf/expanddims_test.pb
+0
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+25
-0
No files found.
src/targets/gpu/CMakeLists.txt
View file @
a3aacad6
...
...
@@ -40,9 +40,9 @@ add_library(migraphx_device
device/div.cpp
device/clip.cpp
device/reduce_sum.cpp
device/pow.cpp
device/reduce_mean.cpp
device/sqrt.cpp
device/reduce_mean.cpp
device/pow.cpp
)
set_target_properties
(
migraphx_device PROPERTIES EXPORT_NAME device
)
rocm_clang_tidy_check
(
migraphx_device
)
...
...
src/targets/gpu/lowering.cpp
View file @
a3aacad6
...
...
@@ -52,9 +52,9 @@
#include <migraphx/gpu/convert.hpp>
#include <migraphx/gpu/clip.hpp>
#include <migraphx/gpu/reduce_sum.hpp>
#include <migraphx/gpu/pow.hpp>
#include <migraphx/gpu/reduce_mean.hpp>
#include <migraphx/gpu/sqrt.hpp>
#include <migraphx/gpu/reduce_mean.hpp>
#include <migraphx/gpu/pow.hpp>
#include <utility>
#include <functional>
#include <algorithm>
...
...
src/tf/tf.cpp
View file @
a3aacad6
...
...
@@ -79,7 +79,8 @@ struct tf_parser
return
result
;
}
std
::
vector
<
size_t
>
parse_axes
(
const
attribute_map
&
attributes
,
const
std
::
string
&
s
)
const
std
::
vector
<
size_t
>
parse_axes
(
const
attribute_map
&
attributes
,
const
std
::
string
&
s
,
const
size_t
num_dims
)
const
{
auto
attrs
=
attributes
.
at
(
s
).
list
().
i
();
std
::
vector
<
size_t
>
axes
;
...
...
@@ -87,14 +88,14 @@ struct tf_parser
if
(
is_nhwc
)
{
std
::
transform
(
axes
.
begin
(),
axes
.
end
(),
axes
.
begin
(),
[
&
](
size_t
axis
)
{
return
parse_axis
(
axis
);
return
parse_axis
(
axis
,
num_dims
);
});
}
return
axes
;
}
template
<
class
T
>
std
::
vector
<
T
>
parse_axes
(
std
::
vector
<
T
>
axes
)
const
std
::
vector
<
T
>
parse_axes
(
std
::
vector
<
T
>
axes
,
const
size_t
num_dims
)
const
{
if
(
is_nhwc
)
{
...
...
@@ -102,7 +103,7 @@ struct tf_parser
std
::
transform
(
axes
.
begin
(),
axes
.
end
(),
std
::
back_inserter
(
new_axes
),
[
&
](
size_t
axis
)
{
return
parse_axis
(
axis
);
});
[
&
](
size_t
axis
)
{
return
parse_axis
(
axis
,
num_dims
);
});
return
new_axes
;
}
return
axes
;
...
...
@@ -117,17 +118,17 @@ struct tf_parser
std
::
vector
<
T
>
new_data
(
prev_data
.
size
());
for
(
size_t
i
=
0
;
i
<
new_data
.
size
();
i
++
)
{
auto
new_idx
=
parse_axis
(
i
);
auto
new_idx
=
parse_axis
(
i
,
new_data
.
size
()
);
new_data
.
at
(
new_idx
)
=
prev_data
.
at
(
i
);
}
prev_data
=
new_data
;
}
template
<
class
T
>
T
parse_axis
(
const
T
&
dim
)
const
T
parse_axis
(
const
T
&
dim
,
const
size_t
num_dims
)
const
{
T
new_dim
=
dim
;
if
(
is_nhwc
)
if
(
is_nhwc
and
num_dims
>=
4
)
{
switch
(
dim
)
{
...
...
@@ -165,6 +166,7 @@ struct tf_parser
add_mem_op
(
"Const"
,
&
tf_parser
::
parse_constant
);
add_mem_op
(
"Conv2D"
,
&
tf_parser
::
parse_conv
);
add_mem_op
(
"DepthwiseConv2dNative"
,
&
tf_parser
::
parse_depthwiseconv
);
add_mem_op
(
"ExpandDims"
,
&
tf_parser
::
parse_expanddims
,
false
);
add_mem_op
(
"FusedBatchNorm"
,
&
tf_parser
::
parse_batchnorm
);
add_mem_op
(
"MatMul"
,
&
tf_parser
::
parse_matmul
,
false
);
add_mem_op
(
"MaxPool"
,
&
tf_parser
::
parse_pooling
);
...
...
@@ -490,6 +492,25 @@ struct tf_parser
return
prog
.
add_instruction
(
op
,
{
l0
,
new_weights
});
}
instruction_ref
parse_expanddims
(
const
std
::
string
&
,
const
attribute_map
&
,
std
::
vector
<
instruction_ref
>
args
)
{
std
::
vector
<
size_t
>
input_dims
=
args
[
0
]
->
get_shape
().
lens
();
std
::
vector
<
int64_t
>
new_dims
(
input_dims
.
begin
(),
input_dims
.
end
());
size_t
num_dims
=
input_dims
.
size
();
int32_t
dim
=
args
[
1
]
->
eval
().
at
<
int32_t
>
();
if
(
dim
<
0
)
{
new_dims
.
insert
(
new_dims
.
begin
()
+
(
num_dims
+
dim
+
1
),
1
);
}
else
{
new_dims
.
insert
(
new_dims
.
begin
()
+
dim
,
1
);
}
return
prog
.
add_instruction
(
op
::
reshape
{
new_dims
},
args
[
0
]);
}
instruction_ref
parse_matmul
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
...
...
@@ -519,11 +540,12 @@ struct tf_parser
instruction_ref
parse_mean
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
auto
axes
=
parse_axes
(
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
());
bool
keep_dims
=
attributes
.
at
(
"keep_dims"
).
b
();
std
::
vector
<
int32_t
>
hw_axes
{
2
,
3
};
// check if conditions for GlobalAvgPool are met
auto
lens
=
args
[
0
]
->
get_shape
().
lens
();
auto
axes
=
parse_axes
(
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
(),
lens
.
size
());
if
(
axes
==
hw_axes
and
lens
.
size
()
==
4
)
{
op
::
pooling
op
{
"average"
};
...
...
@@ -694,14 +716,15 @@ struct tf_parser
std
::
vector
<
instruction_ref
>
args
)
{
op
::
squeeze
op
;
auto
axes
=
attributes
.
at
(
"squeeze_dims"
).
list
().
i
();
auto
input_dims
=
args
[
0
]
->
get_shape
().
lens
();
auto
axes
=
attributes
.
at
(
"squeeze_dims"
).
list
().
i
();
copy
(
axes
,
std
::
back_inserter
(
op
.
axes
));
auto
args0_dims
=
args
[
0
]
->
get_shape
().
lens
();
if
(
op
.
axes
.
empty
())
// no squeeze_dims provided, remove any dim that equals 1
{
for
(
size_t
i
=
0
;
i
<
args0
_dims
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
input
_dims
.
size
();
i
++
)
{
if
(
args0
_dims
.
at
(
i
)
==
1
)
if
(
input
_dims
.
at
(
i
)
==
1
)
{
op
.
axes
.
push_back
(
i
);
}
...
...
test/cpu_ops_test.cpp
View file @
a3aacad6
...
...
@@ -542,6 +542,21 @@ TEST_CASE(erf_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sqrt_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
5
}};
auto
l
=
p
.
add_literal
(
migraphx
::
literal
{
s
,
{
1.02481645
,
0.85643062
,
0.03404123
,
0.92791926
,
0.10569184
}});
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
l
);
p
.
compile
(
migraphx
::
cpu
::
target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.01233218
,
0.92543537
,
0.18450265
,
0.96328566
,
0.32510282
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
log_test
)
{
migraphx
::
program
p
;
...
...
test/gpu/miopen.cpp
View file @
a3aacad6
...
...
@@ -255,6 +255,19 @@ struct test_erf : verify_program<test_erf>
}
};
struct
test_sqrt
:
verify_program
<
test_sqrt
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
6
}};
auto
param
=
p
.
add_parameter
(
"x"
,
s
);
auto
param_abs
=
p
.
add_instruction
(
migraphx
::
op
::
abs
{},
param
);
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
param_abs
);
return
p
;
}
};
struct
test_log
:
verify_program
<
test_log
>
{
migraphx
::
program
create_program
()
const
...
...
test/onnx/onnx_test.cpp
View file @
a3aacad6
...
...
@@ -202,6 +202,16 @@ TEST_CASE(erf_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
sqrt_test
)
{
migraphx
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
10
,
15
}});
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
input
);
auto
prog
=
migraphx
::
parse_onnx
(
"sqrt_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
log_test
)
{
migraphx
::
program
p
;
...
...
test/onnx/sqrt_test.onnx
0 → 100644
View file @
a3aacad6
sqrt-example:C
xy"Sqrt test_sqrtZ
x
b
y
B
test/tf/expanddims_neg_test.pb
0 → 100644
View file @
a3aacad6
File added
test/tf/expanddims_test.pb
0 → 100644
View file @
a3aacad6
File added
test/tf/tf_test.cpp
View file @
a3aacad6
...
...
@@ -159,6 +159,31 @@ TEST_CASE(depthwiseconv_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
expanddims_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}});
p
.
add_literal
(
0
);
p
.
add_instruction
(
migraphx
::
op
::
reshape
{{
1
,
2
,
3
,
4
}},
l0
);
auto
prog
=
optimize_tf
(
"expanddims_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
expanddims_test_neg_dims
)
{
// this check makes sure the pb parses negative dim value correctly
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}});
p
.
add_literal
(
-
1
);
p
.
add_instruction
(
migraphx
::
op
::
reshape
{{
2
,
3
,
4
,
1
}},
l0
);
auto
prog
=
optimize_tf
(
"expanddims_neg_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
identity_test
)
{
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