diff --git a/CMakeLists.txt b/CMakeLists.txt index 83da232f9f56565028ca95876f7ecfbbf355a253..1007e46bf593449373c4b279c0c949024bb445eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ option(USE_EXCEPTION "use std exception" ON) option(LOG_PROFILE "log profile" ON) # select the platform to build option(CPU "cpu" ON) -option(MALI_GPU "mali gpu" OFF) +option(MALI_GPU "mali gpu" ON) option(FPGA "fpga" OFF) if (CPU) diff --git a/src/common/types.cpp b/src/common/types.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2193b440a691de27570a0341f67fd6039d26b1bb --- /dev/null +++ b/src/common/types.cpp @@ -0,0 +1,68 @@ +/* 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. */ + +#include "common/types.h" +#include + +namespace paddle_mobile { + +const std::string G_OP_TYPE_CONV = "conv2d"; +const std::string G_OP_TYPE_BATCHNORM = "batch_norm"; +const std::string G_OP_TYPE_BOX_CODER = "box_coder"; +const std::string G_OP_TYPE_CONCAT = "concat"; +const std::string G_OP_TYPE_ELEMENTWISE_ADD = "elementwise_add"; +const std::string G_OP_TYPE_FUSION_CONV_ADD_RELU = "fusion_conv_add_relu"; +const std::string G_OP_TYPE_FC = "fc"; +const std::string G_OP_TYPE_CONV_ADD = "conv_add"; +const std::string G_OP_TYPE_LRN = "lrn"; +const std::string G_OP_TYPE_MUL = "mul"; +const std::string G_OP_TYPE_MULTICLASS_NMS = "multiclass_nms"; +const std::string G_OP_TYPE_POOL2D = "pool2d"; +const std::string G_OP_TYPE_PRIOR_BOX = "prior_box"; +const std::string G_OP_TYPE_RELU = "relu"; +const std::string G_OP_TYPE_RESHAPE = "reshape"; +const std::string G_OP_TYPE_SIGMOID = "sigmoid"; +const std::string G_OP_TYPE_SOFTMAX = "softmax"; +const std::string G_OP_TYPE_TRANSPOSE = "transpose"; +const std::string G_OP_TYPE_SPLIT = "split"; +const std::string G_OP_TYPE_FEED = "feed"; +const std::string G_OP_TYPE_FETCH = "fetch"; +const std::string G_OP_TYPE_DEPTHWISE_CONV = "depthwise_conv2d"; + +std::unordered_map< + std::string, std::pair, std::vector>> + op_input_output_key = { + {G_OP_TYPE_CONV, {{"Input"}, {"Output"}}}, + {G_OP_TYPE_CONV_ADD, {{"Input"}, {"Out"}}}, + {G_OP_TYPE_RELU, {{"X"}, {"Out"}}}, + {G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}}, + {G_OP_TYPE_MUL, {{"X"}, {"Out"}}}, + {G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}}, + {G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}}, + {G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}}, + {G_OP_TYPE_LRN, {{"X"}, {"Out"}}}, + {G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}}, + {G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}}, + {G_OP_TYPE_FEED, {{"X"}, {"Out"}}}, + {G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}, + {G_OP_TYPE_TRANSPOSE, {{"X"}, {"Out"}}}, + {G_OP_TYPE_BOX_CODER, + {{"PriorBox", "PriorBoxVar", "TargetBox"}, {"OutputBox"}}}, + {G_OP_TYPE_PRIOR_BOX, {{"Image", "Input"}, {"Boxes", "Variances"}}}, + {G_OP_TYPE_MULTICLASS_NMS, {{"BBoxes", "Scores"}, {"Out"}}}, + {G_OP_TYPE_FC, {{"X", "Y", "Z"}, {"Out"}}}, + {G_OP_TYPE_RESHAPE, {{"X"}, {"Out"}}}, + {G_OP_TYPE_DEPTHWISE_CONV, {{"Input"}, {"Output"}}}}; + +} // namespace paddle_mobile diff --git a/src/common/types.h b/src/common/types.h index 73252749be33312520c17511bbfaceadfde7bf7d..30a0663eeef899e3b8ff35bcb062824417362efc 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -71,52 +71,31 @@ enum PMStatus { PMWrongDevice = 0x08 /*!< un-correct device. */ }; -static const std::string G_OP_TYPE_CONV = "conv2d"; -static const std::string G_OP_TYPE_BATCHNORM = "batch_norm"; -static const std::string G_OP_TYPE_BOX_CODER = "box_coder"; -static const std::string G_OP_TYPE_CONCAT = "concat"; -static const std::string G_OP_TYPE_ELEMENTWISE_ADD = "elementwise_add"; -static const std::string G_OP_TYPE_FUSION_CONV_ADD_RELU = - "fusion_conv_add_relu"; -static const std::string G_OP_TYPE_FC = "fc"; -static const std::string G_OP_TYPE_CONV_ADD = "conv_add"; -static const std::string G_OP_TYPE_LRN = "lrn"; -static const std::string G_OP_TYPE_MUL = "mul"; -static const std::string G_OP_TYPE_MULTICLASS_NMS = "multiclass_nms"; -static const std::string G_OP_TYPE_POOL2D = "pool2d"; -static const std::string G_OP_TYPE_PRIOR_BOX = "prior_box"; -static const std::string G_OP_TYPE_RELU = "relu"; -static const std::string G_OP_TYPE_RESHAPE = "reshape"; -static const std::string G_OP_TYPE_SIGMOID = "sigmoid"; -static const std::string G_OP_TYPE_SOFTMAX = "softmax"; -static const std::string G_OP_TYPE_TRANSPOSE = "transpose"; -static const std::string G_OP_TYPE_SPLIT = "split"; -static const std::string G_OP_TYPE_FEED = "feed"; -static const std::string G_OP_TYPE_FETCH = "fetch"; -static const std::string G_OP_TYPE_DEPTHWISE_CONV = "depthwise_conv2d"; +extern const std::string G_OP_TYPE_CONV; +extern const std::string G_OP_TYPE_BATCHNORM; +extern const std::string G_OP_TYPE_BOX_CODER; +extern const std::string G_OP_TYPE_CONCAT; +extern const std::string G_OP_TYPE_ELEMENTWISE_ADD; +extern const std::string G_OP_TYPE_FUSION_CONV_ADD_RELU; +extern const std::string G_OP_TYPE_FC; +extern const std::string G_OP_TYPE_CONV_ADD; +extern const std::string G_OP_TYPE_LRN; +extern const std::string G_OP_TYPE_MUL; +extern const std::string G_OP_TYPE_MULTICLASS_NMS; +extern const std::string G_OP_TYPE_POOL2D; +extern const std::string G_OP_TYPE_PRIOR_BOX; +extern const std::string G_OP_TYPE_RELU; +extern const std::string G_OP_TYPE_RESHAPE; +extern const std::string G_OP_TYPE_SIGMOID; +extern const std::string G_OP_TYPE_SOFTMAX; +extern const std::string G_OP_TYPE_TRANSPOSE; +extern const std::string G_OP_TYPE_SPLIT; +extern const std::string G_OP_TYPE_FEED; +extern const std::string G_OP_TYPE_FETCH; +extern const std::string G_OP_TYPE_DEPTHWISE_CONV; -static std::unordered_map< +extern std::unordered_map< std::string, std::pair, std::vector>> - op_input_output_key = { - {G_OP_TYPE_CONV, {{"Input"}, {"Output"}}}, - {G_OP_TYPE_CONV_ADD, {{"Input"}, {"Out"}}}, - {G_OP_TYPE_RELU, {{"X"}, {"Out"}}}, - {G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}}, - {G_OP_TYPE_MUL, {{"X"}, {"Out"}}}, - {G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}}, - {G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}}, - {G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}}, - {G_OP_TYPE_LRN, {{"X"}, {"Out"}}}, - {G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}}, - {G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}}, - {G_OP_TYPE_FEED, {{"X"}, {"Out"}}}, - {G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}, - {G_OP_TYPE_TRANSPOSE, {{"X"}, {"Out"}}}, - {G_OP_TYPE_BOX_CODER, - {{"PriorBox", "PriorBoxVar", "TargetBox"}, {"OutputBox"}}}, - {G_OP_TYPE_PRIOR_BOX, {{"Image", "Input"}, {"Boxes", "Variances"}}}, - {G_OP_TYPE_MULTICLASS_NMS, {{"BBoxes", "Scores"}, {"Out"}}}, - {G_OP_TYPE_FC, {{"X", "Y", "Z"}, {"Out"}}}, - {G_OP_TYPE_RESHAPE, {{"X"}, {"Out"}}}, - {G_OP_TYPE_DEPTHWISE_CONV, {{"Input"}, {"Output"}}}}; + op_input_output_key; + } // namespace paddle_mobile diff --git a/src/framework/operator.h b/src/framework/operator.h index 6ca0999f706f5e4e62270745c55dc78ee82f9b65..6a89884e9beb23878b422f77a5ed2851da6950e6 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -111,7 +111,8 @@ class OperatorWithKernel : public OperatorBase { std::shared_ptr scope) : OperatorBase(type, inputs, outputs, attrs, scope), param_(inputs, outputs, attrs, *scope) { - kernel_.Init(param_); + PADDLE_MOBILE_ENFORCE(kernel_.Init(param_), " %s kernel init failed", + this->type_.c_str()); } virtual void RunImpl() const { this->kernel_.Compute(this->param_); } diff --git a/src/io/io.cpp b/src/io/io.cpp index c60113bb7882b7482cf5a23e4ad48adb6ec63de8..91f8c5727c91a07a8dceb6f2ac9b848989ec830c 100644 --- a/src/io/io.cpp +++ b/src/io/io.cpp @@ -160,6 +160,8 @@ const framework::Program Loader::LoadProgram( } template class Loader; +template class Loader; +template class Loader; #pragma mark - executor @@ -205,7 +207,10 @@ void Executor::LoadMemory(const framework::VarDesc var_desc, data += sizeof(uint32_t); // 2 Lod information - uint64_t lod_level = *(uint64_t *)data; + uint64_t *lod_level_ptr = new uint64_t(); + memcpy(lod_level_ptr, data, sizeof(uint64_t)); + uint64_t lod_level = *lod_level_ptr; + delete lod_level_ptr; data += sizeof(uint64_t); auto &lod = *tensor->mutable_lod(); @@ -410,5 +415,7 @@ std::vector::Ptype> Executor::Predict( } template class Executor; +template class Executor; +template class Executor; } // namespace paddle_mobile diff --git a/test/net/test_googlenet.cpp b/test/net/test_googlenet.cpp index 6bae5136b60160bdf66faa6b00b0bd05607af0b6..e1bcd5212de214abbf2df5822ebc977619f8caa3 100644 --- a/test/net/test_googlenet.cpp +++ b/test/net/test_googlenet.cpp @@ -20,9 +20,9 @@ int main() { paddle_mobile::Loader loader; bool optimize = true; auto time1 = time(); - auto program = loader.Load(g_googlenet, optimize); - // auto program = loader.Load(g_googlenet_combine + "/model", - // g_googlenet_combine + "/params", optimize); + // auto program = loader.Load(g_googlenet, optimize); + auto program = loader.Load(g_googlenet_combine + "/model", + g_googlenet_combine + "/params", optimize); auto time2 = time(); DLOG << "load cost :" << time_diff(time1, time2) << "ms\n"; paddle_mobile::Executor executor(program, 1, optimize);