未验证 提交 c1d8afd2 编写于 作者: D dolphin8 提交者: GitHub

Merge branch 'develop' into develop

......@@ -15,9 +15,8 @@ else ()
add_definitions(-DX86)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
......
......@@ -17,7 +17,6 @@ limitations under the License. */
#ifdef ENABLE_EXCEPTION
#include <stdio.h>
#include <exception>
#include <sstream>
#include <string>
#endif
......@@ -31,12 +30,11 @@ struct PaddleMobileException : public std::exception {
PaddleMobileException(const char *header, const char *detail,
const char *file, const int line) {
std::stringstream ss;
ss << exception_prefix << "| " << header << "\n";
ss << "| [in file] : " << file << " \n";
ss << "| [on line] : " << line << " \n";
ss << "| [detail] : " << detail;
message = ss.str();
char buffer[1500];
snprintf(buffer, sizeof(buffer),
"%s| %s \n| [in file] : %s\n| [on line] : %d\n| [detail] : %s\n",
exception_prefix.c_str(), header, file, line, detail);
message = std::string(buffer);
}
const char *what() const noexcept { return message.c_str(); }
};
......
......@@ -16,7 +16,6 @@ limitations under the License. */
#include <map>
#include <string>
#include <unordered_set>
#include <vector>
#include "framework/attribute.h"
#include "framework/scope.h"
......@@ -40,13 +39,6 @@ using OpCreator = std::function<framework::OperatorBase<Dtype> *(
const framework::AttributeMap & /*attrs*/,
std::shared_ptr<framework::Scope> /*scope*/)>;
using GradOpMakerFN =
std::function<std::vector<std::unique_ptr<framework::OpDesc>>(
const framework::OpDesc &,
const std::unordered_set<std::string> & /*no_grad_set*/,
std::unordered_map<std::string, std::string> * /*grad_to_var*/,
const std::vector<framework::BlockDesc *> &grad_block)>;
using InferVarTypeFN = std::function<void(const framework::OpDesc & /*op_desc*/,
framework::BlockDesc * /*block*/)>;
......
......@@ -16,7 +16,6 @@ limitations under the License. */
#include <string>
#include <unordered_map>
#include <utility>
namespace paddle_mobile {
enum class Precision : int { FP32 = 0 };
......
......@@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <iostream>
#include "common/log.h"
#pragma once
......
......@@ -17,6 +17,7 @@ limitations under the License. */
#include <string>
#include <unordered_map>
#include <vector>
#include "common/enforce.h"
#include "common/log.h"
#include "common/variant.h"
......
......@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once
#include <assert.h>
#include <initializer_list>
#include <stdexcept>
#include <vector>
......
......@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <type_traits>
......
......@@ -16,7 +16,6 @@ limitations under the License. */
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "tensor.h"
#include "tensor_util.h"
......
......@@ -16,7 +16,6 @@ limitations under the License. */
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "common/enforce.h"
......
......@@ -43,47 +43,6 @@ bool Node::operator==(const Node &in) {
return true;
}
bool Node::CanSplit(std::unordered_set<std::string> complex_compute_set) {
bool split = false;
CanSplit(&split, false, 0, &complex_compute_set, this);
return split;
}
void Node::CanSplit(bool *split, bool spliting, int complex_count,
std::unordered_set<std::string> *complex_compute_set,
Node *pre_node) {
if (spliting) {
if (complex_compute_set->find(this->type_) != complex_compute_set->end()) {
complex_count++;
}
}
if (inputs_.size() > 1 && pre_node != inputs_.back()) {
return;
}
if (inputs_.size() > 1 && pre_node == inputs_.back()) {
if (complex_count > 1) {
*split = true;
return;
}
}
// multi output, to check
if (outputs_.size() > 1) {
spliting = true;
complex_compute_set = 0;
} else {
if (spliting == true && inputs_.size() > 0) {
spliting = false;
} else {
}
}
for (auto &output : outputs_) {
output->CanSplit(split, spliting, complex_count, complex_compute_set, this);
}
}
std::vector<std::shared_ptr<framework::OpDesc>> Node::OpDescs(uint size) {
std::vector<std::shared_ptr<framework::OpDesc>> op_descs;
OpDescs(size - 1, &op_descs);
......@@ -101,107 +60,6 @@ void Node::OpDescs(uint index,
}
}
void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
Node *node, bool adding_thread, int thread_num) {
if (outputs_.size() > 1) {
adding_thread = false;
}
bool can_add_split = false;
// 如果当前节点有多个输出 并且 只有当前节点对应的 op_desc_ 输出数为 1 时支持
if (outputs_.size() > 1 &&
op_input_output_key[op_desc_->type_].second.size() == 1) {
can_add_split = true;
// 遍历当前节点的 output 节点
for (const auto &output : outputs_) {
// 不支持 output 有多个 output 的情况
if (output->outputs_.size() > 0) {
can_add_split = false;
break;
}
//与节点关联的 OpDesc
std::shared_ptr<framework::OpDesc> &op_desc = output->op_desc_;
//获取这个 op 的 inputs key 和 outputs key
auto inputs_and_outputs = op_input_output_key[op_desc->type_];
//判断现在 是否存在这个 op
//判断这个 output 和 input key 的 size 等于 1
if (op_input_output_key.find(op_desc->type_) !=
op_input_output_key.end() &&
inputs_and_outputs.first.size() == 1 &&
inputs_and_outputs.second.size() == 1) {
auto inputs_of_output = op_desc->Input(inputs_and_outputs.first[0]);
auto outputs_of_output = op_desc->Output(inputs_and_outputs.second[0]);
// 判断一下, 如果输入和输出没有同名, 是支持的
for (int i = 0; i < inputs_of_output.size(); ++i) {
std::string input_of_output = inputs_of_output[i];
for (int j = 0; j < outputs_of_output.size(); ++j) {
std::string output_of_output = outputs_of_output[j];
if (input_of_output == output_of_output) {
DLOG << "output的 output 包含 input" << input_of_output;
can_add_split = false;
break;
}
}
}
} else { // 如果模型中包含没有的 op, 则不支持添加 split
DLOG << "找不到 这个 op 类型: " << output->op_desc_->type_;
can_add_split = false;
}
}
}
if (inputs_.size() > 1 && node != inputs_.back()) {
return;
} else if (inputs_.size() > 1 && node == inputs_.back()) {
adding_thread = false;
op_desc->push_back(this->op_desc_);
} else {
op_desc->push_back(this->op_desc_);
}
if (adding_thread) {
Attribute attr;
attr.Set<int>(thread_num);
this->op_desc_->attrs_["thread"] = attr;
}
if (can_add_split) {
adding_thread = true;
std::shared_ptr<OpDesc> split_op_desc = std::make_shared<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_) {
split_outputs.push_back(outputs[0]);
}
DLOG << "add split";
op_desc->push_back(split_op_desc);
}
for (int i = 0; i < outputs_.size(); ++i) {
auto &output = outputs_[i];
if (can_add_split) {
output->OpDescs(op_desc, this, adding_thread, i);
} else {
output->OpDescs(op_desc, this, adding_thread, thread_num);
}
}
}
std::vector<std::shared_ptr<framework::OpDesc>> Node::OpDescs() {
std::vector<std::shared_ptr<framework::OpDesc>> op_descs;
OpDescs(&op_descs, this, false, 0);
return op_descs;
}
std::shared_ptr<Node> Node::To(int size) {
std::shared_ptr<Node> node = std::make_shared<Node>();
this->To(size - 1, node);
......
......@@ -16,8 +16,6 @@ limitations under the License. */
#include <map>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "common/log.h"
......@@ -36,7 +34,6 @@ class Node {
: op_desc_(op_desc), type_(op_desc->Type()) {}
Node &operator>(std::shared_ptr<Node> node);
bool operator==(const Node &in);
bool CanSplit(std::unordered_set<std::string> complex_compute_set);
std::string ToString() const;
std::shared_ptr<Node> To(int size);
uint Depth(uint begin = 0);
......@@ -45,17 +42,11 @@ class Node {
std::map<std::string, std::pair<std::string, std::string>> change_map,
std::vector<std::shared_ptr<Node>> *removed_nodes);
std::vector<std::shared_ptr<framework::OpDesc>> OpDescs(uint size);
std::vector<std::shared_ptr<framework::OpDesc>> OpDescs();
std::shared_ptr<framework::OpDesc> OpDescOfNode() { return op_desc_; }
std::string Type() { return type_; }
void Description();
private:
void CanSplit(bool *split, bool spliting, int complex_count,
std::unordered_set<std::string> *complex_compute_set,
Node *pre_node);
void OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
Node *node, bool adding_thread, int thread_num);
void OpDescs(uint size,
std::vector<std::shared_ptr<framework::OpDesc>> *op_desc);
void To(int index, std::shared_ptr<Node>);
......
......@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once
#include <iostream>
#include <memory>
#include <string>
#include <typeindex>
......
......@@ -15,7 +15,7 @@ limitations under the License. */
#ifdef POOL_OP
#include "pooling.h"
#include <common/types.h>
#include "common/types.h"
namespace paddle_mobile {
namespace operators {
......
......@@ -16,11 +16,12 @@ limitations under the License. */
#pragma once
#include <framework/operator.h>
#include <operators/kernel/pool_kernel.h>
#include <operators/op_param.h>
#include <string>
#include "framework/operator.h"
#include "operators/kernel/pool_kernel.h"
#include "operators/op_param.h"
namespace paddle_mobile {
namespace operators {
using framework::AttributeMap;
......
......@@ -16,10 +16,11 @@ limitations under the License. */
#pragma once
#include <framework/operator.h>
#include <operators/op_param.h>
#include <string>
#include "framework/operator.h"
#include "operators/kernel/sigmoid_kernel.h"
#include "operators/op_param.h"
namespace paddle_mobile {
namespace operators {
......
......@@ -16,10 +16,11 @@ limitations under the License. */
#pragma once
#include <framework/operator.h>
#include <operators/op_param.h>
#include <string>
#include "framework/operator.h"
#include "operators/kernel/softmax_kernel.h"
#include "operators/op_param.h"
namespace paddle_mobile {
namespace operators {
......
......@@ -14,9 +14,10 @@ limitations under the License. */
#ifdef TRANSPOSE_OP
#include "operators/transpose_op.h"
#include <common/enforce.h>
#include <vector>
#include "common/enforce.h"
#include "operators/transpose_op.h"
namespace paddle_mobile {
namespace operators {
......
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
//
// Created by liuRuiLong on 2018/6/6.
//
#include "test_lib_size.h"
static test_lib_size t;
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
//
// Created by liuRuiLong on 2018/6/6.
//
#ifndef PADDLE_MOBILE_TEST_LIB_SIZE_H
#define PADDLE_MOBILE_TEST_LIB_SIZE_H
#include <vector>
//#include <list>
//#include <tuple>
//#include <typeinfo>
//#include <mutex>
//#include <initializer_list>
//#include <map>
//#include <string>
//#include <unordered_map>
//#include <unordered_set>
//#include <algorithm>
//#include <iostream>
//#include <sstream>
#include <memory>
//#include <stdio.h>
//#include <cstring>
void foo() {
// char *str = "1234";
// char dst[10];
// strcpy(dst, str);
// std::cout << "12345" << std::endl;
std::vector<int> vec = {1, 2, 3, 4, 5};
// std::find(vec.begin(), vec.end(), 1);
// std::find(vec.begin(), vec.end(), 1);
// std::list<int> l;
// std::mutex mutex_;
// std::map<int, float> m;
// std::unordered_map<int, float> u_m;
// std::unordered_set<int> u_s;
// std::string ss = "12345";
// printf("%f", ss.c_str());
// std::initializer_list<int> init_list = {1, 2};
// std::tuple<int, int> t = {1, 2};
// std::tuple_element<I, std::tuple<ARGS...>>::type
// std::tuple<>
// int i;
// int j;
// if (typeid(i) == typeid(j)){
// int z = 10;
// }
std::shared_ptr<int> s1 = std::make_shared<int>();
// std::stringstream ss;
// ss << "12345";
}
class test_lib_size {
public:
test_lib_size() {}
// std::shared_ptr<int> Test(){
// std::vector<int> vec = {1, 2, 3};
// std::shared_ptr<int> si = std::make_shared<int>();
// return si;
// }
// void test(){
// int i = 9;
// }
};
#endif // PADDLE_MOBILE_TEST_LIB_SIZE_H
......@@ -12,16 +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 <omp.h>
//#include <omp.h>
#include <iostream>
int main(void) {
#ifdef PADDLE_MOBILE_USE_OPENMP
#pragma omp parallel num_threads(2)
{
int thread_id = omp_get_thread_num();
int nthreads = omp_get_num_threads();
std::cout << "Hello, OMP " << thread_id << "/" << nthreads << "\n";
// int thread_id = omp_get_thread_num();
// int nthreads = omp_get_num_threads();
// std::cout << "Hello, OMP " << thread_id << "/" << nthreads <<
// "\n";
}
#endif
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册