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
9b3eff99
"test/vscode:/vscode.git/clone" did not exist on "4637621adb447bcf35e8bb59d5520929a1bae763"
Commit
9b3eff99
authored
Aug 14, 2018
by
wsttiger
Browse files
Merge branch 'master' into resnet18_demo
parents
256326cc
f0604d78
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
260 additions
and
46 deletions
+260
-46
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+17
-0
test/eval_test.cpp
test/eval_test.cpp
+37
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+39
-44
test/include/basic_ops.hpp
test/include/basic_ops.hpp
+12
-0
test/shape_test.cpp
test/shape_test.cpp
+10
-2
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+145
-0
No files found.
test/dead_code_elimination_test.cpp
View file @
9b3eff99
...
...
@@ -27,6 +27,22 @@ void simple_test()
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
simple_test_nop
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
nop
{});
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
count
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
dce_target
{});
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
count
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
duplicate_test1
()
{
migraph
::
program
p
;
...
...
@@ -82,6 +98,7 @@ void depth_test()
int
main
()
{
simple_test
();
simple_test_nop
();
duplicate_test1
();
duplicate_test2
();
depth_test
();
...
...
test/eval_test.cpp
View file @
9b3eff99
...
...
@@ -112,12 +112,46 @@ void replace_test()
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
replace_instruction
(
sum
,
minus_op
{},
two
,
one
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
1
});
EXPECT
(
result
!=
migraph
::
literal
{
3
});
}
void
replace_ins_test
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
minus
=
p
.
add_instruction
(
minus_op
{},
two
,
one
);
p
.
replace_instruction
(
sum
,
minus
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
1
});
EXPECT
(
result
!=
migraph
::
literal
{
3
});
}
void
replace_ins_test2
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
minus
=
p
.
add_instruction
(
minus_op
{},
two
,
one
);
p
.
add_instruction
(
pass_op
{},
minus
);
p
.
replace_instruction
(
two
,
sum
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
2
});
EXPECT
(
result
!=
migraph
::
literal
{
3
});
}
void
insert_replace_test
()
{
migraph
::
program
p
;
...
...
@@ -129,6 +163,7 @@ void insert_replace_test()
auto
sum0
=
p
.
insert_instruction
(
sum1
,
sum_op
{},
two
,
two
);
p
.
replace_instruction
(
sum1
,
minus_op
{},
sum0
,
two
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
4
});
...
...
@@ -181,6 +216,8 @@ int main()
print_test
();
param_test
();
replace_test
();
replace_ins_test
();
replace_ins_test2
();
insert_replace_test
();
target_test
();
reverse_target_test
();
...
...
test/gpu/miopen.cpp
View file @
9b3eff99
...
...
@@ -14,11 +14,34 @@
#include "test.hpp"
#include "verify.hpp"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
struct
auto_print
{
static
std
::
array
<
std
::
function
<
void
()
>
,
2
>
handlers
;
int
index
;
template
<
class
T
>
auto_print
(
T
&
x
,
int
i
)
:
index
(
i
)
{
handlers
[
index
]
=
[
&
x
]
{
std
::
cout
<<
x
<<
std
::
endl
;
};
}
~
auto_print
()
{
handlers
[
index
]
=
[]
{};
}
};
std
::
array
<
std
::
function
<
void
()
>
,
2
>
auto_print
::
handlers
=
{};
template
<
class
V
>
migraph
::
argument
run_cpu
()
{
V
v
;
auto
p
=
v
.
create_program
();
auto_print
pp
{
p
,
0
};
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
migraph
::
program
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
...
...
@@ -33,6 +56,7 @@ migraph::argument run_gpu()
{
V
v
;
auto
p
=
v
.
create_program
();
auto_print
pp
{
p
,
1
};
p
.
compile
(
migraph
::
gpu
::
target
{});
migraph
::
program
::
parameter_map
m
;
...
...
@@ -47,6 +71,20 @@ migraph::argument run_gpu()
template
<
class
V
>
void
verify_program
()
{
std
::
set_terminate
(
+
[]
{
std
::
cout
<<
"FAILED: "
<<
migraph
::
get_type_name
<
V
>
()
<<
std
::
endl
;
try
{
std
::
rethrow_exception
(
std
::
current_exception
());
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
" what(): "
<<
e
.
what
()
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
;
for
(
auto
&&
handle
:
auto_print
::
handlers
)
handle
();
});
auto
cpu_arg
=
run_cpu
<
V
>
();
auto
gpu_arg
=
run_gpu
<
V
>
();
visit_all
(
cpu_arg
,
gpu_arg
)([](
auto
cpu
,
auto
gpu
)
{
...
...
@@ -55,6 +93,7 @@ void verify_program()
std
::
cout
<<
"FAILED: "
<<
migraph
::
get_type_name
<
V
>
()
<<
std
::
endl
;
}
});
std
::
set_terminate
(
nullptr
);
}
struct
test_literals
...
...
@@ -242,49 +281,6 @@ struct test_batchnorm_inference
}
};
void
batch_norm_inference_test
()
{
migraph
::
program
p
;
const
size_t
width
=
2
,
height
=
2
,
channels
=
4
,
batches
=
2
;
const
float
x_val
=
8.0
f
,
mean_val
=
2.0
f
,
variance_val
=
4.0
f
,
scale_val
=
2.0
f
,
bias_val
=
1.0
f
;
const
float
output_val
=
scale_val
*
(
x_val
-
mean_val
)
/
(
std
::
sqrt
(
variance_val
))
+
bias_val
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
batches
,
channels
,
height
,
width
}};
migraph
::
shape
vars
{
migraph
::
shape
::
float_type
,
{
channels
}};
std
::
vector
<
float
>
x_data
(
width
*
height
*
channels
*
batches
);
std
::
vector
<
float
>
scale_data
(
channels
);
std
::
vector
<
float
>
bias_data
(
channels
);
std
::
vector
<
float
>
mean_data
(
channels
);
std
::
vector
<
float
>
variance_data
(
channels
);
std
::
fill
(
x_data
.
begin
(),
x_data
.
end
(),
x_val
);
std
::
fill
(
mean_data
.
begin
(),
mean_data
.
end
(),
mean_val
);
std
::
fill
(
variance_data
.
begin
(),
variance_data
.
end
(),
variance_val
);
std
::
fill
(
scale_data
.
begin
(),
scale_data
.
end
(),
scale_val
);
std
::
fill
(
bias_data
.
begin
(),
bias_data
.
end
(),
bias_val
);
auto
x
=
p
.
add_literal
(
migraph
::
literal
{
s
,
x_data
});
auto
scale
=
p
.
add_literal
(
migraph
::
literal
{
vars
,
scale_data
});
auto
bias
=
p
.
add_literal
(
migraph
::
literal
{
vars
,
bias_data
});
auto
mean
=
p
.
add_literal
(
migraph
::
literal
{
vars
,
mean_data
});
auto
variance
=
p
.
add_literal
(
migraph
::
literal
{
vars
,
variance_data
});
p
.
add_instruction
(
migraph
::
batch_norm_inference
{},
x
,
mean
,
variance
,
scale
,
bias
);
p
.
compile
(
migraph
::
gpu
::
target
{});
migraph
::
program
::
parameter_map
m
;
m
[
"output"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
p
.
get_parameter_shape
(
"output"
)));
auto
result
=
migraph
::
gpu
::
from_gpu
(
p
.
eval
(
m
));
std
::
vector
<
float
>
result_vector
(
width
*
height
*
channels
*
batches
);
std
::
vector
<
float
>
gold
(
width
*
height
*
channels
*
batches
);
std
::
fill
(
gold
.
begin
(),
gold
.
end
(),
output_val
);
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
test
::
verify_range
(
result_vector
,
gold
));
}
int
main
()
{
verify_program
<
test_add
>
();
...
...
@@ -299,5 +295,4 @@ int main()
verify_program
<
test_contiguous
>
();
verify_program
<
test_transpose
>
();
verify_program
<
test_batchnorm_inference
>
();
batch_norm_inference_test
();
}
test/include/basic_ops.hpp
View file @
9b3eff99
...
...
@@ -80,3 +80,15 @@ struct pass_op
return
inputs
.
front
();
}
};
struct
nop
{
std
::
string
name
()
const
{
return
"nop"
;
}
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
)
const
{
return
{};
}
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
)
const
{
return
{};
}
};
test/shape_test.cpp
View file @
9b3eff99
...
...
@@ -5,6 +5,13 @@
#include <numeric>
#include "test.hpp"
void
test_shape_default
()
{
migraph
::
shape
s
{};
EXPECT
(
s
.
elements
()
==
0
);
EXPECT
(
s
.
bytes
()
==
0
);
}
void
test_shape_assign
()
{
migraph
::
shape
s1
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
...
...
@@ -49,7 +56,7 @@ void test_shape_broadcasted()
EXPECT
(
s
.
broadcasted
());
}
void
test_shape_default
()
void
test_shape_default
_copy
()
{
migraph
::
shape
s1
{};
migraph
::
shape
s2
{};
...
...
@@ -136,12 +143,13 @@ void test_shape4_nonpacked()
int
main
()
{
test_shape_default
();
test_shape_assign
();
test_shape_packed_default
();
test_shape_packed
();
test_shape_transposed
();
test_shape_broadcasted
();
test_shape_default
();
test_shape_default
_copy
();
test_shape4
();
test_shape4_nonpacked
();
}
test/simplify_reshapes_test.cpp
0 → 100644
View file @
9b3eff99
#include <migraph/simplify_reshapes.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct
simplify_reshapes_target
{
std
::
string
name
()
const
{
return
"simplify_reshapes"
;
}
std
::
vector
<
migraph
::
pass
>
get_passes
(
migraph
::
context
&
)
const
{
return
{
migraph
::
simplify_reshapes
{},
migraph
::
dead_code_elimination
{}};
}
migraph
::
context
get_context
()
const
{
return
{};
}
};
migraph
::
literal
get_2x2
()
{
return
migraph
::
literal
{{
migraph
::
shape
::
float_type
,
{
2
,
2
}},
{
1
,
2
,
3
,
4
}};
}
migraph
::
literal
get_2x2_transposed
()
{
return
migraph
::
literal
{{
migraph
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
2
}},
{
1
,
2
,
3
,
4
}};
}
migraph
::
literal
get_2
()
{
return
migraph
::
literal
{{
migraph
::
shape
::
float_type
,
{
2
}},
{
1
,
2
}};
}
migraph
::
literal
get_2_broadcasted
()
{
return
migraph
::
literal
{{
migraph
::
shape
::
float_type
,
{
2
,
1
},
{
1
,
0
}},
{
1
,
2
}};
}
void
double_contig
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
contiguous
{},
c1
);
p
.
add_instruction
(
pass_op
{},
c2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
2
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
get_2x2
());
}
void
double_transpose
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
p
.
add_instruction
(
pass_op
{},
t2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
2
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
get_2x2
());
}
void
double_transpose_contig
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
c1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t2
);
p
.
add_instruction
(
pass_op
{},
c2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
2
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
get_2x2
());
}
void
single_transpose
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
pass_op
{},
t1
);
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
3
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
!=
get_2x2
());
}
void
double_transpose_sin_pass
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
// std::cout << p << std::endl;
// TODO: Fix this
// EXPECT(std::distance(p.begin(), p.end()) == 1);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
get_2x2
());
}
void
single_transpose_sin_pass
()
{
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
2
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
!=
get_2x2
());
}
int
main
()
{
double_contig
();
double_transpose
();
double_transpose_contig
();
single_transpose
();
double_transpose_sin_pass
();
single_transpose_sin_pass
();
}
Prev
1
2
Next
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