提交 579ac441 编写于 作者: 朔-望's avatar 朔-望 提交者: GitHub

Merge pull request #293 from codeWorm2015/develop

fix #292 add protobuf-c, remove third-party folder
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(paddle-mobile) project(paddle-mobile)
add_definitions(-std=c++11)
add_definitions(-DPADDLE_MOBILE_DEBUG="true") add_definitions(-DPADDLE_MOBILE_DEBUG="true")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE RelWithDebInfo) set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
...@@ -11,7 +10,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build) ...@@ -11,7 +10,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp) file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c)
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h) file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
# include headers # include headers
...@@ -28,26 +27,12 @@ include_directories(src/) ...@@ -28,26 +27,12 @@ include_directories(src/)
# INSTALL_COMMAND "make" "PREFIX=${CMAKE_BINARY_DIR}/" "install" # INSTALL_COMMAND "make" "PREFIX=${CMAKE_BINARY_DIR}/" "install"
# ) # )
#set_target_properties(openblas_proj PROPERTIES EXCLUDE_FROM_ALL 1) #set_target_properties(openblas_proj PROPERTIES EXCLUDE_FROM_ALL 1)
# link protobuf
include_directories(third-party/protobuf/include)
if (ANDROID)
link_directories(third-party/protobuf/armeabi-v7a)
else()
# link openblas
link_directories(third-party/protobuf/lib)
endif ()
#add_dependencies(paddle-mobile openblas_proj) #add_dependencies(paddle-mobile openblas_proj)
# gen static # gen static
ADD_LIBRARY(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H}) ADD_LIBRARY(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
if (ANDROID)
# openblas.a need log lib
target_link_libraries(paddle-mobile protobuf-lite)
else()
target_link_libraries(paddle-mobile protobuf-lite)
endif ()
#add_dependencies(paddle-mobile openblas_proj) #add_dependencies(paddle-mobile openblas_proj)
add_subdirectory(test) add_subdirectory(test)
\ No newline at end of file
...@@ -170,7 +170,7 @@ struct ToLog { ...@@ -170,7 +170,7 @@ struct ToLog {
template <typename T> template <typename T>
Print &operator<<(Print &printer, const std::vector<T> &v) { Print &operator<<(Print &printer, const std::vector<T> &v) {
printer << "[\n "; printer << "[ ";
for (int i = 0; i < v.size(); ++i) { for (int i = 0; i < v.size(); ++i) {
const auto &value = v[i]; const auto &value = v[i];
...@@ -179,7 +179,7 @@ Print &operator<<(Print &printer, const std::vector<T> &v) { ...@@ -179,7 +179,7 @@ Print &operator<<(Print &printer, const std::vector<T> &v) {
printer << "\n"; printer << "\n";
} }
} }
printer << " \n]"; printer << " ]";
return printer; return printer;
} }
......
此差异已折叠。
此差异已折叠。
...@@ -16,6 +16,7 @@ limitations under the License. */ ...@@ -16,6 +16,7 @@ limitations under the License. */
#include <map> #include <map>
#include <string> #include <string>
#include <unordered_set>
#include <vector> #include <vector>
#include "framework/attribute.h" #include "framework/attribute.h"
#include "framework/scope.h" #include "framework/scope.h"
......
...@@ -14,9 +14,11 @@ limitations under the License. */ ...@@ -14,9 +14,11 @@ limitations under the License. */
#pragma once #pragma once
#include <unordered_map>
#include "common/enforce.h"
#include "common/log.h" #include "common/log.h"
#include "common/variant.h" #include "common/variant.h"
#include "framework/framework.pb.h" #include "framework/framework.pb-c.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -25,67 +27,80 @@ class BlockDesc; ...@@ -25,67 +27,80 @@ class BlockDesc;
class Attribute { class Attribute {
public: public:
static Attribute GetAttrValue(const proto::OpDesc::Attr &attr_desc) { /*
* PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT = 1,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING = 2,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INTS = 3,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOATS = 4,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRINGS = 5,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN = 6,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS = 7,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK = 8,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG = 9
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE)
*
* */
static Attribute GetAttrValue(
PaddleMobile__Framework__Proto__OpDesc__Attr *attr_desc) {
// std::cout << "begin get attr value" << std::endl; // std::cout << "begin get attr value" << std::endl;
Attribute attr; Attribute attr;
switch (attr_desc.type()) { switch (attr_desc->type) {
case proto::AttrType::BOOLEAN: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN: {
attr.Set<bool>(attr_desc.b()); attr.Set<bool>(attr_desc->b);
break; break;
} }
case proto::AttrType::INT: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT: {
attr.Set<int>(attr_desc.i()); attr.Set<int>(attr_desc->i);
break; break;
} }
case proto::AttrType::FLOAT: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT: {
attr.Set<float>(attr_desc.f()); attr.Set<float>(attr_desc->f);
break; break;
} }
case proto::AttrType::STRING: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING: {
attr.Set<std::string>(attr_desc.s()); attr.Set<std::string>(std::string(attr_desc->s));
break; break;
} }
case proto::AttrType::BOOLEANS: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS: {
std::vector<bool> val(attr_desc.bools_size()); std::vector<bool> val(attr_desc->n_bools);
for (int i = 0; i < attr_desc.bools_size(); ++i) { for (int i = 0; i < attr_desc->n_bools; ++i) {
val[i] = attr_desc.bools(i); val[i] = attr_desc->bools[i];
} }
attr.Set<std::vector<bool>>(val); attr.Set<std::vector<bool>>(val);
break; break;
} }
case proto::AttrType::INTS: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INTS: {
std::vector<int> val(attr_desc.ints_size()); std::vector<int> val(attr_desc->n_ints);
for (int i = 0; i < attr_desc.ints_size(); ++i) { for (int i = 0; i < attr_desc->n_ints; ++i) {
val[i] = attr_desc.ints(i); val[i] = attr_desc->ints[i];
} }
attr.Set<std::vector<int>>(val); attr.Set<std::vector<int>>(val);
break; break;
} }
case proto::AttrType::FLOATS: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOATS: {
std::vector<float> val(attr_desc.floats_size()); std::vector<float> val(attr_desc->n_floats);
for (int i = 0; i < attr_desc.floats_size(); ++i) { for (int i = 0; i < attr_desc->n_floats; ++i) {
val[i] = attr_desc.floats(i); val[i] = attr_desc->floats[i];
} }
attr.Set<std::vector<float>>(val); attr.Set<std::vector<float>>(val);
break; break;
} }
case proto::AttrType::STRINGS: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRINGS: {
std::vector<std::string> val(attr_desc.strings_size()); std::vector<std::string> val(attr_desc->n_strings);
for (int i = 0; i < attr_desc.strings_size(); ++i) { for (int i = 0; i < attr_desc->n_strings; ++i) {
val[i] = attr_desc.strings(i); val[i] = attr_desc->strings[i];
} }
attr.Set<std::vector<std::string>>(val); attr.Set<std::vector<std::string>>(val);
break; break;
} }
case proto::AttrType::LONG: { case PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG: {
attr.Set<int64_t>(attr_desc.l()); attr.Set<int64_t>(attr_desc->l);
break; break;
} }
default: default:
// std::cout << " not support " << std::endl; PADDLE_MOBILE_THROW_EXCEPTION("attr type not support");
break;
} }
// std::cout << "end get attr value" << std::endl;
return attr; return attr;
} }
......
...@@ -14,8 +14,6 @@ limitations under the License. */ ...@@ -14,8 +14,6 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -244,58 +244,5 @@ void AppendLoD(LoD *lod, const LoD &lod_length) { ...@@ -244,58 +244,5 @@ void AppendLoD(LoD *lod, const LoD &lod_length) {
} }
} }
void SerializeToStream(std::ostream &os, const LoDTensor &tensor) {
{ // the 1st field, uint32_t version for LoDTensor
constexpr uint32_t version = 0;
os.write(reinterpret_cast<const char *>(&version), sizeof(version));
}
{
// the 2st field, LoD information
// uint64_t lod_level
// uint64_t lod_level_1 size in byte.
// int* lod_level_1 data
// ...
auto lod = tensor.lod();
uint64_t size = lod.size();
os.write(reinterpret_cast<const char *>(&size), sizeof(size));
for (auto &each : lod) {
size = each.size() * sizeof(framework::LoD::value_type::value_type);
os.write(reinterpret_cast<const char *>(&size), sizeof(size));
os.write(reinterpret_cast<const char *>(each.data()),
static_cast<std::streamsize>(size));
}
}
// the 3st field, Tensor
TensorToStream(os, static_cast<Tensor>(tensor));
}
void DeserializeFromStream(std::istream &is, LoDTensor *tensor) {
{
// the 1st field, unit32_t version for LoDTensor
uint32_t version;
is.read(reinterpret_cast<char *>(&version), sizeof(version));
// PADDLE_ENFORCE_EQ(version, 0U, "Only version 0 is
// supported");
}
{
// the 2st field, LoD information
uint64_t lod_level;
is.read(reinterpret_cast<char *>(&lod_level), sizeof(lod_level));
auto &lod = *tensor->mutable_lod();
lod.resize(lod_level);
for (uint64_t i = 0; i < lod_level; ++i) {
uint64_t size;
is.read(reinterpret_cast<char *>(&size), sizeof(size));
std::vector<size_t> tmp(size / sizeof(size_t));
is.read(reinterpret_cast<char *>(tmp.data()),
static_cast<std::streamsize>(size));
lod[i] = tmp;
}
}
// the 3st filed, Tensor
TensorFromStream(is, static_cast<Tensor *>(tensor));
}
} // namespace framework } // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -17,7 +17,6 @@ limitations under the License. */ ...@@ -17,7 +17,6 @@ limitations under the License. */
#include <string> #include <string>
#include "common/log.h" #include "common/log.h"
#include "common/type_define.h" #include "common/type_define.h"
#include "framework/framework.pb.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/data_layout.h" #include "framework/data_layout.h"
#include "framework/framework.pb.h" #include "framework/program/tensor_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -33,10 +33,10 @@ struct OpKernelType { ...@@ -33,10 +33,10 @@ struct OpKernelType {
// place, data_type, library_type kinds less than 2^8 // place, data_type, library_type kinds less than 2^8
constexpr static int LEFT_SHIFT = 8; constexpr static int LEFT_SHIFT = 8;
proto::VarType::Type data_type_; VarType_Type data_type_;
DataLayout data_layout_; DataLayout data_layout_;
OpKernelType(proto::VarType::Type data_type, OpKernelType(VarType_Type data_type,
DataLayout data_layout = DataLayout::kAnyLayout) DataLayout data_layout = DataLayout::kAnyLayout)
: data_type_(data_type), data_layout_(data_layout) {} : data_type_(data_type), data_layout_(data_layout) {}
......
...@@ -33,12 +33,16 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const { ...@@ -33,12 +33,16 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
return res; return res;
} }
BlockDesc::BlockDesc(const proto::BlockDesc &desc) BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc)
: index_(desc.idx()), parent_index_(desc.parent_idx()) { : index_(desc->idx), parent_index_(desc->idx) {
for (const proto::VarDesc &var_desc : desc.vars()) { for (int i = 0; i < desc->n_vars; ++i) {
vars_[var_desc.name()].reset(new VarDesc(var_desc)); PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i];
vars_[std::string(var_desc->name)] =
std::shared_ptr<VarDesc>(new VarDesc(var_desc));
} }
for (const proto::OpDesc &op_desc : desc.ops()) {
for (int j = 0; j < desc->n_ops; ++j) {
PaddleMobile__Framework__Proto__OpDesc *op_desc = desc->ops[j];
ops_.emplace_back(new framework::OpDesc(op_desc)); ops_.emplace_back(new framework::OpDesc(op_desc));
} }
} }
......
...@@ -14,7 +14,7 @@ limitations under the License. */ ...@@ -14,7 +14,7 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb.h" #include "framework/framework.pb-c.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
#include "framework/program/op_desc.h" #include "framework/program/op_desc.h"
#include "framework/program/var_desc.h" #include "framework/program/var_desc.h"
...@@ -26,8 +26,7 @@ class BlockDesc : PaddleMobileObject { ...@@ -26,8 +26,7 @@ class BlockDesc : PaddleMobileObject {
public: public:
friend class Node; friend class Node;
friend class ProgramOptimize; friend class ProgramOptimize;
BlockDesc(const proto::BlockDesc &desc); BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc);
BlockDesc(const BlockDesc &block_desc) BlockDesc(const BlockDesc &block_desc)
: index_(block_desc.index_), parent_index_(block_desc.parent_index_) { : index_(block_desc.index_), parent_index_(block_desc.parent_index_) {
for (auto &op_desc : block_desc.ops_) { for (auto &op_desc : block_desc.ops_) {
......
...@@ -20,28 +20,28 @@ limitations under the License. */ ...@@ -20,28 +20,28 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
OpDesc::OpDesc(const proto::OpDesc &desc) : type_(desc.type()) { OpDesc::OpDesc(PaddleMobile__Framework__Proto__OpDesc *desc) {
for (int i = 0; i < desc.inputs_size(); ++i) { this->type_ = std::string(desc->type);
const proto::OpDesc::Var &var = desc.inputs(i); for (int i = 0; i < desc->n_inputs; ++i) {
std::vector<std::string> &args = inputs_[var.parameter()]; PaddleMobile__Framework__Proto__OpDesc__Var *var = desc->inputs[i];
int arg_size = var.arguments_size(); std::vector<std::string> &args = inputs_[std::string(var->parameter)];
for (int j = 0; j < arg_size; ++j) { for (int j = 0; j < var->n_arguments; ++j) {
args.push_back(var.arguments(j)); args.emplace_back(std::string(var->arguments[j]));
} }
} }
for (int i = 0; i < desc.outputs_size(); ++i) { for (int i = 0; i < desc->n_outputs; ++i) {
const proto::OpDesc::Var &var = desc.outputs(i); PaddleMobile__Framework__Proto__OpDesc__Var *var = desc->outputs[i];
std::vector<std::string> &args = outputs_[var.parameter()]; std::vector<std::string> &args = outputs_[std::string(var->parameter)];
int arg_size = var.arguments_size(); for (int j = 0; j < var->n_arguments; ++j) {
for (int j = 0; j < arg_size; ++j) { args.emplace_back(std::string(var->arguments[j]));
args.push_back(var.arguments(j));
} }
} }
for (const proto::OpDesc::Attr &attr : desc.attrs()) { for (int k = 0; k < desc->n_attrs; ++k) {
std::string attr_name = attr.name(); PaddleMobile__Framework__Proto__OpDesc__Attr *attr = desc->attrs[k];
if (attr.type() != proto::AttrType::BLOCK) { std::string attr_name(attr->name);
if (attr->type != PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK) {
attrs_[attr_name] = Attribute::GetAttrValue(attr); attrs_[attr_name] = Attribute::GetAttrValue(attr);
} }
} }
......
...@@ -19,7 +19,7 @@ limitations under the License. */ ...@@ -19,7 +19,7 @@ limitations under the License. */
#include "common/log.h" #include "common/log.h"
#include "common/type_define.h" #include "common/type_define.h"
#include "framework/framework.pb.h" #include "framework/framework.pb-c.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
namespace paddle_mobile { namespace paddle_mobile {
...@@ -30,8 +30,7 @@ class OpDesc : PaddleMobileObject { ...@@ -30,8 +30,7 @@ class OpDesc : PaddleMobileObject {
friend class ProgramOptimize; friend class ProgramOptimize;
friend class FusionOpMatcher; friend class FusionOpMatcher;
friend class Node; friend class Node;
explicit OpDesc(const proto::OpDesc &desc); explicit OpDesc(PaddleMobile__Framework__Proto__OpDesc *op_desc);
OpDesc(const OpDesc &op_desc) : type_(op_desc.type_) { OpDesc(const OpDesc &op_desc) : type_(op_desc.type_) {
this->inputs_ = op_desc.inputs_; this->inputs_ = op_desc.inputs_;
this->outputs_ = op_desc.outputs_; this->outputs_ = op_desc.outputs_;
......
...@@ -15,15 +15,15 @@ limitations under the License. */ ...@@ -15,15 +15,15 @@ limitations under the License. */
#include <string> #include <string>
#include <vector> #include <vector>
#include "framework/program/tensor_desc.h"
#include "program_desc.h" #include "program_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) { ProgramDesc::ProgramDesc(PaddleMobile__Framework__Proto__ProgramDesc *desc) {
for (auto &block_desc : desc.blocks()) { for (int i = 0; i < desc->n_blocks; ++i) {
// new framework::BlockDesc(block_desc) blocks_.emplace_back(std::make_shared<BlockDesc>(desc->blocks[i]));
blocks_.emplace_back(std::make_shared<BlockDesc>(block_desc));
} }
} }
...@@ -55,6 +55,21 @@ void ProgramDesc::Description(std::string header) { ...@@ -55,6 +55,21 @@ void ProgramDesc::Description(std::string header) {
LOG(kLOG_DEBUG3) << "argument - " << attr.second; LOG(kLOG_DEBUG3) << "argument - " << attr.second;
} }
} }
for (const auto &var_desc : block->Vars()) {
if (var_desc->Type() == VARTYPE_TYPE_LOD_TENSOR) {
LOG(kLOG_DEBUG1) << "var name: " << var_desc->Name();
const TensorDesc &tensor_desc = var_desc->Tensor_desc();
LOG(kLOG_DEBUG2) << "in var tensor desc dims size: "
<< tensor_desc.Dims().size();
for (int l = 0; l < tensor_desc.Dims().size(); ++l) {
LOG(kLOG_DEBUG3) << "var tensor desc dim " << l
<< " value: " << tensor_desc.Dims()[l];
}
}
}
} }
#endif #endif
} }
......
...@@ -17,6 +17,7 @@ limitations under the License. */ ...@@ -17,6 +17,7 @@ limitations under the License. */
#include <vector> #include <vector>
#include "common/types.h" #include "common/types.h"
#include "framework/framework.pb-c.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
#include "framework/program/block_desc.h" #include "framework/program/block_desc.h"
...@@ -27,8 +28,10 @@ class ProgramDesc : PaddleMobileObject { ...@@ -27,8 +28,10 @@ class ProgramDesc : PaddleMobileObject {
public: public:
friend class Node; friend class Node;
friend class ProgramOptimize; friend class ProgramOptimize;
explicit ProgramDesc(const proto::ProgramDesc &desc); explicit ProgramDesc(PaddleMobile__Framework__Proto__ProgramDesc *desc);
std::shared_ptr<BlockDesc> Block(size_t idx); std::shared_ptr<BlockDesc> Block(size_t idx);
const std::vector<std::shared_ptr<BlockDesc>> &Blocks() { return blocks_; } const std::vector<std::shared_ptr<BlockDesc>> &Blocks() { return blocks_; }
ProgramDesc(const ProgramDesc &program_desc) { ProgramDesc(const ProgramDesc &program_desc) {
for (auto &block : program_desc.blocks_) { for (auto &block : program_desc.blocks_) {
......
/* 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/26.
//
#include "tensor_desc.h"
/* 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. */
#pragma once
#include <vector>
#include "framework/framework.pb-c.h"
namespace paddle_mobile {
namespace framework {
enum VarType_Type {
VARTYPE_TYPE_BOOL = 0,
VARTYPE_TYPE_INT16 = 1,
VARTYPE_TYPE_INT32 = 2,
VARTYPE_TYPE_INT64 = 3,
VARTYPE_TYPE_FP16 = 4,
VARTYPE_TYPE_FP32 = 5,
VARTYPE_TYPE_FP64 = 6,
VARTYPE_TYPE_LOD_TENSOR = 7,
VARTYPE_TYPE_SELECTED_ROWS = 8,
VARTYPE_TYPE_FEED_MINIBATCH = 9,
VARTYPE_TYPE_FETCH_LIST = 10,
VARTYPE_TYPE_STEP_SCOPES = 11,
VARTYPE_TYPE_STEP_LOD_RANK_TABLE = 12,
VARTYPE_TYPE_STEP_LOD_TENSOR_ARRAY = 13,
VARTYPE_TYPE_STEP_PLACE_LIST = 14,
VARTYPE_TYPE_READER = 15,
VARTYPE_TYPE_CHANNEL = 16,
VARTYPE_TYPE_RAW = 17,
VARTYPE_TYPE_TUPLE = 18
};
class TensorDesc {
public:
TensorDesc() = default;
TensorDesc(const TensorDesc &desc) {
this->dims_ = desc.dims_;
this->data_type_ = desc.data_type_;
}
TensorDesc(PaddleMobile__Framework__Proto__VarType__TensorDesc *desc) {
for (int i = 0; i < desc->n_dims; ++i) {
int64_t d = desc->dims[i];
dims_.emplace_back(d);
}
data_type_ = (VarType_Type)desc->data_type;
}
std::vector<int64_t> Dims() const { return dims_; };
VarType_Type DataType() const { return data_type_; }
private:
std::vector<int64_t> dims_;
VarType_Type data_type_;
};
} // namespace framework
} // namespace paddle_mobile
...@@ -16,9 +16,5 @@ limitations under the License. */ ...@@ -16,9 +16,5 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {} // namespace framework
VarDesc::VarDesc(const proto::VarDesc &desc) : desc_(desc) {}
} // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
此差异已折叠。
此差异已折叠。
...@@ -14,7 +14,6 @@ limitations under the License. */ ...@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once #pragma once
#include <vector> #include <vector>
#include "framework.pb.h"
#include "memory/t_malloc.h" #include "memory/t_malloc.h"
#include "platform/data_type.h" #include "platform/data_type.h"
#include "tensor.h" #include "tensor.h"
......
此差异已折叠。
...@@ -33,7 +33,9 @@ class Loader : PaddleMobileObject { ...@@ -33,7 +33,9 @@ class Loader : PaddleMobileObject {
const framework::Program<Dtype, P> Load(const std::string &dirname); const framework::Program<Dtype, P> Load(const std::string &dirname);
private: private:
void LoadVar(framework::LoDTensor *tensor, const std::string &file_path); void LoadVar(framework::Variable *variable,
const framework::VarDesc &var_desc,
const std::string &file_path);
}; };
template <typename Dtype, Precision P = Precision::FP32> template <typename Dtype, Precision P = Precision::FP32>
...@@ -52,7 +54,8 @@ class Executor { ...@@ -52,7 +54,8 @@ class Executor {
protected: protected:
void InitMemory(); void InitMemory();
void LoadMemory(framework::LoDTensor *tensor, const std::string &file_path); void LoadMemory(const framework::VarDesc var_desc,
framework::LoDTensor *tensor, const std::string &file_path);
framework::Program<Dtype> program_; framework::Program<Dtype> program_;
std::shared_ptr<framework::ProgramDesc> to_predict_program_; std::shared_ptr<framework::ProgramDesc> to_predict_program_;
void predict(const framework::Tensor &t, int block_id); void predict(const framework::Tensor &t, int block_id);
......
此差异已折叠。
...@@ -21,7 +21,6 @@ limitations under the License. */ ...@@ -21,7 +21,6 @@ limitations under the License. */
#include "./test_helper.h" #include "./test_helper.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "common/log.h" #include "common/log.h"
#include "framework/framework.pb.h"
#include "framework/lod_tensor.h" #include "framework/lod_tensor.h"
#include "framework/operator.h" #include "framework/operator.h"
#include "framework/program/block_desc.h" #include "framework/program/block_desc.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册