diff --git a/src/common/dep_core.h b/src/common/dep_core.h deleted file mode 100644 index a9fdca5b1de0307ed9bde99dcc65ca92fd5aee53..0000000000000000000000000000000000000000 --- a/src/common/dep_core.h +++ /dev/null @@ -1,67 +0,0 @@ -/* 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 - -#ifdef PADDLE_EXECUTOR_MULTITHREAD -#include -#include -#include -#include "framework/operator.h" - -namespace paddle_mobile { - -class depCore { - public: - template - void analysisDep( - const std::vector>>& ops) { - std::unordered_map vars; - size_t nop = ops.size(); - deps.resize(nop); - next.resize(nop); - for (size_t i = 0; i < nop; i++) { - const auto& op = ops[i]; - for (const auto& kv : op->Inputs()) { - for (const auto& v : kv.second) { - if (vars.find(v) == vars.end()) { - continue; - } - int di = vars[v]; - if (di == i) { - continue; - } - if (std::find(deps[i].begin(), deps[i].end(), di) != deps[i].end()) { - continue; - } - deps[i].push_back(di); - next[di].push_back(i); - } - } - for (const auto& kv : op->Outputs()) { - for (const auto& v : kv.second) { - vars[v] = i; - } - } - } - } - const std::vector& getNext(int i) { return next[i]; } - const std::vector& getDeps(int i) { return deps[i]; } - std::vector> deps; - std::vector> next; -}; - -} // namespace paddle_mobile - -#endif diff --git a/src/common/macros.h b/src/common/macros.h deleted file mode 100644 index ee38f19c9285b369e48c550b67f6c397695e73cf..0000000000000000000000000000000000000000 --- a/src/common/macros.h +++ /dev/null @@ -1,17 +0,0 @@ -/* 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 - -#define EXPORT __attribute__((visibility("default"))) diff --git a/src/common/type_define.h b/src/common/type_define.h index a25a19f11f444c1a92b033c0f721174bda44ed50..bedbd2a75e6de73b4f741cd0dd5ab7fcc36a998e 100644 --- a/src/common/type_define.h +++ b/src/common/type_define.h @@ -15,32 +15,173 @@ limitations under the License. */ #pragma once #include -#include #include #include -#include "framework/attribute.h" -#include "framework/scope.h" namespace paddle_mobile { +typedef enum { + _void = 0, + _float, + _int, + _uint16_t, + _double, + _int64_t, + _size_t, + _int16_t, + _int8_t, + _uint8_t, + _bool, + _string, + _floats = 100, + _ints, + _int64_ts, + _size_ts, + _bools, + _strings, + _const_float = 200, + _const_int, + _block = 300, + _tensor, + _lod_tensor, + _blocks, + _tensors, + _lod_tensors, + _p_block = 400, + _p_tensor, + _p_lod_tensor, + _p_blocks, + _p_tensors, + _p_lod_tensors, + _scopes = 500, + _selected_rows, + _dim0 = 600, + _dim1, + _dim2, + _dim3, + _dim4, + _dim5, + _dim6, + _dim7, + _dim8, + _dim9, +#ifdef PADDLE_MOBILE_CL + _cl_image, +#endif +} kTypeId_t; + +template +struct TypeIdWrapper { + inline std::string name(); + inline kTypeId_t hash_code(); +}; + +template +struct type_id { + const kTypeId_t hash_code() const { return TypeIdWrapper().hash_code(); } + const std::string name() const { return TypeIdWrapper().name(); } + + template + bool operator==(const type_id &operand) const { + return this->hash_code() == operand.hash_code(); + } +}; + +#define OVERIDE_TYPEID_OPERATOR(oprand) \ + template \ + inline bool operator oprand(const kTypeId_t &t0, const type_id &t1) { \ + return t0 oprand t1.hash_code(); \ + } \ + template \ + inline bool operator oprand(const type_id &t0, const kTypeId_t &t1) { \ + return t1 oprand t0.hash_code(); \ + } + +OVERIDE_TYPEID_OPERATOR(==) +OVERIDE_TYPEID_OPERATOR(!=) + namespace framework { -template -class OperatorBase; -class OpDesc; class BlockDesc; -class InferShapeContext; +class Tensor; +class LoDTensor; +class SelectedRows; +class Scope; +#ifdef PADDLE_MOBILE_CL +class CLImage; +#endif + +template +struct Dim; } // namespace framework -using VariableNameMap = std::map>; +#define REGISTER_TYPE_ID(Type, TypeName) \ + template <> \ + struct TypeIdWrapper { \ + inline std::string name() { return std::string(#TypeName); } \ + inline kTypeId_t hash_code() { return kTypeId_t::TypeName; } \ + }; + +REGISTER_TYPE_ID(void, _void) +REGISTER_TYPE_ID(float, _float) +REGISTER_TYPE_ID(int, _int) +REGISTER_TYPE_ID(uint16_t, _uint16_t) +REGISTER_TYPE_ID(double, _double) +REGISTER_TYPE_ID(int64_t, _int64_t) +REGISTER_TYPE_ID(size_t, _size_t) +REGISTER_TYPE_ID(int16_t, _int16_t) +REGISTER_TYPE_ID(int8_t, _int8_t) +REGISTER_TYPE_ID(uint8_t, _uint8_t) +REGISTER_TYPE_ID(bool, _bool) +REGISTER_TYPE_ID(std::string, _string) +REGISTER_TYPE_ID(std::vector, _floats) +REGISTER_TYPE_ID(std::vector, _ints) +REGISTER_TYPE_ID(std::vector, _int64_ts) +REGISTER_TYPE_ID(std::vector, _size_ts) +REGISTER_TYPE_ID(std::vector, _bools) +REGISTER_TYPE_ID(std::vector, _strings) + +REGISTER_TYPE_ID(float const, _const_float) +REGISTER_TYPE_ID(int const, _const_int) + +REGISTER_TYPE_ID(framework::BlockDesc, _block) +REGISTER_TYPE_ID(framework::Tensor, _tensor) +REGISTER_TYPE_ID(framework::LoDTensor, _lod_tensor) +REGISTER_TYPE_ID(std::vector, _blocks) +REGISTER_TYPE_ID(std::vector, _tensors) +REGISTER_TYPE_ID(std::vector, _lod_tensors) + +REGISTER_TYPE_ID(framework::BlockDesc *, _p_block) +REGISTER_TYPE_ID(framework::Tensor *, _p_tensor) +REGISTER_TYPE_ID(framework::LoDTensor *, _p_lod_tensor) +REGISTER_TYPE_ID(std::vector, _p_blocks) +REGISTER_TYPE_ID(std::vector, _p_tensors) +REGISTER_TYPE_ID(std::vector, _p_lod_tensors) + +REGISTER_TYPE_ID(std::vector, _scopes); +REGISTER_TYPE_ID(framework::SelectedRows, _selected_rows) +REGISTER_TYPE_ID(framework::Dim<0>, _dim0) +REGISTER_TYPE_ID(framework::Dim<1>, _dim1) +REGISTER_TYPE_ID(framework::Dim<2>, _dim2) +REGISTER_TYPE_ID(framework::Dim<3>, _dim3) +REGISTER_TYPE_ID(framework::Dim<4>, _dim4) +REGISTER_TYPE_ID(framework::Dim<5>, _dim5) +REGISTER_TYPE_ID(framework::Dim<6>, _dim6) +REGISTER_TYPE_ID(framework::Dim<7>, _dim7) +REGISTER_TYPE_ID(framework::Dim<8>, _dim8) +REGISTER_TYPE_ID(framework::Dim<9>, _dim9) + +#ifdef PADDLE_MOBILE_CL +REGISTER_TYPE_ID(framework::CLImage, _cl_image) +#endif +} // namespace paddle_mobile -template -using OpCreator = std::function *( - const std::string & /*type*/, const VariableNameMap & /*inputs*/, - const VariableNameMap & /*outputs*/, - const framework::AttributeMap & /*attrs*/, framework::Scope * /*scope*/)>; +namespace std { -using InferVarTypeFN = std::function; +template <> +struct hash { + size_t operator()(const paddle_mobile::kTypeId_t &t) const { + return std::hash{}(static_cast(t)); + } +}; -using InferShapeFN = std::function; -}; // namespace paddle_mobile +} // namespace std diff --git a/src/common/types.h b/src/common/types.h old mode 100755 new mode 100644 index 35c1659c5a246c49f6e0ccb31c3e63ce4fdd2e71..f8e1fd26ea34a1f6ab7cd5c6eeac75e901d0e02b --- a/src/common/types.h +++ b/src/common/types.h @@ -14,6 +14,7 @@ limitations under the License. */ #pragma once +#include #include #include #include @@ -211,4 +212,6 @@ extern std::unordered_map< std::string, std::pair, std::vector>> op_input_output_key; +typedef std::map> VariableNameMap; + } // namespace paddle_mobile diff --git a/src/common/variant.h b/src/common/variant.h index 4aa4f47c628caec438ecd00522d90ebf299da6a0..87fd822243dff30deb3fbcd3c61ffbe8807c3938 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -19,6 +19,7 @@ limitations under the License. */ #include #include "common/enforce.h" #include "common/log.h" +#include "common/type_define.h" namespace paddle_mobile { @@ -33,11 +34,11 @@ struct VariantHelper { ? sizeof(F) : VariantHelper::size; - inline static void Destroy(size_t id, void *data) { - if (id == typeid(F).hash_code()) { + inline static void Destroy(kTypeId_t type, void *data) { + if (type == type_id()) { reinterpret_cast(data)->~F(); } else { - VariantHelper::Destroy(id, data); + VariantHelper::Destroy(type, data); } } }; @@ -45,11 +46,11 @@ struct VariantHelper { template struct VariantHelper { static const size_t size = sizeof(F); - inline static void Destroy(size_t id, void *data) { - if (id == typeid(F).hash_code()) { - // reinterpret_cast(data)->~F(); + inline static void Destroy(kTypeId_t type, void *data) { + if (type == type_id()) { + // reinterpret_cast(data)->~F(); } else { - // std::cout << "未匹配到 " << std::endl; + // std::cout << "未匹配到 " << std::endl; } } }; @@ -57,7 +58,7 @@ struct VariantHelper { template class RawData { public: - char data[size]; + char data[size]; // NOLINT RawData() {} RawData(const RawData &raw_data) { memcpy(data, raw_data.data, size); } @@ -69,32 +70,33 @@ class RawData { template struct Variant { + Variant() : type_(invalid_type()) {} + Variant(const Variant &variant) { - type_id = variant.type_id; - data = variant.data; + type_ = variant.type_; + data_ = variant.data_; } - Variant() : type_id(invalid_type()) {} - ~Variant() { - // helper::Destroy(type_id, &data); + virtual ~Variant() { + // helper::Destroy(type_id, &data); } template void Set(Args &&... args) { - helper::Destroy(type_id, data.data); - new (data.data) T(std::forward(args)...); - type_id = typeid(T).hash_code(); + helper::Destroy(type_, data_.data); + new (data_.data) T(std::forward(args)...); + type_ = type_id().hash_code(); } - void SetString(std::string &string) { - helper::Destroy(type_id, data.data); - type_id = typeid(std::string).hash_code(); - strcpy(data.data, string.c_str()); + void SetString(const std::string &string) { + helper::Destroy(type_, data_.data); + type_ = type_id().hash_code(); + strcpy(data_.data, string.c_str()); // NOLINT } std::string GetString() const { - if (type_id == typeid(std::string).hash_code()) { - return std::string(data.data); + if (type_ == type_id()) { + return std::string(data_.data); } else { PADDLE_MOBILE_THROW_EXCEPTION( " bad cast in variant data type not a string "); @@ -104,28 +106,25 @@ struct Variant { template T &Get() const { - if (type_id == typeid(std::string).hash_code()) { + if (type_ == type_id()) { PADDLE_MOBILE_THROW_EXCEPTION( "Please use getString to get an string (to avoid of an issue with " "gcc " "stl lib with string copy)"); exit(0); - } else if (type_id == typeid(T).hash_code()) { - return *const_cast(reinterpret_cast(data.data)); } else { - PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant"); - exit(0); + return *const_cast(reinterpret_cast(data_.data)); } } - size_t TypeId() const { return type_id; } + kTypeId_t TypeId() const { return type_; } private: - static inline size_t invalid_type() { return typeid(void).hash_code(); } + static inline kTypeId_t invalid_type() { return type_id().hash_code(); } typedef VariantHelper helper; - size_t type_id; + kTypeId_t type_ = type_id().hash_code(); // todo use an anto size to suite this. - RawData<64> data; + RawData<64> data_; }; template diff --git a/src/fpga/V1/api.cpp b/src/fpga/V1/api.cpp index 4ad252d41420442844aee25dddd7dcbac22aef2d..2bcae0cb4745bb27c7a995446a6f7e2cfc54c694 100644 --- a/src/fpga/V1/api.cpp +++ b/src/fpga/V1/api.cpp @@ -28,8 +28,8 @@ namespace fpga { void format_image(framework::Tensor *image_tensor) { auto dims = image_tensor->dims(); auto channel = dims[1], height = dims[2], width = dims[3]; - std::type_index input_type = image_tensor->type(); - if (input_type == typeid(float)) { + kTypeId_t input_type = image_tensor->type(); + if (input_type == type_id()) { auto data_ptr = image_tensor->data(); auto external_ptr = reinterpret_cast(image_tensor->external_data); float *p_data = external_ptr == nullptr ? data_ptr : external_ptr; @@ -51,7 +51,7 @@ void format_image(framework::Tensor *image_tensor) { } void format_ofm(framework::Tensor *ofm_tensor) { - if (ofm_tensor->type() == typeid(float)) { + if (ofm_tensor->type() == type_id()) { format_fp32_ofm(ofm_tensor); } else { format_fp16_ofm(ofm_tensor); @@ -72,7 +72,7 @@ void format_fp16_ofm(framework::Tensor *ofm_tensor) { auto p = fpga_malloc(memory_size); // memset(p, 0, memory_size); ofm_tensor->reset_data_ptr(p); - ofm_tensor->set_type(typeid(half)); + ofm_tensor->set_type(type_id().hash_code()); ofm_tensor->fpga_data_num = memory_size / sizeof(half); fpga::fpga_flush(p, memory_size); } @@ -92,7 +92,7 @@ void format_fp16_ofm(framework::Tensor *ofm_tensor, framework::DDim dims) { auto p = fpga_malloc(memory_size); // memset(p, 0, memory_size); ofm_tensor->reset_data_ptr(p); - ofm_tensor->set_type(typeid(half)); + ofm_tensor->set_type(type_id().hash_code()); ofm_tensor->fpga_data_num = memory_size / sizeof(half); fpga::fpga_flush(p, memory_size); } @@ -112,7 +112,7 @@ void format_fp32_ofm(framework::Tensor *ofm_tensor) { auto p = fpga_malloc(memory_size); // memset(p, 0, memory_size); ofm_tensor->reset_data_ptr(p); - ofm_tensor->set_type(typeid(float)); + ofm_tensor->set_type(type_id().hash_code()); ofm_tensor->fpga_data_num = memory_size / sizeof(float); fpga::fpga_flush(p, memory_size); } @@ -171,7 +171,7 @@ void format_filter(framework::Tensor *filter_tensor, float max_value, filter::format_filter(&new_data, num, channel, height, width, group_num, max_value); filter_tensor->reset_data_ptr(new_data); - filter_tensor->set_type(typeid(int8_t)); + filter_tensor->set_type(type_id().hash_code()); } void format_dwconv_filter(framework::Tensor *filter_tensor, float *scale_ptr) { auto dims = filter_tensor->dims(); @@ -182,7 +182,7 @@ void format_dwconv_filter(framework::Tensor *filter_tensor, float *scale_ptr) { fpga_copy(new_data, data_ptr, memory_size); filter::format_dwconv_filter(&new_data, num, height, width, scale_ptr); filter_tensor->reset_data_ptr(new_data); - filter_tensor->set_type(typeid(int16_t)); + filter_tensor->set_type(type_id().hash_code()); } void format_DWDconv_filter(framework::Tensor *filter_tensor, float *scale_ptr, @@ -207,7 +207,7 @@ void format_DWDconv_filter(framework::Tensor *filter_tensor, float *scale_ptr, // framework::make_ddim({num, 1, height, width}); // filter_tensor->Resize(dims_new); filter_tensor->reset_data_ptr(new_data); - filter_tensor->set_type(typeid(int16_t)); + filter_tensor->set_type(type_id().hash_code()); } void format_fc_filter(framework::Tensor *filter_tensor, float max_value) { @@ -222,7 +222,7 @@ void format_fc_filter(framework::Tensor *filter_tensor, float max_value) { filter::format_fc_filter(&new_data, num, channel, height, width, 1, max_value); filter_tensor->reset_data_ptr(new_data); - filter_tensor->set_type(typeid(int8_t)); + filter_tensor->set_type(type_id().hash_code()); } void format_deconv_filter(framework::Tensor *filter_tensor, float max_value, int group_num, int stride) { @@ -249,7 +249,7 @@ void format_deconv_filter(framework::Tensor *filter_tensor, float max_value, framework::make_ddim({num, channel, height, width}); filter_tensor->Resize(dims_new); filter_tensor->reset_data_ptr(new_data); - filter_tensor->set_type(typeid(int8_t)); + filter_tensor->set_type(type_id().hash_code()); } void format_bias_scale_array(float **bias_scale_array, @@ -273,7 +273,7 @@ void format_concat_output(framework::Tensor *out, int height, int width, auto ddim = framework::make_ddim({1, sum_channel, height, width}); out->Resize(ddim); out->reset_data_ptr(data_ptr); - out->set_type(typeid(half)); + out->set_type(type_id().hash_code()); } void format_conv_data(framework::Tensor *filter_tensor, framework::Tensor *ofm_tensor, float **bs_ptr, diff --git a/src/framework/attribute.h b/src/framework/attribute.h index e00cee09b36a4372c938f356900faab88e610010..01c4a8d7d4b59b8c0a92913618b4407de769b044 100644 --- a/src/framework/attribute.h +++ b/src/framework/attribute.h @@ -128,31 +128,30 @@ class Attribute { template static typename Vistor::type_t ApplyVistor(Vistor vistor, Attribute attr) { - if (attr.variant_.TypeId() == typeid(int).hash_code()) { // NOLINT + if (attr.variant_.TypeId() == type_id()) { // NOLINT return vistor(attr.variant_.Get()); - } else if (attr.variant_.TypeId() == typeid(float).hash_code()) { // NOLINT + } else if (attr.variant_.TypeId() == type_id()) { // NOLINT return vistor(attr.variant_.Get()); - } else if (attr.variant_.TypeId() == typeid(string).hash_code()) { + } else if (attr.variant_.TypeId() == type_id()) { return vistor(attr.variant_.GetString()); - } else if (attr.variant_.TypeId() == typeid(vector).hash_code()) { + } else if (attr.variant_.TypeId() == type_id>()) { return vistor(attr.variant_.Get>()); - } else if (attr.variant_.TypeId() == typeid(vector).hash_code()) { + } else if (attr.variant_.TypeId() == type_id>()) { return vistor(attr.variant_.Get>()); - } else if (attr.variant_.TypeId() == typeid(vector).hash_code()) { + } else if (attr.variant_.TypeId() == type_id>()) { return vistor(attr.variant_.Get>()); - } else if (attr.variant_.TypeId() == typeid(bool).hash_code()) { // NOLINT + } else if (attr.variant_.TypeId() == type_id()) { // NOLINT return vistor(attr.variant_.Get()); - } else if (attr.variant_.TypeId() == typeid(vector).hash_code()) { + } else if (attr.variant_.TypeId() == type_id>()) { return vistor(attr.variant_.Get>()); - } else if (attr.variant_.TypeId() == typeid(int64_t).hash_code()) { + } else if (attr.variant_.TypeId() == type_id()) { return vistor(attr.variant_.Get()); - } else if (attr.variant_.TypeId() == - typeid(framework::BlockDesc *).hash_code()) { + } else if (attr.variant_.TypeId() == type_id()) { return vistor(attr.variant_.Get()); } else if (attr.variant_.TypeId() == - typeid(vector).hash_code()) { + type_id>()) { return vistor(attr.variant_.Get>()); - } else if (attr.variant_.TypeId() == typeid(vector).hash_code()) { + } else if (attr.variant_.TypeId() == type_id>()) { return vistor(attr.variant_.Get>()); } else { PADDLE_MOBILE_THROW_EXCEPTION("type not support"); diff --git a/src/framework/cl/cl_tensor.h b/src/framework/cl/cl_tensor.h index 93a3648bfe8054ed0b54728bb7000423949f494a..a0ed438f9773dbacaaa7446d594719c0cf12b32e 100644 --- a/src/framework/cl/cl_tensor.h +++ b/src/framework/cl/cl_tensor.h @@ -53,12 +53,12 @@ class CLTensor : TensorBase { int64_t size = numel() * sizeof(T); holder_.reset(new PlaceholderImpl( - size, reinterpret_cast(const_cast(data)), typeid(T), - context_, command_queue_)); + size, reinterpret_cast(const_cast(data)), + type_id().hash_code(), context_, command_queue_)); return reinterpret_cast(holder_->ptr()); } - inline cl_mem mutable_data(std::type_index type) { + inline cl_mem mutable_data(kTypeId_t type) { if (holder_ != nullptr) { holder_->set_type(type); } @@ -77,7 +77,7 @@ class CLTensor : TensorBase { */ template inline cl_mem mutable_data() { - return reinterpret_cast(mutable_data(typeid(T))); + return reinterpret_cast(mutable_data(type_id().hash_code())); } /** @@ -132,7 +132,7 @@ class CLTensor : TensorBase { void *host_ptr_ = nullptr; struct PlaceholderImpl : public Placeholder { - PlaceholderImpl(size_t size, void *input, std::type_index type, + PlaceholderImpl(size_t size, void *input, kTypeId_t type, cl_context context, cl_command_queue command_queue) : ptr_(clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, reinterpret_cast(input), NULL)), @@ -142,7 +142,7 @@ class CLTensor : TensorBase { context_(context), command_queue_(command_queue) {} - PlaceholderImpl(size_t size, std::type_index type, cl_context context, + PlaceholderImpl(size_t size, kTypeId_t type, cl_context context, cl_command_queue command_queue) : ptr_(clCreateBuffer(context, CL_MEM_READ_WRITE, size, NULL, NULL)), size_(size), @@ -155,9 +155,9 @@ class CLTensor : TensorBase { virtual void *ptr() const { return static_cast(ptr_.get()); } - virtual std::type_index type() const { return type_; } + virtual kTypeId_t type() const { return type_; } - virtual void set_type(std::type_index type) { type_ = type; } + virtual void set_type(kTypeId_t type) { type_ = type; } virtual void resize(size_t size) { if (size > capatity_) { @@ -175,7 +175,7 @@ class CLTensor : TensorBase { size_t capatity_; /* the current type of memory */ - std::type_index type_; + kTypeId_t type_; cl_context context_; cl_command_queue command_queue_; diff --git a/src/framework/data_type.cpp b/src/framework/data_type.cpp index 0bcf7d9f67dae28db5a316476778b4132b39b274..5eaf3ecaf599d5ed34c5396bbba2c9e0e68736fd 100644 --- a/src/framework/data_type.cpp +++ b/src/framework/data_type.cpp @@ -16,17 +16,17 @@ limitations under the License. */ #include #include #include +#include "common/type_define.h" namespace paddle_mobile { namespace framework { struct DataTypeMap { - std::unordered_map + std::unordered_map cpp_to_proto_; - std::unordered_map proto_to_cpp_; + std::unordered_map proto_to_cpp_; std::unordered_map proto_to_str_; - std::unordered_map cpp_to_size_; + std::unordered_map cpp_to_size_; }; static DataTypeMap* InitDataTypeMap(); @@ -42,10 +42,11 @@ template static inline void RegisterType( DataTypeMap* map, _PaddleMobile__Framework__Proto__VarType__Type proto_type, const std::string& name) { - map->proto_to_cpp_.emplace(static_cast(proto_type), typeid(T)); - map->cpp_to_proto_.emplace(typeid(T), proto_type); + map->proto_to_cpp_.emplace(static_cast(proto_type), + type_id().hash_code()); + map->cpp_to_proto_.emplace(type_id().hash_code(), proto_type); map->proto_to_str_.emplace(static_cast(proto_type), name); - map->cpp_to_size_.emplace(typeid(T), sizeof(T)); + map->cpp_to_size_.emplace(type_id().hash_code(), sizeof(T)); } static DataTypeMap* InitDataTypeMap() { @@ -70,17 +71,15 @@ static DataTypeMap* InitDataTypeMap() { return retv; } -_PaddleMobile__Framework__Proto__VarType__Type ToDataType( - std::type_index type) { +_PaddleMobile__Framework__Proto__VarType__Type ToDataType(kTypeId_t type) { auto it = gDataTypeMap().cpp_to_proto_.find(type); if (it != gDataTypeMap().cpp_to_proto_.end()) { return it->second; } - PADDLE_MOBILE_THROW_EXCEPTION("Not support %s as tensor type", type.name()); + PADDLE_MOBILE_THROW_EXCEPTION("Not support %d as tensor type", type); } -std::type_index ToTypeIndex( - _PaddleMobile__Framework__Proto__VarType__Type type) { +kTypeId_t ToTypeIndex(_PaddleMobile__Framework__Proto__VarType__Type type) { auto it = gDataTypeMap().proto_to_cpp_.find(static_cast(type)); if (it != gDataTypeMap().proto_to_cpp_.end()) { return it->second; diff --git a/src/framework/data_type.h b/src/framework/data_type.h index 231bb62e1f7a24bdf65b417d18679ca31bf13d83..bda823ada49b108e1f3279173f87daefc3403b5b 100644 --- a/src/framework/data_type.h +++ b/src/framework/data_type.h @@ -15,18 +15,17 @@ limitations under the License. */ #pragma once #include -#include #include "common/enforce.h" +#include "common/type_define.h" #include "framework/framework.pb-c.h" namespace paddle_mobile { namespace framework { -extern _PaddleMobile__Framework__Proto__VarType__Type ToDataType( - std::type_index type); -extern std::type_index ToTypeIndex( - _PaddleMobile__Framework__Proto__VarType__Type type); +_PaddleMobile__Framework__Proto__VarType__Type ToDataType(kTypeId_t type); + +kTypeId_t ToTypeIndex(_PaddleMobile__Framework__Proto__VarType__Type type); inline _PaddleMobile__Framework__Proto__VarType__Type ToDataType(int type) { return static_cast<_PaddleMobile__Framework__Proto__VarType__Type>(type); diff --git a/src/framework/ddim.h b/src/framework/ddim.h index 74dd288ba88108af3de895c3ef535dedaa5edfc2..8ba0756a6b6774a5641242c03ebeb86454b38ad2 100644 --- a/src/framework/ddim.h +++ b/src/framework/ddim.h @@ -22,7 +22,7 @@ limitations under the License. */ #include "common/enforce.h" #include "common/variant.h" -#include "dim.h" +#include "framework/dim.h" namespace paddle_mobile { namespace framework { @@ -40,25 +40,25 @@ struct DDim { template static typename Vistor::type_t ApplyVistor(Vistor vistor, const DDim &d) { - if (d.var.TypeId() == typeid(Dim<0>).hash_code()) { + if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<1>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<2>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<3>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<4>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<5>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<6>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<7>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<8>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); - } else if (d.var.TypeId() == typeid(Dim<9>).hash_code()) { + } else if (d.var.TypeId() == type_id>()) { return vistor(d.var.Get>()); } else { PADDLE_MOBILE_ENFORCE(false, " dim not support"); diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index b9f455bd2708c82bd2165dc34e0a22150de40fac..f337d1d184d0d4880a28df7d066301ca0d3e1460 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -62,7 +62,7 @@ Executor::Executor(const Program &program, use_optimize_ ? program_.optimizeProgram : program_.originProgram; PADDLE_MOBILE_ENFORCE(program_desc_ != nullptr, "program_desc_ should not be nullptr"); -#ifndef PADDLE_MOBILE_FPGA +#if !defined(PADDLE_MOBILE_FPGA) && !defined(PADDLE_MOBILE_CL) pass::MemoryOptPass()(program_desc_.get(), program_.scope.get()); #endif // resize feed and fetch list @@ -302,25 +302,9 @@ bool Executor::varInputMemory( const std::shared_ptr &var_desc, Variable *var) const { #ifdef PADDLE_MOBILE_FPGA framework::LoDTensor *tensor = var->template GetMutable(); - tensor->init(typeid(float)); + tensor->init(type_id().hash_code()); return true; #endif - auto TypeId = [](const VarType_Type &type) -> std::type_index { - switch (type) { - case VARTYPE_TYPE_BOOL: - return typeid(bool); - case VARTYPE_TYPE_FP32: - return typeid(float); - case VARTYPE_TYPE_INT8: - return typeid(int8_t); - case VARTYPE_TYPE_INT32: - return typeid(int); - case VARTYPE_TYPE_INT64: - return typeid(int64_t); - default: - PADDLE_MOBILE_THROW_EXCEPTION("got unhandled var type `%d`", type); - } - }; auto type = var_desc->Type(); if (type == VARTYPE_TYPE_LOD_TENSOR) { @@ -390,13 +374,6 @@ void Executor::SetInput(const Tensor &input, framework::LoDTensor &target = feed_var->template GetMutable()->at(index); - if (config_.load_when_predict) { - if (input_dim_last_ != input.dims()) { - InitNoPersistableMemory(input); - input_dim_last_ = input.dims(); - } - } - target.Resize(input.dims()); target.ShareDataWith(input); } @@ -412,13 +389,6 @@ void Executor::SetInput(const LoDTensor &input, framework::LoDTensor &target = feed_var->template GetMutable()->at(index); - if (config_.load_when_predict) { - if (input_dim_last_ != input.dims()) { - InitNoPersistableMemory(input); - input_dim_last_ = input.dims(); - } - } - target.Resize(input.dims()); target.ShareDataWith(input); target.set_lod(input.lod()); diff --git a/src/framework/load_ops.h b/src/framework/load_ops.h index a969a73b9edfe1e7a475ea7191bfcd552d09357c..983a544cda8faa756562914d26f36c4ab8608be2 100644 --- a/src/framework/load_ops.h +++ b/src/framework/load_ops.h @@ -268,6 +268,9 @@ LOAD_OP1(sequence_expand, CPU); #ifdef SEQUENCE_POOL_OP LOAD_OP1(sequence_pool, CPU); #endif +#ifdef SEQUENCE_SOFTMAX_OP +LOAD_OP1(sequence_softmax, CPU); +#endif #ifdef LOG_OP LOAD_OP1(log, CPU); #endif diff --git a/src/framework/lod_tensor.cpp b/src/framework/lod_tensor.cpp index e165e55507ed04a9b63e4ad5eb002f206c71d96c..0a1a6f881d0aaf20cc9ca6a109e2915464025aa4 100644 --- a/src/framework/lod_tensor.cpp +++ b/src/framework/lod_tensor.cpp @@ -12,52 +12,12 @@ 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 "lod_tensor.h" +#include "framework/lod_tensor.h" #include namespace paddle_mobile { namespace framework { -// std::ostream &operator<<(std::ostream &os, const LoD &lod) { -// os << "{"; -// for (auto &v : lod) { -// os << "{"; -// bool is_first = true; -// for (auto &i : v) { -// if (is_first) { -// os << i; -// is_first = false; -// } else { -// os << ", " << i; -// } -// } -// os << "}"; -// } -// os << "}"; -// -// return os; -//} -// -// std::ostream &operator<<(std::ostream &os, const LoDTensor &t) { -// PADDLE_MOBILE_ENFORCE(t.type().hash_code() == typeid(float).hash_code(), -// "t.type() is not float"); -// os << "dim: " << t.dims() << "\n"; -// os << "lod: " << t.lod() << "\n"; -// // only print first ten elements -// int64_t size = t.numel() < 10 ? t.numel() : 10; -// for (int64_t i = 0; i < size; ++i) { -// os << t.data()[i] << " "; -// } -// -// return os; -//} - -// std::string LoDToString(const LoD &lod) { -// std::ostringstream stream; -// stream << lod; -// return stream.str(); -//} - LoD SliceInLevel(const LoD &in, size_t level, size_t elem_begin, size_t elem_end) { PADDLE_MOBILE_ENFORCE(level < in.size(), "level should >= in.size()"); diff --git a/src/framework/lod_tensor.h b/src/framework/lod_tensor.h index e96fe0e501f06814914677d0fb6248a11fa1dde5..6d67b517ff38a3bb4b2ae6978de1290079596aa6 100644 --- a/src/framework/lod_tensor.h +++ b/src/framework/lod_tensor.h @@ -211,17 +211,17 @@ inline Print &operator<<(Print &printer, const LoDTensor &tensor) { stride = stride > 0 ? stride : 1; #ifndef PADDLE_MOBILE_FPGA for (int i = 0; i < tensor.numel(); i += stride) { - if (tensor.type() == typeid(float)) { + if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int32_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int64_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int8_t)) { + } else if (tensor.type() == type_id()) { printer << static_cast(tensor.data()[i]) << " "; - } else if (tensor.type() == typeid(int32_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(bool)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; } } diff --git a/src/framework/mixed_vector.h b/src/framework/mixed_vector.h index 031d73179c991229ec99ebdde927b0ad1532d82b..6e46164fb791fdc28a9dddff4b38c3d3b346b5c7 100644 --- a/src/framework/mixed_vector.h +++ b/src/framework/mixed_vector.h @@ -17,7 +17,6 @@ #include #include #include - #include "framework/tensor.h" #include "framework/tensor_util.h" @@ -198,7 +197,7 @@ class Vector { } size_t capacity() const { - return cpu_vec_.memory_size() / SizeOfType(typeid(T)); + return cpu_vec_.memory_size() / SizeOfType(type_id().hash_code()); } // reserve data diff --git a/src/framework/op_info.h b/src/framework/op_info.h index 16b3487955ce05721e6e3f3e79b6d8ebd180e020..c250f61664108b57cb5eba7411638fd4d5b8dc9b 100644 --- a/src/framework/op_info.h +++ b/src/framework/op_info.h @@ -14,13 +14,24 @@ limitations under the License. */ #pragma once +#include #include #include "common/log.h" #include "common/type_define.h" +#include "framework/scope.h" namespace paddle_mobile { namespace framework { +template +class OperatorBase; + +template +using OpCreator = std::function *( + const std::string & /*type*/, const VariableNameMap & /*inputs*/, + const VariableNameMap & /*outputs*/, + const framework::AttributeMap & /*attrs*/, framework::Scope * /*scope*/)>; + template struct OpInfo { OpCreator creator_; @@ -79,8 +90,6 @@ class OpInfoMap { private: OpInfoMap() = default; std::unordered_map> map_; - - // DISABLE_COPY_AND_ASSIGN(OpInfoMap); }; } // namespace framework diff --git a/src/framework/operator.h b/src/framework/operator.h index 93f23e9d1067392a0bb43e8f764dd6695249d996..c8b3a5ccf796c5cce33efb697cd6d6aef8b9d21c 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -14,6 +14,7 @@ limitations under the License. */ #pragma once +#include #include #include #include diff --git a/src/framework/program/block_desc.h b/src/framework/program/block_desc.h index dd33a274266cb503cea0b960c026276d90cea57a..86dd832d1b108878313d5a34ada3ce5a2b9c321e 100644 --- a/src/framework/program/block_desc.h +++ b/src/framework/program/block_desc.h @@ -14,6 +14,8 @@ limitations under the License. */ #pragma once +#include +#include #include "framework/framework.pb-c.h" #include "framework/program/op_desc.h" #include "framework/program/var_desc.h" @@ -26,8 +28,8 @@ class BlockDesc { friend class Node; friend class ProgramOptimize; BlockDesc() {} - BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc); - BlockDesc(const BlockDesc &block_desc) + explicit BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc); + explicit BlockDesc(const BlockDesc &block_desc) : index_(block_desc.index_), parent_index_(block_desc.parent_index_) { for (auto &op_desc : block_desc.ops_) { std::shared_ptr copy_op_desc = std::make_shared(*op_desc); diff --git a/src/framework/program/op_desc.h b/src/framework/program/op_desc.h index f9579df034ccfb3e68863b27eef1df935ba266d5..89c877ba120db630f30dc21d48c0347b0668cb22 100644 --- a/src/framework/program/op_desc.h +++ b/src/framework/program/op_desc.h @@ -18,7 +18,8 @@ limitations under the License. */ #include #include "common/log.h" -#include "common/type_define.h" +#include "common/types.h" +#include "framework/attribute.h" #include "framework/framework.pb-c.h" namespace paddle_mobile { diff --git a/src/framework/program/program-optimize/node.h b/src/framework/program/program-optimize/node.h index b86fc96a67e290540c94487497fced55abf09041..5b5ae7796f3c99f991100d3313563900fcf59250 100644 --- a/src/framework/program/program-optimize/node.h +++ b/src/framework/program/program-optimize/node.h @@ -16,6 +16,7 @@ limitations under the License. */ #include #include +#include #include #include #include diff --git a/src/framework/program/program_desc.cpp b/src/framework/program/program_desc.cpp index 23781fe77962608b515ebb7c0479f284ebfc4277..88cac11d283cd0c5b72a6809deb34df8206c3e25 100644 --- a/src/framework/program/program_desc.cpp +++ b/src/framework/program/program_desc.cpp @@ -72,7 +72,7 @@ void ProgramDesc::Description(std::string header) const { } } for (auto &attr : op->GetAttrMap()) { - if (attr.first == "op_callstack") continue; + if (attr.first == "op_callstack" || attr.first == "sub_block") continue; LOG(kLOG_DEBUG2) << "attr name: " << attr.first; LOG(kLOG_DEBUG3) << "argument - " << attr.second; } diff --git a/src/framework/tensor.h b/src/framework/tensor.h index 4fb06c654983b9e1b8441b074d5a30220fb960a2..fe2f266137b98df778e21818a42ab7f9e13e617d 100644 --- a/src/framework/tensor.h +++ b/src/framework/tensor.h @@ -19,8 +19,6 @@ limitations under the License. */ #include #include #include -#include -#include #include #include "common/enforce.h" @@ -83,7 +81,7 @@ class Tensor : public TensorBase { return *this; } - inline void *mutable_data(std::type_index type) { + inline void *mutable_data(const kTypeId_t type) { if (holder_ != nullptr) { holder_->set_type(type); } @@ -108,7 +106,7 @@ class Tensor : public TensorBase { template inline T *mutable_data() { static_assert(std::is_pod::value, "T must be POD"); - return reinterpret_cast(mutable_data(typeid(T))); + return reinterpret_cast(mutable_data(type_id().hash_code())); } /** @@ -165,9 +163,9 @@ class Tensor : public TensorBase { check_memory_size(); PADDLE_MOBILE_ENFORCE( (std::is_same::value || - holder_->type().hash_code() == typeid(T).hash_code()), - "Tensor holds the wrong type, it holds %s, requested %s", - this->holder_->type().name(), typeid(T).name()); + holder_->type() == type_id().hash_code()), + "Tensor holds the wrong type, it holds %d, requested %d", + this->holder_->type(), type_id().hash_code()); return reinterpret_cast(reinterpret_cast(holder_->ptr()) + offset_); @@ -179,9 +177,9 @@ class Tensor : public TensorBase { check_memory_size(); PADDLE_MOBILE_ENFORCE( (std::is_same::value || - holder_->type().hash_code() == typeid(T).hash_code()), - "Tensor holds the wrong type, it holds %s, requested %s", - this->holder_->type().name(), typeid(T).name()); + holder_->type() == type_id().hash_code()), + "Tensor holds the wrong type, it holds %d, requested %d", + this->holder_->type(), type_id().hash_code()); return reinterpret_cast( reinterpret_cast(holder_->ptr()) + offset_); @@ -189,7 +187,7 @@ class Tensor : public TensorBase { private: struct PlaceholderImpl : public Placeholder { - PlaceholderImpl(size_t size, std::type_index type) + PlaceholderImpl(size_t size, const kTypeId_t type) : ptr_(static_cast(memory::Alloc(size)), memory::PODDeleter()), size_(size), @@ -203,9 +201,9 @@ class Tensor : public TensorBase { virtual void *ptr() const { return static_cast(ptr_.get()); } - virtual std::type_index type() const { return type_; } + virtual kTypeId_t type() const { return type_; } - virtual void set_type(std::type_index type) { type_ = type; } + virtual void set_type(const kTypeId_t type) { type_ = type; } virtual void resize(size_t size) { if (size > capatity_) { @@ -223,7 +221,7 @@ class Tensor : public TensorBase { size_t capatity_; /* the current type of memory */ - std::type_index type_; + kTypeId_t type_; }; #ifdef PADDLE_MOBILE_FPGA @@ -231,13 +229,13 @@ class Tensor : public TensorBase { inline void reset_data_ptr(void *p) { ((PlaceholderImpl *)(holder_.get()))->ptr_.reset((uint8_t *)p); // NOLINT } - inline void set_type(std::type_index type) { holder_->set_type(type); } + inline void set_type(const kTypeId_t type) { holder_->set_type(type); } inline void *get_data() { return ( void *)(((PlaceholderImpl *)(holder_.get()))->ptr_.get()); // NOLINT } - inline void *init(std::type_index type) { + inline void *init(const kTypeId_t type) { if (holder_ != nullptr) { holder_->set_type(type); } @@ -265,15 +263,15 @@ inline Print &operator<<(Print &printer, const Tensor &tensor) { stride = stride > 0 ? stride : 1; #ifndef PADDLE_MOBILE_FPGA for (int i = 0; i < tensor.numel(); i += stride) { - if (tensor.type() == typeid(float)) { + if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int32_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int64_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; - } else if (tensor.type() == typeid(int8_t)) { + } else if (tensor.type() == type_id()) { printer << static_cast(tensor.data()[i]) << " "; - } else if (tensor.type() == typeid(int32_t)) { + } else if (tensor.type() == type_id()) { printer << tensor.data()[i] << " "; } } diff --git a/src/framework/tensor_base.h b/src/framework/tensor_base.h index e5ab7793c0eb392126359b050b9f0b8bc25c3515..027f1165a08509431fd1281f7b05174a7c64b7cc 100644 --- a/src/framework/tensor_base.h +++ b/src/framework/tensor_base.h @@ -14,10 +14,8 @@ limitations under the License. */ #pragma once -#include -#include - #include "common/enforce.h" +#include "common/type_define.h" #include "common/types.h" #include "framework/ddim.h" @@ -29,8 +27,8 @@ struct SizeOfTypeFunctor; template struct SizeOfTypeFunctor { - size_t operator()(std::type_index type) const { - if (typeid(T).hash_code() == type.hash_code()) { + size_t operator()(const kTypeId_t type) const { + if (type_id().hash_code() == type) { return sizeof(T); } else { return 0UL; @@ -40,12 +38,12 @@ struct SizeOfTypeFunctor { template <> struct SizeOfTypeFunctor<> { - size_t operator()(std::type_index type) const { return 0UL; } + size_t operator()(const kTypeId_t type) const { return 0UL; } }; template struct SizeOfTypeFunctor { - size_t operator()(std::type_index type) const { + size_t operator()(const kTypeId_t type) const { SizeOfTypeFunctor head; size_t head_size = head(type); if (head_size != 0) { @@ -56,13 +54,13 @@ struct SizeOfTypeFunctor { } }; -static inline size_t SizeOfType(std::type_index type) { +static inline size_t SizeOfType(const kTypeId_t type) { SizeOfTypeFunctor functor; size_t size = functor(type); - PADDLE_MOBILE_ENFORCE(size != 0UL, "Cannot get size of type %s", type.name()); + PADDLE_MOBILE_ENFORCE(size != 0UL, "Cannot get size of type %d", type); return size; } @@ -78,7 +76,7 @@ class TensorBase { /*! Return the numel of the memory block. */ inline int64_t numel() const { return product(dims_); } - std::type_index type() const { + kTypeId_t type() const { PADDLE_MOBILE_ENFORCE( holder_ != nullptr, "Tensor not initialized yet when Tensor::type() is called.") @@ -114,9 +112,9 @@ class TensorBase { virtual size_t size() const = 0; - virtual std::type_index type() const = 0; + virtual kTypeId_t type() const = 0; - virtual void set_type(std::type_index type) = 0; + virtual void set_type(kTypeId_t type) = 0; virtual void resize(size_t size) = 0; }; diff --git a/src/framework/variable.h b/src/framework/variable.h index 5bff63f068ca13fa6252006c4618a7f8a9d3b2f7..30486cb34721a06ef5babf5cc796302b23834617 100644 --- a/src/framework/variable.h +++ b/src/framework/variable.h @@ -16,13 +16,10 @@ limitations under the License. */ #include #include -#include -#include -#include "../common/variant.h" +#include "common/variant.h" namespace paddle_mobile { namespace framework { -using std::string; class Variable { public: @@ -33,7 +30,7 @@ class Variable { template const T GetValue() const { - if (typeid(T) == typeid(std::string)) { + if (type_id().hash_code() == type_id().hash_code()) { PADDLE_MOBILE_THROW_EXCEPTION( "Please use getString to get an string (to avoid of an issue with " "gcc " @@ -60,38 +57,40 @@ class Variable { template bool IsType() const { - return holder_ != nullptr && holder_->Type() == typeid(T); + return holder_ != nullptr && holder_->Type() == type_id().hash_code(); } void Clear() { holder_.reset(); } - std::type_index Type() const { return holder_->Type(); } + kTypeId_t Type() const { return holder_->Type(); } private: struct Placeholder { Placeholder() = default; virtual ~Placeholder() = default; - virtual const std::type_info &Type() const = 0; + virtual kTypeId_t Type() const = 0; virtual void *Ptr() const = 0; }; template struct PlaceholderImp : public Placeholder { - explicit PlaceholderImp(T *ptr) : ptr_(ptr), type_(typeid(T)) {} + explicit PlaceholderImp(T *ptr) + : ptr_(ptr), type_(type_id().hash_code()) {} - virtual const std::type_info &Type() const { return type_; } - virtual void *Ptr() const override { - return static_cast(ptr_.get()); - } + kTypeId_t Type() const override { return type_; } + void *Ptr() const override { return static_cast(ptr_.get()); } std::unique_ptr ptr_; - const std::type_info &type_; + kTypeId_t type_; }; - Variant variant; - std::unique_ptr holder_; + friend class Scope; - string name_; + + Variant variant; + std::unique_ptr holder_; + std::string name_; }; + } // namespace framework } // namespace paddle_mobile diff --git a/src/io/api_paddle_mobile.cc b/src/io/api_paddle_mobile.cc index 1f4769b282385207a5b53d6d678364393d7da6cc..e7782de201b9306ea3a65708ef12a00ca8f981c2 100644 --- a/src/io/api_paddle_mobile.cc +++ b/src/io/api_paddle_mobile.cc @@ -128,7 +128,7 @@ void ConvertTensors(const framework::Tensor &src, PaddleTensor *des) { des->layout = src.layout == framework::LAYOUT_HWC ? LAYOUT_HWC : LAYOUT_CHW; auto num = src.numel(); - if (src.type() == typeid(float)) { + if (src.type() == type_id()) { des->data.Reset(const_cast(src.data()), num * sizeof(float)); } else { @@ -143,7 +143,7 @@ void PaddleMobilePredictor::FeedPaddleTensors( auto num = inputs.size(); std::vector tensors(num, framework::Tensor()); for (int i = 0; i < num; i++) { - tensors[i].init(typeid(float)); + tensors[i].init(type_id().hash_code()); ConvertPaddleTensors(inputs[i], &tensors[i]); } paddle_mobile_->FeedTensorData(tensors); diff --git a/src/io/paddle_inference_api.h b/src/io/paddle_inference_api.h index e8c2c1daaa7bb41ccb7da0a969d941e0131249ab..b1e787c6496ee3c01918c1a9a143f35d7119f7a1 100644 --- a/src/io/paddle_inference_api.h +++ b/src/io/paddle_inference_api.h @@ -24,8 +24,8 @@ limitations under the License. */ #include #include #include -#include #include +#include "common/type_define.h" namespace paddle_mobile { @@ -88,7 +88,7 @@ struct PaddleTensor { // TODO(Superjomn) for LoD support, add a vector> field if needed. PaddleBuf data; // blob of data. PaddleDType dtype; - std::type_index dtypeid = typeid(float); + kTypeId_t dtypeid; LayoutType layout; }; diff --git a/src/operators/beam_search_decode_op.cpp b/src/operators/beam_search_decode_op.cpp index 9b01d2e17f363d3b729102a9747f6dc6682ea8aa..1038234fe8ecf1b68f5fdcd52c1f1b4491658ae7 100644 --- a/src/operators/beam_search_decode_op.cpp +++ b/src/operators/beam_search_decode_op.cpp @@ -14,8 +14,6 @@ limitations under the License. */ #ifdef BEAM_SEARCH_DECODE_OP -#pragma once - #include "operators/beam_search_decode_op.h" namespace paddle_mobile { diff --git a/src/operators/beam_search_op.cpp b/src/operators/beam_search_op.cpp index 502510ebeefd29336531fac24d279e009f6b8d6d..5f83e536672daf6ae83f07209c40e6f900a9514d 100644 --- a/src/operators/beam_search_op.cpp +++ b/src/operators/beam_search_op.cpp @@ -14,8 +14,6 @@ limitations under the License. */ #ifdef BEAM_SEARCH_OP -#pragma once - #include "operators/beam_search_op.h" namespace paddle_mobile { diff --git a/src/operators/kernel/arm/compare_kernel.cpp b/src/operators/kernel/arm/compare_kernel.cpp index d83fae1748bc9b942425219ea169b63d5c84b867..35bb13363cea5a8de173cc7491afa5cc421e5746 100644 --- a/src/operators/kernel/arm/compare_kernel.cpp +++ b/src/operators/kernel/arm/compare_kernel.cpp @@ -192,10 +192,10 @@ bool LessThanKernel::Init(CompareParam *param) { template <> void LessThanKernel::Compute(const CompareParam ¶m) { - if (param.input_x_->type() == typeid(int64_t)) { + if (param.input_x_->type() == type_id().hash_code()) { CompareCompute()(param.input_x_, param.input_y_, param.axis_, param.output_); - } else if (param.input_x_->type() == typeid(float)) { + } else if (param.input_x_->type() == type_id().hash_code()) { CompareCompute()(param.input_x_, param.input_y_, param.axis_, param.output_); } else { diff --git a/src/operators/kernel/arm/concat_kernel.cpp b/src/operators/kernel/arm/concat_kernel.cpp index 3c6a6f151f9b05ad0b69b40298ee5a47797d70af..3e585ec7214239ab5752d197e207fd55c6dffa68 100644 --- a/src/operators/kernel/arm/concat_kernel.cpp +++ b/src/operators/kernel/arm/concat_kernel.cpp @@ -27,7 +27,7 @@ bool ConcatKernel::Init(ConcatParam *param) { template <> void ConcatKernel::Compute(const ConcatParam ¶m) { - if (param.Inputs()[0]->type() == typeid(int8_t)) { + if (param.Inputs()[0]->type() == type_id().hash_code()) { ConcatCompute(param); } else { ConcatCompute(param); diff --git a/src/operators/kernel/arm/convolution/conv_common.cpp b/src/operators/kernel/arm/convolution/conv_common.cpp index 86c6e8d3373f743f485e4a69599e8c8323ba0083..5a5c04c656c120c93e4b14b1242fa9accb3c2244 100644 --- a/src/operators/kernel/arm/convolution/conv_common.cpp +++ b/src/operators/kernel/arm/convolution/conv_common.cpp @@ -28,7 +28,7 @@ void InitBaseConvKernel(ConvParam *param) { bool depth5x5 = conv5x5 && param->Groups() == param->Input()->dims()[1] && param->Input()->dims()[1] == param->Output()->dims()[1]; - if (param->Filter()->type() == typeid(int8_t)) { + if (param->Filter()->type() == type_id().hash_code()) { #ifndef __aarch64__ if (depth3x3 && param->Strides()[0] < 3 && param->Strides()[0] == param->Strides()[1]) { diff --git a/src/operators/kernel/arm/dequantize_kernel.cpp b/src/operators/kernel/arm/dequantize_kernel.cpp index c9dfd6f93667cf283e83e21c0a1f3725bb847956..7c0d1cea18c90145c5dbc06de7cb97fa5ed289b6 100644 --- a/src/operators/kernel/arm/dequantize_kernel.cpp +++ b/src/operators/kernel/arm/dequantize_kernel.cpp @@ -34,7 +34,7 @@ void DequantizeKernel::Compute(const DequantizeParam ¶m) { LoDTensor *output = param.output_; float activation_scale = param.activation_scale_->data()[0]; float weight_scale = param.weight_scale_; - const int32_t *x = input->data(); + const int32_t *x = input->data(); float *y = output->mutable_data(); size_t size = output->numel(); // float scale = 1.f / (activation_scale * weight_scale); diff --git a/src/operators/kernel/arm/quantize_kernel.cpp b/src/operators/kernel/arm/quantize_kernel.cpp index 79186be79e5b4207e9f6b2b221bc1a4160e4e67e..515e9cf40dad4eedd307bc59309177910330a3bf 100644 --- a/src/operators/kernel/arm/quantize_kernel.cpp +++ b/src/operators/kernel/arm/quantize_kernel.cpp @@ -36,7 +36,7 @@ inline float32_t vmaxvq_f32(float32x4_t r) { template inline void QuantizeOffline(const Tensor *input, const float scale, const float max_abs, Tensor *output) { - const float *x = input->data(); + const float *x = input->data(); int8_t *y = output->mutable_data(); size_t remain = input->numel(); #if defined(__ARM_NEON__) || defined(__ARM_NEON) @@ -88,7 +88,7 @@ inline void QuantizeOffline(const Tensor *input, const float scale, template inline void QuantizeOnline(const Tensor *input, const float scale, Tensor *output) { - const float *x = input->data(); + const float *x = input->data(); int8_t *y = output->mutable_data(); size_t remain = input->numel(); #if defined(__ARM_NEON__) || defined(__ARM_NEON) @@ -143,7 +143,7 @@ static void Quantize(const Tensor *input, const float max_abs, float find_abs_max(const Tensor *input) { float max_abs = 0.f; - const float *x = input->data(); + const float *x = input->data(); size_t remain = input->numel(); #if defined(__ARM_NEON__) || defined(__ARM_NEON) size_t loop = remain >> 4; diff --git a/src/operators/kernel/arm/tensor_array_read_write_kernel.cpp b/src/operators/kernel/arm/tensor_array_read_write_kernel.cpp index 72fbb4cadbac4ef824692cfcaf55dd2d5c5a1166..bdf10574a82c920edfdfc870efe2f175ad7d7d07 100644 --- a/src/operators/kernel/arm/tensor_array_read_write_kernel.cpp +++ b/src/operators/kernel/arm/tensor_array_read_write_kernel.cpp @@ -28,7 +28,9 @@ void WriteToArrayKernel::Compute( const WriteToArrayParam ¶m) { int64_t offset = param.index_->data()[0]; if (offset >= param.output_->size()) { - param.output_->resize(offset + 1); + while (param.output_->size() <= offset) { + param.output_->emplace_back(); + } } framework::LoDTensor *out_tensor = &(param.output_->at(offset)); diff --git a/src/operators/kernel/arm/transpose2_kernel.cpp b/src/operators/kernel/arm/transpose2_kernel.cpp index 6928df71e65dfe0aa28ceddda8f379f60fb65908..54c88015cb06728544258ddb47d6ce751130bc19 100644 --- a/src/operators/kernel/arm/transpose2_kernel.cpp +++ b/src/operators/kernel/arm/transpose2_kernel.cpp @@ -126,13 +126,13 @@ void Transpose2Kernel::Compute(const Transpose2Param ¶m) { const std::vector &axis = param.Axis(); bool shuffle_channel = IsShuffleChannel(axis); if (shuffle_channel) { - if (param.InputX()->type() == typeid(int8_t)) { + if (param.InputX()->type() == type_id().hash_code()) { ShuffleChannelCompute(param); } else { ShuffleChannelCompute(param); } } else { - if (param.InputX()->type() == typeid(int8_t)) { + if (param.InputX()->type() == type_id().hash_code()) { Transpose2Compute(param); } else { Transpose2Compute(param); diff --git a/src/operators/kernel/arm/while_kernel.cpp b/src/operators/kernel/arm/while_kernel.cpp index 63cd150ec977a5acf1fc24b1dd9bae75bf57b580..4794fd122cce141487598a19261fd3e0f66cfb27 100644 --- a/src/operators/kernel/arm/while_kernel.cpp +++ b/src/operators/kernel/arm/while_kernel.cpp @@ -35,6 +35,7 @@ class StepExecutor { auto op_handler = framework::OpRegistry::CreateOp( op_desc->Type(), op_desc->GetInputs(), op_desc->GetOutputs(), op_desc->GetAttrMap(), scope_); + op_handler->Init(); ops_of_block_[i] = op_handler; } } diff --git a/src/operators/kernel/central-arm-func/mul_arm_func.h b/src/operators/kernel/central-arm-func/mul_arm_func.h index 1f22ab98989644430e2484ca8d57fe2c4047e2f7..01d668021ba1affa4d827fdacbadbac7a66c794a 100644 --- a/src/operators/kernel/central-arm-func/mul_arm_func.h +++ b/src/operators/kernel/central-arm-func/mul_arm_func.h @@ -37,7 +37,7 @@ void MulCompute(const MulParam ¶m) { if (out_dim.size() != 2) { out->Resize({x_matrix.dims()[0], y_matrix.dims()[1]}); } - if (param.InputX()->type() == typeid(int8_t)) { + if (param.InputX()->type() == type_id().hash_code()) { out->mutable_data(); math::MatMul(x_matrix, false, y_matrix, false, static_cast(1), out, diff --git a/src/operators/kernel/central-arm-func/sum_arm_func.h b/src/operators/kernel/central-arm-func/sum_arm_func.h index 36c7ac9694bde85fbf702ad8adf5ffda8744da1d..7d41c898db991c098c91e882fdb330f5ffb2b9bf 100644 --- a/src/operators/kernel/central-arm-func/sum_arm_func.h +++ b/src/operators/kernel/central-arm-func/sum_arm_func.h @@ -144,7 +144,7 @@ void SumCompute(const SumParam ¶m) { } } else { PADDLE_MOBILE_THROW_EXCEPTION( - "Unexpected branch, output variable type is %s", outvar->Type().name()); + "Unexpected branch, output variable type is %d", outvar->Type()); } } } // namespace operators diff --git a/src/operators/kernel/fpga/V1/elementwise_add_kernel.cpp b/src/operators/kernel/fpga/V1/elementwise_add_kernel.cpp index c549e5a6eee98f38f1806367054b925440e3ebf1..db4d2afbc1735ac7f733a9dea673c748bc6edc29 100644 --- a/src/operators/kernel/fpga/V1/elementwise_add_kernel.cpp +++ b/src/operators/kernel/fpga/V1/elementwise_add_kernel.cpp @@ -25,7 +25,7 @@ template <> bool ElementwiseAddKernel::Init(ElementwiseAddParam *param) { auto *input_y = const_cast(param->InputY()); auto *out = param->Out(); - if (input_y->type() != typeid(float)) { + if (input_y->type() != type_id()) { paddle_mobile::fpga::ActivationType activation_enable = paddle_mobile::fpga::NONE; int16_t leaky_relu_negative_slope = 0; @@ -62,11 +62,10 @@ bool ElementwiseAddKernel::Init(ElementwiseAddParam *param) { param->SetFpgaArgs(ewaddArgs); } else { param->float_input_x.Resize(param->InputX()->dims()); - param->float_input_x.init(typeid(float)); + param->float_input_x.init(type_id().hash_code()); fpga::format_fp32_ofm(&(param->float_input_x)); param->float_out.Resize(param->InputX()->dims()); - // param->float_out.init(typeid(float)); param->float_out.mutable_data(param->InputX()->dims()); fpga::format_fp32_ofm(&(param->float_out)); @@ -118,7 +117,7 @@ template <> void ElementwiseAddKernel::Compute( const ElementwiseAddParam ¶m) { auto input_y = const_cast(param.InputY()); - if (input_y->type() != typeid(float)) { + if (input_y->type() != type_id()) { fpga::ComputeFpgaEWAdd(param.FpgaArgs()); } else { auto input_x = const_cast(param.InputX()); diff --git a/src/operators/kernel/fpga/V1/elementwise_mul_kernel.cpp b/src/operators/kernel/fpga/V1/elementwise_mul_kernel.cpp index e421ddb78ff4f1a0f0c51c985db9c26666001d03..d744ae2c07810ae89418641799a37ea978d14139 100644 --- a/src/operators/kernel/fpga/V1/elementwise_mul_kernel.cpp +++ b/src/operators/kernel/fpga/V1/elementwise_mul_kernel.cpp @@ -27,11 +27,11 @@ struct MulFunctor { template <> bool ElementwiseMulKernel::Init(ElementwiseMulParam *param) { param->float_input_x.Resize(param->InputX()->dims()); - param->float_input_x.init(typeid(float)); + param->float_input_x.init(type_id().hash_code()); fpga::format_fp32_ofm(&(param->float_input_x)); param->float_out.Resize(param->InputX()->dims()); - param->float_out.init(typeid(float)); + param->float_out.init(type_id().hash_code()); fpga::format_fp32_ofm(&(param->float_out)); auto *out = param->Out(); diff --git a/src/operators/kernel/fpga/V1/feed_kernel.cpp b/src/operators/kernel/fpga/V1/feed_kernel.cpp index f57c517bb00b8d676beaabf24c662efcbe752aeb..28559b2b4bb96404febf5cf65a75e264166df20f 100644 --- a/src/operators/kernel/fpga/V1/feed_kernel.cpp +++ b/src/operators/kernel/fpga/V1/feed_kernel.cpp @@ -23,7 +23,7 @@ bool FeedKernel::Init(FeedParam *param) { int col = param->Col(); DLOG << "col = " << col; auto input = const_cast(¶m->InputX()->at(col)); - input->init(typeid(float)); + input->init(type_id().hash_code()); input->Resize(output->dims()); if (output->dims().size() != 4) { @@ -39,12 +39,12 @@ void FeedKernel::Compute(const FeedParam ¶m) { auto output = param.Out(); int col = param.Col(); auto input = const_cast(¶m.InputX()->at(col)); - std::type_index input_type = input->type(); + kTypeId_t input_type = input->type(); - if (input_type == typeid(float)) { - input->init(typeid(float)); - } else { // input_type == typeid(int8_t) - input->init(typeid(int8_t)); + if (input_type == type_id()) { + input->init(type_id().hash_code()); + } else { + input->init(type_id().hash_code()); } input->Resize(output->dims()); @@ -62,7 +62,7 @@ void FeedKernel::Compute(const FeedParam ¶m) { fpga::format_image(input); auto output_ptr = output->data(); fpga::BypassArgs args = {fpga::DATA_TYPE_FP32}; - if (input_type == typeid(float)) { + if (input_type == type_id()) { auto input_ptr = input->data(); auto external_ptr = reinterpret_cast(input->external_data); float *p_data = external_ptr == nullptr ? input_ptr : external_ptr; @@ -81,7 +81,7 @@ void FeedKernel::Compute(const FeedParam ¶m) { args.output.scale_address = output->scale; fpga::PerformBypass(args); input->external_data = nullptr; - } else { // input_type == typeid(int8_t) + } else { auto input_ptr = input->data(); auto external_ptr = reinterpret_cast(input->external_data); int8_t *p_data = external_ptr == nullptr ? input_ptr : external_ptr; diff --git a/src/operators/kernel/fpga/V1/fetch_kernel.cpp b/src/operators/kernel/fpga/V1/fetch_kernel.cpp index fad1e77643a017659bea3c27d4475aea2c00787d..87ede2af1ab2fa3225c0cd3e75c3fe0c8c8fb509 100644 --- a/src/operators/kernel/fpga/V1/fetch_kernel.cpp +++ b/src/operators/kernel/fpga/V1/fetch_kernel.cpp @@ -21,10 +21,10 @@ bool FetchKernel::Init(FetchParam *param) { int col = param->Col(); DLOG << "col = " << col; auto output = &(param->Out()->at(col)); - if (input->type() == typeid(float)) { + if (input->type() == type_id()) { return true; } - output->init(typeid(float)); + output->init(type_id().hash_code()); output->Resize(input->dims()); fpga::format_fp32_ofm(output); int outC = 1; @@ -78,7 +78,7 @@ void FetchKernel::Compute(const FetchParam ¶m) { auto input = const_cast(param.InputX()); int col = param.Col(); auto output = ¶m.Out()->at(col); - if (input->type() == typeid(float)) { + if (input->type() == type_id()) { output->ShareDataWith(*input); return; } diff --git a/src/operators/kernel/fpga/V1/pool_kernel.cpp b/src/operators/kernel/fpga/V1/pool_kernel.cpp index 994fa151621956aa791d36cc0f4cd829dc88f3d1..7c8dba1696ecc15ba9748aabf1973445d23de95c 100644 --- a/src/operators/kernel/fpga/V1/pool_kernel.cpp +++ b/src/operators/kernel/fpga/V1/pool_kernel.cpp @@ -28,7 +28,7 @@ bool PoolKernel::Init(PoolParam *param) { vector paddings = param->Paddings(); std::string pooling_type = param->PoolingType(); - if (input->type() == typeid(float)) { + if (input->type() == type_id()) { int channels = input->dims()[1]; int height = input->dims()[2]; int width = input->dims()[3]; @@ -70,7 +70,7 @@ template <> void PoolKernel::Compute(const PoolParam ¶m) { auto *input = const_cast(param.Input()); - if (input->type() == typeid(float)) { + if (input->type() == type_id()) { auto *output = param.Output(); auto in = input->data(); auto N = input->dims()[0]; diff --git a/src/operators/kernel/fpga/V1/proposal_kernel.cpp b/src/operators/kernel/fpga/V1/proposal_kernel.cpp index 09c135ff5cdff0755dc41d96f90d4a3e3b345c27..bd6703bb81f1a4b70f2a3406b312160116ad38f5 100644 --- a/src/operators/kernel/fpga/V1/proposal_kernel.cpp +++ b/src/operators/kernel/fpga/V1/proposal_kernel.cpp @@ -37,11 +37,11 @@ bool ProposalKernel::Init(ProposalParam *param) { param->float_bbox = std::make_shared(); param->float_bbox->Resize(param->bbox_deltas_->dims()); - param->float_bbox->init(typeid(float)); + param->float_bbox->init(type_id().hash_code()); fpga::format_fp32_ofm(param->float_bbox.get()); param->float_score = std::make_shared(); param->float_score->Resize(param->scores_->dims()); - param->float_score->init(typeid(float)); + param->float_score->init(type_id().hash_code()); fpga::format_fp32_ofm(param->float_score.get()); auto input = param->bbox_deltas_; @@ -437,7 +437,6 @@ void ProposalKernel::Compute(const ProposalParam ¶m) { bbox_height = (uint32_t)(input_bbox->dims()[2]); bbox_width = (uint32_t)(input_bbox->dims()[3]); - // score_tmp->init(typeid(half)); std::shared_ptr score_tmp = std::make_shared(); score_tmp->Resize(param.scores_->dims()); score_tmp->mutable_data(); diff --git a/src/operators/kernel/fpga/V1/slice_kernel.cpp b/src/operators/kernel/fpga/V1/slice_kernel.cpp index 39e5c64b34c2a6b0629a7f2ab07a8683e9c45edd..2fd6ef542e72ab3aceedee22f79bd591a00b7712 100644 --- a/src/operators/kernel/fpga/V1/slice_kernel.cpp +++ b/src/operators/kernel/fpga/V1/slice_kernel.cpp @@ -25,7 +25,7 @@ bool SliceKernel::Init(SliceParam* param) { fpga::format_fp16_ofm(output); DLOG << "input: " << param->input_; DLOG << "output: " << param->output_; - if (param->input_->type() != typeid(half)) { + if (param->input_->type() != type_id()) { DLOG << "wrong type"; } return true; diff --git a/src/operators/kernel/fpga/V1/softmax_kernel.cpp b/src/operators/kernel/fpga/V1/softmax_kernel.cpp index 5537565bc2a4dc7563148617daf47eaa9a50ba91..ba86787c646c3fc67992c76f5ce34efdcb5bbe4a 100644 --- a/src/operators/kernel/fpga/V1/softmax_kernel.cpp +++ b/src/operators/kernel/fpga/V1/softmax_kernel.cpp @@ -26,7 +26,7 @@ bool SoftmaxKernel::Init(SoftmaxParam *param) { auto dims = framework::vectorize(input->dims()); half *input_ptr; auto out = param->Out(); - if (input->type() == typeid(float)) { + if (input->type() == type_id()) { out->Resize(framework::make_ddim(dims)); out->mutable_data(framework::make_ddim(dims)); } else { @@ -50,7 +50,7 @@ bool SoftmaxKernel::Init(SoftmaxParam *param) { if (channel != 2) { // Use CPU out->Resize(framework::make_ddim(dims)); out->mutable_data(framework::make_ddim(dims)); - float_input->init(typeid(float)); + float_input->init(type_id().hash_code()); float_input->mutable_data(framework::make_ddim(dims)); // fpga::format_fp32_ofm(float_input); // fpga::format_fp32_ofm(out); @@ -91,7 +91,7 @@ bool SoftmaxKernel::Init(SoftmaxParam *param) { template <> void SoftmaxKernel::Compute(const SoftmaxParam ¶m) { auto *in_x = (param.InputX()); - if (in_x->type() == typeid(half)) { + if (in_x->type() == type_id()) { fpga::PerformBypass(param.FpgaArgs()); if (param.FpgaArgs().output.activation.activation_type != fpga::SOFTMAX) { Tensor *out = param.Out(); diff --git a/src/operators/math/gemm/cblas.cc b/src/operators/math/gemm/cblas.cc index 058b61f1114c664e8e5ac3ae31f85e4186b9fd8a..4428826552a6a05fc0ee64f173e81d60405d1249 100644 --- a/src/operators/math/gemm/cblas.cc +++ b/src/operators/math/gemm/cblas.cc @@ -14,8 +14,6 @@ limitations under the License. */ #if defined(__ARM_NEON__) || defined(__ARM_NEON) -#pragma once - #include "operators/math/gemm/cblas.h" #include "operators/math/gemm/executor.h" #include "operators/math/gemm/strategy.h" diff --git a/src/operators/one_hot_op.cpp b/src/operators/one_hot_op.cpp index 396f55318a80dc3177a0ae5f4b151eaec7806a6d..4367c2161eed977f2805a25b79a9ce126f0d5953 100644 --- a/src/operators/one_hot_op.cpp +++ b/src/operators/one_hot_op.cpp @@ -14,8 +14,6 @@ limitations under the License. */ #ifdef ONE_HOT_OP -#pragma once - #include "operators/one_hot_op.h" namespace paddle_mobile { diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 8679174e4cd5e3efe3abb0d8a7eff0a0c6290516..e144bf623ff5b28803bb454dbb11fcc810e9ca94 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -19,6 +19,7 @@ limitations under the License. */ #include "common/log.h" #include "common/type_define.h" #include "common/types.h" +#include "framework/attribute.h" #include "framework/lod_tensor.h" #include "framework/scope.h" #include "framework/tensor.h" diff --git a/test/fpga/test_marker_api.cpp b/test/fpga/test_marker_api.cpp index 48038e7b8fa9213e983f3ab25b17c6e8b83b84db..29cf6561df1afae1fae5494bcb8fa6606d3999df 100644 --- a/test/fpga/test_marker_api.cpp +++ b/test/fpga/test_marker_api.cpp @@ -104,7 +104,7 @@ void dump_stride_float(std::string filename, void dump_stride(std::string filename, paddle_mobile::PaddleTensor input_tensor) { - if (input_tensor.dtypeid == typeid(float)) { + if (input_tensor.dtypeid == type_id().hash_code()) { dump_stride_float(filename, input_tensor); } else { std::cout << "only support dumping float data" << std::endl; @@ -156,13 +156,13 @@ int main() { std::cout << "Finishing initializing data" << std::endl; struct PaddleTensor t_img_info, t_img; - t_img_info.dtypeid = typeid(float); + t_img_info.dtypeid = type_id().hash_code(); t_img_info.layout = LAYOUT_HWC; t_img_info.shape = std::vector({1, 3}); t_img_info.name = "Image information"; t_img_info.data.Reset(img_info, 3 * sizeof(float)); - t_img.dtypeid = typeid(float); + t_img.dtypeid = type_id().hash_code(); // quantize(&img, img_length); // t_img.dtypeid = typeid(int8_t); t_img.layout = LAYOUT_HWC; @@ -209,7 +209,7 @@ int main() { std::cout << "Finishing initializing data" << std::endl; struct PaddleTensor t_img1; - t_img1.dtypeid = typeid(float); + t_img1.dtypeid = type_id().hash_code(); t_img1.layout = LAYOUT_HWC; t_img1.shape = std::vector({1, 14, 14, 144}); t_img1.name = "Image information"; diff --git a/test/fpga/test_mobilenet_api.cpp b/test/fpga/test_mobilenet_api.cpp index 4b372773937722942b70c584dda1eeb22339841f..09392e9d38f8a0312715da2aae74e1e039c2452e 100644 --- a/test/fpga/test_mobilenet_api.cpp +++ b/test/fpga/test_mobilenet_api.cpp @@ -96,7 +96,7 @@ void dump_stride_float(std::string filename, PaddleTensor input_tensor) { } void dump_stride(std::string filename, PaddleTensor input_tensor) { - if (input_tensor.dtypeid == typeid(float)) { + if (input_tensor.dtypeid == type_id().hash_code()) { dump_stride_float(filename, input_tensor); } else { std::cout << "only support dumping float data" << std::endl; @@ -131,7 +131,7 @@ int main() { std::cout << "Finishing initializing data" << std::endl; struct PaddleTensor t_img; t_img.dtype = FLOAT32; - t_img.dtypeid = typeid(float); + t_img.dtypeid = type_id().hash_code(); // quantize(&img, img_length); // t_img.dtype = INT8; // t_img.dtypeid = typeid(int8_t); diff --git a/test/fpga/test_rfcn_api.cpp b/test/fpga/test_rfcn_api.cpp index c62eeda9929ecaf1a3aca624301fd274872ea919..e86743cc7e7b8fdb48a034aebd5a53224674b6f5 100644 --- a/test/fpga/test_rfcn_api.cpp +++ b/test/fpga/test_rfcn_api.cpp @@ -20,8 +20,8 @@ limitations under the License. */ #include #include "../../src/io/paddle_inference_api.h" -using namespace paddle_mobile; -using namespace paddle_mobile::fpga; +using namespace paddle_mobile; // NOLINT +using namespace paddle_mobile::fpga; // NOLINT static const char *g_image = "../models/rfcn/data.bin"; static const char *g_model = "../models/rfcn/model"; @@ -86,7 +86,7 @@ int main() { struct PaddleTensor t_img1; - t_img1.dtypeid = typeid(float); + t_img1.dtypeid = type_id().hash_code(); t_img1.layout = LAYOUT_HWC; t_img1.shape = std::vector({1, 224, 224, 3}); t_img1.name = "Image information"; @@ -117,13 +117,13 @@ int main() { std::cout << "Finishing initializing data" << std::endl; struct PaddleTensor t_img_info, t_img; - t_img.dtypeid = typeid(float); + t_img.dtypeid = type_id().hash_code(); t_img_info.layout = LAYOUT_HWC; t_img_info.shape = std::vector({1, 3}); t_img_info.name = "Image information"; t_img_info.data.Reset(img_info, 3 * sizeof(float)); - t_img.dtypeid = typeid(float); + t_img.dtypeid = type_id().hash_code(); t_img.layout = LAYOUT_HWC; t_img.shape = std::vector({1, 432, 1280, 3}); t_img.name = "Image information"; diff --git a/test/fpga/test_yolo_api.cpp b/test/fpga/test_yolo_api.cpp index 4ef890506eb1c40638242b9767267756a64da787..f8f1a48abca74b76f77e7f8d59371b7672a8b453 100644 --- a/test/fpga/test_yolo_api.cpp +++ b/test/fpga/test_yolo_api.cpp @@ -95,7 +95,7 @@ void dump_stride_float(std::string filename, PaddleTensor input_tensor) { } void dump_stride(std::string filename, PaddleTensor input_tensor) { - if (input_tensor.dtypeid == typeid(float)) { + if (input_tensor.dtypeid == type_id().hash_code()) { dump_stride_float(filename, input_tensor); } else { std::cout << "only support dumping float data" << std::endl; @@ -131,10 +131,10 @@ int main() { std::cout << "Finishing initializing data" << std::endl; struct PaddleTensor t_img; // t_img.dtype = FLOAT32; - // t_img.dtypeid = typeid(float); + // t_img.dtypeid = type_id().hash_code(); quantize(&img, img_length); t_img.dtype = INT8; - t_img.dtypeid = typeid(int8_t); + t_img.dtypeid = type_id().hash_code(); t_img.layout = LAYOUT_HWC; t_img.shape = std::vector({1, 256, 416, 3}); t_img.name = "Image information"; diff --git a/test/operators/test_dequantize_op.cpp b/test/operators/test_dequantize_op.cpp index 41390d74a92d9cab615244600079373e84fb31d2..981439c66fdf9902b4451a322099f2e885a1b396 100644 --- a/test/operators/test_dequantize_op.cpp +++ b/test/operators/test_dequantize_op.cpp @@ -19,7 +19,7 @@ limitations under the License. */ namespace paddle_mobile { void dequantize(const Tensor* input, const float scale, Tensor* output) { - const int32_t* x = input->data(); + const int32_t* x = input->data(); float* y = output->mutable_data(); size_t size = output->numel(); for (size_t i = 0; i < size; ++i) { diff --git a/test/operators/test_gru_op.cpp b/test/operators/test_gru_op.cpp index 704a4df0294e46cd661d5b010398baa6fa40a740..b14c4642fd7638aed0473790ac9ca3bc18476160 100644 --- a/test/operators/test_gru_op.cpp +++ b/test/operators/test_gru_op.cpp @@ -20,8 +20,8 @@ namespace paddle_mobile { template int TestGruOp(int in_channels, int out_channels, std::string opname) { - int input_c = in_channels; - int output_c = out_channels; + size_t input_c = in_channels; + size_t output_c = out_channels; paddle_mobile::framework::LoD lod{{0, input_c}}; int batch_size = lod.size(); framework::DDim input_shape = framework::make_ddim({input_c, output_c * 3}); diff --git a/test/operators/test_quantize_op.cpp b/test/operators/test_quantize_op.cpp index 2f8e08806be426e3cb23804514a01b0ca44a0fe1..d8e72e9b1472d0de48143b37ee2a7fe48ad4e174 100644 --- a/test/operators/test_quantize_op.cpp +++ b/test/operators/test_quantize_op.cpp @@ -65,7 +65,7 @@ static void quantize(const Tensor *input, const float scale, Tensor *output) { int output_w = output->dims()[3]; size_t input_spatial = input_h * input_w; size_t output_spatial = output_h * output_w; - const float *x = input->data(); + const float *x = input->data(); int8_t *y = output->mutable_data(); for (int nc = 0; nc < batch_size * channels; ++nc) { @@ -81,7 +81,7 @@ static void quantize(const Tensor *input, const float scale, Tensor *output) { static float find_abs_max(const Tensor *input) { float max_abs = 0.f; - const float *x = input->data(); + const float *x = input->data(); size_t size = input->numel(); for (size_t i = 0; i < size; ++i) { float value = std::abs(x[i]);