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
d18238bb
Commit
d18238bb
authored
May 21, 2019
by
Paul
Browse files
Add more tests
parent
2c60e428
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
152 additions
and
19 deletions
+152
-19
test/eval_test.cpp
test/eval_test.cpp
+88
-19
test/generate.cpp
test/generate.cpp
+11
-0
test/perf_report.cpp
test/perf_report.cpp
+28
-0
test/program_test.cpp
test/program_test.cpp
+25
-0
No files found.
test/eval_test.cpp
View file @
d18238bb
...
...
@@ -65,6 +65,23 @@ struct reverse_pass
{
std
::
string
name
()
const
{
return
"reverse_pass"
;
}
void
apply
(
migraphx
::
program
&
p
)
const
{
std
::
reverse
(
p
.
begin
(),
p
.
end
());
}
};
struct
reverse_target
{
std
::
string
name
()
const
{
return
"reverse"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{
reverse_pass
{}};
}
migraphx
::
context
get_context
()
const
{
return
{};
}
};
struct
invert_pass
{
std
::
string
name
()
const
{
return
"invert_pass"
;
}
void
apply
(
migraphx
::
program
&
p
)
const
{
for
(
auto
ins
:
migraphx
::
iterator_for
(
p
))
...
...
@@ -81,19 +98,19 @@ struct reverse_pass
}
};
struct
re
ver
se
_target
struct
in
ver
t
_target
{
std
::
string
name
()
const
{
return
"
re
ver
se
"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{
re
ver
se
_pass
{}};
}
std
::
string
name
()
const
{
return
"
in
ver
t
"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{
in
ver
t
_pass
{}};
}
migraphx
::
context
get_context
()
const
{
return
{};
}
};
struct
double_
re
ver
se
_target
struct
double_
in
ver
t
_target
{
std
::
string
name
()
const
{
return
"double_
re
ver
se
"
;
}
std
::
string
name
()
const
{
return
"double_
in
ver
t
"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{
re
ver
se
_pass
{},
re
ver
se
_pass
{}};
return
{
in
ver
t
_pass
{},
in
ver
t
_pass
{}};
}
migraphx
::
context
get_context
()
const
{
return
{};
}
};
...
...
@@ -167,20 +184,38 @@ TEST_CASE(param_error_test)
"Parameter not found: y"
));
}
TEST_CASE
(
param
_shape_error_test
)
TEST_CASE
(
get_
param
1
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
y
=
p
.
add_parameter
(
"y"
,
s
);
p
.
add_instruction
(
sum_op
{},
x
,
y
);
EXPECT
(
bool
{
p
.
get_parameter
(
"x"
)
==
x
});
EXPECT
(
bool
{
p
.
get_parameter
(
"y"
)
==
y
});
EXPECT
(
bool
{
p
.
get_parameter
(
"nonexistent"
)
==
p
.
end
()});
}
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}});
TEST_CASE
(
get_param2
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
EXPECT
(
bool
{
p
.
get_parameter
(
"nonexistent"
)
==
p
.
end
()});
}
TEST_CASE
(
get_param_shapes
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
y
=
p
.
add_parameter
(
"y"
,
s
);
p
.
add_instruction
(
sum_op
{},
x
,
y
);
EXPECT
(
test
::
throws
<
migraphx
::
exception
>
(
[
&
]
{
p
.
eval
({{
"x"
,
migraphx
::
literal
{
1
}.
get_argument
()},
{
"y"
,
migraphx
::
literal
{
2
}.
get_argument
()}});
},
"Incorrect shape"
));
auto
m
=
p
.
get_parameter_shapes
();
EXPECT
(
m
.
count
(
"nonexistent"
)
==
0
);
EXPECT
(
m
.
at
(
"x"
)
==
s
);
EXPECT
(
m
.
at
(
"y"
)
==
s
);
}
TEST_CASE
(
replace_test
)
...
...
@@ -249,6 +284,40 @@ TEST_CASE(insert_replace_test)
EXPECT
(
result
!=
migraphx
::
literal
{
5
});
}
TEST_CASE
(
remove_test1
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
removed
=
p
.
add_instruction
(
minus_op
{},
sum
,
one
);
p
.
remove_instruction
(
removed
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
EXPECT
(
result
!=
migraphx
::
literal
{
1
});
}
TEST_CASE
(
remove_test2
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
removed
=
p
.
add_instruction
(
minus_op
{},
two
,
one
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
remove_instruction
(
removed
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
EXPECT
(
result
!=
migraphx
::
literal
{
1
});
}
TEST_CASE
(
target_test
)
{
migraphx
::
program
p
;
...
...
@@ -262,27 +331,27 @@ TEST_CASE(target_test)
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
}
TEST_CASE
(
re
ver
se
_target_test
)
TEST_CASE
(
in
ver
t
_target_test
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
two
,
one
);
p
.
compile
(
re
ver
se
_target
{});
p
.
compile
(
in
ver
t
_target
{});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
1
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
}
TEST_CASE
(
double_
re
ver
se
_target_test
)
TEST_CASE
(
double_
in
ver
t
_target_test
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
two
,
one
);
p
.
compile
(
double_
re
ver
se
_target
{});
p
.
compile
(
double_
in
ver
t
_target
{});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
...
...
test/generate.cpp
0 → 100644
View file @
d18238bb
#include <migraphx/generate.hpp>
#include "test.hpp"
TEST_CASE
(
generate
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
4
,
1
,
1
}};
EXPECT
(
migraphx
::
generate_literal
(
s
,
1
)
==
migraphx
::
generate_argument
(
s
,
1
));
EXPECT
(
migraphx
::
generate_literal
(
s
,
1
)
!=
migraphx
::
generate_argument
(
s
,
0
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/perf_report.cpp
0 → 100644
View file @
d18238bb
#include <migraphx/program.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/ranges.hpp>
#include "test.hpp"
TEST_CASE
(
perf_report
)
{
migraphx
::
program
p
;
std
::
stringstream
ss
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
migraphx
::
op
::
add
{},
one
,
two
);
p
.
compile
(
migraphx
::
cpu
::
target
{});
p
.
perf_report
(
ss
,
2
,
{});
std
::
string
output
=
ss
.
str
();
EXPECT
(
migraphx
::
contains
(
output
,
"Summary:"
));
EXPECT
(
migraphx
::
contains
(
output
,
"Rate:"
));
EXPECT
(
migraphx
::
contains
(
output
,
"Total time:"
));
EXPECT
(
migraphx
::
contains
(
output
,
"Total instructions time:"
));
EXPECT
(
migraphx
::
contains
(
output
,
"Overhead time:"
));
EXPECT
(
migraphx
::
contains
(
output
,
"Overhead:"
));
EXPECT
(
not
migraphx
::
contains
(
output
,
"fast"
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/program_test.cpp
View file @
d18238bb
...
...
@@ -31,6 +31,31 @@ TEST_CASE(program_equality)
EXPECT
(
x
==
y
);
}
TEST_CASE
(
program_not_equality1
)
{
migraphx
::
program
x
;
migraphx
::
program
y
=
create_program
();
EXPECT
(
x
!=
y
);
x
=
y
;
EXPECT
(
x
==
y
);
}
TEST_CASE
(
program_not_equality2
)
{
migraphx
::
program
x
;
migraphx
::
program
y
=
create_program
();
EXPECT
(
x
!=
y
);
y
=
x
;
EXPECT
(
x
==
y
);
}
TEST_CASE
(
program_default_copy_construct
)
{
migraphx
::
program
x
;
migraphx
::
program
y
;
EXPECT
(
x
==
y
);
}
TEST_CASE
(
program_copy
)
{
auto
create_program_1
=
[]
{
...
...
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