|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- /**
- * \file dnn/test/common/padding.h
- * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
- *
- * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- */
- #pragma once
- #include <cstddef>
- #include <iostream>
- #include "megdnn/basic_types.h"
- #include "megdnn/opr_param_defs.h"
-
- namespace megdnn {
- namespace test {
- namespace padding {
-
- struct TestArg {
- param::Padding param;
- TensorShape src;
- TensorShape dst;
- TestArg(param::Padding _param, TensorShape _src, TensorShape _dst)
- : param(_param), src(_src), dst(_dst) {}
- };
-
- inline std::vector<TestArg> get_args() {
- size_t src_shape_dim0 = 5;
- size_t src_shape_dim1 = 5;
- size_t src_shape_dim2 = 5;
- size_t src_shape_dim3 = 5;
- size_t src_shape_dim4 = 5;
- size_t src_shape_dim5 = 5;
- size_t src_shape_dim6 = 5;
-
- size_t dst_shape_dim0 = 8;
- size_t dst_shape_dim1 = 8;
- size_t dst_shape_dim2 = 8;
- size_t dst_shape_dim3 = 8;
- size_t dst_shape_dim4 = 8;
- size_t dst_shape_dim5 = 8;
- size_t dst_shape_dim6 = 8;
-
- std::vector<TestArg> args;
-
- param::Padding cur_param;
-
- cur_param.front_offset_dim0 = 0;
- cur_param.front_offset_dim1 = 0;
- cur_param.front_offset_dim2 = 0;
- cur_param.front_offset_dim3 = 0;
- cur_param.front_offset_dim4 = 0;
- cur_param.front_offset_dim5 = 0;
- cur_param.front_offset_dim6 = 0;
- cur_param.back_offset_dim0 = 0;
- cur_param.back_offset_dim1 = 0;
- cur_param.back_offset_dim2 = 0;
- cur_param.back_offset_dim3 = 0;
- cur_param.back_offset_dim4 = 0;
- cur_param.back_offset_dim5 = 0;
- cur_param.back_offset_dim6 = 0;
-
- cur_param.padding_val = 2;
-
- cur_param.front_offset_dim0 = 1;
- cur_param.back_offset_dim0 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
- cur_param.front_offset_dim1 = 2;
- cur_param.back_offset_dim1 = 1;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.front_offset_dim2 = 1;
- cur_param.back_offset_dim2 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.front_offset_dim3 = 0;
- cur_param.back_offset_dim3 = 3;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.front_offset_dim4 = 3;
- cur_param.back_offset_dim4 = 0;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.front_offset_dim5 = 1;
- cur_param.back_offset_dim5 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.front_offset_dim6 = 0;
- cur_param.front_offset_dim6 = 3;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- return args;
-
- }
-
- inline std::vector<TestArg> get_args_backward() {
- size_t src_shape_dim0 = 8;
- size_t src_shape_dim1 = 8;
- size_t src_shape_dim2 = 8;
- size_t src_shape_dim3 = 8;
- size_t src_shape_dim4 = 8;
- size_t src_shape_dim5 = 8;
- size_t src_shape_dim6 = 8;
-
- size_t dst_shape_dim0 = 5;
- size_t dst_shape_dim1 = 5;
- size_t dst_shape_dim2 = 5;
- size_t dst_shape_dim3 = 5;
- size_t dst_shape_dim4 = 5;
- size_t dst_shape_dim5 = 5;
- size_t dst_shape_dim6 = 5;
-
- std::vector<TestArg> args;
-
- param::Padding cur_param;
-
- cur_param.front_offset_dim0 = 0;
- cur_param.front_offset_dim1 = 0;
- cur_param.front_offset_dim2 = 0;
- cur_param.front_offset_dim3 = 0;
- cur_param.front_offset_dim4 = 0;
- cur_param.front_offset_dim5 = 0;
- cur_param.front_offset_dim6 = 0;
- cur_param.back_offset_dim0 = 0;
- cur_param.back_offset_dim1 = 0;
- cur_param.back_offset_dim2 = 0;
- cur_param.back_offset_dim3 = 0;
- cur_param.back_offset_dim4 = 0;
- cur_param.back_offset_dim5 = 0;
- cur_param.back_offset_dim6 = 0;
-
- cur_param.padding_val = 2;
-
- cur_param.front_offset_dim0 = 1;
- cur_param.back_offset_dim0 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0},
- TensorShape{dst_shape_dim0});
-
-
- cur_param.front_offset_dim1 = 2;
- cur_param.back_offset_dim1 = 1;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param, TensorShape{src_shape_dim0, src_shape_dim1},
- TensorShape{dst_shape_dim0, dst_shape_dim1});
-
- cur_param.front_offset_dim2 = 1;
- cur_param.back_offset_dim2 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2});
-
- cur_param.front_offset_dim3 = 0;
- cur_param.back_offset_dim3 = 3;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1,
- src_shape_dim2, src_shape_dim3},
- TensorShape{dst_shape_dim0, dst_shape_dim1,
- dst_shape_dim2, dst_shape_dim3});
-
- cur_param.front_offset_dim4 = 3;
- cur_param.back_offset_dim4 =0;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4});
-
- cur_param.front_offset_dim5 = 1;
- cur_param.back_offset_dim5 = 2;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5});
-
- cur_param.front_offset_dim6 = 0;
- cur_param.back_offset_dim6 = 3;
-
- cur_param.padding_mode = param::Padding::PaddingMode::CONSTANT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REPLICATE;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- cur_param.padding_mode = param::Padding::PaddingMode::REFLECT;
- args.emplace_back(
- cur_param,
- TensorShape{src_shape_dim0, src_shape_dim1, src_shape_dim2,
- src_shape_dim3, src_shape_dim4, src_shape_dim5,
- src_shape_dim6},
- TensorShape{dst_shape_dim0, dst_shape_dim1, dst_shape_dim2,
- dst_shape_dim3, dst_shape_dim4, dst_shape_dim5,
- dst_shape_dim6});
-
- return args;
-
- }
-
- } // namespace padding
- } // namespace test
- } // namespace megdnn
|