From 0ab88c428366a6f8bf433a252cb4a462d3e2aa01 Mon Sep 17 00:00:00 2001 From: MyPandaShaoxiang Date: Tue, 7 Aug 2018 16:52:33 +0800 Subject: [PATCH 01/11] add reshape op --- saber/funcs/reshape.h | 12 ++--- saber/saber_funcs_param.h | 2 +- test/saber/test_saber_reshape.cpp | 89 +++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 test/saber/test_saber_reshape.cpp diff --git a/saber/funcs/reshape.h b/saber/funcs/reshape.h index 17158d6a3..754116b94 100644 --- a/saber/funcs/reshape.h +++ b/saber/funcs/reshape.h @@ -49,10 +49,10 @@ class Reshape : public BaseFunc< Shape output_shape; output_shape.resize(param.shape_params.size()); - CHECK_EQ(input[0]->is_continue_mem(), true) << "input tensor must not have roi"; + CHECK_EQ(input[0] -> is_continue_mem(), true) << "input tensor must not have roi"; - Shape input_shape = input[0]->valid_shape(); - int valid_size = input[0]->valid_size(); + Shape input_shape = input[0] -> valid_shape(); + int valid_size = input[0] -> valid_size(); int infer_axis = -1; int count_axis = 1; for (int i = 0; i < param.shape_params.size(); ++i) { @@ -72,7 +72,7 @@ class Reshape : public BaseFunc< if (infer_axis >= 0){ output_shape[infer_axis] = valid_size / count_axis; } - return output[0]->set_shape(output_shape); + return output[0] -> set_shape(output_shape); } //Reshape ops do nothing virtual SaberStatus init_impl(ImplEnum implenum) override { @@ -95,14 +95,14 @@ class Reshape : public BaseFunc< virtual void pick_best_static() override { //saber impl - this->_best_impl = this->_impl[0]; + this -> _best_impl = this -> _impl[0]; } //virtual void pick_best_runtime(Input_v input, Output_v output, Param_t& param) override {} virtual void pick_best_specify(ImplEnum implenum) override { //saber impl - this->_best_impl = this->_impl[0]; + this -> _best_impl = this -> _impl[0]; } }; diff --git a/saber/saber_funcs_param.h b/saber/saber_funcs_param.h index 17ab1e4c6..983c7aa6e 100644 --- a/saber/saber_funcs_param.h +++ b/saber/saber_funcs_param.h @@ -256,7 +256,7 @@ struct NormalizeParam { }; template - struct PoolingParam { +struct PoolingParam { PoolingParam() : window_h(-1), window_w(-1) , pad_h(-1), pad_w(-1) , stride_h(-1), stride_w(-1) diff --git a/test/saber/test_saber_reshape.cpp b/test/saber/test_saber_reshape.cpp new file mode 100644 index 000000000..eb98e7cef --- /dev/null +++ b/test/saber/test_saber_reshape.cpp @@ -0,0 +1,89 @@ + +#include "saber/funcs/reshape.h" + +#include +#include + +#include "saber/core/context.h" +#include "saber/saber_types.h" +#include "saber/core/tensor_op.h" +#include "test/saber/test_saber_func.h" +#include "test/saber/test_saber_base.h" +#include "saber/core/tensor_op.h" + +using namespace anakin::saber; + +template +void reshape_cpu_func(const std::vector*>& input, std::vector*>& output, ReshapeParam& param) { + Shape in_shape = input[0] -> valid_shape(); + Shape param_shape = param.shape_params; + Shape out_shape; + out_shape.resize(param_shape.size()); + int infer_axis = 0; + int num_axis = 1; + int infer_count=0; + for (int i=0; i < param_shape.size(); ++i){ + CHECK_LT(i, in_shape.size()) << "param index exceed input dims"; + if ( param_shape[i] == 0){ + out_shape[i] = in_shape[i]; + num_axis *= out_shape[i]; + } else if (param_shape[i] == -1){ + infer_axis = i; + ++infer_count; + } else { + out_shape[i] = param_shape[i]; + num_axis *= out_shape[i]; + } + CHECK_EQ(infer_count, 1) << "infer axises cannot exceed 1"; + if (infer_axis >= 0){ + out_shape[infer_axis] = input[0] -> valid_size() / num_axis; + } + } + //output[0] -> copy_from(*input[0]); + output[0] -> set_shape(out_shape); +} + +TEST(TestSaberFunc, test_func_reshape) { +#ifdef USE_CUDA + //Init the test_base + TestSaberBase testbase; + + for (int rs0 : {-1, 2}){ + for (int rs1 : {-1, 4}){ + for (int rs2 : {-1, 8}){ + for (int rs3 : {-1, 16}){ + std::vector new_shape{rs0, rs1, rs2, rs3}; + if (std::count(new_shape.begin(), new_shape.end(), -1) == 1){ + ReshapeParam param(new_shape); + for (int n : {1, 2}){ + for (int c : {1, 4}){ + for (int h: {32, 64}){ + for (int w : {32, 64}){ + testbase.set_param(param); + testbase.set_input_shape(Shape({n, c, h, w})); + testbase.run_test(reshape_cpu_func); + } + } + } + } + } + } + } + } + } + +#endif + +} + + + +int main(int argc, const char** argv) { + // initial logger + //logger::init(argv[0]); + + InitTest(); + RUN_ALL_TESTS(argv[0]); + return 0; +} + From a65bc39e461e04ef1c72e05a442d087ff7acf610 Mon Sep 17 00:00:00 2001 From: MyPandaShaoxiang Date: Tue, 7 Aug 2018 16:53:03 +0800 Subject: [PATCH 02/11] merge to commit --- test/saber/test_saber_base.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/saber/test_saber_base.h b/test/saber/test_saber_base.h index b5a8e9537..f9512d530 100644 --- a/test/saber/test_saber_base.h +++ b/test/saber/test_saber_base.h @@ -183,6 +183,7 @@ namespace saber{ CHECK_LT(param_index,_params.size())<<"param index out of range"; Context ctx(0,1,1); + print_tensor(*_outputs_dev[0][0]); for(int input_index=0;input_index<_inputs_dev.size();++input_index){ _baseOp.init(_inputs_dev[input_index],_outputs_dev[input_index], _params[param_index],strategy,implenum,ctx); @@ -206,6 +207,7 @@ namespace saber{ virtual void get_cpu_result(CpuFunc_t CpuFunc,int param_index=0){ CHECK_EQ(_inputs_dev.size(),_outputs_dev.size())<<"input and output number must be equal"; CHECK_EQ(_outputs_hd.size(),_outputs_dev.size())<<"input and output number must be equal"; + for(int i=0;i<_inputs_dev.size();++i){ CpuFunc(_inputs_host[i],_outputs_host[i],_params[param_index]);//depend on cpu func form? @@ -226,9 +228,11 @@ namespace saber{ LOG(INFO)<<"max_ratio:"< Date: Tue, 7 Aug 2018 17:53:34 +0800 Subject: [PATCH 03/11] add reshape test --- saber/saber_funcs_param.h | 102 ++++++++++++++++++++++++++++ test/saber/test_saber_base.h | 17 ++--- test/saber/test_saber_normalize.cpp | 26 ++----- test/saber/test_saber_reshape.cpp | 19 +++--- 4 files changed, 128 insertions(+), 36 deletions(-) diff --git a/saber/saber_funcs_param.h b/saber/saber_funcs_param.h index b82ae4c2b..a2a7dd5ab 100644 --- a/saber/saber_funcs_param.h +++ b/saber/saber_funcs_param.h @@ -420,6 +420,108 @@ struct SliceParam { int axis; std::vector slice_points; }; +template +struct ReshapeParam { + ReshapeParam() = default; + explicit ReshapeParam(std::vector shape_param_in){ + int count = 0; + for (int i = 0; i < shape_param_in.size(); ++i) { + if (shape_param_in[i] == -1){ + count ++; + } + } + CHECK_LE(count, 1) << "shape parameter contains multiple -1 dims"; + shape_params = shape_param_in; + } + ReshapeParam(const ReshapeParam &right) { + shape_params = right.shape_params; + } + ReshapeParam &operator=(const ReshapeParam &right) { + shape_params = right.shape_params; + return *this; + } + bool operator==(const ReshapeParam &right) { + bool comp_eq = shape_params.size() == right.shape_params.size(); + for (int i = 0; i < shape_params.size(); ++i) { + if (!comp_eq){ + return false; + } + comp_eq = shape_params[i] == right.shape_params[i]; + } + return true; + } + std::vector shape_params; +}; + template + struct PoolingParam { + PoolingParam() : window_h(-1), window_w(-1) + , pad_h(-1), pad_w(-1) + , stride_h(-1), stride_w(-1) + , pooling_type(Pooling_unknow) + , global_pooling(false) + , cmp_out_shape_floor_as_conv(false) + {} + PoolingParam(int window_h_in, int window_w_in, int pad_h_in + , int pad_w_in, int stride_h_in, int stride_w_in, PoolingType type + , bool global_pooling_in = false, bool cmp_out_shape_floor_as_conv_in = false) + : window_h(window_h_in), window_w(window_w_in) + , pad_h(pad_h_in), pad_w(pad_w_in) + , stride_h(stride_h_in), stride_w(stride_w_in) + , pooling_type(type) + , global_pooling(global_pooling_in) + , cmp_out_shape_floor_as_conv(cmp_out_shape_floor_as_conv_in) + {} + PoolingParam(const PoolingParam &right) + : window_h(right.window_h) + , window_w(right.window_w) + , pad_h(right.pad_h) + , pad_w(right.pad_w) + , stride_h(right.stride_h) + , stride_w(right.stride_w) + , pooling_type(right.pooling_type) + , global_pooling(right.global_pooling) + , cmp_out_shape_floor_as_conv(right.cmp_out_shape_floor_as_conv) + {} + PoolingParam &operator=(const PoolingParam &right) { + window_h = right.window_h; + window_w = right.window_w; + pad_h = right.pad_h; + pad_w = right.pad_w; + stride_h = right.stride_h; + stride_w = right.stride_w; + pooling_type = right.pooling_type; + global_pooling = right.global_pooling; + cmp_out_shape_floor_as_conv = right.cmp_out_shape_floor_as_conv; + return *this; + } + bool operator==(const PoolingParam &right) { + bool comp_eq = true; + comp_eq = comp_eq && (window_h == right.window_h); + comp_eq = comp_eq && (window_w == right.window_w); + comp_eq = comp_eq && (pad_h == right.pad_h); + comp_eq = comp_eq && (pad_w == right.pad_w); + comp_eq = comp_eq && (stride_h == right.stride_h); + comp_eq = comp_eq && (stride_w == right.stride_w); + comp_eq = comp_eq && (pooling_type == right.pooling_type); + comp_eq = comp_eq && (global_pooling == right.global_pooling); + comp_eq = comp_eq && (cmp_out_shape_floor_as_conv == right.cmp_out_shape_floor_as_conv); + return comp_eq; + } + inline bool pooling_padded() { + return (pad_h || pad_w); + } + int window_h; + int window_w; + int pad_h; + int pad_w; + int stride_h; + int stride_w; + PoolingType pooling_type; + bool global_pooling; + bool cmp_out_shape_floor_as_conv; + }; + + } } #endif //SABER_FUNCS_PARAM_H diff --git a/test/saber/test_saber_base.h b/test/saber/test_saber_base.h index 8fba378ba..11757f0e2 100644 --- a/test/saber/test_saber_base.h +++ b/test/saber/test_saber_base.h @@ -201,6 +201,9 @@ class TestSaberBase{ _outputs_dev[i][j] -> re_alloc(sh, Dtype); _outputs_host[i][j] -> re_alloc(sh, Dtype); _outputs_hd[i][j] -> re_alloc(sh, Dtype); + + fill_tensor_const(*_outputs_dev[i][j],0); + fill_tensor_const(*_outputs_host[i][j],0); } } } @@ -244,12 +247,10 @@ class TestSaberBase{ return status; } typename TensorD :: API :: stream_t stream = ctx.get_compute_stream(); - //always 0? _outputs_dev[input_index][0] -> record_event(stream); - _outputs_dev[input_index][0] -> sync();// + _outputs_dev[input_index][0] -> sync(); } - //print_tensor(*_outputs_hd[0][0]); } t.end(ctx); float ts = t.get_average_ms(); @@ -280,11 +281,11 @@ class TestSaberBase{ _outputs_hd[i][j] -> valid_size(), max_ratio[i], max_diff[i]); LOG(INFO) << "input_shape:(" << sh.num() << "," << sh.channel() << "," << sh.height() << "," << sh.width() << ")"; LOG(INFO) << "max_ratio:" << max_ratio[i]; - if(max_ratio[i] <= succ_ratio && (_outputs_hd[i][0]->valid_shape() == _outputs_host[i][0]->valid_shape())) + if(max_ratio[i] <= succ_ratio && (_outputs_hd[i][0]->valid_shape() == _outputs_host[i][0]->valid_shape())){ LOG(INFO) << "Test Passed!"; - else + } else { LOG(FATAL) << "Test Failed!!"<< "output:(" << i << "-" << j << ")"; - //LOG(ERROR)<<"Test Failed!!"; + } } } } @@ -301,8 +302,8 @@ class TestSaberBase{ Env :: env_init(); Env :: env_init(); - std :: vector runtype{"STATIC","RUNTIME","SPECIFY"}; - std :: vector impltype{"VENDER","SABER"}; + std :: vector runtype{"STATIC", "RUNTIME", "SPECIFY"}; + std :: vector impltype{"VENDER", "SABER"}; for(auto strate : {SPECIFY, RUNTIME, STATIC}){ for(auto implenum : {VENDER_IMPL, SABER_IMPL}){ LOG(INFO) << "TESTING: strategy:" << runtype[strate-1] << ",impltype:" << impltype[(int)implenum]; diff --git a/test/saber/test_saber_normalize.cpp b/test/saber/test_saber_normalize.cpp index c7f88f019..d5445257f 100644 --- a/test/saber/test_saber_normalize.cpp +++ b/test/saber/test_saber_normalize.cpp @@ -1,4 +1,3 @@ - #include "core/context.h" #include "funcs/normalize.h" #include "test_saber_func.h" @@ -10,7 +9,7 @@ using namespace anakin::saber; /*CPU function form: - void FuncName(const std::vector*>& input,std::vector*>& output,Param& param,Shape shape) + void FuncName(const std::vector*>& input,std::vector*>& output,Param& param,Shape shape) */ template void norm_cpu_nchw(const std::vector*>& input,std::vector*>& output,NormalizeParam& param) { @@ -68,10 +67,9 @@ void norm_cpu_nchw(const std::vector*>& input,std::vector*>& input,std::vector*>& input,std::vector*>& input, std::vect out_shape[i] = param_shape[i]; num_axis *= out_shape[i]; } - CHECK_EQ(infer_count, 1) << "infer axises cannot exceed 1"; - if (infer_axis >= 0){ - out_shape[infer_axis] = input[0] -> valid_size() / num_axis; - } } - //output[0] -> copy_from(*input[0]); + CHECK_LE(infer_count, 1) << "infer axises cannot exceed 1"; + if (infer_axis >= 0){ + out_shape[infer_axis] = input[0] -> valid_size() / num_axis; + } output[0] -> set_shape(out_shape); } @@ -48,13 +47,15 @@ TEST(TestSaberFunc, test_func_reshape) { //Init the test_base TestSaberBase testbase; - for (int rs0 : {-1, 2}){ - for (int rs1 : {-1, 4}){ - for (int rs2 : {-1, 8}){ - for (int rs3 : {-1, 16}){ + //test shape contain -1 + for (int rs0 : {0, -1, 2}){ + for (int rs1 : {0, -1, 4}){ + for (int rs2 : {0, -1, 8}){ + for (int rs3 : {0, -1, 16}){ std::vector new_shape{rs0, rs1, rs2, rs3}; if (std::count(new_shape.begin(), new_shape.end(), -1) == 1){ ReshapeParam param(new_shape); + LOG(INFO) << "new_shape:"< Date: Tue, 14 Aug 2018 15:23:37 +0800 Subject: [PATCH 04/11] fix testbase --- test/saber/test_saber_base.h | 18 +++++++++++------- test/saber/test_saber_reshape.cpp | 24 ++++++++++++++++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/test/saber/test_saber_base.h b/test/saber/test_saber_base.h index 11757f0e2..5966d58a8 100644 --- a/test/saber/test_saber_base.h +++ b/test/saber/test_saber_base.h @@ -22,6 +22,7 @@ #include "saber/saber_types.h" #include "saber/core/tensor_op.h" #include "test/saber/test_saber_func.h" +#include "saber/core/data_traits.h" #include "utils/unit_test/aktest.h" #include "utils/logger/logger.h" @@ -36,6 +37,7 @@ namespace saber{ template class Param> class TestSaberBase{ public: + typedef typename DataTrait :: Dtype dtype; typedef Param Param_t; typedef Op Op_t; typedef Tensor TensorH; @@ -149,7 +151,7 @@ class TestSaberBase{ } } } - void fill_inputs (double minv, double maxv){ + void fill_inputs (float minv, float maxv){ int input_size = _inputs_dev.size(); CHECK_EQ(input_size, _inputs_host.size()) << "dev and host inputs num must be equal"; if(_input_type == RANDOM){ @@ -174,7 +176,7 @@ class TestSaberBase{ clear_datas(); std::vector shape_v; for (int i=0; i<_op_input_num; ++i){ - shape_v.push_back(input[0] -> shape()); + shape_v.push_back(input[0] -> valid_shape()); } add_inputs_shape(shape_v); for(int i = 0; i < _op_input_num; ++i) @@ -202,6 +204,7 @@ class TestSaberBase{ _outputs_host[i][j] -> re_alloc(sh, Dtype); _outputs_hd[i][j] -> re_alloc(sh, Dtype); + //init output_dev and output_host to equal fill_tensor_const(*_outputs_dev[i][j],0); fill_tensor_const(*_outputs_host[i][j],0); } @@ -277,7 +280,8 @@ class TestSaberBase{ for(int i = 0; i < _outputs_host.size(); ++i){ Shape sh = _inputs_host[i][0] -> shape(); for(int j = 0; j<_op_output_num; ++j){ - tensor_cmp_host((const float*)_outputs_hd[i][j] -> data(), (const float*)_outputs_host[i][j] -> data(), + tensor_cmp_host(static_cast(_outputs_hd[i][j] -> data()), + static_cast(_outputs_host[i][j] -> data()), _outputs_hd[i][j] -> valid_size(), max_ratio[i], max_diff[i]); LOG(INFO) << "input_shape:(" << sh.num() << "," << sh.channel() << "," << sh.height() << "," << sh.width() << ")"; LOG(INFO) << "max_ratio:" << max_ratio[i]; @@ -289,7 +293,7 @@ class TestSaberBase{ } } } - void set_rand_limit (double minv, double maxv){ + void set_rand_limit (float minv, float maxv){ _max_value = maxv; _min_value = minv; } @@ -323,9 +327,9 @@ class TestSaberBase{ int _op_output_num; Op_t _base_op; TestDataType _input_type; - double _special_value; - double _max_value{255.0}; - double _min_value{-255.0}; + dtype _special_value; + float _max_value{255.0}; + float _min_value{-255.0}; std :: vector _inputs_host; std :: vector _inputs_dev; std :: vector _outputs_dev; diff --git a/test/saber/test_saber_reshape.cpp b/test/saber/test_saber_reshape.cpp index a991f6e26..09812f629 100644 --- a/test/saber/test_saber_reshape.cpp +++ b/test/saber/test_saber_reshape.cpp @@ -46,7 +46,20 @@ TEST(TestSaberFunc, test_func_reshape) { #ifdef USE_CUDA //Init the test_base TestSaberBase testbase; - + auto param_check = [](std::vector new_shape, std::vector in_shape) -> bool { + CHECK_EQ(new_shape.size(), in_shape.size()) << "invalid check"; + int new_count=1; + int in_count=1; + for(int i=0; i 0){ + in_count *= in_shape[i]; + if (new_shape[i] !=-1){ + new_count *= new_shape[i]; + } + } + } + return new_count <= in_count; + }; //test shape contain -1 for (int rs0 : {0, -1, 2}){ for (int rs1 : {0, -1, 4}){ @@ -60,9 +73,12 @@ TEST(TestSaberFunc, test_func_reshape) { for (int c : {1, 4}){ for (int h: {32, 64}){ for (int w : {32, 64}){ - testbase.set_param(param); - testbase.set_input_shape(Shape({n, c, h, w})); - testbase.run_test(reshape_cpu_func); + Shape in_shape({n, c, h, w}); + if (param_check(new_shape, in_shape)){ + testbase.set_param(param); + testbase.set_input_shape(in_shape); + testbase.run_test(reshape_cpu_func); + } } } } From 925d5e460e95733df0292b6feb589030d1172b44 Mon Sep 17 00:00:00 2001 From: MyPandaShaoxiang Date: Tue, 14 Aug 2018 16:18:05 +0800 Subject: [PATCH 05/11] fix reshape cpu func --- test/saber/test_saber_reshape.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/saber/test_saber_reshape.cpp b/test/saber/test_saber_reshape.cpp index 09812f629..d67d88904 100644 --- a/test/saber/test_saber_reshape.cpp +++ b/test/saber/test_saber_reshape.cpp @@ -19,7 +19,7 @@ void reshape_cpu_func(const std::vector*>& input, std::vect Shape param_shape = param.shape_params; Shape out_shape; out_shape.resize(param_shape.size()); - int infer_axis = 0; + int infer_axis = -1; int num_axis = 1; int infer_count=0; for (int i=0; i < param_shape.size(); ++i){ @@ -60,7 +60,7 @@ TEST(TestSaberFunc, test_func_reshape) { } return new_count <= in_count; }; - //test shape contain -1 + //test shape contain -1 and 0 for (int rs0 : {0, -1, 2}){ for (int rs1 : {0, -1, 4}){ for (int rs2 : {0, -1, 8}){ @@ -87,6 +87,23 @@ TEST(TestSaberFunc, test_func_reshape) { } } } + }//for rs0 + //test shape normal + std::vector new_shapes; + std::vector in_shapes; + new_shapes.emplace_back(Shape({1, 1, 3, 64})); + in_shapes.emplace_back(Shape({1, 3, 4, 16})); + new_shapes.emplace_back(Shape({1, 4, 3, 64})); + in_shapes.emplace_back(Shape({1, 1, 1, 3*64*4})); + new_shapes.emplace_back(Shape({2, 2, 3, 64})); + in_shapes.emplace_back(Shape({1, 2, 1, 2*3*64})); + new_shapes.emplace_back(Shape({32, 32, 3, 64})); + in_shapes.emplace_back(Shape({1, 3, 64, 32*32})); + for (int i=0; i param(new_shapes[i]); + testbase.set_param(param); + testbase.set_input_shape(in_shapes[i]); + testbase.run_test(reshape_cpu_func); } #endif From a36c949d7d345f33a4090eb6b09a2be3426b027b Mon Sep 17 00:00:00 2001 From: MyPandaShaoxiang Date: Mon, 20 Aug 2018 19:18:15 +0800 Subject: [PATCH 06/11] fix reshape --- saber/funcs/reshape.h | 1 + test/saber/test_saber_base.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/saber/funcs/reshape.h b/saber/funcs/reshape.h index 754116b94..747371a6e 100644 --- a/saber/funcs/reshape.h +++ b/saber/funcs/reshape.h @@ -18,6 +18,7 @@ #include "saber/funcs/base.h" #include "saber/funcs/impl/impl_base.h" +#include "saber/saber_funcs_param.h" namespace anakin { diff --git a/test/saber/test_saber_base.h b/test/saber/test_saber_base.h index 642bc6f1d..351fef8a2 100644 --- a/test/saber/test_saber_base.h +++ b/test/saber/test_saber_base.h @@ -288,8 +288,8 @@ class TestSaberBase{ Shape sh = _inputs_host[0][0] -> shape(); for(int i = 0; i < _outputs_host.size(); ++i){ for(int j = 0; j<_op_output_num; ++j){ - tensor_cmp_host(static_cast(_outputs_hd[i][j] -> data()), - static_cast(_outputs_host[i][j] -> data()), + tensor_cmp_host(static_cast(_outputs_hd[i][j] -> data()), + static_cast(_outputs_host[i][j] -> data()), _outputs_hd[i][j] -> valid_size(), max_ratio[i], max_diff[i]); LOG(INFO) << "input_shape:(" << sh.num() << "," << sh.channel() << "," << sh.height() << "," << sh.width() << ")"; LOG(INFO) << "max_ratio:" << max_ratio[i]; From d56f8161e7bf01afb6936b09aca51c6c3804d10b Mon Sep 17 00:00:00 2001 From: MyPandaShaoxiang Date: Thu, 23 Aug 2018 18:43:21 +0800 Subject: [PATCH 07/11] add reshape param --- saber/saber_funcs_param.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/saber/saber_funcs_param.h b/saber/saber_funcs_param.h index 9c4f6e399..66930f053 100644 --- a/saber/saber_funcs_param.h +++ b/saber/saber_funcs_param.h @@ -1586,6 +1586,38 @@ struct PriorBoxParam { std::vector order; }; +template +struct ReshapeParam { + ReshapeParam() = default; + explicit ReshapeParam(std::vector shape_param_in){ + int count = 0; + for (int i = 0; i < shape_param_in.size(); ++i) { + if (shape_param_in[i] == -1){ + count ++; + } + } + CHECK_LE(count, 1) << "shape parameter contains multiple -1 dims"; + shape_params = shape_param_in; + } + ReshapeParam(const ReshapeParam &right) { + shape_params = right.shape_params; + } + ReshapeParam &operator=(const ReshapeParam &right) { + shape_params = right.shape_params; + return *this; + } + bool operator==(const ReshapeParam &right) { + bool comp_eq = shape_params.size() == right.shape_params.size(); + for (int i = 0; i < shape_params.size(); ++i) { + if (!comp_eq){ + return false; + } + comp_eq = shape_params[i] == right.shape_params[i]; + } + return true; + } + std::vector shape_params; +}; template struct ResizeParam { From fe711f36915f76e0a3fd570a473d307b1790b92c Mon Sep 17 00:00:00 2001 From: TianXiaogang Date: Thu, 23 Aug 2018 19:55:39 +0800 Subject: [PATCH 08/11] Update test_saber_conv.cpp --- test/saber/test_saber_conv.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/saber/test_saber_conv.cpp b/test/saber/test_saber_conv.cpp index dd8369610..627603208 100644 --- a/test/saber/test_saber_conv.cpp +++ b/test/saber/test_saber_conv.cpp @@ -114,6 +114,7 @@ TEST(TestSaberFunc, test_saber_conv_results) { for (auto group : group_v) { Shape weights_s({out_channels, in_channels, kernel_h, kernel_w}, Layout_NCHW); Shape bias_s({1, out_channels, 1, 1}, Layout_NCHW); + #ifdef USE_CUDA Tensor weights_dev; Tensor bias_dev; From a02d7ae3fdabe63d8b0de28dd7ac7be1c71fcafc Mon Sep 17 00:00:00 2001 From: TianXiaogang Date: Thu, 23 Aug 2018 19:56:21 +0800 Subject: [PATCH 09/11] Update test_saber_conv.cpp --- test/saber/test_saber_conv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/saber/test_saber_conv.cpp b/test/saber/test_saber_conv.cpp index 627603208..840cf936b 100644 --- a/test/saber/test_saber_conv.cpp +++ b/test/saber/test_saber_conv.cpp @@ -112,9 +112,9 @@ TEST(TestSaberFunc, test_saber_conv_results) { for (auto in_channels : input_channels_v) for (auto out_channels : output_channels_v) for (auto group : group_v) { + Shape weights_s({out_channels, in_channels, kernel_h, kernel_w}, Layout_NCHW); Shape bias_s({1, out_channels, 1, 1}, Layout_NCHW); - #ifdef USE_CUDA Tensor weights_dev; Tensor bias_dev; From 052bc3c88bf3e28128ba4b68997187e6c2a4700b Mon Sep 17 00:00:00 2001 From: TianXiaogang Date: Thu, 23 Aug 2018 19:57:30 +0800 Subject: [PATCH 10/11] Update test_saber_conv.cpp --- test/saber/test_saber_conv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/saber/test_saber_conv.cpp b/test/saber/test_saber_conv.cpp index 840cf936b..ab13f40cf 100644 --- a/test/saber/test_saber_conv.cpp +++ b/test/saber/test_saber_conv.cpp @@ -112,7 +112,7 @@ TEST(TestSaberFunc, test_saber_conv_results) { for (auto in_channels : input_channels_v) for (auto out_channels : output_channels_v) for (auto group : group_v) { - + Shape weights_s({out_channels, in_channels, kernel_h, kernel_w}, Layout_NCHW); Shape bias_s({1, out_channels, 1, 1}, Layout_NCHW); #ifdef USE_CUDA From fe67fb50e2e1610c03fcb549d4911728b4f13c6b Mon Sep 17 00:00:00 2001 From: TianXiaogang Date: Thu, 23 Aug 2018 19:58:04 +0800 Subject: [PATCH 11/11] Update test_saber_normalize.cpp --- test/saber/test_saber_normalize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/saber/test_saber_normalize.cpp b/test/saber/test_saber_normalize.cpp index d5445257f..ab1741f94 100644 --- a/test/saber/test_saber_normalize.cpp +++ b/test/saber/test_saber_normalize.cpp @@ -1,3 +1,4 @@ + #include "core/context.h" #include "funcs/normalize.h" #include "test_saber_func.h"