提交 b74b616f 编写于 作者: L liuruilong

format files

上级 c9c6562e
......@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once;
#include <string>
#include <utility>
#include <unordered_map>
#include <utility>
namespace paddle_mobile {
enum class Precision : int { FP32 = 0 };
......@@ -94,18 +94,18 @@ static const std::string G_OP_TYPE_FEED = "feed";
static const std::string G_OP_TYPE_FETCH = "fetch";
static std::unordered_map<
std::string, std::pair<std::vector<std::string>, std::vector<std::string>>>
op_input_output_key = {{G_OP_TYPE_CONV, {{"Input"}, {"Output"}}},
{G_OP_TYPE_RELU, {{"X"}, {"Out"}}},
{G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}},
{G_OP_TYPE_MUL, {{"X"}, {"Out"}}},
{G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}},
{G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}},
{G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}},
{G_OP_TYPE_LRN, {{"X"}, {"Out"}}},
{G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}},
{G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}},
{G_OP_TYPE_FEED, {{"X"}, {"Out"}}},
{G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}};
std::string, std::pair<std::vector<std::string>, std::vector<std::string>>>
op_input_output_key = {{G_OP_TYPE_CONV, {{"Input"}, {"Output"}}},
{G_OP_TYPE_RELU, {{"X"}, {"Out"}}},
{G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}},
{G_OP_TYPE_MUL, {{"X"}, {"Out"}}},
{G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}},
{G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}},
{G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}},
{G_OP_TYPE_LRN, {{"X"}, {"Out"}}},
{G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}},
{G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}},
{G_OP_TYPE_FEED, {{"X"}, {"Out"}}},
{G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}};
} // namespace paddle_mobile
......@@ -19,20 +19,20 @@ limitations under the License. */
#include <utility>
#include <vector>
#include "common/types.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 "framework/variable.h"
#include "common/types.h"
#include "common/variant.h"
#include "framework/attribute.h"
#include "framework/op_registry.h"
#include "framework/op_info.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/program/block_desc.h"
#include "framework/program/program-optimize/node.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
namespace paddle_mobile {
namespace framework {
......@@ -77,6 +77,7 @@ class OperatorBase : PaddleMobileObject {
* @b 根据输入形状和参数计算出输出形状
* */
virtual void InferShape() const = 0;
protected:
std::shared_ptr<Scope> scope_;
std::string type_;
......
......@@ -82,11 +82,14 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
DLOG << "当前 op desc 输出数不为 1 ";
can_add_split = false;
}
for (const auto& output : outputs_) {
if (op_input_output_key.find(output->op_desc_->type_) != op_input_output_key.end()) {
for (const auto &output : outputs_) {
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 outputs_of_output = output->op_desc_->Output(inputs_and_outputs.second[0]);
auto inputs_of_output = output->op_desc_->Input(inputs_and_outputs.first[0]);
auto outputs_of_output =
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) {
std::string input_of_output = inputs_of_output[i];
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,
if (can_add_split) {
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;
auto outputs = this->op_desc_->Output(op_input_output_key[this->op_desc_->Type()].second[0]);
split_op_desc->inputs_ = {{op_input_output_key[G_OP_TYPE_SPLIT].first[0], outputs}};
auto &split_outputs = split_op_desc->outputs_[op_input_output_key[G_OP_TYPE_SPLIT].second[0]];
for (const auto& output : outputs_) {
auto outputs = this->op_desc_->Output(
op_input_output_key[this->op_desc_->Type()].second[0]);
split_op_desc->inputs_ = {
{op_input_output_key[G_OP_TYPE_SPLIT].first[0], outputs}};
auto &split_outputs =
split_op_desc->outputs_[op_input_output_key[G_OP_TYPE_SPLIT].second[0]];
for (const auto &output : outputs_) {
split_outputs.push_back(outputs[0]);
}
DLOG << "add split";
......
......@@ -19,7 +19,7 @@ namespace paddle_mobile {
namespace framework {
//std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
// std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
std::shared_ptr<ProgramDesc> ProgramOptimize::FushionOptimize(
std::shared_ptr<ProgramDesc> ori_des) {
......
......@@ -18,15 +18,14 @@ limitations under the License. */
#include "common/log.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/program/var_desc.h"
#include "framework/program/program_desc.h"
#include "framework/lod_tensor.h"
#include "framework/operator.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 {
using framework::Variable;
......@@ -202,7 +201,6 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
// DLOG << "var name-- " << var_desc->Name();
auto var = scope->Var(var_desc->Name());
if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) {
if (var_desc->Persistable() &&
var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH &&
......@@ -226,7 +224,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
if (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);
......@@ -238,7 +237,8 @@ template class Loader<CPU, Precision::FP32>;
#pragma mark - executor
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) {
if (use_optimize_) {
to_predict_program_ = program_.optimizeProgram;
......
......@@ -30,7 +30,8 @@ namespace paddle_mobile {
template <typename Dtype, Precision P = Precision::FP32>
class Loader : PaddleMobileObject {
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:
void LoadVar(framework::Variable *variable,
......@@ -45,7 +46,8 @@ class Executor {
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);
......
......@@ -31,7 +31,8 @@ class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher {
void FolderNodes(framework::Node &node) {
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs =
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; }
};
......
......@@ -35,7 +35,8 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
void FolderNodes(framework::Node &node) {
vector<std::shared_ptr<framework::OpDesc>> origin_descs =
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; }
......
......@@ -20,7 +20,6 @@ limitations under the License. */
namespace paddle_mobile {
namespace operators {
template <typename T>
struct ReluFunctor {
inline T operator()(T in) const { return in > 0 ? in : 0; }
......
......@@ -27,7 +27,8 @@ template class ReluOp<CPU, float>;
/*
* @b 每一个 op 都需要注册一下的,
* USE_OP的参数 和 REGISTER_OPERATOR的第一个参数 都是需要和model中类型对应起来的
* USE_OP的参数 和 REGISTER_OPERATOR的第一个参数
* 都是需要和model中类型对应起来的
* */
namespace ops = paddle_mobile::operators;
USE_OP(relu);
......
......@@ -38,7 +38,7 @@ class ReluOp : public framework::OperatorWithKernel<DeviceType> {
scope),
param_(inputs, outputs, attrs, *scope) {}
/*
/*
* @b op 进行运算, 调用相应的 kernel 进行运算
* */
void RunImpl() const {
......
......@@ -17,9 +17,9 @@ limitations under the License. */
#include <string>
#include <vector>
#include "io.h"
#include "common/log.h"
#include "framework/op_registry.h"
#include "io.h"
#include "operators/conv_op.h"
#include "operators/elementwise_add_op.h"
#include "operators/pool_op.h"
......
......@@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "io.h"
#include "../test_helper.h"
#include "io.h"
int main() {
paddle_mobile::Loader<paddle_mobile::CPU> loader;
......
......@@ -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
limitations under the License. */
#include "io.h"
#include "../test_helper.h"
#include "framework/program/program-optimize/node.h"
#include "framework/program/program-optimize/program_optimize.h"
#include "io.h"
int main() {
paddle_mobile::Loader<paddle_mobile::CPU> loader;
// "../../../test/models/googlenet"
auto program = loader.Load(g_googlenet);
paddle_mobile::framework::ProgramOptimize optimize;
// program.originProgram->Description("origin");
// program.originProgram->Description("origin");
auto optimize_program = optimize.FushionOptimize(program.originProgram);
if (optimize_program != nullptr) {
optimize_program->Description("optimize");
......
......@@ -128,8 +128,7 @@ int main() {
DLOG << "----------**********----------";
DLOG << "begin to run BatchNormOp Test";
paddle_mobile::Loader<paddle_mobile::CPU> loader;
auto program = loader.Load(std::string(
g_resnet));
auto program = loader.Load(std::string(g_resnet));
/// input x (4,10,2,2)
paddle_mobile::framework::Tensor inputx1;
......
......@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once
#include <chrono>
#include <random>
#include <fstream>
#include <random>
#include "common/log.h"
#include "framework/ddim.h"
......
......@@ -20,7 +20,6 @@ limitations under the License. */
#include "./test_helper.h"
#include "common/enforce.h"
#include "io.h"
#include "common/log.h"
#include "framework/lod_tensor.h"
#include "framework/operator.h"
......@@ -30,3 +29,4 @@ limitations under the License. */
#include "framework/scope.h"
#include "framework/tensor.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.
先完成此消息的编辑!
想要评论请 注册