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
c31c616c
Commit
c31c616c
authored
Jun 25, 2021
by
Shucai Xiao
Browse files
add unit tests
parent
7135da72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
0 deletions
+131
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+78
-0
test/verify/test_scatter0.cpp
test/verify/test_scatter0.cpp
+26
-0
test/verify/test_scatter1.cpp
test/verify/test_scatter1.cpp
+27
-0
No files found.
test/ref_ops_test.cpp
View file @
c31c616c
...
...
@@ -3651,6 +3651,84 @@ TEST_CASE(rsqrt_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
scatter_test
)
{
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
std
::
vector
<
float
>
vd
(
sd
.
elements
(),
0.0
f
);
migraphx
::
shape
si
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
std
::
vector
<
int
>
vi
=
{
1
,
0
,
2
,
0
,
2
,
1
};
migraphx
::
shape
su
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
std
::
vector
<
float
>
vu
=
{
1.0
,
1.1
,
1.2
,
2.0
,
2.1
,
2.2
};
auto
ld
=
mm
->
add_literal
(
migraphx
::
literal
{
sd
,
vd
});
auto
li
=
mm
->
add_literal
(
migraphx
::
literal
{
si
,
vi
});
auto
lu
=
mm
->
add_literal
(
migraphx
::
literal
{
su
,
vu
});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatter"
,
{{
"axis"
,
0
}}),
ld
,
li
,
lu
);
mm
->
add_return
({
r
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
2.0
,
1.1
,
0.0
,
1.0
,
0.0
,
2.2
,
0.0
,
2.1
,
1.2
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
std
::
vector
<
float
>
vd
(
sd
.
elements
(),
0.0
f
);
migraphx
::
shape
si
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
std
::
vector
<
int
>
vi
=
{
1
,
0
,
2
,
0
,
2
,
1
};
migraphx
::
shape
su
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
std
::
vector
<
float
>
vu
=
{
1.0
,
1.1
,
1.2
,
2.0
,
2.1
,
2.2
};
auto
ld
=
mm
->
add_literal
(
migraphx
::
literal
{
sd
,
vd
});
auto
li
=
mm
->
add_literal
(
migraphx
::
literal
{
si
,
vi
});
auto
lu
=
mm
->
add_literal
(
migraphx
::
literal
{
su
,
vu
});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatter"
,
{{
"axis"
,
-
2
}}),
ld
,
li
,
lu
);
mm
->
add_return
({
r
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
2.0
,
1.1
,
0.0
,
1.0
,
0.0
,
2.2
,
0.0
,
2.1
,
1.2
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
std
::
vector
<
float
>
vd
(
sd
.
elements
(),
0.0
f
);
migraphx
::
shape
si
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
std
::
vector
<
int
>
vi
=
{
1
,
0
,
2
,
0
,
2
,
1
};
migraphx
::
shape
su
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
std
::
vector
<
float
>
vu
=
{
1.0
,
1.1
,
1.2
,
2.0
,
2.1
,
2.2
};
auto
ld
=
mm
->
add_literal
(
migraphx
::
literal
{
sd
,
vd
});
auto
li
=
mm
->
add_literal
(
migraphx
::
literal
{
si
,
vi
});
auto
lu
=
mm
->
add_literal
(
migraphx
::
literal
{
su
,
vu
});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatter"
,
{{
"axis"
,
1
}}),
ld
,
li
,
lu
);
mm
->
add_return
({
r
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.1
,
1.0
,
1.2
,
2.0
,
2.2
,
2.1
,
0.0
,
0.0
,
0.0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
sigmoid_test
)
{
migraphx
::
program
p
;
...
...
test/verify/test_scatter0.cpp
0 → 100644
View file @
c31c616c
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_scatter0
:
verify_program
<
test_scatter0
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
si
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
std
::
vector
<
int
>
vi
=
{
1
,
0
,
2
,
0
,
2
,
1
};
migraphx
::
shape
su
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
pd
=
mm
->
add_parameter
(
"data"
,
sd
);
auto
li
=
mm
->
add_literal
(
migraphx
::
literal
{
si
,
vi
});
auto
pu
=
mm
->
add_parameter
(
"update"
,
su
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatter"
,
{{
"axis"
,
-
1
}}),
pd
,
li
,
pu
);
mm
->
add_return
({
r
});
return
p
;
}
};
test/verify/test_scatter1.cpp
0 → 100644
View file @
c31c616c
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_scatter1
:
verify_program
<
test_scatter1
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
si
{
migraphx
::
shape
::
int32_type
,
{
2
,
3
}};
std
::
vector
<
int
>
vi
=
{
1
,
0
,
2
,
0
,
2
,
1
};
migraphx
::
shape
su
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
pd
=
mm
->
add_parameter
(
"data"
,
sd
);
auto
li
=
mm
->
add_literal
(
migraphx
::
literal
{
si
,
vi
});
auto
pu
=
mm
->
add_parameter
(
"update"
,
su
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatter"
,
{{
"axis"
,
-
2
}}),
pd
,
li
,
pu
);
mm
->
add_return
({
r
});
return
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