diff --git a/CMakeLists.txt b/CMakeLists.txt index 32e909e1cce001dff49a90d7753be780e14f08ea..1abe068f0c6a2a54b4bcdcc675630859ef499c63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,32 @@ cmake_minimum_required(VERSION 3.0) project(paddle-mobile) -#add_definitions(-DPADDLE_MOBILE_DEBUG) -#add_definitions(-DENABLE_EXCEPTION) + +option(DEBUGING "enable debug mode" OFF) +option(USE_OPENMP "openmp support" OFF) +option(USE_EXCEPTION "use std exception" OFF) + +if (DEBUGING) + set(CMAKE_BUILD_TYPE Debug) +else() + set(CMAKE_BUILD_TYPE Release) +endif () + +if(DEBUGING) + message(STATUS "debuging") + add_definitions(-DPADDLE_MOBILE_DEBUG) + +else() + message(STATUS "releasing") + add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden) +endif() + +if (USE_EXCEPTION) + add_definitions(-DENABLE_EXCEPTION) + add_definitions(-fexceptions) +else() + add_definitions(-fno-exceptions) + +endif () if(IS_MAC) add_definitions(-DX86) @@ -15,9 +40,7 @@ else () add_definitions(-DX86) endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") -set(CMAKE_BUILD_TYPE Release) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build) @@ -29,7 +52,6 @@ file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h) include_directories(src/) -option(USE_OPENMP "openmp support" OFF) if(USE_OPENMP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") add_definitions(-DPADDLE_MOBILE_USE_OPENMP) @@ -97,6 +119,11 @@ else () add_definitions(-DTRANSPOSE_OP) endif() + add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H}) -add_subdirectory(test) +if(DEBUGING) + add_subdirectory(test) +endif() + + diff --git a/src/common/macros.h b/src/common/macros.h new file mode 100644 index 0000000000000000000000000000000000000000..ee38f19c9285b369e48c550b67f6c397695e73cf --- /dev/null +++ b/src/common/macros.h @@ -0,0 +1,17 @@ +/* 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/framework/data_layout.h b/src/framework/data_layout.h index cb7bad66e3b3c4263a84b2c6f3beae0e82cec9cb..902c057d04f043b31ac8c8d074d928ed09cf3c1b 100644 --- a/src/framework/data_layout.h +++ b/src/framework/data_layout.h @@ -39,7 +39,7 @@ inline DataLayout StringToDataLayout(const std::string &str) { } else if (s == "ANYLAYOUT") { return DataLayout::kAnyLayout; } else { - PADDLE_MOBILE_THROW_EXCEPTION("Unknown storage order string: %s", s) + PADDLE_MOBILE_THROW_EXCEPTION("Unknown storage order string: %s", s.c_str()) } } diff --git a/src/framework/ddim.cpp b/src/framework/ddim.cpp index 925287ebf63562914ce9bc87c8f8120f5d84bee8..3a4a3abb7cd4c632251e6f0190e32c99dd232c01 100644 --- a/src/framework/ddim.cpp +++ b/src/framework/ddim.cpp @@ -277,30 +277,9 @@ int arity(const DDim &d) { ArityVisitor arityVisitor = ArityVisitor(); return DDim::ApplyVistor(arityVisitor, d); } - /// \cond HIDDEN - - /// \endcond - - // struct OSVistor : Vistor { - // OSVistor(std::ostream &os) : os_(os) {} - // - // template - // std::ostream &operator()(Dim dim) const { - // return os_ << dim; - // } - // - // private: - // std::ostream &os_; - //}; - - // std::ostream &operator<<(std::ostream &os, const DDim &ddim) { - // auto vistor = OSVistor(os); - // DDim::ApplyVistor(vistor, ddim); - // return os; - //} #ifdef PADDLE_MOBILE_DEBUG -inline Print &operator<<(Print &printer, const DDim &ddim) { +Print &operator<<(Print &printer, const DDim &ddim) { for (int j = 0; j < ddim.size(); ++j) { printer << ddim[j] << " "; } diff --git a/src/framework/ddim.h b/src/framework/ddim.h index 01317c583fe89f2b5234ce36248c9ed529aa2a33..c1d917dff612de3a42168c47d0bacd3ac7bdd3ad 100644 --- a/src/framework/ddim.h +++ b/src/framework/ddim.h @@ -147,5 +147,9 @@ DDim flatten_to_1d(const DDim &src); DDim stride(const DDim &ddim); DDim stride_numel(const DDim &ddim); + +#ifdef PADDLE_MOBILE_DEBUG +Print &operator<<(Print &printer, const DDim &ddim); +#endif } // namespace framework } // namespace paddle_mobile diff --git a/src/framework/scope.cpp b/src/framework/scope.cpp index 664499d7e635c75ecc277bfc708dda908a25b170..2f7ff247b846f0a5f3e59c5c2f317a59598fc643 100644 --- a/src/framework/scope.cpp +++ b/src/framework/scope.cpp @@ -22,7 +22,6 @@ namespace paddle_mobile { namespace framework { Scope &Scope::NewScope() const { - std::unique_lock lock(mutex_); kids_.push_back(new Scope(this)); return *kids_.back(); } @@ -72,7 +71,6 @@ std::vector Scope::LocalVarNames() const { } void Scope::DeleteScope(Scope *scope) const { - std::unique_lock lock(mutex_); auto it = std::find(kids_.begin(), kids_.end(), scope); kids_.erase(it); delete scope; diff --git a/src/framework/scope.h b/src/framework/scope.h index 27702b88c0c188957b46496dcc4a548a54355c14..d714f61af3bd443c09fcef7aacee2416b90b5e02 100644 --- a/src/framework/scope.h +++ b/src/framework/scope.h @@ -15,7 +15,6 @@ limitations under the License. */ #pragma once #include -#include #include #include "variable.h" @@ -70,8 +69,6 @@ class Scope { mutable std::unordered_map vars_; mutable std::list kids_; Scope const *parent_{nullptr}; - - mutable std::mutex mutex_; }; } // namespace framework } // namespace paddle_mobile diff --git a/src/framework/tensor.h b/src/framework/tensor.h index 674edd67733ef8d0520d28f5c131e9da6746ad17..a22d0ba0e17ab1c9e098a024eee984e817317f2a 100644 --- a/src/framework/tensor.h +++ b/src/framework/tensor.h @@ -14,13 +14,13 @@ limitations under the License. */ #pragma once -#include #include #include #include #include #include #include +#include "common/enforce.h" #include "framework/data_layout.h" #include "framework/ddim.h" diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 22890c4453d8a91b21bc7848a87d8159be804d90..75f6f5ee2215bd5785c791ab8b1b99adf6fa98ae 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -167,8 +167,6 @@ class OpParam { const Scope &scope) { auto var_vec = var_map.at(key); if (!var_vec.empty()) { - // std::cout << " get var value -- " << var_vec[0] << - // std::endl; auto var = scope.FindVar(var_vec[0]); return var->GetMutable(); } else { diff --git a/tools/build.sh b/tools/build.sh index 6a0b7b57929352dce3a26a1f3bd9be6e9719d911..aa59bd3d2834fc83db7bed24e7ee4ac7ea132294 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -46,7 +46,7 @@ build_for_android() { if [ "${PLATFORM}" = "arm-v7a" ]; then ABI="armeabi-v7a with NEON" ARM_PLATFORM="V7" - CXX_FLAGS="-O3 -std=c++11 -s -march=armv7-a -mfpu=neon -mfloat-abi=softfp -pie -fPIE -w -Wno-error=format-security -fno-exceptions" + CXX_FLAGS="-O3 -std=c++11 -s -march=armv7-a -mfpu=neon -mfloat-abi=softfp -pie -fPIE -w -Wno-error=format-security" elif [ "${PLATFORM}" = "arm-v8a" ]; then ABI="arm64-v8a" ARM_PLATFORM="V8"