|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #include "test/common/norm.h"
- #include "megdnn/dtype.h"
- #include "megdnn/oprs.h"
- #include "test/common/benchmarker.h"
- #include "test/common/checker.h"
- #include "test/naive/fixture.h"
-
- namespace megdnn {
- namespace test {
- TEST_F(NAIVE, L2NORM_FP32_DIM0) {
- Checker<Norm> checker(handle(), false);
- Norm::Param param;
- param.p = 2;
- param.dim = 0;
- checker.set_param(param);
- checker.exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- });
- }
- TEST_F(NAIVE, L2NORM_FP32_DIM1) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 2;
- param.dim = 1;
- checker.set_param(param);
- checker.exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 1, 3, 4}, dtype::Float32(),
- {12.000, 13.0384, 14.1421, 15.2971, 16.4924, 17.7200,
- 18.9737, 20.2485, 21.5407, 22.8473, 24.1661, 25.4951}),
- });
- }
- TEST_F(NAIVE, L2NORM_FP32_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 2;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 2, 3, 1}, dtype::Float32(),
- {3.7417, 11.2250, 19.1311, 27.0924, 35.0714, 43.0581})});
- }
- // l2, fp16
- TEST_F(NAIVE, L2NORM_FP16_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 2;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float16(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 2, 3, 1}, dtype::Float16(),
- {3.7422, 11.2266, 19.1250, 27.0938, 35.0625, 43.0625})});
- }
- // l1, fp32,fp16
- TEST_F(NAIVE, L1NORM_FP32_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 1;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 2, 3, 1}, dtype::Float32(), {6, 22, 38, 54, 70, 86}),
- });
- }
- TEST_F(NAIVE, L1NORM_FP16_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 1;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float16(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue(
- {1, 2, 3, 1}, dtype::Float16(), {6, 22, 38, 54, 70, 86}),
- });
- }
- // l0, fp32,fp16
- TEST_F(NAIVE, L0NORM_FP32_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 0;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float32(), {3, 4, 4, 4, 4, 4}),
- });
- }
- TEST_F(NAIVE, L0NORM_FP16_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.p = 0;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float16(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float16(), {3, 4, 4, 4, 4, 4}),
- });
- }
- // inf
- TEST_F(NAIVE, INF_NORM_FP32_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- using Mode = Norm::Param::Mode;
-
- param.dim = 3;
- param.mode = Mode::INF_NORM;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float32(), {3, 7, 11, 15, 19, 23}),
- });
- }
- TEST_F(NAIVE, INF_NORM_FP16_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- using Mode = Norm::Param::Mode;
-
- param.dim = 3;
- param.mode = Mode::INF_NORM;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float16(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float16(), {3, 7, 11, 15, 19, 23}),
- });
- }
- // -inf
- TEST_F(NAIVE, NEG_INF_NORM_FP32_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.mode = Norm::Param::Mode::NEG_INF_NORM;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float32(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float32(), {0, 4, 8, 12, 16, 20}),
- });
- }
- TEST_F(NAIVE, NEG_INF_NORM_FP16_DIM3) {
- Checker<Norm> checker(handle());
- Norm::Param param;
- param.mode = Norm::Param::Mode::NEG_INF_NORM;
- param.dim = 3;
- checker.set_param(param).exect(
- Testcase{
- TensorValue(
- {1, 2, 3, 4}, dtype::Float16(),
- {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}),
- {}},
- Testcase{
- {},
- TensorValue({1, 2, 3, 1}, dtype::Float16(), {0, 4, 8, 12, 16, 20}),
- });
- }
-
- } // namespace test
- } // namespace megdnn
|