diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 96f1e34fdda67fa16eb0c068c931f11c61edd5f8..cd836d7c5b09cc78afe0475ceb4bde4824b65d8e 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -60,7 +60,10 @@ set(FETCHCONTENT_BASE_DIR ${fc_patch}) ############################################################################### # https://github.com/google/brotli/pull/655 option(BUILD_SHARED_LIBS "Build shared libraries" ON) -option(NDEBUG "debug option" OFF) +option(WITH_PPS_DEBUG "debug option" OFF) +if (WITH_PPS_DEBUG) + add_definitions("-DPPS_DEBUG") +endif() option(WITH_ASR "build asr" ON) option(WITH_CLS "build cls" ON) @@ -71,7 +74,7 @@ option(WITH_GPU "NNet using GPU." OFF) option(WITH_PROFILING "enable c++ profling" OFF) option(WITH_TESTING "unit test" ON) -option(WITH_ONNX "u2 support onnx runtime" ON) +option(WITH_ONNX "u2 support onnx runtime" OFF) ############################################################################### # Include Third Party diff --git a/runtime/build.sh b/runtime/build.sh index 12cd23ee387b93330043853731210a034b7e6045..6888901026ed3cd85f1917d163a353c1644e0b18 100755 --- a/runtime/build.sh +++ b/runtime/build.sh @@ -9,9 +9,11 @@ mkdir -p ${BUILD_DIR} BUILD_TYPE=Release #BUILD_TYPE=Debug BUILD_SO=OFF +BUILD_ONNX=ON BUILD_ASR=ON BUILD_CLS=ON BUILD_VAD=ON +PPS_DEBUG=OFF FASTDEPLOY_INSTALL_DIR="" # the build script had verified in the paddlepaddle docker image. @@ -21,9 +23,11 @@ FASTDEPLOY_INSTALL_DIR="" cmake -B ${BUILD_DIR} \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DBUILD_SHARED_LIBS=${BUILD_SO} \ + -DWITH_ONNX=${BUILD_ONNX} \ -DWITH_ASR=${BUILD_ASR} \ -DWITH_CLS=${BUILD_CLS} \ -DWITH_VAD=${BUILD_VAD} \ - -DFASTDEPLOY_INSTALL_DIR=${FASTDEPLOY_INSTALL_DIR} + -DFASTDEPLOY_INSTALL_DIR=${FASTDEPLOY_INSTALL_DIR} \ + -DWITH_PPS_DEBUG=${PPS_DEBUG} cmake --build ${BUILD_DIR} -j diff --git a/runtime/build_android.sh b/runtime/build_android.sh index ac3980a8f51a3c7c7985ead1d5b4cdd170c15089..ce78e67cf68e59b55d8d9fa6d7e34e668975fb98 100755 --- a/runtime/build_android.sh +++ b/runtime/build_android.sh @@ -2,7 +2,7 @@ set -ex -ANDROID_NDK=/workspace/zhanghui/android-sdk/android-ndk-r25c +ANDROID_NDK=/mnt/masimeng/workspace/software/android-ndk-r25b/ # Setting up Android toolchanin ANDROID_ABI=arm64-v8a # 'arm64-v8a', 'armeabi-v7a' @@ -14,7 +14,7 @@ TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake # Create build directory BUILD_ROOT=build/Android BUILD_DIR=${BUILD_ROOT}/${ANDROID_ABI}-api-21 -FASTDEPLOY_INSTALL_DIR="/workspace/zhanghui/paddle/FastDeploy/build/Android/arm64-v8a-api-21/install" +FASTDEPLOY_INSTALL_DIR="/mnt/masimeng/workspace/FastDeploy/build/Android/arm64-v8a-api-21/install" mkdir -p ${BUILD_DIR} cd ${BUILD_DIR} diff --git a/runtime/cmake/glog.cmake b/runtime/cmake/glog.cmake index 91341ca956397bcfff68c338786e1cadc19adf0f..6c38963ae690595c064c5dc8e1b9a9220b2cc998 100644 --- a/runtime/cmake/glog.cmake +++ b/runtime/cmake/glog.cmake @@ -28,7 +28,7 @@ endif() if(ANDROID) add_library(extern_glog INTERFACE) - add_dependencies(glog gflags) + add_dependencies(extern_glog gflags) else() # UNIX add_library(extern_glog ALIAS glog) add_dependencies(glog gflags) diff --git a/runtime/engine/asr/nnet/u2_nnet.cc b/runtime/engine/asr/nnet/u2_nnet.cc index c03d2610cc68c02f50dd758808911faa6a3656d2..968b6ceead3f4854a4539826ca3ec3863418cb2e 100644 --- a/runtime/engine/asr/nnet/u2_nnet.cc +++ b/runtime/engine/asr/nnet/u2_nnet.cc @@ -223,7 +223,7 @@ void U2Nnet::ForwardEncoderChunkImpl( VLOG(3) << "feats shape: " << feats.shape()[0] << ", " << feats.shape()[1] << ", " << feats.shape()[2]; -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("feat", std::ios_base::app | std::ios_base::out); path << offset_; @@ -269,7 +269,7 @@ void U2Nnet::ForwardEncoderChunkImpl( cnn_cache_ = outputs[2]; #endif -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_logits", std::ios_base::app | std::ios_base::out); @@ -299,7 +299,7 @@ void U2Nnet::ForwardEncoderChunkImpl( encoder_outs_.push_back(chunk_out); VLOG(2) << "encoder_outs_ size: " << encoder_outs_.size(); -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_logits_list", std::ios_base::app | std::ios_base::out); @@ -332,7 +332,7 @@ void U2Nnet::ForwardEncoderChunkImpl( CHECK_EQ(outputs.size(), 1); paddle::Tensor ctc_log_probs = outputs[0]; -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_logprob", std::ios_base::app | std::ios_base::out); @@ -371,7 +371,7 @@ void U2Nnet::ForwardEncoderChunkImpl( std::memcpy( out_prob->data(), ctc_log_probs_ptr, T * D * sizeof(kaldi::BaseFloat)); -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_logits_list_ctc", std::ios_base::app | std::ios_base::out); @@ -462,7 +462,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, } } -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_logits_concat", std::ios_base::app | std::ios_base::out); @@ -486,7 +486,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, paddle::Tensor encoder_out = paddle::concat(encoder_outs_, 1); VLOG(2) << "encoder_outs_ size: " << encoder_outs_.size(); -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_out0", std::ios_base::app | std::ios_base::out); @@ -505,7 +505,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, } #endif // end TEST_DEBUG -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("encoder_out", std::ios_base::app | std::ios_base::out); @@ -536,7 +536,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, CHECK_EQ(probs_shape[0], num_hyps); CHECK_EQ(probs_shape[1], max_hyps_len); -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("decoder_logprob", std::ios_base::app | std::ios_base::out); @@ -554,7 +554,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, } #endif // end TEST_DEBUG -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("hyps_lens", std::ios_base::app | std::ios_base::out); @@ -570,7 +570,7 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, } #endif // end TEST_DEBUG -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::stringstream path("hyps_tensor", std::ios_base::app | std::ios_base::out); diff --git a/runtime/engine/cls/nnet/CMakeLists.txt b/runtime/engine/cls/nnet/CMakeLists.txt index 652e05b341ac66a3a1da266c87ca57173553255e..bb7f8eec139e8eb29926edc271d33eb14d415f3d 100644 --- a/runtime/engine/cls/nnet/CMakeLists.txt +++ b/runtime/engine/cls/nnet/CMakeLists.txt @@ -3,7 +3,7 @@ set(srcs panns_interface.cc ) -add_library(cls ${srcs}) +add_library(cls SHARED ${srcs}) target_link_libraries(cls PRIVATE ${FASTDEPLOY_LIBS} kaldi-matrix kaldi-base frontend utils ) set(bin_name panns_nnet_main) diff --git a/runtime/engine/cls/nnet/panns_nnet.cc b/runtime/engine/cls/nnet/panns_nnet.cc index 2edf71f2e517b6b19b9a50d7a4bfc257bcccfb85..6ab7f7bb60e5cdd7f34f32f871a1df9de267d513 100644 --- a/runtime/engine/cls/nnet/panns_nnet.cc +++ b/runtime/engine/cls/nnet/panns_nnet.cc @@ -49,23 +49,22 @@ int ClsNnet::Init(const ClsNnetConf& conf) { // init model fastdeploy::RuntimeOption runtime_option; -#ifdef USE_ORT_BACKEND +#ifdef USE_PADDLE_INFERENCE_BACKEND + runtime_option.SetModelPath(conf.model_file_path_, + conf.param_file_path_, + fastdeploy::ModelFormat::PADDLE); + runtime_option.UsePaddleInferBackend(); +#elif defined(USE_ORT_BACKEND) runtime_option.SetModelPath( conf.model_file_path_, "", fastdeploy::ModelFormat::ONNX); // onnx runtime_option.UseOrtBackend(); // onnx -#endif -#ifdef USE_PADDLE_LITE_BACKEND +#elif defined(USE_PADDLE_LITE_BACKEND) runtime_option.SetModelPath(conf.model_file_path_, conf.param_file_path_, fastdeploy::ModelFormat::PADDLE); runtime_option.UseLiteBackend(); #endif -#ifdef USE_PADDLE_INFERENCE_BACKEND - runtime_option.SetModelPath(conf.model_file_path_, - conf.param_file_path_, - fastdeploy::ModelFormat::PADDLE); - runtime_option.UsePaddleInferBackend(); -#endif + runtime_option.SetCpuThreadNum(conf.num_cpu_thread_); // runtime_option.DeletePaddleBackendPass("simplify_with_basic_ops_pass"); runtime_ = std::unique_ptr(new fastdeploy::Runtime()); @@ -105,7 +104,7 @@ int ClsNnet::Forward(const char* wav_path, conf_.wav_normal_, conf_.wav_normal_type_, conf_.wav_norm_mul_factor_); -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::ofstream fp("cls.wavform", std::ios::out); for (int i = 0; i < wavform.size(); ++i) { @@ -138,7 +137,7 @@ int ClsNnet::Forward(const char* wav_path, feats[i * feat_dim + j] = PowerTodb(feats[i * feat_dim + j]); } } -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::ofstream fp("cls.feat", std::ios::out); for (int i = 0; i < num_frames; ++i) { @@ -162,7 +161,7 @@ int ClsNnet::Forward(const char* wav_path, #ifdef WITH_PROFILING printf("fast deploy infer consume: %fs\n", timer.Elapsed()); #endif -#ifndef NDEBUG +#ifdef PPS_DEBUG { std::ofstream fp("cls.logits", std::ios::out); for (int i = 0; i < model_out.size(); ++i) { diff --git a/runtime/engine/cls/nnet/panns_nnet_main.cc b/runtime/engine/cls/nnet/panns_nnet_main.cc index 4407208231187f6a3a447c78d54440018f5bbb8e..20f3312c97e666d0e7d8195007ba7f0b31fc7881 100644 --- a/runtime/engine/cls/nnet/panns_nnet_main.cc +++ b/runtime/engine/cls/nnet/panns_nnet_main.cc @@ -15,8 +15,8 @@ #include #include -#include "base/flags.h" -#include "base/log.h" +#include "gflags/gflags.h" +#include "glog/logging.h" #include "cls/nnet/panns_interface.h" DEFINE_string(conf_path, "", "config path"); diff --git a/runtime/engine/common/base/log_impl.h b/runtime/engine/common/base/log_impl.h index 2cc96c45cea3655f1d90b0052bf746cc58665b1f..fd6cce19248999879a0969c4c683d983633da345 100644 --- a/runtime/engine/common/base/log_impl.h +++ b/runtime/engine/common/base/log_impl.h @@ -90,7 +90,7 @@ class LogMessage { } // namespace ppspeech -#ifdef NDEBUG +#ifndef PPS_DEBUG #define DLOG_INFO \ ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::INFO, false) #define DLOG_WARNING \ @@ -145,7 +145,7 @@ class LogMessage { #define CHECK_LT(x, y) CHECK((x) < (y)) #define CHECK_GE(x, y) CHECK((x) >= (y)) #define CHECK_GT(x, y) CHECK((x) > (y)) -#ifndef NDEBUG +#ifdef PPS_DEBUG #define DCHECK(x) CHECK(x) #define DCHECK_EQ(x, y) CHECK_EQ(x, y) #define DCHECK_NE(x, y) CHECK_NE(x, y) @@ -153,7 +153,7 @@ class LogMessage { #define DCHECK_LT(x, y) CHECK_LT(x, y) #define DCHECK_GE(x, y) CHECK_GE(x, y) #define DCHECK_GT(x, y) CHECK_GT(x, y) -#else // NDEBUG +#else #define DCHECK(condition) \ while (false) CHECK(condition) #define DCHECK_EQ(val1, val2) \ diff --git a/runtime/engine/common/frontend/CMakeLists.txt b/runtime/engine/common/frontend/CMakeLists.txt index e63049d3bbc9500cccde9041703d80f3e5c31ac7..0b95b650354f605e49dd2650f326db45d55f0262 100644 --- a/runtime/engine/common/frontend/CMakeLists.txt +++ b/runtime/engine/common/frontend/CMakeLists.txt @@ -7,6 +7,7 @@ add_library(kaldi-native-fbank-core rfft.cc ) target_link_libraries(kaldi-native-fbank-core PUBLIC utils base) +target_compile_options(kaldi-native-fbank-core PUBLIC "-fPIC") add_library(frontend STATIC cmvn.cc diff --git a/runtime/engine/kaldi/base/kaldi-error.h b/runtime/engine/kaldi/base/kaldi-error.h index a9904a752cda6dc278f7e7855953e22685f8d8e9..98bef74fcb6ca2ea18b718e83e8905c5f3c69951 100644 --- a/runtime/engine/kaldi/base/kaldi-error.h +++ b/runtime/engine/kaldi/base/kaldi-error.h @@ -181,7 +181,7 @@ private: // Also see KALDI_COMPILE_TIME_ASSERT, defined in base/kaldi-utils.h, and // KALDI_ASSERT_IS_INTEGER_TYPE and KALDI_ASSERT_IS_FLOATING_TYPE, also defined // there. -#ifndef NDEBUG +#ifdef PPS_DEBUG #define KALDI_ASSERT(cond) \ do { \ if (cond) \ diff --git a/runtime/engine/vad/interface/CMakeLists.txt b/runtime/engine/vad/interface/CMakeLists.txt index 29c3f31ab47fa104ac0d6bb4e45a6d9922189ba7..e056ec398bed3eddf00e073ff4878470295e6543 100644 --- a/runtime/engine/vad/interface/CMakeLists.txt +++ b/runtime/engine/vad/interface/CMakeLists.txt @@ -2,7 +2,7 @@ set(srcs vad_interface.cc ) -add_library(pps_vad_interface ${srcs}) +add_library(pps_vad_interface SHARED ${srcs}) target_link_libraries(pps_vad_interface PUBLIC pps_vad extern_glog) diff --git a/runtime/engine/vad/nnet/CMakeLists.txt b/runtime/engine/vad/nnet/CMakeLists.txt index c1dec533ceb3b122cc59d4804c4539dc89a9cb77..3ca951d9005af17dc3379ec46b218b3154b87a74 100644 --- a/runtime/engine/vad/nnet/CMakeLists.txt +++ b/runtime/engine/vad/nnet/CMakeLists.txt @@ -12,4 +12,8 @@ target_link_libraries(${bin_name} pps_vad) file(RELATIVE_PATH DEST_DIR ${ENGINE_ROOT} ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS pps_vad DESTINATION lib) -install(TARGETS glog DESTINATION lib) \ No newline at end of file +if(ANDROID) + install(TARGETS extern_glog DESTINATION lib) +else() # UNIX + install(TARGETS glog DESTINATION lib) +endif()