From 1cdb7b7cf8bafaf346ff0f96d3a440b93588eed2 Mon Sep 17 00:00:00 2001 From: wangliu Date: Thu, 7 Jun 2018 17:45:53 +0800 Subject: [PATCH] control compile commands by build mode --- CMakeLists.txt | 25 +++++++++++++++++++------ src/common/macros.h | 3 +++ src/framework/data_layout.h | 2 +- src/framework/ddim.cpp | 23 +---------------------- src/framework/ddim.h | 4 ++++ src/operators/op_param.h | 2 -- tools/build.sh | 2 +- 7 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 src/common/macros.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 32e909e1cc..a97ce28c92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,22 @@ cmake_minimum_required(VERSION 3.0) project(paddle-mobile) -#add_definitions(-DPADDLE_MOBILE_DEBUG) -#add_definitions(-DENABLE_EXCEPTION) + +option(DEBUGING "enable debug mode" ON) +option(USE_OPENMP "openmp support" OFF) + +if (DEBUGING) + set(CMAKE_BUILD_TYPE Release) + else() + set(CMAKE_BUILD_TYPE debug) +endif () + +if(DEBUGING) + add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden) + add_definitions(-fno-exceptions) +else() + add_definitions(-DPADDLE_MOBILE_DEBUG) + add_definitions(-DENABLE_EXCEPTION) +endif() if(IS_MAC) add_definitions(-DX86) @@ -15,9 +30,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 +42,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 +109,7 @@ else () add_definitions(-DTRANSPOSE_OP) endif() + add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H}) -add_subdirectory(test) +#add_subdirectory(test) diff --git a/src/common/macros.h b/src/common/macros.h new file mode 100644 index 0000000000..e6773f2e18 --- /dev/null +++ b/src/common/macros.h @@ -0,0 +1,3 @@ +#pragma once + +#define EXPORT __attribute__((visibility("default"))) \ No newline at end of file diff --git a/src/framework/data_layout.h b/src/framework/data_layout.h index cb7bad66e3..902c057d04 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 925287ebf6..3a4a3abb7c 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 01317c583f..c1d917dff6 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/operators/op_param.h b/src/operators/op_param.h index 22890c4453..75f6f5ee22 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 6a0b7b5792..aa59bd3d28 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" -- GitLab