提交 b74b616f 编写于 作者: L liuruilong

format files

上级 c9c6562e
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once; #pragma once;
#include <string> #include <string>
#include <utility>
#include <unordered_map> #include <unordered_map>
#include <utility>
namespace paddle_mobile { namespace paddle_mobile {
enum class Precision : int { FP32 = 0 }; enum class Precision : int { FP32 = 0 };
......
...@@ -19,20 +19,20 @@ limitations under the License. */ ...@@ -19,20 +19,20 @@ limitations under the License. */
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "common/types.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "common/variant.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/op_info.h"
#include "common/type_define.h" #include "common/type_define.h"
#include "framework/variable.h" #include "common/types.h"
#include "common/variant.h"
#include "framework/attribute.h" #include "framework/attribute.h"
#include "framework/op_registry.h" #include "framework/op_info.h"
#include "framework/op_kernel_type.h" #include "framework/op_kernel_type.h"
#include "framework/program/block_desc.h" #include "framework/op_registry.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
#include "framework/program/block_desc.h"
#include "framework/program/program-optimize/node.h" #include "framework/program/program-optimize/node.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -77,6 +77,7 @@ class OperatorBase : PaddleMobileObject { ...@@ -77,6 +77,7 @@ class OperatorBase : PaddleMobileObject {
* @b 根据输入形状和参数计算出输出形状 * @b 根据输入形状和参数计算出输出形状
* */ * */
virtual void InferShape() const = 0; virtual void InferShape() const = 0;
protected: protected:
std::shared_ptr<Scope> scope_; std::shared_ptr<Scope> scope_;
std::string type_; std::string type_;
......
...@@ -82,11 +82,14 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc, ...@@ -82,11 +82,14 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
DLOG << "当前 op desc 输出数不为 1 "; DLOG << "当前 op desc 输出数不为 1 ";
can_add_split = false; can_add_split = false;
} }
for (const auto& output : outputs_) { for (const auto &output : outputs_) {
if (op_input_output_key.find(output->op_desc_->type_) != op_input_output_key.end()) { if (op_input_output_key.find(output->op_desc_->type_) !=
op_input_output_key.end()) {
auto inputs_and_outputs = op_input_output_key[output->op_desc_->type_]; auto inputs_and_outputs = op_input_output_key[output->op_desc_->type_];
auto outputs_of_output = output->op_desc_->Output(inputs_and_outputs.second[0]); auto outputs_of_output =
auto inputs_of_output = output->op_desc_->Input(inputs_and_outputs.first[0]); output->op_desc_->Output(inputs_and_outputs.second[0]);
auto inputs_of_output =
output->op_desc_->Input(inputs_and_outputs.first[0]);
for (int i = 0; i < inputs_of_output.size(); ++i) { for (int i = 0; i < inputs_of_output.size(); ++i) {
std::string input_of_output = inputs_of_output[i]; std::string input_of_output = inputs_of_output[i];
for (int j = 0; j < outputs_of_output.size(); ++j) { for (int j = 0; j < outputs_of_output.size(); ++j) {
...@@ -121,13 +124,17 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc, ...@@ -121,13 +124,17 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
if (can_add_split) { if (can_add_split) {
adding_thread = true; adding_thread = true;
std::shared_ptr<class OpDesc> split_op_desc = std::make_shared<class OpDesc>(); std::shared_ptr<class OpDesc> split_op_desc =
std::make_shared<class OpDesc>();
split_op_desc->type_ = G_OP_TYPE_SPLIT; split_op_desc->type_ = G_OP_TYPE_SPLIT;
auto outputs = this->op_desc_->Output(op_input_output_key[this->op_desc_->Type()].second[0]); auto outputs = this->op_desc_->Output(
op_input_output_key[this->op_desc_->Type()].second[0]);
split_op_desc->inputs_ = {{op_input_output_key[G_OP_TYPE_SPLIT].first[0], outputs}};
auto &split_outputs = split_op_desc->outputs_[op_input_output_key[G_OP_TYPE_SPLIT].second[0]]; split_op_desc->inputs_ = {
for (const auto& output : outputs_) { {op_input_output_key[G_OP_TYPE_SPLIT].first[0], outputs}};
auto &split_outputs =
split_op_desc->outputs_[op_input_output_key[G_OP_TYPE_SPLIT].second[0]];
for (const auto &output : outputs_) {
split_outputs.push_back(outputs[0]); split_outputs.push_back(outputs[0]);
} }
DLOG << "add split"; DLOG << "add split";
......
...@@ -19,7 +19,7 @@ namespace paddle_mobile { ...@@ -19,7 +19,7 @@ namespace paddle_mobile {
namespace framework { namespace framework {
//std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {} // std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
std::shared_ptr<ProgramDesc> ProgramOptimize::FushionOptimize( std::shared_ptr<ProgramDesc> ProgramOptimize::FushionOptimize(
std::shared_ptr<ProgramDesc> ori_des) { std::shared_ptr<ProgramDesc> ori_des) {
......
...@@ -18,15 +18,14 @@ limitations under the License. */ ...@@ -18,15 +18,14 @@ limitations under the License. */
#include "common/log.h" #include "common/log.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "common/enforce.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/operator.h"
#include "framework/lod_tensor.h"
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
#include "framework/program/var_desc.h" #include "framework/lod_tensor.h"
#include "framework/program/program_desc.h" #include "framework/operator.h"
#include "framework/program/program-optimize/program_optimize.h" #include "framework/program/program-optimize/program_optimize.h"
#include "framework/program/program_desc.h"
#include "framework/program/var_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
namespace paddle_mobile { namespace paddle_mobile {
using framework::Variable; using framework::Variable;
...@@ -202,7 +201,6 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -202,7 +201,6 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
// DLOG << "var name-- " << var_desc->Name(); // DLOG << "var name-- " << var_desc->Name();
auto var = scope->Var(var_desc->Name()); auto var = scope->Var(var_desc->Name());
if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) {
if (var_desc->Persistable() && if (var_desc->Persistable() &&
var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH && var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH &&
...@@ -226,7 +224,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -226,7 +224,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
if (optimize) { if (optimize) {
framework::ProgramOptimize program_optimize; framework::ProgramOptimize program_optimize;
program.optimizeProgram = program_optimize.FushionOptimize(originProgramDesc); program.optimizeProgram =
program_optimize.FushionOptimize(originProgramDesc);
} }
paddle_mobile__framework__proto__program_desc__free_unpacked(c_program, NULL); paddle_mobile__framework__proto__program_desc__free_unpacked(c_program, NULL);
...@@ -238,7 +237,8 @@ template class Loader<CPU, Precision::FP32>; ...@@ -238,7 +237,8 @@ template class Loader<CPU, Precision::FP32>;
#pragma mark - executor #pragma mark - executor
template <typename Dtype, Precision P> template <typename Dtype, Precision P>
Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size, bool use_optimize) Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
bool use_optimize)
: program_(p), batch_size_(batch_size), use_optimize_(use_optimize) { : program_(p), batch_size_(batch_size), use_optimize_(use_optimize) {
if (use_optimize_) { if (use_optimize_) {
to_predict_program_ = program_.optimizeProgram; to_predict_program_ = program_.optimizeProgram;
......
...@@ -30,7 +30,8 @@ namespace paddle_mobile { ...@@ -30,7 +30,8 @@ namespace paddle_mobile {
template <typename Dtype, Precision P = Precision::FP32> template <typename Dtype, Precision P = Precision::FP32>
class Loader : PaddleMobileObject { class Loader : PaddleMobileObject {
public: public:
const framework::Program<Dtype, P> Load(const std::string &dirname, bool optimize = true); const framework::Program<Dtype, P> Load(const std::string &dirname,
bool optimize = true);
private: private:
void LoadVar(framework::Variable *variable, void LoadVar(framework::Variable *variable,
...@@ -45,7 +46,8 @@ class Executor { ...@@ -45,7 +46,8 @@ class Executor {
Executor() = default; Executor() = default;
Executor(const framework::Program<Dtype> p, int batch_size = 1, bool use_optimize = true); Executor(const framework::Program<Dtype> p, int batch_size = 1,
bool use_optimize = true);
// std::shared_ptr<framework::Tensor> Predict(framework::Tensor &t); // std::shared_ptr<framework::Tensor> Predict(framework::Tensor &t);
......
...@@ -31,7 +31,8 @@ class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher { ...@@ -31,7 +31,8 @@ class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher {
void FolderNodes(framework::Node &node) { void FolderNodes(framework::Node &node) {
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs = std::vector<std::shared_ptr<framework::OpDesc>> origin_descs =
node.OpDescs(node_.Depth()); node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{G_OP_TYPE_ELEMENTWISE_ADD, {"Y", "Z"}}}); node.Folder(node_.Depth(), Type(),
{{G_OP_TYPE_ELEMENTWISE_ADD, {"Y", "Z"}}});
} }
std::string Type() { return G_OP_TYPE_FUSION_CONV_ADD_RELU; } std::string Type() { return G_OP_TYPE_FUSION_CONV_ADD_RELU; }
}; };
......
...@@ -35,7 +35,8 @@ class FusionFcMatcher : public framework::FusionOpMatcher { ...@@ -35,7 +35,8 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
void FolderNodes(framework::Node &node) { void FolderNodes(framework::Node &node) {
vector<std::shared_ptr<framework::OpDesc>> origin_descs = vector<std::shared_ptr<framework::OpDesc>> origin_descs =
node.OpDescs(node_.Depth()); node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{G_OP_TYPE_ELEMENTWISE_ADD, {"Y", "Z"}}}); node.Folder(node_.Depth(), Type(),
{{G_OP_TYPE_ELEMENTWISE_ADD, {"Y", "Z"}}});
} }
std::string Type() { return G_OP_TYPE_FC; } std::string Type() { return G_OP_TYPE_FC; }
......
...@@ -20,7 +20,6 @@ limitations under the License. */ ...@@ -20,7 +20,6 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
template <typename T> template <typename T>
struct ReluFunctor { struct ReluFunctor {
inline T operator()(T in) const { return in > 0 ? in : 0; } inline T operator()(T in) const { return in > 0 ? in : 0; }
......
...@@ -27,7 +27,8 @@ template class ReluOp<CPU, float>; ...@@ -27,7 +27,8 @@ template class ReluOp<CPU, float>;
/* /*
* @b 每一个 op 都需要注册一下的, * @b 每一个 op 都需要注册一下的,
* USE_OP的参数 和 REGISTER_OPERATOR的第一个参数 都是需要和model中类型对应起来的 * USE_OP的参数 和 REGISTER_OPERATOR的第一个参数
* 都是需要和model中类型对应起来的
* */ * */
namespace ops = paddle_mobile::operators; namespace ops = paddle_mobile::operators;
USE_OP(relu); USE_OP(relu);
......
...@@ -17,9 +17,9 @@ limitations under the License. */ ...@@ -17,9 +17,9 @@ limitations under the License. */
#include <string> #include <string>
#include <vector> #include <vector>
#include "io.h"
#include "common/log.h" #include "common/log.h"
#include "framework/op_registry.h" #include "framework/op_registry.h"
#include "io.h"
#include "operators/conv_op.h" #include "operators/conv_op.h"
#include "operators/elementwise_add_op.h" #include "operators/elementwise_add_op.h"
#include "operators/pool_op.h" #include "operators/pool_op.h"
......
...@@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "io.h"
#include "../test_helper.h" #include "../test_helper.h"
#include "io.h"
int main() { int main() {
paddle_mobile::Loader<paddle_mobile::CPU> loader; paddle_mobile::Loader<paddle_mobile::CPU> loader;
......
...@@ -12,17 +12,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,17 +12,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "io.h"
#include "../test_helper.h" #include "../test_helper.h"
#include "framework/program/program-optimize/node.h" #include "framework/program/program-optimize/node.h"
#include "framework/program/program-optimize/program_optimize.h" #include "framework/program/program-optimize/program_optimize.h"
#include "io.h"
int main() { int main() {
paddle_mobile::Loader<paddle_mobile::CPU> loader; paddle_mobile::Loader<paddle_mobile::CPU> loader;
// "../../../test/models/googlenet" // "../../../test/models/googlenet"
auto program = loader.Load(g_googlenet); auto program = loader.Load(g_googlenet);
paddle_mobile::framework::ProgramOptimize optimize; paddle_mobile::framework::ProgramOptimize optimize;
// program.originProgram->Description("origin"); // program.originProgram->Description("origin");
auto optimize_program = optimize.FushionOptimize(program.originProgram); auto optimize_program = optimize.FushionOptimize(program.originProgram);
if (optimize_program != nullptr) { if (optimize_program != nullptr) {
optimize_program->Description("optimize"); optimize_program->Description("optimize");
......
...@@ -128,8 +128,7 @@ int main() { ...@@ -128,8 +128,7 @@ int main() {
DLOG << "----------**********----------"; DLOG << "----------**********----------";
DLOG << "begin to run BatchNormOp Test"; DLOG << "begin to run BatchNormOp Test";
paddle_mobile::Loader<paddle_mobile::CPU> loader; paddle_mobile::Loader<paddle_mobile::CPU> loader;
auto program = loader.Load(std::string( auto program = loader.Load(std::string(g_resnet));
g_resnet));
/// input x (4,10,2,2) /// input x (4,10,2,2)
paddle_mobile::framework::Tensor inputx1; paddle_mobile::framework::Tensor inputx1;
......
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once #pragma once
#include <chrono> #include <chrono>
#include <random>
#include <fstream> #include <fstream>
#include <random>
#include "common/log.h" #include "common/log.h"
#include "framework/ddim.h" #include "framework/ddim.h"
......
...@@ -20,7 +20,6 @@ limitations under the License. */ ...@@ -20,7 +20,6 @@ limitations under the License. */
#include "./test_helper.h" #include "./test_helper.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "io.h"
#include "common/log.h" #include "common/log.h"
#include "framework/lod_tensor.h" #include "framework/lod_tensor.h"
#include "framework/operator.h" #include "framework/operator.h"
...@@ -30,3 +29,4 @@ limitations under the License. */ ...@@ -30,3 +29,4 @@ limitations under the License. */
#include "framework/scope.h" #include "framework/scope.h"
#include "framework/tensor.h" #include "framework/tensor.h"
#include "framework/variable.h" #include "framework/variable.h"
#include "io.h"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册