diff --git a/CMakeLists.txt b/CMakeLists.txt index f4fb9f42ef39389853e654eb4dbdb6a46139e5f1..32e909e1cce001dff49a90d7753be780e14f08ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +set(CMAKE_BUILD_TYPE Release) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build) diff --git a/src/common/enforce.h b/src/common/enforce.h index 4b7c8dc0e267bc2862d2665e71085d679dceb1ff..51d2110e32433686d1b3353bc63b92a564a13e9d 100644 --- a/src/common/enforce.h +++ b/src/common/enforce.h @@ -17,7 +17,6 @@ limitations under the License. */ #ifdef ENABLE_EXCEPTION #include #include -#include #include #endif @@ -31,12 +30,11 @@ struct PaddleMobileException : public std::exception { PaddleMobileException(const char *header, const char *detail, const char *file, const int line) { - std::stringstream ss; - ss << exception_prefix << "| " << header << "\n"; - ss << "| [in file] : " << file << " \n"; - ss << "| [on line] : " << line << " \n"; - ss << "| [detail] : " << detail; - message = ss.str(); + char buffer[1500]; + snprintf(buffer, sizeof(buffer), + "%s| %s \n| [in file] : %s\n| [on line] : %d\n| [detail] : %s\n", + exception_prefix.c_str(), header, file, line, detail); + message = std::string(buffer); } const char *what() const noexcept { return message.c_str(); } }; diff --git a/src/common/type_define.h b/src/common/type_define.h index 63665bf7933f773b2b3de40ade9c700e3e93e6a9..c26cdd91e0694d44cca9443503d3e263ee21f201 100644 --- a/src/common/type_define.h +++ b/src/common/type_define.h @@ -16,7 +16,6 @@ limitations under the License. */ #include #include -#include #include #include "framework/attribute.h" #include "framework/scope.h" @@ -40,13 +39,6 @@ using OpCreator = std::function *( const framework::AttributeMap & /*attrs*/, std::shared_ptr /*scope*/)>; -using GradOpMakerFN = - std::function>( - const framework::OpDesc &, - const std::unordered_set & /*no_grad_set*/, - std::unordered_map * /*grad_to_var*/, - const std::vector &grad_block)>; - using InferVarTypeFN = std::function; diff --git a/src/common/types.h b/src/common/types.h index 0c0a6ac1c04cbc9e3ddb916fc656280c36e47d5f..272db3ef70f5bf923487fd29b2666f94707040bf 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -16,7 +16,6 @@ limitations under the License. */ #include #include -#include namespace paddle_mobile { enum class Precision : int { FP32 = 0 }; diff --git a/src/framework/attribute.h b/src/framework/attribute.h index bd95326949dfb5e30be4f9739e06f592030c8e83..2eddb27ed49c82d2d5f1b3bb1ce6d3b1c65d3f3e 100644 --- a/src/framework/attribute.h +++ b/src/framework/attribute.h @@ -17,6 +17,7 @@ limitations under the License. */ #include #include #include + #include "common/enforce.h" #include "common/log.h" #include "common/variant.h" diff --git a/src/framework/lod_tensor.h b/src/framework/lod_tensor.h index bab3db1389610e7ed5db1a387004bdf95267867f..3b34d664d3608dd361ed7c7bb549870284adcc33 100644 --- a/src/framework/lod_tensor.h +++ b/src/framework/lod_tensor.h @@ -16,7 +16,6 @@ limitations under the License. */ #include #include -#include #include #include "tensor.h" #include "tensor_util.h" diff --git a/src/framework/operator.h b/src/framework/operator.h index 17a8359d8caf8b70c4aa2b3d50c0f8cdbf78549c..d9b74e8887944774aefadf5ead0a74b1f7eac79d 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -16,7 +16,6 @@ limitations under the License. */ #include #include -#include #include #include "common/enforce.h" diff --git a/src/framework/program/program-optimize/node.cpp b/src/framework/program/program-optimize/node.cpp index bbec2c68b611dbf87eadc8fd274155cdccc3accd..d128d11edbcac4d1fa916feb7348970abc50147a 100644 --- a/src/framework/program/program-optimize/node.cpp +++ b/src/framework/program/program-optimize/node.cpp @@ -43,47 +43,6 @@ bool Node::operator==(const Node &in) { return true; } -bool Node::CanSplit(std::unordered_set complex_compute_set) { - bool split = false; - CanSplit(&split, false, 0, &complex_compute_set, this); - return split; -} - -void Node::CanSplit(bool *split, bool spliting, int complex_count, - std::unordered_set *complex_compute_set, - Node *pre_node) { - if (spliting) { - if (complex_compute_set->find(this->type_) != complex_compute_set->end()) { - complex_count++; - } - } - - if (inputs_.size() > 1 && pre_node != inputs_.back()) { - return; - } - if (inputs_.size() > 1 && pre_node == inputs_.back()) { - if (complex_count > 1) { - *split = true; - return; - } - } - - // multi output, to check - if (outputs_.size() > 1) { - spliting = true; - complex_compute_set = 0; - } else { - if (spliting == true && inputs_.size() > 0) { - spliting = false; - } else { - } - } - - for (auto &output : outputs_) { - output->CanSplit(split, spliting, complex_count, complex_compute_set, this); - } -} - std::vector> Node::OpDescs(uint size) { std::vector> op_descs; OpDescs(size - 1, &op_descs); @@ -101,107 +60,6 @@ void Node::OpDescs(uint index, } } -void Node::OpDescs(std::vector> *op_desc, - Node *node, bool adding_thread, int thread_num) { - if (outputs_.size() > 1) { - adding_thread = false; - } - - bool can_add_split = false; - // 如果当前节点有多个输出 并且 只有当前节点对应的 op_desc_ 输出数为 1 时支持 - if (outputs_.size() > 1 && - op_input_output_key[op_desc_->type_].second.size() == 1) { - can_add_split = true; - - // 遍历当前节点的 output 节点 - for (const auto &output : outputs_) { - // 不支持 output 有多个 output 的情况 - if (output->outputs_.size() > 0) { - can_add_split = false; - break; - } - - //与节点关联的 OpDesc - std::shared_ptr &op_desc = output->op_desc_; - - //获取这个 op 的 inputs key 和 outputs key - auto inputs_and_outputs = op_input_output_key[op_desc->type_]; - - //判断现在 是否存在这个 op - //判断这个 output 和 input key 的 size 等于 1 - if (op_input_output_key.find(op_desc->type_) != - op_input_output_key.end() && - inputs_and_outputs.first.size() == 1 && - inputs_and_outputs.second.size() == 1) { - auto inputs_of_output = op_desc->Input(inputs_and_outputs.first[0]); - auto outputs_of_output = op_desc->Output(inputs_and_outputs.second[0]); - - // 判断一下, 如果输入和输出没有同名, 是支持的 - for (int i = 0; i < inputs_of_output.size(); ++i) { - std::string input_of_output = inputs_of_output[i]; - for (int j = 0; j < outputs_of_output.size(); ++j) { - std::string output_of_output = outputs_of_output[j]; - if (input_of_output == output_of_output) { - DLOG << "output的 output 包含 input" << input_of_output; - can_add_split = false; - break; - } - } - } - } else { // 如果模型中包含没有的 op, 则不支持添加 split - DLOG << "找不到 这个 op 类型: " << output->op_desc_->type_; - can_add_split = false; - } - } - } - - if (inputs_.size() > 1 && node != inputs_.back()) { - return; - } else if (inputs_.size() > 1 && node == inputs_.back()) { - adding_thread = false; - op_desc->push_back(this->op_desc_); - } else { - op_desc->push_back(this->op_desc_); - } - if (adding_thread) { - Attribute attr; - attr.Set(thread_num); - this->op_desc_->attrs_["thread"] = attr; - } - - if (can_add_split) { - adding_thread = true; - std::shared_ptr split_op_desc = std::make_shared(); - split_op_desc->type_ = G_OP_TYPE_SPLIT; - auto outputs = this->op_desc_->Output( - op_input_output_key[this->op_desc_->Type()].second[0]); - split_op_desc->inputs_ = { - {op_input_output_key[G_OP_TYPE_SPLIT].first[0], outputs}}; - auto &split_outputs = - split_op_desc->outputs_[op_input_output_key[G_OP_TYPE_SPLIT].second[0]]; - for (const auto &output : outputs_) { - split_outputs.push_back(outputs[0]); - } - DLOG << "add split"; - op_desc->push_back(split_op_desc); - } - - for (int i = 0; i < outputs_.size(); ++i) { - auto &output = outputs_[i]; - if (can_add_split) { - output->OpDescs(op_desc, this, adding_thread, i); - } else { - output->OpDescs(op_desc, this, adding_thread, thread_num); - } - } -} - -std::vector> Node::OpDescs() { - std::vector> op_descs; - OpDescs(&op_descs, this, false, 0); - return op_descs; -} - std::shared_ptr Node::To(int size) { std::shared_ptr node = std::make_shared(); this->To(size - 1, node); diff --git a/src/framework/program/program-optimize/node.h b/src/framework/program/program-optimize/node.h index 7c224295cbfda18d8122820d848775d5c515bdfe..dd19b84fd55dd37cf634c9793e35e72ee2202b19 100644 --- a/src/framework/program/program-optimize/node.h +++ b/src/framework/program/program-optimize/node.h @@ -16,8 +16,6 @@ limitations under the License. */ #include #include -#include -#include #include #include "common/log.h" @@ -49,16 +47,10 @@ class Node { std::map> change_map, std::vector> *removed_nodes); std::vector> OpDescs(uint size); - std::vector> OpDescs(); std::shared_ptr OpDescOfNode() { return op_desc_; } std::string Type() { return type_; } private: - void CanSplit(bool *split, bool spliting, int complex_count, - std::unordered_set *complex_compute_set, - Node *pre_node); - void OpDescs(std::vector> *op_desc, - Node *node, bool adding_thread, int thread_num); void OpDescs(uint size, std::vector> *op_desc); void To(int index, std::shared_ptr); diff --git a/src/operators/math/pooling.cpp b/src/operators/math/pooling.cpp index 09bc2a6ae4a7b5f2876350375a333c457c72b68a..11bce0978f789f4f02b44fbb24fdd8bd1219257e 100644 --- a/src/operators/math/pooling.cpp +++ b/src/operators/math/pooling.cpp @@ -15,7 +15,7 @@ limitations under the License. */ #ifdef POOL_OP #include "pooling.h" -#include +#include "common/types.h" namespace paddle_mobile { namespace operators { diff --git a/src/operators/pool_op.h b/src/operators/pool_op.h index 9ad0bd3e3b95503c53bbeed6a8bca7fdb48ac23e..8dc99ae686390041b3c99c2df71d91ae9801a1f2 100644 --- a/src/operators/pool_op.h +++ b/src/operators/pool_op.h @@ -16,11 +16,12 @@ limitations under the License. */ #pragma once -#include -#include -#include #include +#include "framework/operator.h" +#include "operators/kernel/pool_kernel.h" +#include "operators/op_param.h" + namespace paddle_mobile { namespace operators { using framework::AttributeMap; diff --git a/src/operators/sigmoid_op.h b/src/operators/sigmoid_op.h index 3757e2de168e75764b9d8d1d249fe3d8c87d817a..7cdeb41af1b20ddf05ac80d7de0962c4bfe8dff4 100644 --- a/src/operators/sigmoid_op.h +++ b/src/operators/sigmoid_op.h @@ -16,10 +16,11 @@ limitations under the License. */ #pragma once -#include -#include #include + +#include "framework/operator.h" #include "operators/kernel/sigmoid_kernel.h" +#include "operators/op_param.h" namespace paddle_mobile { namespace operators { diff --git a/src/operators/softmax_op.h b/src/operators/softmax_op.h index 1c764248cb72f84adb7665ced0a4375a3cd79624..5cac4d8a3394b07e978ba41e18fd7fbb7f4756d7 100644 --- a/src/operators/softmax_op.h +++ b/src/operators/softmax_op.h @@ -16,10 +16,11 @@ limitations under the License. */ #pragma once -#include -#include #include + +#include "framework/operator.h" #include "operators/kernel/softmax_kernel.h" +#include "operators/op_param.h" namespace paddle_mobile { namespace operators { diff --git a/src/operators/transpose_op.cpp b/src/operators/transpose_op.cpp index c8e16f9e4b42037eee84dbe5cd023b67e781f2a5..3abebc77ba6733bf1bfa73846ec1a077a494de2f 100644 --- a/src/operators/transpose_op.cpp +++ b/src/operators/transpose_op.cpp @@ -14,9 +14,10 @@ limitations under the License. */ #ifdef TRANSPOSE_OP -#include "operators/transpose_op.h" -#include #include + +#include "common/enforce.h" +#include "operators/transpose_op.h" namespace paddle_mobile { namespace operators { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7bde05f70c85b9ea363e58ff483d45436fd7abd2..124e1c2d60d81fe0d6f19ffa1936f3d1d8e7eb16 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -122,13 +122,9 @@ else () target_link_libraries(test-enforce paddle-mobile) # gen test - test if openmp works - ADD_EXECUTABLE(test-openmp common/test_openmp.cc test_helper.h test_include.h executor_for_test.h) + ADD_EXECUTABLE(test-openmp common/test_openmp.cpp test_helper.h test_include.h executor_for_test.h) target_link_libraries(test-openmp paddle-mobile) - # gen test - ADD_EXECUTABLE(test-yolo net/test_yolo.cpp test_helper.h test_include.h executor_for_test.h) - target_link_libraries(test-yolo paddle-mobile) - # gen test ADD_EXECUTABLE(test-mobilenetssd net/test_mobilenet+ssd.cpp test_helper.h test_include.h executor_for_test.h) target_link_libraries(test-mobilenetssd paddle-mobile) diff --git a/test/common/test_lib_size.cpp b/test/common/test_lib_size.cpp new file mode 100644 index 0000000000000000000000000000000000000000..805668f359f0e0959ea7122f25cdaa0ad2d7ec77 --- /dev/null +++ b/test/common/test_lib_size.cpp @@ -0,0 +1,21 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +// +// Created by liuRuiLong on 2018/6/6. +// + +#include "test_lib_size.h" + +static test_lib_size t; diff --git a/test/common/test_lib_size.h b/test/common/test_lib_size.h new file mode 100644 index 0000000000000000000000000000000000000000..ab5cd359b73f1c5c5df4176ab444e48c85dbd95b --- /dev/null +++ b/test/common/test_lib_size.h @@ -0,0 +1,93 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +// +// Created by liuRuiLong on 2018/6/6. +// + +#ifndef PADDLE_MOBILE_TEST_LIB_SIZE_H +#define PADDLE_MOBILE_TEST_LIB_SIZE_H + +#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +//#include +//#include +#include +//#include +//#include + +void foo() { + // char *str = "1234"; + // char dst[10]; + // strcpy(dst, str); + + // std::cout << "12345" << std::endl; + std::vector vec = {1, 2, 3, 4, 5}; + + // std::find(vec.begin(), vec.end(), 1); + // std::find(vec.begin(), vec.end(), 1); + + // std::list l; + // std::mutex mutex_; + + // std::map m; + // std::unordered_map u_m; + // std::unordered_set u_s; + // std::string ss = "12345"; + // printf("%f", ss.c_str()); + + // std::initializer_list init_list = {1, 2}; + // std::tuple t = {1, 2}; + + // std::tuple_element>::type + + // std::tuple<> + + // int i; + // int j; + // if (typeid(i) == typeid(j)){ + // int z = 10; + // } + + std::shared_ptr s1 = std::make_shared(); + + // std::stringstream ss; + // ss << "12345"; +} + +class test_lib_size { + public: + test_lib_size() {} + // std::shared_ptr Test(){ + // std::vector vec = {1, 2, 3}; + // std::shared_ptr si = std::make_shared(); + // return si; + // } + + // void test(){ + // int i = 9; + // } +}; + +#endif // PADDLE_MOBILE_TEST_LIB_SIZE_H diff --git a/test/common/test_openmp.cpp b/test/common/test_openmp.cpp index 7393810a3cd5cafcd75e3964cc21d31036d83817..c92fc919936b067ad70f40e3f5b3acd725e845e2 100644 --- a/test/common/test_openmp.cpp +++ b/test/common/test_openmp.cpp @@ -12,15 +12,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include +//#include #include int main(void) { #pragma omp parallel num_threads(2) { - int thread_id = omp_get_thread_num(); - int nthreads = omp_get_num_threads(); - std::cout << "Hello, OMP " << thread_id << "/" << nthreads << "\n"; + // int thread_id = omp_get_thread_num(); + // int nthreads = omp_get_num_threads(); + // std::cout << "Hello, OMP " << thread_id << "/" << nthreads << + // "\n"; } return 0; }