From 363f46463240ae0e3e5acd0d9f2d0b7316f14161 Mon Sep 17 00:00:00 2001 From: zhaoyangstar Date: Wed, 12 Aug 2020 09:00:58 +0000 Subject: [PATCH] [Compile] Enable time profile option in tiny_publish, test=develop --- CMakeLists.txt | 2 ++ lite/core/CMakeLists.txt | 2 ++ lite/core/profile/CMakeLists.txt | 2 +- lite/core/profile/profiler.cc | 14 ++++++++------ lite/tools/build.sh | 5 +++++ lite/tools/build_android.sh | 12 ++++++++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e598f1dcd5..ad0bad7fc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,8 @@ if (WITH_LITE AND LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) include(external/gtest) # download, build, install gtest include(ccache) # set ccache for compilation include(external/protobuf) # download, build, install protobuf + elseif (LITE_WITH_PROFILE) + include(external/gflags) # download, build, install gflags endif() # for opencl diff --git a/lite/core/CMakeLists.txt b/lite/core/CMakeLists.txt index d51a93971f..42c3b9e5b8 100644 --- a/lite/core/CMakeLists.txt +++ b/lite/core/CMakeLists.txt @@ -140,6 +140,8 @@ if (NOT LITE_ON_TINY_PUBLISH) add_subdirectory(mir) add_subdirectory(profile) add_subdirectory(arena) +elseif (LITE_WITH_PROFILE) + add_subdirectory(profile) endif() # for mobile, unnecessary to compile the following testings. diff --git a/lite/core/profile/CMakeLists.txt b/lite/core/profile/CMakeLists.txt index b7ddd810af..700ff89ccd 100644 --- a/lite/core/profile/CMakeLists.txt +++ b/lite/core/profile/CMakeLists.txt @@ -5,5 +5,5 @@ endif() lite_cc_library(basic_profiler SRCS basic_profiler.cc DEPS gflags) lite_cc_test(test_basic_profiler SRCS basic_profiler_test.cc DEPS basic_profiler) -lite_cc_library(lite_profiler SRCS profiler.cc DEPS context) +lite_cc_library(lite_profiler SRCS profiler.cc DEPS context gflags) lite_cc_test(test_lite_timer SRCS test_timer.cc DEPS lite_profiler) diff --git a/lite/core/profile/profiler.cc b/lite/core/profile/profiler.cc index e098513883..0fd0d3d500 100644 --- a/lite/core/profile/profiler.cc +++ b/lite/core/profile/profiler.cc @@ -127,14 +127,16 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { // Title. if (concise) { ss << "Timing cycle = " << units_.front().Timer(type)->LapTimes().Size() - << std::endl; + << "\n"; ss << "===== Concise " << TypeStr.find(type)->second << " Profiler Summary: " << name_ << ", Exclude " << w - << " warm-ups =====" << std::endl; + << " warm-ups =====" + << "\n"; } else { ss << "===== Detailed " << TypeStr.find(type)->second << " Profiler Summary: " << name_ << ", Exclude " << w - << " warm-ups =====" << std::endl; + << " warm-ups =====" + << "\n"; } ss << setw(20) << left << "OperatorType" << " " << setw(30) << left << "KerneAttr(Place)" @@ -169,7 +171,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << " " << setw(12) << left << "LocalWorkSize"; } #endif - ss << std::endl; + ss << "\n"; // Profile information. if (concise) { @@ -248,7 +250,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << item.second.cl_max << " " << left << fixed << setprecision(2) << cl_percent << "% "; #endif - ss << std::endl; + ss << "\n"; // clang-format on } } else { @@ -310,7 +312,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << unit.Character().global_work_size << " " << setw(12) << left << fixed << unit.Character().local_work_size; #endif - ss << std::endl; + ss << "\n"; } } return ss.str(); diff --git a/lite/tools/build.sh b/lite/tools/build.sh index 07456e48ef..06da3e47e0 100755 --- a/lite/tools/build.sh +++ b/lite/tools/build.sh @@ -110,6 +110,10 @@ function make_tiny_publish_so { local lang=$3 local android_stl=$4 + if [ ${WITH_PROFILE} == "ON" ]; then + prepare_thirdparty + fi + cur_dir=$(pwd) build_dir=$cur_dir/build.lite.${os}.${abi}.${lang} if [ -d $build_dir ] @@ -134,6 +138,7 @@ function make_tiny_publish_so { -DLITE_ON_TINY_PUBLISH=ON \ -DANDROID_STL_TYPE=$android_stl \ -DLITE_BUILD_EXTRA=$BUILD_EXTRA \ + -DLITE_WITH_PROFILE=${WITH_PROFILE} \ -DLITE_WITH_CV=$BUILD_CV \ -DLITE_BUILD_TAILOR=$BUILD_TAILOR \ -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \ diff --git a/lite/tools/build_android.sh b/lite/tools/build_android.sh index 7f8cd218fd..13092593a8 100755 --- a/lite/tools/build_android.sh +++ b/lite/tools/build_android.sh @@ -32,6 +32,8 @@ MEDIATEK_APU_SDK_ROOT="$(pwd)/apu_ddk" # Download APU SDK from https://paddlelit WITH_OPENCL=OFF # options of adding training ops WITH_TRAIN=OFF +# options of time profile +WITH_PROFILE=OFF # num of threads used during compiling.. readonly NUM_PROC=${LITE_BUILD_THREADS:-4} ##################################################################################################### @@ -146,6 +148,10 @@ function make_tiny_publish_so { prepare_opencl_source_code $workspace $build_dir fi + # 3rd party is needed when profile option is ON + if [ "${WITH_PROFILE}" == "ON" ]; then + prepare_thirdparty + fi local cmake_mutable_options=" -DLITE_BUILD_EXTRA=$WITH_EXTRA \ @@ -155,6 +161,7 @@ function make_tiny_publish_so { -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \ -DLITE_WITH_JAVA=$WITH_JAVA \ -DLITE_WITH_CV=$WITH_CV \ + -DLITE_WITH_PROFILE=$WITH_PROFILE \ -DLITE_WITH_NPU=$WITH_HUAWEI_KIRIN_NPU \ -DNPU_DDK_ROOT=$HUAWEI_KIRIN_NPU_SDK_ROOT \ -DLITE_WITH_APU=$WITH_MEDIATEK_APU \ @@ -329,6 +336,11 @@ function main { WITH_STRIP="${i#*=}" shift ;; + # ON or OFF, default OFF + --with_profile=*) + WITH_PROFILE="${i#*=}" + shift + ;; # string, absolute path to optimized model dir --opt_model_dir=*) OPTMODEL_DIR="${i#*=}" -- GitLab