From e6459329d5d05bdf1a361ed2bcc047475d85a56d Mon Sep 17 00:00:00 2001 From: eclipsess Date: Sat, 19 May 2018 11:20:10 +0800 Subject: [PATCH] code style --- test/operators/test_elementwise_add_op.cpp | 205 ++++++++++----------- test/operators/test_mul_op.cpp | 196 ++++++++++---------- 2 files changed, 198 insertions(+), 203 deletions(-) diff --git a/test/operators/test_elementwise_add_op.cpp b/test/operators/test_elementwise_add_op.cpp index 54aab5d4a6..b967c24918 100644 --- a/test/operators/test_elementwise_add_op.cpp +++ b/test/operators/test_elementwise_add_op.cpp @@ -17,114 +17,112 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ==============================================================================*/ #pragma once -#include "operators/elementwise_add_op.h" #include "../test_include.h" +#include "operators/elementwise_add_op.h" namespace paddle_mobile { - namespace framework { - - template - class TestElementwiseAddOp { - public: - TestElementwiseAddOp(const Program p) : program_(p) { - if (use_optimize_) { - to_predict_program_ = program_.optimizeProgram; - } else { - to_predict_program_ = program_.originProgram; - } - - const std::vector> blocks = - to_predict_program_->Blocks(); - // DLOG << " **block size " << blocks.size(); - for (int i = 0; i < blocks.size(); ++i) { - std::shared_ptr block_desc = blocks[i]; - std::vector> ops = block_desc->Ops(); - // DLOG << " ops " << ops.size(); - for (int j = 0; j < ops.size(); ++j) { - std::shared_ptr op = ops[j]; - // if (op->Type() == - // "elementwise_add") { - // if - // (op->GetAttrMap().at("axis").Get() - // != -1) { - // DLOG << "attr: axis = - // " - // << - // op->GetAttrMap().at("axis").Get(); - // } - // } - // DLOG << "op:" << op->Type(); - if (op->Type() == "elementwise_add" && - op->Input("X")[0] == "batch_norm_2.tmp_2") { - DLOG << " elementwise_add attr size: " - << op->GetAttrMap().size(); - DLOG << " inputs size: " << op->GetInputs().size(); - DLOG << " outputs size: " << op->GetOutputs().size(); - DLOG << " Input X is : " << op->Input("X")[0]; - DLOG << " Input Y is : " << op->Input("Y")[0]; - DLOG << " Output Out is : " << op->Output("Out")[0]; - Attribute axis_attr = op->GetAttrMap().at("axis"); - int axis = axis_attr.Get(); - DLOG << " Attr axis is : " << axis; - - std::shared_ptr> - add = std::make_shared< - operators::ElementwiseAddOp>( - op->Type(), op->GetInputs(), op->GetOutputs(), - op->GetAttrMap(), program_.scope); - ops_of_block_[*block_desc.get()].push_back(add); - } - } +namespace framework { + +template class TestElementwiseAddOp { + public: + TestElementwiseAddOp(const Program p) : program_(p) { + if (use_optimize_) { + to_predict_program_ = program_.optimizeProgram; + } else { + to_predict_program_ = program_.originProgram; + } + + const std::vector> blocks = + to_predict_program_->Blocks(); + // DLOG << " **block size " << blocks.size(); + for (int i = 0; i < blocks.size(); ++i) { + std::shared_ptr block_desc = blocks[i]; + std::vector> ops = block_desc->Ops(); + // DLOG << " ops " << ops.size(); + for (int j = 0; j < ops.size(); ++j) { + std::shared_ptr op = ops[j]; + // if (op->Type() == + // "elementwise_add") { + // if + // (op->GetAttrMap().at("axis").Get() + // != -1) { + // DLOG << "attr: axis = + // " + // << + // op->GetAttrMap().at("axis").Get(); + // } + // } + // DLOG << "op:" << op->Type(); + if (op->Type() == "elementwise_add" && + op->Input("X")[0] == "batch_norm_2.tmp_2") { + DLOG << " elementwise_add attr size: " + << op->GetAttrMap().size(); + DLOG << " inputs size: " << op->GetInputs().size(); + DLOG << " outputs size: " << op->GetOutputs().size(); + DLOG << " Input X is : " << op->Input("X")[0]; + DLOG << " Input Y is : " << op->Input("Y")[0]; + DLOG << " Output Out is : " << op->Output("Out")[0]; + Attribute axis_attr = op->GetAttrMap().at("axis"); + int axis = axis_attr.Get(); + DLOG << " Attr axis is : " << axis; + + std::shared_ptr> + add = std::make_shared< + operators::ElementwiseAddOp>( + op->Type(), op->GetInputs(), op->GetOutputs(), + op->GetAttrMap(), program_.scope); + ops_of_block_[*block_desc.get()].push_back(add); } } - - std::shared_ptr predict_add(Tensor &t1, Tensor &t2) { - // feed - auto scope = program_.scope; - Variable *x_feed_value = scope->Var("batch_norm_2.tmp_2"); - auto tensor_x = x_feed_value->GetMutable(); - tensor_x->ShareDataWith(t1); - - Variable *y_feed_value = scope->Var("batch_norm_0.tmp_3"); - auto tensor_y = y_feed_value->GetMutable(); - tensor_y->ShareDataWith(t2); - - Variable *con_output = scope->Var("elementwise_add_0.tmp_0"); - Tensor *output_tensor = con_output->GetMutable(); - output_tensor->mutable_data({1, 3, 224, 224}); - // DLOG << typeid(output_tensor).name(); - // DLOG << "output_tensor dims: " << output_tensor->dims(); - - std::shared_ptr out_tensor = std::make_shared(); - out_tensor.reset(output_tensor); - - predict_add(t1, t2, 0); - return out_tensor; - } - - private: - const framework::Program program_; - std::shared_ptr to_predict_program_; - std::map>>> - ops_of_block_; - bool use_optimize_ = false; - - void predict_add(const Tensor &t1, const Tensor &t2, int block_id) { - std::shared_ptr to_predict_block = - to_predict_program_->Block(block_id); - for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); - ++j) { - auto op = ops_of_block_[*to_predict_block.get()][j]; - DLOG << "op -> run()"; - op->Run(); - } - } - }; - - template - class TestElementwiseAddOp; - } // namespace framework + } + } + + std::shared_ptr predict_add(Tensor &t1, Tensor &t2) { + // feed + auto scope = program_.scope; + Variable *x_feed_value = scope->Var("batch_norm_2.tmp_2"); + auto tensor_x = x_feed_value->GetMutable(); + tensor_x->ShareDataWith(t1); + + Variable *y_feed_value = scope->Var("batch_norm_0.tmp_3"); + auto tensor_y = y_feed_value->GetMutable(); + tensor_y->ShareDataWith(t2); + + Variable *con_output = scope->Var("elementwise_add_0.tmp_0"); + Tensor *output_tensor = con_output->GetMutable(); + output_tensor->mutable_data({1, 3, 224, 224}); + // DLOG << typeid(output_tensor).name(); + // DLOG << "output_tensor dims: " << output_tensor->dims(); + + std::shared_ptr out_tensor = std::make_shared(); + out_tensor.reset(output_tensor); + + predict_add(t1, t2, 0); + return out_tensor; + } + + private: + const framework::Program program_; + std::shared_ptr to_predict_program_; + std::map>>> + ops_of_block_; + bool use_optimize_ = false; + + void predict_add(const Tensor &t1, const Tensor &t2, int block_id) { + std::shared_ptr to_predict_block = + to_predict_program_->Block(block_id); + for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); + ++j) { + auto op = ops_of_block_[*to_predict_block.get()][j]; + DLOG << "op -> run()"; + op->Run(); + } + } +}; + +template class TestElementwiseAddOp; +} // namespace framework } // namespace paddle_mobile int main() { DLOG << "----------**********----------"; @@ -162,4 +160,3 @@ int main() { << output_add_ptr[226]; return 0; } - diff --git a/test/operators/test_mul_op.cpp b/test/operators/test_mul_op.cpp index dbfb22429f..2f92ba33c6 100644 --- a/test/operators/test_mul_op.cpp +++ b/test/operators/test_mul_op.cpp @@ -17,119 +17,117 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ==============================================================================*/ #pragma once -#include "operators/mul_op.h" #include "../test_include.h" +#include "operators/mul_op.h" namespace paddle_mobile { - namespace framework { - - template - class TestMulOp { - public: - TestMulOp(const Program p) : program_(p) { - if (use_optimize_) { - to_predict_program_ = program_.optimizeProgram; - } else { - to_predict_program_ = program_.originProgram; - } +namespace framework { + +template class TestMulOp { + public: + TestMulOp(const Program p) : program_(p) { + if (use_optimize_) { + to_predict_program_ = program_.optimizeProgram; + } else { + to_predict_program_ = program_.originProgram; + } - const std::vector> blocks = - to_predict_program_->Blocks(); - // DLOG << " **block size " << blocks.size(); - for (int i = 0; i < blocks.size(); ++i) { - std::shared_ptr block_desc = blocks[i]; - std::vector> ops = block_desc->Ops(); - // DLOG << " ops " << ops.size(); - for (int j = 0; j < ops.size(); ++j) { - std::shared_ptr op = ops[j]; - // if (op->Type() == "mul") { - // DLOG << "x_num_col_dims : - // " - // << op->GetAttrMap() - // .at("x_num_col_dims") - // .Get(); - // DLOG << "y_num_col_dims : - // " - // << op->GetAttrMap() - // .at("y_num_col_dims") - // .Get(); - // DLOG << " Input X is : " - // << op->Input("X")[0]; - // } - // DLOG << "op:" << op->Type(); - if (op->Type() == "mul" && - op->Input("X")[0] == "pool2d_0.tmp_0") { - DLOG << " mul attr size: " << op->GetAttrMap().size(); - DLOG << " inputs size: " << op->GetInputs().size(); - DLOG << " outputs size: " << op->GetOutputs().size(); - DLOG << " Input X is : " << op->Input("X")[0]; - DLOG << " Input Y is : " << op->Input("Y")[0]; - DLOG << " Output Out is : " << op->Output("Out")[0]; - DLOG << "x_num_col_dims : " - << op->GetAttrMap().at("x_num_col_dims").Get(); - DLOG << "y_num_col_dims : " - << op->GetAttrMap().at("y_num_col_dims").Get(); - - std::shared_ptr> add = - std::make_shared>( - op->Type(), op->GetInputs(), op->GetOutputs(), - op->GetAttrMap(), program_.scope); - ops_of_block_[*block_desc.get()].push_back(add); - } - } + const std::vector> blocks = + to_predict_program_->Blocks(); + // DLOG << " **block size " << blocks.size(); + for (int i = 0; i < blocks.size(); ++i) { + std::shared_ptr block_desc = blocks[i]; + std::vector> ops = block_desc->Ops(); + // DLOG << " ops " << ops.size(); + for (int j = 0; j < ops.size(); ++j) { + std::shared_ptr op = ops[j]; + // if (op->Type() == "mul") { + // DLOG << "x_num_col_dims : + // " + // << op->GetAttrMap() + // .at("x_num_col_dims") + // .Get(); + // DLOG << "y_num_col_dims : + // " + // << op->GetAttrMap() + // .at("y_num_col_dims") + // .Get(); + // DLOG << " Input X is : " + // << op->Input("X")[0]; + // } + // DLOG << "op:" << op->Type(); + if (op->Type() == "mul" && + op->Input("X")[0] == "pool2d_0.tmp_0") { + DLOG << " mul attr size: " << op->GetAttrMap().size(); + DLOG << " inputs size: " << op->GetInputs().size(); + DLOG << " outputs size: " << op->GetOutputs().size(); + DLOG << " Input X is : " << op->Input("X")[0]; + DLOG << " Input Y is : " << op->Input("Y")[0]; + DLOG << " Output Out is : " << op->Output("Out")[0]; + DLOG << "x_num_col_dims : " + << op->GetAttrMap().at("x_num_col_dims").Get(); + DLOG << "y_num_col_dims : " + << op->GetAttrMap().at("y_num_col_dims").Get(); + + std::shared_ptr> add = + std::make_shared>( + op->Type(), op->GetInputs(), op->GetOutputs(), + op->GetAttrMap(), program_.scope); + ops_of_block_[*block_desc.get()].push_back(add); } } + } + } - std::shared_ptr predict_add(Tensor &t1, Tensor &t2) { - // feed - auto scope = program_.scope; - Variable *x_feed_value = scope->Var("pool2d_0.tmp_0"); - auto tensor_x = x_feed_value->GetMutable(); - tensor_x->ShareDataWith(t1); + std::shared_ptr predict_add(Tensor &t1, Tensor &t2) { + // feed + auto scope = program_.scope; + Variable *x_feed_value = scope->Var("pool2d_0.tmp_0"); + auto tensor_x = x_feed_value->GetMutable(); + tensor_x->ShareDataWith(t1); - Variable *y_feed_value = scope->Var("fc_0.w_0"); - auto tensor_y = y_feed_value->GetMutable(); - tensor_y->ShareDataWith(t2); + Variable *y_feed_value = scope->Var("fc_0.w_0"); + auto tensor_y = y_feed_value->GetMutable(); + tensor_y->ShareDataWith(t2); - Variable *con_output = scope->Var("fc_0.tmp_0"); - Tensor *output_tensor = con_output->GetMutable(); - output_tensor->mutable_data({3, 3}); - // DLOG << typeid(output_tensor).name(); - // DLOG << "output_tensor dims: " << output_tensor->dims(); + Variable *con_output = scope->Var("fc_0.tmp_0"); + Tensor *output_tensor = con_output->GetMutable(); + output_tensor->mutable_data({3, 3}); + // DLOG << typeid(output_tensor).name(); + // DLOG << "output_tensor dims: " << output_tensor->dims(); - std::shared_ptr out_tensor = std::make_shared(); - out_tensor.reset(output_tensor); + std::shared_ptr out_tensor = std::make_shared(); + out_tensor.reset(output_tensor); - predict_add(t1, t2, 0); - return out_tensor; - } + predict_add(t1, t2, 0); + return out_tensor; + } - private: - const framework::Program program_; - std::shared_ptr to_predict_program_; - std::map>>> - ops_of_block_; - bool use_optimize_ = false; - - void predict_add(const Tensor &t1, const Tensor &t2, int block_id) { - std::shared_ptr to_predict_block = - to_predict_program_->Block(block_id); - for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); - ++j) { - auto op = ops_of_block_[*to_predict_block.get()][j]; - DLOG << "op -> run()"; - op->Run(); - } - } - }; + private: + const framework::Program program_; + std::shared_ptr to_predict_program_; + std::map>>> + ops_of_block_; + bool use_optimize_ = false; + + void predict_add(const Tensor &t1, const Tensor &t2, int block_id) { + std::shared_ptr to_predict_block = + to_predict_program_->Block(block_id); + for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); + ++j) { + auto op = ops_of_block_[*to_predict_block.get()][j]; + DLOG << "op -> run()"; + op->Run(); + } + } +}; - template - class TestMulOp; - } // namespace framework -} // namespaece paddle_mobile +template class TestMulOp; +} // namespace framework +} // namespace paddle_mobile -int main () { +int main() { DLOG << "----------**********----------"; DLOG << "begin to run MulOp Test"; paddle_mobile::Loader loader; -- GitLab