diff --git a/CMakeLists.txt b/CMakeLists.txt index eb0ffd459e28644deec4ad71e107d40e502e05f0..dad11ad655119418dcb5c52b1476f4cc81a628e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,8 @@ else () add_definitions(-DX86) endif() - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") -set(CMAKE_BUILD_TYPE RelWithDebInfo) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +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..7fed63c3c0b947b9bc35aa3c4c0afcdcb7a5be0c 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,12 @@ 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..380e862b081efeb152f79256ed40729e301a5c17 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,12 +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/common/variant.h b/src/common/variant.h index c198ff511c2e90e0387238aede9f1373f0379d3c..b72070e4c14b04ef44386b6d537f42fe2ad4d6d9 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -12,7 +12,6 @@ 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 "common/log.h" diff --git a/src/framework/attribute.h b/src/framework/attribute.h index 7db107ceef0d8fa293184bbc01f10ec687984605..4c19bca37e23cb0fce4cb8f22f0c06ecc70aa885 100644 --- a/src/framework/attribute.h +++ b/src/framework/attribute.h @@ -15,8 +15,9 @@ limitations under the License. */ #pragma once #include -#include #include +#include + #include "common/enforce.h" #include "common/log.h" #include "common/variant.h" diff --git a/src/framework/ddim.h b/src/framework/ddim.h index f0b9db9506804478dd68ddde8821cd717b35cbe8..682abd300d61d325d6d248747ad5b3b832197a84 100644 --- a/src/framework/ddim.h +++ b/src/framework/ddim.h @@ -14,7 +14,6 @@ limitations under the License. */ #pragma once -#include #include #include #include diff --git a/src/framework/dim.h b/src/framework/dim.h index b84f6954932edff65da177307660bba7784b7e45..9022bb5a1f956dfa8342dafb93597c54086c723e 100644 --- a/src/framework/dim.h +++ b/src/framework/dim.h @@ -14,7 +14,6 @@ limitations under the License. */ #pragma once -#include #include #include #include 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/fusion_op_register.h b/src/framework/program/program-optimize/fusion_op_register.h index 4cc83f8c80ab86ee6dcc1e3c395f872419da2be7..ff50dcafbc5524e350c1d2774933e257f80582ca 100644 --- a/src/framework/program/program-optimize/fusion_op_register.h +++ b/src/framework/program/program-optimize/fusion_op_register.h @@ -17,8 +17,8 @@ limitations under the License. */ #include #include -#include "framework/operator.h" #include "node.h" +#include "framework/operator.h" namespace paddle_mobile { namespace framework { diff --git a/src/framework/program/program-optimize/node.cpp b/src/framework/program/program-optimize/node.cpp index ed49c541110e9f38ad76cbfa3ee58b6f3a7e784b..abce1f57e77d177f46808c29fa9dde55ef69c615 100644 --- a/src/framework/program/program-optimize/node.cpp +++ b/src/framework/program/program-optimize/node.cpp @@ -12,8 +12,8 @@ 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 "framework/program/program-optimize/node.h" #include "framework/operator.h" +#include "framework/program/program-optimize/node.h" namespace paddle_mobile { @@ -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 24d9ce2fe538fcb25110602afcdab264bf5941b5..4a16f0ac8002ab58c0c549f9c85ede7d49ec30dc 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" @@ -36,7 +34,6 @@ class Node { : op_desc_(op_desc), type_(op_desc->Type()) {} Node &operator>(std::shared_ptr node); bool operator==(const Node &in); - bool CanSplit(std::unordered_set complex_compute_set); std::string ToString() const; std::shared_ptr To(int size); uint Depth(uint begin = 0); @@ -45,17 +42,11 @@ 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_; } void Description(); 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/framework/variable.h b/src/framework/variable.h index 769616cd1238f49f1aa676d837b0b4850eb1a246..e1527b3a331eb67c31aec5011bf84de3dc9bc247 100644 --- a/src/framework/variable.h +++ b/src/framework/variable.h @@ -14,7 +14,6 @@ limitations under the License. */ #pragma once -#include #include #include #include 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..f173a9aab73e6c5cd47b1861a6295b1e092622b6 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/op_param.h" +#include "operators/kernel/pool_kernel.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..d7a770bca7701861e7074dca88eeb8d9f9cb7610 100644 --- a/src/operators/sigmoid_op.h +++ b/src/operators/sigmoid_op.h @@ -16,9 +16,10 @@ limitations under the License. */ #pragma once -#include -#include #include + +#include "framework/operator.h" +#include "operators/op_param.h" #include "operators/kernel/sigmoid_kernel.h" namespace paddle_mobile { diff --git a/src/operators/softmax_op.h b/src/operators/softmax_op.h index 1c764248cb72f84adb7665ced0a4375a3cd79624..ffe5168d75e7ef5493ec2e1afada621fd0f0304f 100644 --- a/src/operators/softmax_op.h +++ b/src/operators/softmax_op.h @@ -16,9 +16,10 @@ limitations under the License. */ #pragma once -#include -#include #include + +#include "framework/operator.h" +#include "operators/op_param.h" #include "operators/kernel/softmax_kernel.h" namespace paddle_mobile { 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..b73b8e6ad8ba99245b93758756d11bfa8ca53280 --- /dev/null +++ b/test/common/test_lib_size.cpp @@ -0,0 +1,10 @@ +// +// 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..e46bdae6c1d9e8681f530073fb4bd2b64efd0bfa --- /dev/null +++ b/test/common/test_lib_size.h @@ -0,0 +1,94 @@ +// +// 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..144aab53e87eb4dbfccc2948580defcd60e476e3 100644 --- a/test/common/test_openmp.cpp +++ b/test/common/test_openmp.cpp @@ -12,15 +12,15 @@ 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; }