提交 b8831606 编写于 作者: L liuruilong

format files

上级 30d22c55
此差异已折叠。
...@@ -202,34 +202,34 @@ size_t foo__bar__baz_bah__pack_to_buffer ...@@ -202,34 +202,34 @@ size_t foo__bar__baz_bah__pack_to_buffer
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
# define PROTOBUF_C__BEGIN_DECLS extern "C" { #define PROTOBUF_C__BEGIN_DECLS extern "C" {
# define PROTOBUF_C__END_DECLS } #define PROTOBUF_C__END_DECLS }
#else #else
# define PROTOBUF_C__BEGIN_DECLS #define PROTOBUF_C__BEGIN_DECLS
# define PROTOBUF_C__END_DECLS #define PROTOBUF_C__END_DECLS
#endif #endif
PROTOBUF_C__BEGIN_DECLS PROTOBUF_C__BEGIN_DECLS
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
# ifdef PROTOBUF_C_EXPORT #ifdef PROTOBUF_C_EXPORT
# define PROTOBUF_C__API __declspec(dllexport) #define PROTOBUF_C__API __declspec(dllexport)
# else
# define PROTOBUF_C__API __declspec(dllimport)
# endif
#else #else
# define PROTOBUF_C__API #define PROTOBUF_C__API __declspec(dllimport)
#endif
#else
#define PROTOBUF_C__API
#endif #endif
#if !defined(PROTOBUF_C__NO_DEPRECATED) && \ #if !defined(PROTOBUF_C__NO_DEPRECATED) && \
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
# define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__)) #define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__))
#else #else
# define PROTOBUF_C__DEPRECATED #define PROTOBUF_C__DEPRECATED
#endif #endif
#ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE #ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
#define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \ #define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \
, _##enum_name##_IS_INT_SIZE = INT_MAX , _##enum_name##_IS_INT_SIZE = INT_MAX
#endif #endif
...@@ -441,9 +441,7 @@ protobuf_c_message_pack_to_buffer(&message, &tmp); ...@@ -441,9 +441,7 @@ protobuf_c_message_pack_to_buffer(&message, &tmp);
*/ */
struct ProtobufCBuffer { struct ProtobufCBuffer {
/** Append function. Consumes the `len` bytes stored at `data`. */ /** Append function. Consumes the `len` bytes stored at `data`. */
void (*append)(ProtobufCBuffer *buffer, void (*append)(ProtobufCBuffer *buffer, size_t len, const uint8_t *data);
size_t len,
const uint8_t *data);
}; };
/** /**
...@@ -733,10 +731,8 @@ struct ProtobufCService { ...@@ -733,10 +731,8 @@ struct ProtobufCService {
/** Service descriptor. */ /** Service descriptor. */
const ProtobufCServiceDescriptor *descriptor; const ProtobufCServiceDescriptor *descriptor;
/** Function to invoke the service. */ /** Function to invoke the service. */
void (*invoke)(ProtobufCService *service, void (*invoke)(ProtobufCService *service, unsigned method_index,
unsigned method_index, const ProtobufCMessage *input, ProtobufCClosure closure,
const ProtobufCMessage *input,
ProtobufCClosure closure,
void *closure_data); void *closure_data);
/** Function to destroy the service. */ /** Function to destroy the service. */
void (*destroy)(ProtobufCService *service); void (*destroy)(ProtobufCService *service);
...@@ -772,8 +768,7 @@ struct ProtobufCServiceDescriptor { ...@@ -772,8 +768,7 @@ struct ProtobufCServiceDescriptor {
* \return A string containing the version number of protobuf-c. * \return A string containing the version number of protobuf-c.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const char * const char *protobuf_c_version(void);
protobuf_c_version(void);
/** /**
* Get the version of the protobuf-c library. Note that this is the version of * Get the version of the protobuf-c library. Note that this is the version of
...@@ -783,8 +778,7 @@ protobuf_c_version(void); ...@@ -783,8 +778,7 @@ protobuf_c_version(void);
* protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH. * protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
uint32_t uint32_t protobuf_c_version_number(void);
protobuf_c_version_number(void);
/** /**
* The version of the protobuf-c headers, represented as a string using the same * The version of the protobuf-c headers, represented as a string using the same
...@@ -818,10 +812,8 @@ protobuf_c_version_number(void); ...@@ -818,10 +812,8 @@ protobuf_c_version_number(void);
* If not found or if the optimize_for = CODE_SIZE option was set. * If not found or if the optimize_for = CODE_SIZE option was set.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCEnumValue * const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value_by_name(
protobuf_c_enum_descriptor_get_value_by_name( const ProtobufCEnumDescriptor *desc, const char *name);
const ProtobufCEnumDescriptor *desc,
const char *name);
/** /**
* Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric
...@@ -839,10 +831,8 @@ protobuf_c_enum_descriptor_get_value_by_name( ...@@ -839,10 +831,8 @@ protobuf_c_enum_descriptor_get_value_by_name(
* If not found. * If not found.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCEnumValue * const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value(
protobuf_c_enum_descriptor_get_value( const ProtobufCEnumDescriptor *desc, int value);
const ProtobufCEnumDescriptor *desc,
int value);
/** /**
* Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
...@@ -858,10 +848,8 @@ protobuf_c_enum_descriptor_get_value( ...@@ -858,10 +848,8 @@ protobuf_c_enum_descriptor_get_value(
* If not found or if the optimize_for = CODE_SIZE option was set. * If not found or if the optimize_for = CODE_SIZE option was set.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCFieldDescriptor * const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field_by_name(
protobuf_c_message_descriptor_get_field_by_name( const ProtobufCMessageDescriptor *desc, const char *name);
const ProtobufCMessageDescriptor *desc,
const char *name);
/** /**
* Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
...@@ -877,10 +865,8 @@ protobuf_c_message_descriptor_get_field_by_name( ...@@ -877,10 +865,8 @@ protobuf_c_message_descriptor_get_field_by_name(
* If not found. * If not found.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCFieldDescriptor * const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field(
protobuf_c_message_descriptor_get_field( const ProtobufCMessageDescriptor *desc, unsigned value);
const ProtobufCMessageDescriptor *desc,
unsigned value);
/** /**
* Determine the number of bytes required to store the serialised message. * Determine the number of bytes required to store the serialised message.
...@@ -891,9 +877,7 @@ protobuf_c_message_descriptor_get_field( ...@@ -891,9 +877,7 @@ protobuf_c_message_descriptor_get_field(
* Number of bytes. * Number of bytes.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
size_t size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
/** /**
* Unpack a serialised message into an in-memory representation. * Unpack a serialised message into an in-memory representation.
...@@ -913,12 +897,9 @@ protobuf_c_message_get_packed_size(const ProtobufCMessage *message); ...@@ -913,12 +897,9 @@ protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
* If an error occurred during unpacking. * If an error occurred during unpacking.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
ProtobufCMessage * ProtobufCMessage *protobuf_c_message_unpack(
protobuf_c_message_unpack( const ProtobufCMessageDescriptor *descriptor, ProtobufCAllocator *allocator,
const ProtobufCMessageDescriptor *descriptor, size_t len, const uint8_t *data);
ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
/** /**
* Free an unpacked message object. * Free an unpacked message object.
...@@ -933,9 +914,7 @@ protobuf_c_message_unpack( ...@@ -933,9 +914,7 @@ protobuf_c_message_unpack(
* specify the default allocator. * specify the default allocator.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_message_free_unpacked(ProtobufCMessage *message,
protobuf_c_message_free_unpacked(
ProtobufCMessage *message,
ProtobufCAllocator *allocator); ProtobufCAllocator *allocator);
/** /**
...@@ -950,11 +929,11 @@ protobuf_c_message_free_unpacked( ...@@ -950,11 +929,11 @@ protobuf_c_message_free_unpacked(
* Message is invalid. * Message is invalid.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
protobuf_c_boolean protobuf_c_boolean protobuf_c_message_check(const ProtobufCMessage *);
protobuf_c_message_check(const ProtobufCMessage *);
/** Message initialiser. */ /** Message initialiser. */
#define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL } #define PROTOBUF_C_MESSAGE_INIT(descriptor) \
{ descriptor, 0, NULL }
/** /**
* Initialise a message object from a message descriptor. * Initialise a message object from a message descriptor.
...@@ -965,9 +944,7 @@ protobuf_c_message_check(const ProtobufCMessage *); ...@@ -965,9 +944,7 @@ protobuf_c_message_check(const ProtobufCMessage *);
* Allocated block of memory of size `descriptor->sizeof_message`. * Allocated block of memory of size `descriptor->sizeof_message`.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_message_init(const ProtobufCMessageDescriptor *descriptor,
protobuf_c_message_init(
const ProtobufCMessageDescriptor *descriptor,
void *message); void *message);
/** /**
...@@ -977,8 +954,7 @@ protobuf_c_message_init( ...@@ -977,8 +954,7 @@ protobuf_c_message_init(
* The service object to free. * The service object to free.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_destroy(ProtobufCService *service);
protobuf_c_service_destroy(ProtobufCService *service);
/** /**
* Look up a `ProtobufCMethodDescriptor` by name. * Look up a `ProtobufCMethodDescriptor` by name.
...@@ -996,36 +972,29 @@ protobuf_c_service_destroy(ProtobufCService *service); ...@@ -996,36 +972,29 @@ protobuf_c_service_destroy(ProtobufCService *service);
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCMethodDescriptor * const ProtobufCMethodDescriptor *
protobuf_c_service_descriptor_get_method_by_name( protobuf_c_service_descriptor_get_method_by_name(
const ProtobufCServiceDescriptor *desc, const ProtobufCServiceDescriptor *desc, const char *name);
const char *name);
/** /**
* Initialise a `ProtobufCBufferSimple` object. * Initialise a `ProtobufCBufferSimple` object.
*/ */
#define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \ #define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \
{ \ { \
{ protobuf_c_buffer_simple_append }, \ {protobuf_c_buffer_simple_append}, sizeof(array_of_bytes), 0, \
sizeof(array_of_bytes), \ (array_of_bytes), 0, NULL \
0, \ }
(array_of_bytes), \
0, \
NULL \
}
/** /**
* Clear a `ProtobufCBufferSimple` object, freeing any allocated memory. * Clear a `ProtobufCBufferSimple` object, freeing any allocated memory.
*/ */
#define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \ #define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \
do { \ do { \
if ((simp_buf)->must_free_data) { \ if ((simp_buf)->must_free_data) { \
if ((simp_buf)->allocator != NULL) \ if ((simp_buf)->allocator != NULL) \
(simp_buf)->allocator->free( \ (simp_buf)->allocator->free((simp_buf)->allocator, (simp_buf)->data); \
(simp_buf)->allocator, \
(simp_buf)->data); \
else \ else \
free((simp_buf)->data); \ free((simp_buf)->data); \
} \ } \
} while (0) } while (0)
/** /**
* The `append` method for `ProtobufCBufferSimple`. * The `append` method for `ProtobufCBufferSimple`.
...@@ -1039,23 +1008,16 @@ do { \ ...@@ -1039,23 +1008,16 @@ do { \
* Data to append. * Data to append.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, size_t len,
protobuf_c_buffer_simple_append(
ProtobufCBuffer *buffer,
size_t len,
const unsigned char *data); const unsigned char *data);
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_generated_init(
protobuf_c_service_generated_init( ProtobufCService *service, const ProtobufCServiceDescriptor *descriptor,
ProtobufCService *service,
const ProtobufCServiceDescriptor *descriptor,
ProtobufCServiceDestroy destroy); ProtobufCServiceDestroy destroy);
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_invoke_internal(ProtobufCService *service,
protobuf_c_service_invoke_internal(
ProtobufCService *service,
unsigned method_index, unsigned method_index,
const ProtobufCMessage *input, const ProtobufCMessage *input,
ProtobufCClosure closure, ProtobufCClosure closure,
......
...@@ -16,8 +16,8 @@ limitations under the License. */ ...@@ -16,8 +16,8 @@ limitations under the License. */
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
#include <unordered_set> #include <unordered_set>
#include <vector>
#include "framework/attribute.h" #include "framework/attribute.h"
#include "framework/scope.h" #include "framework/scope.h"
......
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once #pragma once
#include <unordered_map> #include <unordered_map>
#include "common/log.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "common/log.h"
#include "common/variant.h" #include "common/variant.h"
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
...@@ -27,7 +27,6 @@ class BlockDesc; ...@@ -27,7 +27,6 @@ class BlockDesc;
class Attribute { class Attribute {
public: public:
/* /*
* PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0, * PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT = 1, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT = 1,
...@@ -42,7 +41,8 @@ class Attribute { ...@@ -42,7 +41,8 @@ class Attribute {
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE) PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE)
* *
* */ * */
static Attribute GetAttrValue(PaddleMobile__Framework__Proto__OpDesc__Attr *attr_desc) { 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) {
......
此差异已折叠。
此差异已折叠。
...@@ -33,17 +33,18 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const { ...@@ -33,17 +33,18 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
return res; return res;
} }
BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc): index_(desc->idx), parent_index_(desc->idx) { BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc)
: index_(desc->idx), parent_index_(desc->idx) {
for (int i = 0; i < desc->n_vars; ++i) { for (int i = 0; i < desc->n_vars; ++i) {
PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i]; PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i];
vars_[std::string(var_desc->name)] = std::shared_ptr<VarDesc>(new VarDesc(var_desc)); vars_[std::string(var_desc->name)] =
std::shared_ptr<VarDesc>(new VarDesc(var_desc));
} }
for (int j = 0; j < desc->n_ops; ++j) { for (int j = 0; j < desc->n_ops; ++j) {
PaddleMobile__Framework__Proto__OpDesc *op_desc = desc->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));
} }
} }
} // namespace framework } // namespace framework
......
...@@ -15,9 +15,9 @@ limitations under the License. */ ...@@ -15,9 +15,9 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.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"
#include "framework/paddle_mobile_object.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
......
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#include <string> #include <string>
#include <vector> #include <vector>
#include "program_desc.h"
#include "framework/program/tensor_desc.h" #include "framework/program/tensor_desc.h"
#include "program_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -70,7 +70,6 @@ void ProgramDesc::Description(std::string header) { ...@@ -70,7 +70,6 @@ void ProgramDesc::Description(std::string header) {
} }
} }
} }
} }
#endif #endif
} }
......
/* 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. // Created by liuRuiLong on 2018/5/26.
// //
......
...@@ -21,7 +21,7 @@ limitations under the License. */ ...@@ -21,7 +21,7 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
enum VarType_Type{ enum VarType_Type {
VARTYPE_TYPE_BOOL = 0, VARTYPE_TYPE_BOOL = 0,
VARTYPE_TYPE_INT16 = 1, VARTYPE_TYPE_INT16 = 1,
VARTYPE_TYPE_INT32 = 2, VARTYPE_TYPE_INT32 = 2,
...@@ -59,17 +59,13 @@ class TensorDesc { ...@@ -59,17 +59,13 @@ class TensorDesc {
data_type_ = (VarType_Type)desc->data_type; data_type_ = (VarType_Type)desc->data_type;
} }
std::vector<int64_t> Dims() const { std::vector<int64_t> Dims() const { return dims_; };
return dims_; VarType_Type DataType() const { return data_type_; }
};
VarType_Type DataType() const {
return data_type_;
}
private: private:
std::vector<int64_t> dims_; std::vector<int64_t> dims_;
VarType_Type data_type_; VarType_Type data_type_;
}; };
} } // namespace framework
} } // namespace paddle_mobile
...@@ -16,8 +16,5 @@ limitations under the License. */ ...@@ -16,8 +16,5 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {} // namespace framework
} // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
#include "framework/program/tensor_desc.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
#include "framework/program/tensor_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -48,7 +48,6 @@ PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL = 0, ...@@ -48,7 +48,6 @@ PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL = 0,
*/ */
class VarDesc { class VarDesc {
public: public:
VarDesc(const VarDesc &var_desc) { VarDesc(const VarDesc &var_desc) {
...@@ -65,7 +64,6 @@ class VarDesc { ...@@ -65,7 +64,6 @@ class VarDesc {
VarType_Type type_; VarType_Type type_;
VarType_Type data_type_; VarType_Type data_type_;
* */ * */
} }
VarDesc(PaddleMobile__Framework__Proto__VarDesc *desc) { VarDesc(PaddleMobile__Framework__Proto__VarDesc *desc) {
type_ = (VarType_Type)desc->type->type; type_ = (VarType_Type)desc->type->type;
...@@ -94,9 +92,7 @@ class VarDesc { ...@@ -94,9 +92,7 @@ class VarDesc {
default: default:
data_type_ = tensor_desc_.DataType(); data_type_ = tensor_desc_.DataType();
break; break;
} }
} }
std::string Name() const { return name_; } std::string Name() const { return name_; }
...@@ -104,42 +100,40 @@ class VarDesc { ...@@ -104,42 +100,40 @@ class VarDesc {
bool Persistable() const { return persistable_; } bool Persistable() const { return persistable_; }
const TensorDesc &Tensor_desc() const { const TensorDesc &Tensor_desc() const { return tensor_desc_; }
return tensor_desc_;
}
// const proto::VarType::ChannelDesc &channel_desc() const { // const proto::VarType::ChannelDesc &channel_desc() const {
// switch (desc_.type().type()) { // switch (desc_.type().type()) {
// case proto::VarType::CHANNEL: // case proto::VarType::CHANNEL:
// return desc_.type().channel(); // return desc_.type().channel();
// default: // default:
// break; // break;
// } // }
// } // }
// proto::VarType::Type GetDataType() const { // proto::VarType::Type GetDataType() const {
// switch (desc_.type().type()) { // switch (desc_.type().type()) {
// case proto::VarType::CHANNEL: // case proto::VarType::CHANNEL:
// return channel_desc().data_type(); // return channel_desc().data_type();
// break; // break;
// default: // default:
// return tensor_desc().data_type(); // return tensor_desc().data_type();
// } // }
// } // }
// template <typename T> // template <typename T>
// std::vector<T> RepeatedToVector( // std::vector<T> RepeatedToVector(
// const google::protobuf::RepeatedField<T> &repeated_field) const { // const google::protobuf::RepeatedField<T> &repeated_field) const {
// std::vector<T> ret; // std::vector<T> ret;
// ret.reserve(repeated_field.size()); // ret.reserve(repeated_field.size());
// std::copy(repeated_field.begin(), repeated_field.end(), // std::copy(repeated_field.begin(), repeated_field.end(),
// std::back_inserter(ret)); // std::back_inserter(ret));
// return ret; // return ret;
// } // }
// std::vector<int64_t> GetShape() const { // std::vector<int64_t> GetShape() const {
// return this->RepeatedToVector(tensor_desc().dims()); // return this->RepeatedToVector(tensor_desc().dims());
// } // }
private: private:
std::string name_; std::string name_;
...@@ -147,7 +141,6 @@ class VarDesc { ...@@ -147,7 +141,6 @@ class VarDesc {
TensorDesc tensor_desc_; TensorDesc tensor_desc_;
VarType_Type type_; VarType_Type type_;
VarType_Type data_type_; VarType_Type data_type_;
}; };
} // namespace framework } // namespace framework
......
...@@ -16,15 +16,15 @@ limitations under the License. */ ...@@ -16,15 +16,15 @@ limitations under the License. */
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include "common/log.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "framework/scope.h" #include "common/log.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/operator.h"
#include "framework/program/program_desc.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 {
...@@ -40,7 +40,7 @@ void ReadBinaryFile(const std::string &filename, std::string *contents) { ...@@ -40,7 +40,7 @@ void ReadBinaryFile(const std::string &filename, std::string *contents) {
fin.close(); fin.close();
} }
static size_t ReadBuffer (const char *file_name, uint8_t **out) { static size_t ReadBuffer(const char *file_name, uint8_t **out) {
printf("%s \n", file_name); printf("%s \n", file_name);
FILE *fp; FILE *fp;
fp = fopen(file_name, "rb"); fp = fopen(file_name, "rb");
...@@ -56,7 +56,7 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) { ...@@ -56,7 +56,7 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) {
size_t cur_len = 0; size_t cur_len = 0;
size_t nread; size_t nread;
while ((nread=fread(*out + cur_len, 1, size - cur_len, fp)) != 0) { while ((nread = fread(*out + cur_len, 1, size - cur_len, fp)) != 0) {
cur_len += nread; cur_len += nread;
} }
fclose(fp); fclose(fp);
...@@ -64,7 +64,8 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) { ...@@ -64,7 +64,8 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) {
} }
template <typename Dtype, Precision P> template <typename Dtype, Precision P>
void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::VarDesc &var_desc, void Loader<Dtype, P>::LoadVar(framework::Variable *variable,
const framework::VarDesc &var_desc,
const std::string &file_path) { const std::string &file_path) {
auto tensor = variable->GetMutable<framework::LoDTensor>(); auto tensor = variable->GetMutable<framework::LoDTensor>();
std::ifstream is(file_path); std::ifstream is(file_path);
...@@ -109,22 +110,22 @@ void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::V ...@@ -109,22 +110,22 @@ void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::V
const framework::TensorDesc &desc = var_desc.Tensor_desc(); const framework::TensorDesc &desc = var_desc.Tensor_desc();
PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor_desc = NULL; PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor_desc = NULL;
// void *v; // void *v;
// PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure()(tensor_desc, buf.get()); // PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure()(tensor_desc,
// buf.get());
// DLOG << "PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure- " << tensor_desc;
// DLOG << "PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure- " <<
// tensor_desc;
// framework::TensorDesc &tensor_desc = variable-> // framework::TensorDesc &tensor_desc = variable->
// PaddleMobile__Framework__Proto__ProgramDesc *c_program; // PaddleMobile__Framework__Proto__ProgramDesc *c_program;
// uint8_t *proto_buf = NULL; // uint8_t *proto_buf = NULL;
// size_t read_size = ReadBuffer(file_path.c_str(), &proto_buf); // size_t read_size = ReadBuffer(file_path.c_str(), &proto_buf);
// c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL, read_size, buf); // c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL,
// read_size, buf);
// paddle_mobile__framework__proto__var_type__tensor_desc__init()
// paddle_mobile__framework__proto__var_type__tensor_desc__init()
int memory_size = 1; int memory_size = 1;
for (auto l : desc.Dims()) { for (auto l : desc.Dims()) {
...@@ -173,7 +174,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -173,7 +174,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
PADDLE_MOBILE_ENFORCE(buf != NULL, "read from __model__ is null"); PADDLE_MOBILE_ENFORCE(buf != NULL, "read from __model__ is null");
c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL, read_size, buf); c_program = paddle_mobile__framework__proto__program_desc__unpack(
NULL, read_size, buf);
PADDLE_MOBILE_ENFORCE(c_program != NULL, "program is null"); PADDLE_MOBILE_ENFORCE(c_program != NULL, "program is null");
...@@ -194,14 +196,14 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -194,14 +196,14 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
for (const auto &block : originProgramDesc->Blocks()) { for (const auto &block : originProgramDesc->Blocks()) {
for (int i = 0; i < block->Vars().size(); ++i) { for (int i = 0; i < block->Vars().size(); ++i) {
std::shared_ptr<framework::VarDesc> var_desc = block->Vars()[i]; std::shared_ptr<framework::VarDesc> var_desc = block->Vars()[i];
// 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 &&
var_desc->Type() != framework::VARTYPE_TYPE_FETCH_LIST) { var_desc->Type() != framework::VARTYPE_TYPE_FETCH_LIST) {
// DLOG << "to load var "; // DLOG << "to load var ";
LoadVar(var, *var_desc, dirname + "/" + var_desc->Name()); LoadVar(var, *var_desc, dirname + "/" + var_desc->Name());
} }
...@@ -247,7 +249,8 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p) : program_(p) { ...@@ -247,7 +249,8 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p) : program_(p) {
} }
template <typename Dtype, Precision P> template <typename Dtype, Precision P>
void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework::LoDTensor *tensor, void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
framework::LoDTensor *tensor,
const std::string &file_path) { const std::string &file_path) {
std::ifstream is(file_path); std::ifstream is(file_path);
PADDLE_MOBILE_ENFORCE(is.is_open(), "open file: %s failed", PADDLE_MOBILE_ENFORCE(is.is_open(), "open file: %s failed",
...@@ -290,7 +293,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework ...@@ -290,7 +293,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework
const framework::TensorDesc &desc = var_desc.Tensor_desc(); const framework::TensorDesc &desc = var_desc.Tensor_desc();
int memory_size = 1; int memory_size = 1;
for (auto l : desc.Dims()) { for (auto l : desc.Dims()) {
memory_size *= l; memory_size *= l;
...@@ -335,7 +337,8 @@ void Executor<Dtype, P>::InitMemory() { ...@@ -335,7 +337,8 @@ void Executor<Dtype, P>::InitMemory() {
auto var = program_.scope->Var(var_desc->Name()); auto var = program_.scope->Var(var_desc->Name());
if (var_desc->Persistable()) { if (var_desc->Persistable()) {
auto tensor = var->template GetMutable<framework::LoDTensor>(); auto tensor = var->template GetMutable<framework::LoDTensor>();
LoadMemory(*var_desc, tensor, program_.model_path + "/" + var_desc->Name()); LoadMemory(*var_desc, tensor,
program_.model_path + "/" + var_desc->Name());
} else { } else {
if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) {
auto tensor = var->template GetMutable<framework::Tensor>(); auto tensor = var->template GetMutable<framework::Tensor>();
......
...@@ -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::Variable *variable, const framework::VarDesc &var_desc, 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(const framework::VarDesc var_desc, 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);
......
...@@ -116,8 +116,7 @@ inline std::string DataTypeToString(const VarType_Type type) { ...@@ -116,8 +116,7 @@ inline std::string DataTypeToString(const VarType_Type type) {
} }
} }
inline std::ostream &operator<<(std::ostream &out, inline std::ostream &operator<<(std::ostream &out, const VarType_Type &type) {
const VarType_Type &type) {
out << DataTypeToString(type); out << DataTypeToString(type);
return out; return out;
} }
......
...@@ -58,7 +58,6 @@ class Executor4Test : public Executor<DeviceType> { ...@@ -58,7 +58,6 @@ class Executor4Test : public Executor<DeviceType> {
for (std::shared_ptr<BlockDesc> block_desc : blocks) { for (std::shared_ptr<BlockDesc> block_desc : blocks) {
std::vector<std::shared_ptr<OpDesc>> ops = block_desc->Ops(); std::vector<std::shared_ptr<OpDesc>> ops = block_desc->Ops();
for (std::shared_ptr<OpDesc> op : ops) { for (std::shared_ptr<OpDesc> op : ops) {
if (op->Type() == op_type) { if (op->Type() == op_type) {
/// test first meeting op in program /// test first meeting op in program
std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>> std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册