From 559d9dfb5657b2d967716424e48bdc25df39c216 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Thu, 24 May 2018 10:49:54 +0800 Subject: [PATCH] add graph optimize, format code --- src/common/log.cpp | 5 + src/common/log.h | 40 ++-- src/common/type_define.h | 17 -- src/common/types.h | 18 -- src/common/variant.cpp | 17 -- src/common/variant.h | 20 +- src/framework/attribute.cpp | 49 +++-- src/framework/attribute.h | 51 +++-- src/framework/block_desc.cpp | 50 ----- src/framework/block_desc.h | 70 ------ src/framework/data_layout.h | 14 -- src/framework/ddim.cc | 1 + src/framework/executor.h | 6 +- src/framework/framework.pb.h | 2 +- src/framework/op_desc.h | 51 ----- src/framework/operator.h | 37 +++- src/framework/paddle_mobile_object.cpp | 18 -- src/framework/paddle_mobile_object.h | 18 -- src/framework/program-optimize/node.cpp | 96 -------- src/framework/program-optimize/node.h | 52 ----- .../program-optimize/program_optimize.cpp | 73 ------ .../program-optimize/program_optimize.h | 41 ---- src/framework/program.cpp | 21 -- src/framework/program.h | 40 ---- src/framework/program/block_desc.cpp | 33 +++ src/framework/program/block_desc.h | 71 ++++++ src/framework/{ => program}/op_desc.cpp | 39 +++- src/framework/program/op_desc.h | 63 ++++++ .../program-optimize/fusion_op_register.cpp | 1 + .../program-optimize/fusion_op_register.h | 44 ++++ .../program/program-optimize/node.cpp | 207 ++++++++++++++++++ src/framework/program/program-optimize/node.h | 54 +++++ .../program-optimize/program_optimize.cpp | 93 ++++++++ .../program-optimize/program_optimize.h | 25 +++ src/framework/program/program.cpp | 3 + src/framework/program/program.h | 22 ++ src/framework/program/program_desc.cpp | 53 +++++ src/framework/program/program_desc.h | 33 +++ src/framework/program/var_desc.cpp | 10 + src/framework/{ => program}/var_desc.h | 24 +- src/framework/program_desc.cpp | 36 --- src/framework/program_desc.h | 42 ---- src/framework/scope.h | 18 -- src/framework/selected_rows.h | 18 -- src/framework/var_desc.cpp | 28 --- src/framework/var_type.h | 18 -- src/framework/variable.h | 18 -- src/io.cpp | 14 +- src/io.h | 2 +- src/operators/fusion_conv_add_relu_op.cpp | 1 + src/operators/fusion_conv_add_relu_op.h | 34 +++ src/operators/fusion_fc_op.cpp | 1 + src/operators/fusion_fc_op.h | 36 +++ src/platform/data_type.h | 2 +- test/common/test_log.cpp | 14 ++ test/framework/test_load.cpp | 30 ++- test/framework/test_optimize.cpp | 44 ++-- test/operators/test_cov_op.cpp | 31 ++- test/test_include.h | 13 +- 59 files changed, 1016 insertions(+), 966 deletions(-) create mode 100644 src/common/log.cpp delete mode 100644 src/framework/block_desc.cpp delete mode 100644 src/framework/block_desc.h delete mode 100644 src/framework/op_desc.h delete mode 100644 src/framework/program-optimize/node.cpp delete mode 100644 src/framework/program-optimize/node.h delete mode 100644 src/framework/program-optimize/program_optimize.cpp delete mode 100644 src/framework/program-optimize/program_optimize.h delete mode 100644 src/framework/program.cpp delete mode 100644 src/framework/program.h create mode 100644 src/framework/program/block_desc.cpp create mode 100644 src/framework/program/block_desc.h rename src/framework/{ => program}/op_desc.cpp (61%) create mode 100644 src/framework/program/op_desc.h create mode 100644 src/framework/program/program-optimize/fusion_op_register.cpp create mode 100644 src/framework/program/program-optimize/fusion_op_register.h create mode 100644 src/framework/program/program-optimize/node.cpp create mode 100644 src/framework/program/program-optimize/node.h create mode 100644 src/framework/program/program-optimize/program_optimize.cpp create mode 100644 src/framework/program/program-optimize/program_optimize.h create mode 100644 src/framework/program/program.cpp create mode 100644 src/framework/program/program.h create mode 100644 src/framework/program/program_desc.cpp create mode 100644 src/framework/program/program_desc.h create mode 100644 src/framework/program/var_desc.cpp rename src/framework/{ => program}/var_desc.h (58%) delete mode 100644 src/framework/program_desc.cpp delete mode 100644 src/framework/program_desc.h delete mode 100644 src/framework/var_desc.cpp create mode 100644 src/operators/fusion_conv_add_relu_op.cpp create mode 100644 src/operators/fusion_conv_add_relu_op.h create mode 100644 src/operators/fusion_fc_op.cpp create mode 100644 src/operators/fusion_fc_op.h diff --git a/src/common/log.cpp b/src/common/log.cpp new file mode 100644 index 0000000000..3eb4d051c1 --- /dev/null +++ b/src/common/log.cpp @@ -0,0 +1,5 @@ +#include "log.h" + +namespace paddle_mobile { + +} diff --git a/src/common/log.h b/src/common/log.h index e62461c52f..eed5c821b8 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -1,32 +1,16 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once +#include #ifdef PADDLE_MOBILE_DEBUG - #include #include #include -#include +#endif namespace paddle_mobile { +#ifdef PADDLE_MOBILE_DEBUG + enum LogLevel { kNO_LOG, kLOG_ERROR, @@ -111,7 +95,6 @@ struct ToLog { << (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__) \ << "] [line: " << __LINE__ << "] ") \ .str()) -} // namespace paddle_mobile #define LOGF(level, format, ...) \ if (level > paddle_mobile::log_level) { \ @@ -125,8 +108,6 @@ struct ToLog { #else -namespace paddle_mobile { - enum LogLevel { kNO_LOG, kLOG_ERROR, @@ -170,6 +151,17 @@ struct ToLog { #define LOGF(level, format, ...) #define DLOGF(format, ...) -} // namespace paddle_mobile #endif + +template +Print &operator<<(Print &printer, const std::vector &v) { + printer << "[ "; + for (const auto &value : v) { + printer << value << " "; + } + printer << " ]"; + return printer; +} + +} // namespace paddle_mobile \ No newline at end of file diff --git a/src/common/type_define.h b/src/common/type_define.h index 43eb6b2066..47d6c7090a 100644 --- a/src/common/type_define.h +++ b/src/common/type_define.h @@ -1,20 +1,3 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ #pragma once; #include diff --git a/src/common/types.h b/src/common/types.h index 61807be870..058dc7fecc 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,21 +1,3 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once; namespace paddle_mobile { diff --git a/src/common/variant.cpp b/src/common/variant.cpp index e05a9d0df3..e69de29bb2 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -1,17 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ diff --git a/src/common/variant.h b/src/common/variant.h index b1b924059d..051b8d09a3 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -1,23 +1,7 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #include +#include "common/log.h" + #pragma once namespace paddle_mobile { diff --git a/src/framework/attribute.cpp b/src/framework/attribute.cpp index a3b9cf6a4f..362775baaf 100644 --- a/src/framework/attribute.cpp +++ b/src/framework/attribute.cpp @@ -1,21 +1,34 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ +#include "attribute.h" namespace paddle_mobile { -namespace framework {} +namespace framework { + + + +/* + * Variant, std::vector, + std::vector, bool, std::vector, BlockDesc *, + int64_t> + * */ + +struct PrintVistor: Vistor{ + PrintVistor(Print &printer):printer_(printer){ + } + template + Print &operator()(const T &value){ + printer_ << value; + return printer_; + } + private: + Print &printer_; +}; + +Print &operator<<(Print &printer, const Attribute &attr) { + Attribute::ApplyVistor(PrintVistor(printer), attr); +// std::vector v = {"1", "2"}; +// printer << (v); + return printer; +} + +} } // namespace paddle_mobile diff --git a/src/framework/attribute.h b/src/framework/attribute.h index c6cbb80442..f86cba4180 100644 --- a/src/framework/attribute.h +++ b/src/framework/attribute.h @@ -1,25 +1,8 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once +#include "common/log.h" #include "common/variant.h" -#include "framework.pb.h" +#include "framework/framework.pb.h" namespace paddle_mobile { namespace framework { @@ -104,6 +87,31 @@ class Attribute { return variant_.Get(); } + template + static typename Vistor::type_t ApplyVistor(Vistor vistor, Attribute attr) { + if (attr.variant_.TypeId() == typeid(int).hash_code()) { + return vistor(attr.variant_.Get()); + } else if (attr.variant_.TypeId() == typeid(float).hash_code()) { + return vistor(attr.variant_.Get()); + } else if (attr.variant_.TypeId() == typeid(std::string).hash_code()) { + return vistor(attr.variant_.Get()); + } else if (attr.variant_.TypeId() == typeid(std::vector).hash_code()) { + return vistor(attr.variant_.Get>()); + } else if (attr.variant_.TypeId() == typeid(std::vector).hash_code()) { + return vistor(attr.variant_.Get>()); + } else if (attr.variant_.TypeId() == typeid(std::vector).hash_code()) { + return vistor(attr.variant_.Get>()); + } else if (attr.variant_.TypeId() == typeid(bool).hash_code()) { + return vistor(attr.variant_.Get()); + } else if (attr.variant_.TypeId() == typeid(std::vector).hash_code()) { + return vistor(attr.variant_.Get>()); + } else if (attr.variant_.TypeId() == typeid(int64_t).hash_code()) { + return vistor(attr.variant_.Get()); + } else { + throw std::bad_exception(); + } + } + private: Variant, std::vector, std::vector, bool, std::vector, BlockDesc *, @@ -130,5 +138,10 @@ class AttrReader { const AttributeMap &attrs_; }; + + + +Print &operator<<(Print &printer, const Attribute &op_desc); + } // namespace framework } // namespace paddle_mobile diff --git a/src/framework/block_desc.cpp b/src/framework/block_desc.cpp deleted file mode 100644 index 5f7c1295f1..0000000000 --- a/src/framework/block_desc.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#include "block_desc.h" - -namespace paddle_mobile { -namespace framework { - -std::vector> BlockDesc::Vars() const { - std::vector> res; - for (const auto &p : vars_) { - res.push_back(p.second); - } - return res; -} - -std::vector> BlockDesc::Ops() const { - std::vector> res; - for (const auto &op : ops_) { - res.push_back(op); - } - return res; -} - -BlockDesc::BlockDesc(const proto::BlockDesc &desc) : desc_(desc) { - for (const proto::VarDesc &var_desc : desc_.vars()) { - vars_[var_desc.name()].reset(new VarDesc(var_desc)); - } - for (const proto::OpDesc &op_desc : desc_.ops()) { - ops_.emplace_back(new framework::OpDesc(op_desc)); - } -} - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/block_desc.h b/src/framework/block_desc.h deleted file mode 100644 index 02ff14e52e..0000000000 --- a/src/framework/block_desc.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include "framework.pb.h" -#include "op_desc.h" -#include "paddle_mobile_object.h" -#include "var_desc.h" - -namespace paddle_mobile { -namespace framework { - -class BlockDesc : PaddleMobileObject { - public: - BlockDesc(const proto::BlockDesc &desc); - - const int &ID() const { return desc_.idx(); } - - const int &Parent() const { return desc_.parent_idx(); } - - bool operator==(const paddle_mobile::framework::BlockDesc &in_block) const { - return this->ID() == in_block.ID() && this->Parent() == in_block.Parent(); - } - - bool operator<(const paddle_mobile::framework::BlockDesc &in_block) const { - return this->ID() < in_block.ID() && this->Parent() < in_block.Parent(); - } - - std::vector> Vars() const; - std::vector> Ops() const; - - private: - proto::BlockDesc desc_; - std::vector> ops_; - std::unordered_map> vars_; -}; - -} // namespace framework -} // namespace paddle_mobile - -namespace std { - -template <> -struct hash { - typedef paddle_mobile::framework::BlockDesc argument_type; - typedef std::size_t result_type; - result_type operator()(argument_type const &s) const noexcept { - result_type const h1(std::hash{}(s.ID())); - result_type const h2(std::hash{}(s.ID())); - return h1 ^ (h2 << 1); - } -}; - -} // namespace std diff --git a/src/framework/data_layout.h b/src/framework/data_layout.h index d669486fbc..99c011055b 100644 --- a/src/framework/data_layout.h +++ b/src/framework/data_layout.h @@ -1,17 +1,3 @@ -/* Copyright (c) 2016 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. */ - #pragma once #include diff --git a/src/framework/ddim.cc b/src/framework/ddim.cc index 8ea1946dd6..db6f2cd6ab 100644 --- a/src/framework/ddim.cc +++ b/src/framework/ddim.cc @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "ddim.h" +#include namespace paddle_mobile { namespace framework { diff --git a/src/framework/executor.h b/src/framework/executor.h index 82a1430f05..aaf87fb101 100644 --- a/src/framework/executor.h +++ b/src/framework/executor.h @@ -18,11 +18,11 @@ limitations under the License. */ #include #include -#include "block_desc.h" +#include "framework/program/block_desc.h" #include "framework.pb.h" #include "operator.h" -#include "program.h" -#include "program_desc.h" +#include "framework/program/program.h" +#include "framework/program/program_desc.h" #include "scope.h" #include "tensor.h" #include "variable.h" diff --git a/src/framework/framework.pb.h b/src/framework/framework.pb.h index fa75a92e57..c595963cb5 100644 --- a/src/framework/framework.pb.h +++ b/src/framework/framework.pb.h @@ -124,7 +124,7 @@ void AddDescriptors(); void InitDefaults(); } // namespace protobuf_framework_2eproto -enum VarType_Type { +enum VarType_Type { VarType_Type_BOOL = 0, VarType_Type_INT16 = 1, VarType_Type_INT32 = 2, diff --git a/src/framework/op_desc.h b/src/framework/op_desc.h deleted file mode 100644 index e2465989bb..0000000000 --- a/src/framework/op_desc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include "common/type_define.h" -#include "framework.pb.h" -#include "paddle_mobile_object.h" - -namespace paddle_mobile { -namespace framework { - -class OpDesc : PaddleMobileObject { - public: - OpDesc(const proto::OpDesc &desc); - const std::vector &Input(const std::string &name) const; - const std::vector &Output(const std::string &name) const; - Attribute GetAttr(const std::string &name) const; - - const VariableNameMap &GetInputs() { return inputs_; } - - const VariableNameMap &GetOutputs() { return outputs_; } - - const AttributeMap &GetAttrMap() const; - - const std::string &Type() { return desc_.type(); }; - - private: - proto::OpDesc desc_; - VariableNameMap inputs_; - VariableNameMap outputs_; - AttributeMap attrs_; -}; - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/operator.h b/src/framework/operator.h index 4ec7575820..527fb61aa7 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -18,17 +18,19 @@ limitations under the License. */ #include #include #include + #include "common/type_define.h" #include "common/types.h" #include "common/variant.h" -#include "framework/attribute.h" -#include "framework/block_desc.h" -#include "framework/op_info.h" -#include "framework/op_kernel_type.h" -#include "framework/paddle_mobile_object.h" #include "framework/scope.h" #include "framework/tensor.h" +#include "framework/op_info.h" #include "framework/variable.h" +#include "framework/attribute.h" +#include "framework/op_kernel_type.h" +#include "framework/program/block_desc.h" +#include "framework/paddle_mobile_object.h" +#include "framework/program/program-optimize/node.h" namespace paddle_mobile { namespace framework { @@ -102,5 +104,30 @@ class OpKernelBase : PaddleMobileObject { std::shared_ptr<::paddle_mobile::framework::Scope> scope) \ : parent_cls(type, inputs, outputs, attrs, scope) {} +class FusionOpMatcher: PaddleMobileObject{ + public: + FusionOpMatcher() {} + + virtual std::string Type() = 0; + + virtual void FolderNodes(Node &node) { + node.Folder(node_.Depth(), Type(), {}); + + } + + virtual Node &BeginNode() { + return node_; + } + + std::string BeginType() { + return node_.BeginType(); + } + + protected: + Node node_; + std::string type_; + std::shared_ptr new_opdesc_; +}; + } // namespace framework } // namespace paddle_mobile diff --git a/src/framework/paddle_mobile_object.cpp b/src/framework/paddle_mobile_object.cpp index eeaabe6ea4..8040ec7bb8 100644 --- a/src/framework/paddle_mobile_object.cpp +++ b/src/framework/paddle_mobile_object.cpp @@ -1,19 +1 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #include "paddle_mobile_object.h" diff --git a/src/framework/paddle_mobile_object.h b/src/framework/paddle_mobile_object.h index 062bac75b2..1d426a8c39 100644 --- a/src/framework/paddle_mobile_object.h +++ b/src/framework/paddle_mobile_object.h @@ -1,21 +1,3 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once #include diff --git a/src/framework/program-optimize/node.cpp b/src/framework/program-optimize/node.cpp deleted file mode 100644 index a6cc775e4c..0000000000 --- a/src/framework/program-optimize/node.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#include - -#include "node.h" - -namespace paddle_mobile { - -namespace framework { - -Node &Node::operator>(std::shared_ptr node) { - outputs_.push_back(node); - std::shared_ptr this_node; - node->inputs_.push_back(this); - return *node; -} - -bool Node::operator==(const Node &in) { - if (in.type_ == this->type_) { - if (this->outputs_.size() == in.outputs_.size()) { - for (int i = 0; i < outputs_.size(); ++i) { - if (!(*outputs_[i] == *in.outputs_[i])) { - return false; - } - } - } else { - return false; - } - } else { - return false; - } - return true; -} - -std::string Node::ToString(std::string blank, const Node *node) const { - std::stringstream ss; - ss << type_ << "-> \n"; - - if (inputs_.size() > 1 && node != inputs_.back()) { - return ss.str(); - } else if (inputs_.size() > 1 && node == inputs_.back()) { - ss << "\n" << blank << type_ << "\n"; - } - - for (int i = 0; i < outputs_.size(); ++i) { - ss << blank << outputs_[i]->ToString(blank + " ", this) << ""; - } - return ss.str(); -} - -std::string Node::ToString() const { return this->ToString(" ", this); } - -Node &Node::To(int index) { - if (index == 0) { - this->outputs_.clear(); - } - - for (int j = 0; j < this->outputs_.size(); ++j) { - outputs_[j]->To(index - 1); - } - return *this; -} - -uint Node::depth(uint begin) { - uint depth = 0; - begin++; - for (int i = 0; i < outputs_.size(); ++i) { - uint output_depth = outputs_[i]->depth(begin); - depth = output_depth > depth ? output_depth : depth; - } - return begin > depth ? begin : depth; -} - -Print &operator<<(Print &printer, const Node &node) { - printer << node.ToString(); - return printer; -} - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program-optimize/node.h b/src/framework/program-optimize/node.h deleted file mode 100644 index 0a6cb0a524..0000000000 --- a/src/framework/program-optimize/node.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include -#include - -#include "common/log.h" -#include "framework/op_desc.h" -#include "framework/paddle_mobile_object.h" - -namespace paddle_mobile { -namespace framework { - -class Node : PaddleMobileObject { - public: - Node(const std::string &type) : type_(type) {} - Node(std::shared_ptr op_desc) - : op_desc_(op_desc), type_(op_desc->Type()){}; - Node &operator>(std::shared_ptr node); - bool operator==(const Node &in); - std::string ToString() const; - Node &To(int index); - uint depth(uint begin = 0); - - private: - std::shared_ptr op_desc_; - std::string ToString(std::string blank, const Node *node) const; - std::vector> outputs_; - std::vector inputs_; - std::string type_; -}; - -Print &operator<<(Print &printer, const Node &node); -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program-optimize/program_optimize.cpp b/src/framework/program-optimize/program_optimize.cpp deleted file mode 100644 index ea923790a9..0000000000 --- a/src/framework/program-optimize/program_optimize.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#include "program_optimize.h" - -namespace paddle_mobile { - -namespace framework { - -std::shared_ptr ProgramOptimize::Optimize() {} - -std::shared_ptr ProgramOptimize::FushionOptimize( - std::shared_ptr ori_des) { - for (int i = 0; i < ori_des->Blocks().size(); ++i) { - std::unordered_map> output_nodes; - std::shared_ptr begin_node; - auto block = ori_des->Block(i); - // DLOG << " ops size: " << block->Ops().size(); - for (int j = 0; j < block->Ops().size(); ++j) { - auto op = block->Ops()[j]; - auto op_type = op->Type(); - // DLOG << "op type: " << op_type << " index: " << j; - if (op_input_output_key.find(op->Type()) == op_input_output_key.end()) { - return NULL; - } - - std::shared_ptr node = std::make_shared(op); - if (j == 0) { - begin_node = node; - } - - auto input_keys = op_input_output_key.at(op->Type()).first; - for (auto input_key : input_keys) { - auto op_inputs = op->Input(input_key); - for (int l = 0; l < op_inputs.size(); ++l) { - std::string input_key = op_inputs[l]; - if (output_nodes.find(input_key) != output_nodes.end()) { - auto input_node = output_nodes[input_key]; - *input_node > node; - } - } - } - - auto output_keys = op_input_output_key.at(op_type).second; - for (auto output_key : output_keys) { - auto op_outputs = op->Output(output_key); - for (int k = 0; k < op_outputs.size(); ++k) { - output_nodes[op_outputs[k]] = node; - } - } - } - - DLOG << "node: \n" << *begin_node; - } - return ori_des; -} -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program-optimize/program_optimize.h b/src/framework/program-optimize/program_optimize.h deleted file mode 100644 index bb32493bf2..0000000000 --- a/src/framework/program-optimize/program_optimize.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include "framework/operator.h" -#include "framework/program_desc.h" -#include "node.h" - -namespace paddle_mobile { - -namespace framework { -class ProgramOptimize { - public: - ProgramOptimize() {} - std::shared_ptr Optimize(); - std::shared_ptr FushionOptimize( - std::shared_ptr ori_des); - - private: - // std::shared_ptr ori_desc_; - std::vector>> - outputs_nodes_; -}; -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program.cpp b/src/framework/program.cpp deleted file mode 100644 index a3b9cf6a4f..0000000000 --- a/src/framework/program.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -namespace paddle_mobile { -namespace framework {} -} // namespace paddle_mobile diff --git a/src/framework/program.h b/src/framework/program.h deleted file mode 100644 index 07f175bf37..0000000000 --- a/src/framework/program.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include "common/types.h" -#include "paddle_mobile_object.h" -#include "program_desc.h" -#include "scope.h" - -namespace paddle_mobile { -namespace framework { - -template -class Program : PaddleMobileObject { - public: - std::shared_ptr originProgram; - std::shared_ptr optimizeProgram; - std::shared_ptr scope; - - private: -}; - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program/block_desc.cpp b/src/framework/program/block_desc.cpp new file mode 100644 index 0000000000..7329574406 --- /dev/null +++ b/src/framework/program/block_desc.cpp @@ -0,0 +1,33 @@ +#include "block_desc.h" + +namespace paddle_mobile { +namespace framework { + +std::vector> BlockDesc::Vars() const { + std::vector> res; + for (const auto &p : vars_) { + res.push_back(p.second); + } + return res; +} + +std::vector> BlockDesc::Ops() const { + std::vector> res; + for (const auto &op : ops_) { + res.push_back(op); + } + return res; +} + +BlockDesc::BlockDesc(const proto::BlockDesc &desc): + index_(desc.idx()), parent_index_(desc.parent_idx()) { + for (const proto::VarDesc &var_desc : desc.vars()) { + vars_[var_desc.name()].reset(new VarDesc(var_desc)); + } + for (const proto::OpDesc &op_desc : desc.ops()) { + ops_.emplace_back(new framework::OpDesc(op_desc)); + } +} + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/block_desc.h b/src/framework/program/block_desc.h new file mode 100644 index 0000000000..810418a516 --- /dev/null +++ b/src/framework/program/block_desc.h @@ -0,0 +1,71 @@ +#pragma once + +#include "framework/framework.pb.h" +#include "framework/program/op_desc.h" +#include "framework/program/var_desc.h" +#include "framework/paddle_mobile_object.h" + + +namespace paddle_mobile { +namespace framework { + +class BlockDesc : PaddleMobileObject { + public: + friend class Node; + friend class ProgramOptimize; + BlockDesc(const proto::BlockDesc &desc); + + BlockDesc(const BlockDesc &block_desc): + index_(block_desc.index_), + parent_index_(block_desc.parent_index_) { + for (auto &op_desc : block_desc.ops_) { + std::shared_ptr copy_op_desc = std::make_shared(*op_desc); + ops_.push_back(copy_op_desc); + } + + for (auto &var_desc : block_desc.vars_) { + std::shared_ptr copy_var_desc = + std::make_shared(*var_desc.second); + vars_[var_desc.first] = copy_var_desc; + } + } + + const int &ID() const { return index_; } + + const int &Parent() const { return parent_index_; } + + bool operator==(const paddle_mobile::framework::BlockDesc &in_block) const { + return this->ID() == in_block.ID() && this->Parent() == in_block.Parent(); + } + + bool operator<(const paddle_mobile::framework::BlockDesc &in_block) const { + return this->ID() < in_block.ID() && this->Parent() < in_block.Parent(); + } + + std::vector> Vars() const; + std::vector> Ops() const; + + private: + int index_; + int parent_index_; + std::vector> ops_; + std::unordered_map> vars_; +}; + +} // namespace framework +} // namespace paddle_mobile + +namespace std { + +template <> +struct hash { + typedef paddle_mobile::framework::BlockDesc argument_type; + typedef std::size_t result_type; + result_type operator()(argument_type const &s) const noexcept { + result_type const h1(std::hash{}(s.ID())); + result_type const h2(std::hash{}(s.ID())); + return h1 ^ (h2 << 1); + } +}; + +} // namespace std diff --git a/src/framework/op_desc.cpp b/src/framework/program/op_desc.cpp similarity index 61% rename from src/framework/op_desc.cpp rename to src/framework/program/op_desc.cpp index 73037ecf30..8853e95c7a 100644 --- a/src/framework/op_desc.cpp +++ b/src/framework/program/op_desc.cpp @@ -12,19 +12,17 @@ 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/5/4. -// -#include "framework/op_desc.h" #include #include +#include "framework/program/op_desc.h" + namespace paddle_mobile { namespace framework { -OpDesc::OpDesc(const proto::OpDesc &desc) : desc_(desc) { - for (int i = 0; i < desc_.inputs_size(); ++i) { - const proto::OpDesc::Var &var = desc_.inputs(i); +OpDesc::OpDesc(const proto::OpDesc &desc):type_(desc.type()) { + for (int i = 0; i < desc.inputs_size(); ++i) { + const proto::OpDesc::Var &var = desc.inputs(i); std::vector &args = inputs_[var.parameter()]; int arg_size = var.arguments_size(); for (int j = 0; j < arg_size; ++j) { @@ -32,8 +30,8 @@ OpDesc::OpDesc(const proto::OpDesc &desc) : desc_(desc) { } } - for (int i = 0; i < desc_.outputs_size(); ++i) { - const proto::OpDesc::Var &var = desc_.outputs(i); + for (int i = 0; i < desc.outputs_size(); ++i) { + const proto::OpDesc::Var &var = desc.outputs(i); std::vector &args = outputs_[var.parameter()]; int arg_size = var.arguments_size(); for (int j = 0; j < arg_size; ++j) { @@ -41,7 +39,7 @@ OpDesc::OpDesc(const proto::OpDesc &desc) : desc_(desc) { } } - for (const proto::OpDesc::Attr &attr : desc_.attrs()) { + for (const proto::OpDesc::Attr &attr : desc.attrs()) { std::string attr_name = attr.name(); if (attr.type() != proto::AttrType::BLOCK) { attrs_[attr_name] = Attribute::GetAttrValue(attr); @@ -62,9 +60,28 @@ Attribute OpDesc::GetAttr(const std::string &name) const { return it->second; } -const std::unordered_map &OpDesc::GetAttrMap() const { +std::unordered_map &OpDesc::GetAttrMap() { return attrs_; } +Print &operator<<(Print &printer, const OpDesc &op_desc) { + OpDesc &no_const_op_desc = const_cast(op_desc); + printer << "inputs: \n"; + for (const auto &input : no_const_op_desc.GetInputs()) { + printer << input.first << " : " << input.second << "\n"; + } + + printer << "outputs: \n"; + for (const auto &output : no_const_op_desc.GetOutputs()) { + printer << output.first << " : " << output.second << "\n"; + } + + printer << "outputs: \n"; + for (const auto &attr : no_const_op_desc.GetAttrMap()) { + printer << attr.first << " : " << attr.second << "\n"; + } + return printer; +} + } // namespace framework } // namespace paddle_mobile diff --git a/src/framework/program/op_desc.h b/src/framework/program/op_desc.h new file mode 100644 index 0000000000..ec8da73bd5 --- /dev/null +++ b/src/framework/program/op_desc.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +#include "common/log.h" +#include "common/type_define.h" +#include "framework/framework.pb.h" +#include "framework/paddle_mobile_object.h" + +namespace paddle_mobile { +namespace framework { + +class OpDesc : PaddleMobileObject { + public: + friend class ProgramOptimize; + friend class FusionOpMatcher; + friend class Node; + explicit OpDesc(const proto::OpDesc &desc); + + OpDesc(const OpDesc &op_desc): type_(op_desc.type_) { + this->inputs_ = op_desc.inputs_; + this->outputs_ = op_desc.outputs_; + this->attrs_ = op_desc.attrs_; + } + + OpDesc() { + } + const std::vector &Input(const std::string &name) const; + const std::vector &Output(const std::string &name) const; + Attribute GetAttr(const std::string &name) const; + + VariableNameMap &GetInputs() { return inputs_; } + + VariableNameMap &GetOutputs() { return outputs_; } + + AttributeMap &GetAttrMap(); + + const std::string &Type() { return type_; } + + void SetInputs(VariableNameMap inputs){ + inputs_ = inputs; + } + + void SetOutputs(VariableNameMap outputs){ + outputs_ = outputs; + } + + void SetAttrMap(AttributeMap attrs){ + attrs_ = attrs; + } + + private: + std::string type_; + VariableNameMap inputs_; + VariableNameMap outputs_; + AttributeMap attrs_; +}; + +Print &operator<<(Print &printer, const OpDesc &op_desc); + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program-optimize/fusion_op_register.cpp b/src/framework/program/program-optimize/fusion_op_register.cpp new file mode 100644 index 0000000000..e4cbca7ba7 --- /dev/null +++ b/src/framework/program/program-optimize/fusion_op_register.cpp @@ -0,0 +1 @@ +#include "fusion_op_register.h" diff --git a/src/framework/program/program-optimize/fusion_op_register.h b/src/framework/program/program-optimize/fusion_op_register.h new file mode 100644 index 0000000000..37c5c01d0d --- /dev/null +++ b/src/framework/program/program-optimize/fusion_op_register.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +#include "framework/operator.h" +#include "node.h" + +namespace paddle_mobile { +namespace framework { + +class FusionOpRegister { + public: + static FusionOpRegister *Instance() { + static FusionOpRegister *regist = nullptr; + if (regist == nullptr) { + regist = new FusionOpRegister(); + } + return regist; + } + + void regist(FusionOpMatcher* matcher) { + std::shared_ptr shared_matcher(matcher); + matchers_[matcher->Type()] = shared_matcher; + } + + const std::map> Matchers() { + return matchers_; + } + + private: + std::map> matchers_; + FusionOpRegister() {} +}; + +class FusionOpRegistrar{ + public: + explicit FusionOpRegistrar(FusionOpMatcher* matcher){ + FusionOpRegister::Instance()->regist(matcher); + } +}; + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program-optimize/node.cpp b/src/framework/program/program-optimize/node.cpp new file mode 100644 index 0000000000..e47e0f227a --- /dev/null +++ b/src/framework/program/program-optimize/node.cpp @@ -0,0 +1,207 @@ +#include + +#include "framework/program/program-optimize/node.h" + +namespace paddle_mobile { + +namespace framework { + +Node &Node::operator>(std::shared_ptr node) { + outputs_.push_back(node); + std::shared_ptr this_node; + node->inputs_.push_back(this); + return *node; +} + +bool Node::operator==(const Node &in) { + if (in.type_ == this->type_) { + if (this->outputs_.size() == in.outputs_.size()) { + for (int i = 0; i < outputs_.size(); ++i) { + if (!(*outputs_[i] == *in.outputs_[i])) { + return false; + } + } + } else { + return false; + } + } else { + return false; + } + return true; +} + +// std::shared_ptr Node::MatchTheFirstNode(std::string type){ +// +// for (const auto &node : outputs_){ +// if (node->type_ == type){ +// return node; +// }else{ +// +// } +// } +//} + +std::vector> Node::OpDescs(uint size) { + std::vector> op_descs; + OpDescs(size - 1, &op_descs); + return op_descs; +} + +void Node::OpDescs(uint index, + std::vector> *op_desc) { + if (index == 0) { + return; + } + op_desc->push_back(this->op_desc_); + for (auto &output : outputs_) { + output->OpDescs(index, op_desc); + } +} + +void Node::OpDescs(std::vector> *op_desc, Node *node) { + auto iter = std::find(op_desc->begin(), op_desc->end(), this->op_desc_); + if (inputs_.size() > 1 && node != inputs_.back()) { + return; + } else if (inputs_.size() > 1 && node == inputs_.back()) { + op_desc->push_back(this->op_desc_); + } else { + op_desc->push_back(this->op_desc_); + } + + for (auto &output : outputs_) { + output->OpDescs(op_desc, this); + } +} + +std::vector> Node::OpDescs() { + std::vector> op_descs; + OpDescs(&op_descs, this); + return op_descs; +} + +std::string Node::ToString(std::string blank, const Node *node) const { + std::stringstream ss; + ss << type_ << "-> \n"; + + if (inputs_.size() > 1 && node != inputs_.back()) { + return ss.str(); + } else if (inputs_.size() > 1 && node == inputs_.back()) { + ss << "\n" << blank << type_ << "\n"; + } + + for (int i = 0; i < outputs_.size(); ++i) { + ss << blank << outputs_[i]->ToString(blank + " ", this) << ""; + } + return ss.str(); +} + +std::string Node::ToString() const { return this->ToString(" ", this); } + +std::shared_ptr Node::To(int size) { + std::shared_ptr node = std::make_shared(); + this->To(size - 1, node); + return node; +} + +// Node &Node::To(int size) { +// if (size == 1) { +// this->outputs_.clear(); +// } +// +// for (int j = 0; j < this->outputs_.size(); ++j) { +// outputs_[j]->To(size - 1); +// } +// return *this; +//} + +void Node::To(int index, std::shared_ptr node) { + node->type_ = this->type_; + if (index != 0) { + } else { + return; + } + + for (int j = 0; j < this->outputs_.size(); ++j) { + std::shared_ptr sub_node = std::make_shared(); + node->outputs_.push_back(sub_node); + outputs_[j]->To(index - 1, sub_node); + } +} + +uint Node::Depth(uint begin) { + uint depth = 0; + begin++; + for (int i = 0; i < outputs_.size(); ++i) { + uint output_depth = outputs_[i]->Depth(begin); + depth = output_depth > depth ? output_depth : depth; + } + return begin > depth ? begin : depth; +} + +Node &Node::Folder( + uint size, std::string type, + std::map> change) { + std::shared_ptr op_desc = + std::make_shared(); + op_desc->inputs_ = this->op_desc_->inputs_; + std::vector> outputs; + this->Folder(op_desc, &outputs, size - 1, &change, this); + this->outputs_ = outputs; + this->type_ = type; + this->op_desc_ = op_desc; + this->op_desc_->type_ = type; + return *this; +} + +void Node::Folder( + std::shared_ptr op_desc, + std::vector> *outputs, uint index, + std::map> *change, + Node *begin_node) { + if (change->find(this->type_) != change->end()) { + auto change_pair = (*change)[this->type_]; + op_desc->GetInputs()[change_pair.second] = + this->op_desc_->GetInputs()[change_pair.first]; + } + + for (auto &attr_pair : this->op_desc_->attrs_) { + op_desc->attrs_.emplace(attr_pair.first, attr_pair.second); + } + if (index > 0) { + --index; + for (auto output : outputs_) { + output->Folder(op_desc, outputs, index, change, begin_node); + } + } else { + for (auto &op_output : this->op_desc_->outputs_) { + op_desc->outputs_.emplace(op_output.first, op_output.second); + } + + for (auto &output : this->outputs_) { + auto iter = + std::find(output->inputs_.begin(), output->inputs_.end(), this); + + if (iter != output->inputs_.end()) { + output->inputs_.erase(iter); + } + output->inputs_.push_back(begin_node); + outputs->push_back(output); + } + } +} + +void Node::Description() { + if (op_desc_.get()) { + DLOG << *op_desc_; + } else { + DLOG << " null "; + } +} + +Print &operator<<(Print &printer, const Node &node) { + printer << node.ToString(); + return printer; +} + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program-optimize/node.h b/src/framework/program/program-optimize/node.h new file mode 100644 index 0000000000..77dc9624d8 --- /dev/null +++ b/src/framework/program/program-optimize/node.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include + +#include "common/log.h" +#include "framework/program/op_desc.h" +#include "framework/paddle_mobile_object.h" + +namespace paddle_mobile { +namespace framework { + +class Node : PaddleMobileObject { + public: + Node() {} + explicit Node(const std::string &type) : type_(type) {} + explicit Node(std::shared_ptr op_desc) + : op_desc_(op_desc), type_(op_desc->Type()) {} + Node &operator>(std::shared_ptr node); + bool operator==(const Node &in); + std::string ToString() const; + std::shared_ptr To(int size); + uint Depth(uint begin = 0); + Node &Folder( + uint size, std::string type, + std::map> change_map); + std::vector> OpDescs(uint size); + std::vector> OpDescs(); + void OpDescs(std::vector> *op_desc, Node *node); + std::shared_ptr OpDesc() { return op_desc_; } + std::string BeginType() { return type_; } + void Description(); + + private: + void OpDescs(uint size, + std::vector> *op_desc); + void To(int index, std::shared_ptr); + void Folder( + std::shared_ptr op_desc, + std::vector> *outputs, uint index, + std::map> *change, + Node *begin_node); + std::shared_ptr op_desc_; + std::string ToString(std::string blank, const Node *node) const; + std::vector> outputs_; + std::vector inputs_; + std::string type_; +}; + +Print &operator<<(Print &printer, const Node &node); +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program-optimize/program_optimize.cpp b/src/framework/program/program-optimize/program_optimize.cpp new file mode 100644 index 0000000000..606edce3e6 --- /dev/null +++ b/src/framework/program/program-optimize/program_optimize.cpp @@ -0,0 +1,93 @@ +#include "framework/program/program-optimize/program_optimize.h" +#include "framework/program/program-optimize/fusion_op_register.h" + +namespace paddle_mobile { + +namespace framework { + +std::shared_ptr ProgramOptimize::Optimize() {} + +std::shared_ptr ProgramOptimize::FushionOptimize( + std::shared_ptr ori_des) { + + ProgramDesc *optimize_program = new ProgramDesc(*ori_des); + + for (int i = 0; i < optimize_program->Blocks().size(); ++i) { + std::unordered_map> output_nodes; + std::unordered_map>> + type_map; + + std::shared_ptr begin_node; + auto block = optimize_program->Block(i); + // DLOG << " ops size: " << block->Ops().size(); + for (int j = 0; j < block->Ops().size(); ++j) { + auto op = block->Ops()[j]; + auto op_type = op->Type(); + if (op_input_output_key.find(op->Type()) == op_input_output_key.end()) { + LOG(kLOG_ERROR) << "return null "; + return nullptr; + } + + std::shared_ptr node = std::make_shared(op); + + // + type_map[op->Type()].push_back(node); + + if (j == 0) { + begin_node = node; + } + + auto input_keys = op_input_output_key.at(op->Type()).first; + for (auto input_key : input_keys) { + auto op_inputs = op->Input(input_key); + for (int l = 0; l < op_inputs.size(); ++l) { + std::string input_key = op_inputs[l]; + if (output_nodes.find(input_key) != output_nodes.end()) { + auto input_node = output_nodes[input_key]; + *input_node > node; + } + } + } + + auto output_keys = op_input_output_key.at(op_type).second; + for (auto output_key : output_keys) { + auto op_outputs = op->Output(output_key); + for (int k = 0; k < op_outputs.size(); ++k) { + output_nodes[op_outputs[k]] = node; + } + } + } + + for (auto ®isted : FusionOpRegister::Instance()->Matchers()) { + std::string fusion_type = registed.first; + std::shared_ptr matcher = registed.second; + // DLOG << " registed node \n " << matcher->BeginNode(); + + auto match_vector = type_map[matcher->BeginType()]; + + for (auto &match_node : match_vector) { + auto depth = matcher->BeginNode().Depth(); + auto sub_node = match_node->To(depth); + // DLOG << " sub node: " << *sub_node; + if (*sub_node == matcher->BeginNode()) { + // DLOG << " match success " << " fusion node: \n" << + // matcher->BeginNode() << "\nsub node: \n" << *sub_node; + // DLOG << "match node\n"<< *match_node; + matcher->FolderNodes(*match_node); + // DLOG << " after match node\n"<< *match_node; + // match_node->Description(); + + // DLOG << "begin node: \n" << *begin_node; + } + } + } + +// DLOG << "node: \n" << *begin_node; + block->ops_ = begin_node->OpDescs(); + + } + std::shared_ptr shared_optimzie(optimize_program); + return shared_optimzie; +} +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program-optimize/program_optimize.h b/src/framework/program/program-optimize/program_optimize.h new file mode 100644 index 0000000000..e23d561399 --- /dev/null +++ b/src/framework/program/program-optimize/program_optimize.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +#include "framework/operator.h" +#include "framework/program/program_desc.h" +#include "node.h" + +namespace paddle_mobile { + +namespace framework { +class ProgramOptimize { + public: + ProgramOptimize() {} + std::shared_ptr Optimize(); + std::shared_ptr FushionOptimize( + std::shared_ptr ori_des); + private: + // std::shared_ptr ori_desc_; + std::vector>> + outputs_nodes_; +}; +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program.cpp b/src/framework/program/program.cpp new file mode 100644 index 0000000000..9ed874e1b9 --- /dev/null +++ b/src/framework/program/program.cpp @@ -0,0 +1,3 @@ +namespace paddle_mobile { +namespace framework {} +} // namespace paddle_mobile diff --git a/src/framework/program/program.h b/src/framework/program/program.h new file mode 100644 index 0000000000..603da8274b --- /dev/null +++ b/src/framework/program/program.h @@ -0,0 +1,22 @@ +#pragma once + +#include "common/types.h" +#include "framework/paddle_mobile_object.h" +#include "framework/program/program_desc.h" +#include "framework/scope.h" + +namespace paddle_mobile { +namespace framework { + +template +class Program : PaddleMobileObject { + public: + std::shared_ptr originProgram; + std::shared_ptr optimizeProgram; + std::shared_ptr scope; + + private: +}; + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program_desc.cpp b/src/framework/program/program_desc.cpp new file mode 100644 index 0000000000..f8e4397a63 --- /dev/null +++ b/src/framework/program/program_desc.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include "program_desc.h" + +namespace paddle_mobile { +namespace framework { + +ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) { + for (auto &block_desc : desc.blocks()) { + // new framework::BlockDesc(block_desc) + blocks_.emplace_back(std::make_shared(block_desc)); + } +} + +void ProgramDesc::Description(std::string header) { +#ifdef PADDLE_MOBILE_DEBUG + if (header.size()){ + LOG(kLOG_INFO) << header; + } + for (const auto &block : this->blocks_) { + LOG(kLOG_DEBUG) << "block: " << block->ID(); + LOG(kLOG_INFO) << "block ops size: " << block->Ops().size(); + for (int j = 0; j < block->Ops().size(); ++j) { + const auto &op = block->Ops()[j]; + LOG(kLOG_DEBUG1) << "op: " << op->Type(); + for (auto &input : op->GetInputs()) { + LOG(kLOG_DEBUG2) << "input parameter: " << input.first; + for (auto &n : input.second) { + LOG(kLOG_DEBUG3) << "argument - " << n; + } + } + for (auto &output : op->GetOutputs()) { + LOG(kLOG_DEBUG2) << "output parameter: " << output.first; + for (auto &n : output.second) { + LOG(kLOG_DEBUG3) << "argument - " << n; + } + } + for (auto &attr : op->GetAttrMap()) { + LOG(kLOG_DEBUG2) << "attr name:: " << attr.first; + LOG(kLOG_DEBUG3) << "argument - " << attr.second; + } + } + } +#endif +} + +std::shared_ptr ProgramDesc::Block(size_t idx) { + return blocks_[idx]; +} + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/program_desc.h b/src/framework/program/program_desc.h new file mode 100644 index 0000000000..adf201aab6 --- /dev/null +++ b/src/framework/program/program_desc.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "common/types.h" +#include "framework/program/block_desc.h" +#include "framework/paddle_mobile_object.h" + +namespace paddle_mobile { +namespace framework { + +class ProgramDesc : PaddleMobileObject { + public: + friend class Node; + friend class ProgramOptimize; + explicit ProgramDesc(const proto::ProgramDesc &desc); + std::shared_ptr Block(size_t idx); + const std::vector> &Blocks() { return blocks_; } + ProgramDesc(const ProgramDesc &program_desc) { + for (auto &block : program_desc.blocks_) { + std::shared_ptr copy_block = + std::make_shared(*block); + blocks_.push_back(copy_block); + } + } + + void Description(std::string header = ""); + private: + std::vector> blocks_; +}; + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/program/var_desc.cpp b/src/framework/program/var_desc.cpp new file mode 100644 index 0000000000..d5dd644286 --- /dev/null +++ b/src/framework/program/var_desc.cpp @@ -0,0 +1,10 @@ +#include "var_desc.h" + +namespace paddle_mobile { + +namespace framework { + +VarDesc::VarDesc(const proto::VarDesc &desc) : desc_(desc) {} + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/framework/var_desc.h b/src/framework/program/var_desc.h similarity index 58% rename from src/framework/var_desc.h rename to src/framework/program/var_desc.h index 82d07a383e..4a963e8d6d 100644 --- a/src/framework/var_desc.h +++ b/src/framework/program/var_desc.h @@ -1,25 +1,7 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once -#include "framework.pb.h" -#include "paddle_mobile_object.h" +#include "framework/framework.pb.h" +#include "framework/paddle_mobile_object.h" namespace paddle_mobile { namespace framework { @@ -28,6 +10,8 @@ class VarDesc { public: VarDesc(const proto::VarDesc &desc); + VarDesc(const VarDesc &var_desc):desc_(var_desc.desc_) {} + std::string Name() const { return desc_.name(); } proto::VarType::Type GetType() const { return desc_.type().type(); } diff --git a/src/framework/program_desc.cpp b/src/framework/program_desc.cpp deleted file mode 100644 index 5537dacdeb..0000000000 --- a/src/framework/program_desc.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* 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/5/4. -// - -#include "framework/program_desc.h" - -namespace paddle_mobile { -namespace framework { - -ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) : desc_(desc) { - for (auto &block_desc : *desc_.mutable_blocks()) { - // new framework::BlockDesc(block_desc) - blocks_.emplace_back(std::make_shared(block_desc)); - } -} - -std::shared_ptr ProgramDesc::Block(size_t idx) { - return blocks_[idx]; -} - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/program_desc.h b/src/framework/program_desc.h deleted file mode 100644 index 79adc70a6f..0000000000 --- a/src/framework/program_desc.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#pragma once - -#include - -#include "block_desc.h" -#include "common/types.h" -#include "paddle_mobile_object.h" - -namespace paddle_mobile { -namespace framework { - -class ProgramDesc : PaddleMobileObject { - public: - ProgramDesc(const proto::ProgramDesc &desc); - std::shared_ptr Block(size_t idx); - const std::vector> &Blocks() { return blocks_; }; - - private: - std::vector> blocks_; - proto::ProgramDesc desc_; -}; - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/scope.h b/src/framework/scope.h index 13e569e52b..907f7f241f 100644 --- a/src/framework/scope.h +++ b/src/framework/scope.h @@ -1,21 +1,3 @@ - -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ #pragma once #include //std::list diff --git a/src/framework/selected_rows.h b/src/framework/selected_rows.h index 3488450e23..e295564009 100644 --- a/src/framework/selected_rows.h +++ b/src/framework/selected_rows.h @@ -1,21 +1,3 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once #include diff --git a/src/framework/var_desc.cpp b/src/framework/var_desc.cpp deleted file mode 100644 index f0049e0489..0000000000 --- a/src/framework/var_desc.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - -#include "var_desc.h" - -namespace paddle_mobile { - -namespace framework { - -VarDesc::VarDesc(const proto::VarDesc &desc) : desc_(desc) {} - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/framework/var_type.h b/src/framework/var_type.h index 8ead7901d5..a539a49d3f 100644 --- a/src/framework/var_type.h +++ b/src/framework/var_type.h @@ -1,21 +1,3 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ - #pragma once #include "framework.pb.h" #include "lod_tensor.h" diff --git a/src/framework/variable.h b/src/framework/variable.h index 3a9cf3843f..78c402e340 100644 --- a/src/framework/variable.h +++ b/src/framework/variable.h @@ -1,21 +1,3 @@ - -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ #pragma once #include diff --git a/src/io.cpp b/src/io.cpp index 60fde1c08f..f11764e726 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -14,14 +14,14 @@ limitations under the License. */ #include -#include "../src/io.h" +#include "io.h" #include "common/log.h" -#include "framework/framework.pb.h" -#include "framework/lod_tensor.h" -#include "framework/program_desc.h" #include "framework/scope.h" #include "framework/tensor.h" -#define PADDLE_MOBILE_DEBUG 1 +#include "framework/lod_tensor.h" +#include "framework/framework.pb.h" +#include "framework/program/program_desc.h" + namespace paddle_mobile { void ReadBinaryFile(const std::string &filename, std::string *contents) { @@ -152,7 +152,7 @@ const framework::Program Loader::Load( LoadVar(tensor, dirname + "/" + var_desc->Name()); } } else { - // TODO by someone + // TODO(codeWorm): some. } } } @@ -303,7 +303,7 @@ const framework::Program Loader::Load( is.read(static_cast(memory), memory_size * type_size); is.close(); } else { - // TODO + // TODO } } } diff --git a/src/io.h b/src/io.h index e177792ee0..7a8d5863eb 100644 --- a/src/io.h +++ b/src/io.h @@ -19,7 +19,7 @@ limitations under the License. */ #include "common/types.h" #include "framework/lod_tensor.h" #include "framework/paddle_mobile_object.h" -#include "framework/program.h" +#include "framework/program/program.h" namespace paddle_mobile { diff --git a/src/operators/fusion_conv_add_relu_op.cpp b/src/operators/fusion_conv_add_relu_op.cpp new file mode 100644 index 0000000000..379092b469 --- /dev/null +++ b/src/operators/fusion_conv_add_relu_op.cpp @@ -0,0 +1 @@ +#include "fusion_conv_add_relu_op.h" diff --git a/src/operators/fusion_conv_add_relu_op.h b/src/operators/fusion_conv_add_relu_op.h new file mode 100644 index 0000000000..991f67396b --- /dev/null +++ b/src/operators/fusion_conv_add_relu_op.h @@ -0,0 +1,34 @@ +#pragma once + +#include "framework/operator.h" +#include "framework/program/program-optimize/fusion_op_register.h" + +namespace paddle_mobile { +namespace operators { + +class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher { + public: + FushionConvAddReluOpMatcher() { + node_ = framework::Node("conv2d"); + node_ > std::make_shared("elementwise_add") > std::make_shared("relu"); + } + + void FolderNodes(framework::Node &node) { + std::vector> origin_descs = node.OpDescs(node_.Depth()); + node.Folder(node_.Depth(), Type(), {{"elementwise_add" , {"Y", "Z"}}}); + } + + std::string Type() { + return "FusionConvAddRelu"; + } +}; + +class FusionFcOp { + public: + private: +}; + +static framework::FusionOpRegistrar fc_registrar(new FushionConvAddReluOpMatcher()); + +} +} diff --git a/src/operators/fusion_fc_op.cpp b/src/operators/fusion_fc_op.cpp new file mode 100644 index 0000000000..486b4799a7 --- /dev/null +++ b/src/operators/fusion_fc_op.cpp @@ -0,0 +1 @@ +#include "fusion_fc_op.h" \ No newline at end of file diff --git a/src/operators/fusion_fc_op.h b/src/operators/fusion_fc_op.h new file mode 100644 index 0000000000..eb03ced84f --- /dev/null +++ b/src/operators/fusion_fc_op.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include "framework/operator.h" +#include "framework/program/program-optimize/fusion_op_register.h" + +namespace paddle_mobile { +namespace operators { + +class FusionFcMatcher : public framework::FusionOpMatcher { + public: + FusionFcMatcher() { + node_ = framework::Node("mul"); + node_ > std::make_shared("elementwise_add"); + } + + void FolderNodes(framework::Node &node) { + std::vector> origin_descs = node.OpDescs(node_.Depth()); + node.Folder(node_.Depth(), Type(), {{"elementwise_add" , {"Y", "Z"}}}); + } + + std::string Type() { + return "fc"; + } +}; + +class FusionFcOp { + public: + private: +}; + +static framework::FusionOpRegistrar fc_registrar(new FusionFcMatcher()); + +} // namespace operators +} // namespace paddle_mobile diff --git a/src/platform/data_type.h b/src/platform/data_type.h index 401c7eb119..86e5c0ac77 100644 --- a/src/platform/data_type.h +++ b/src/platform/data_type.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. +/* 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. diff --git a/test/common/test_log.cpp b/test/common/test_log.cpp index 777743b4fe..6707d9ccd9 100644 --- a/test/common/test_log.cpp +++ b/test/common/test_log.cpp @@ -1,3 +1,17 @@ +/* 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. */ + #include "common/log.h" int main() { diff --git a/test/framework/test_load.cpp b/test/framework/test_load.cpp index 153429bae6..d805070675 100644 --- a/test/framework/test_load.cpp +++ b/test/framework/test_load.cpp @@ -1,20 +1,16 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ +/* 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. */ #include "io.h" diff --git a/test/framework/test_optimize.cpp b/test/framework/test_optimize.cpp index f11531f8ad..5a85c4edaf 100644 --- a/test/framework/test_optimize.cpp +++ b/test/framework/test_optimize.cpp @@ -1,23 +1,19 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -#include "framework/program-optimize/node.h" -#include "framework/program-optimize/program_optimize.h" +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. */ + +#include "framework/program/program-optimize/node.h" +#include "framework/program/program-optimize/program_optimize.h" #include "io.h" using namespace paddle_mobile; @@ -28,13 +24,13 @@ int main() { Loader loader; // "../../../test/models/googlenet" auto program = loader.Load("../models/googlenet"); - ProgramOptimize optimize; - +// program.originProgram->Description("origin"); auto optimize_program = optimize.FushionOptimize(program.originProgram); - if (optimize_program) { - + if (optimize_program != nullptr) { +// optimize_program->Description("optimize"); } else { - DLOG << "optimize_program is null"; + LOG(kLOG_ERROR) << "optimize_program is null"; } + return 0; } diff --git a/test/operators/test_cov_op.cpp b/test/operators/test_cov_op.cpp index b460040d13..4e88b86ba5 100644 --- a/test/operators/test_cov_op.cpp +++ b/test/operators/test_cov_op.cpp @@ -1,20 +1,16 @@ -/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -==============================================================================*/ +/* 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. */ #include "../framework/executor_for_test.h" #include "../test_helper.h" @@ -22,6 +18,7 @@ SOFTWARE. int main() { paddle_mobile::Loader loader; + //../models/image_classification_resnet.inference.model auto program = loader.Load(std::string("../models/googlenet")); if (program.originProgram == nullptr) { DLOG << "program file read fail"; diff --git a/test/test_include.h b/test/test_include.h index 27ed715b2d..092ebe7c3d 100644 --- a/test/test_include.h +++ b/test/test_include.h @@ -12,17 +12,18 @@ 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/block_desc.h" +#include +#include +#include + +#include "framework/program/block_desc.h" #include "framework/framework.pb.h" #include "framework/lod_tensor.h" #include "framework/operator.h" -#include "framework/program.h" -#include "framework/program_desc.h" +#include "framework/program/program.h" +#include "framework/program/program_desc.h" #include "framework/scope.h" #include "framework/tensor.h" #include "framework/variable.h" #include "io.h" #include "test_helper.h" -#include -#include -#include \ No newline at end of file -- GitLab