diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f1a91..1d45ad7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(wenet VERSION 0.1) # 测试模块参数设置 option(GRPC "build with gRPC" OFF) -option(ONNX "build with onnx" ON) +option(ONNX "build with ONNX" OFF) +option(GLOGS "build with GLOGS" OFF) +option(OPENFST "build with FST" ON) # set color string(ASCII 27 Esc) set(ColourReset "${Esc}[m") @@ -17,14 +19,24 @@ set(LIB_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib_files) set(FETCHCONTENT_BASE_DIR ${LIB_BASE_DIR}) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-local) - +if(GLOGS) + include(gflags) + include(glog) + add_executable(glog_main "glogs.cc") + target_link_libraries(glog_main ${third_party_libraries}) +endif() if(GRPC) include(grpc) add_subdirectory(bin_grpc) endif() + if(ONNX) include(onnx) add_executable(main "onnx.cc") - target_link_libraries(main ${third_party_libraries}) + target_link_libraries(onnx_main ${third_party_libraries}) +endif() +if(OPENFST) + include(openfst) + add_executable(fst_main "fst.cc") + target_link_libraries(fst_main ${third_party_libraries} dl) endif() -# 只需要link一个库列表 diff --git a/bin_test/fst.cc b/bin_test/fst.cc new file mode 100644 index 0000000..5364d29 --- /dev/null +++ b/bin_test/fst.cc @@ -0,0 +1,28 @@ +#include +#include + +using namespace fst; +int main() { + // 创建一个新的 FST + StdVectorFst fst; + + // 添加状态 + fst.AddState(); // 0 + fst.AddState(); // 1 + fst.AddState(); // 2 + + // 设置起始状态 + fst.SetStart(0); + + // 添加转移(弧) + fst.AddArc(0, fst::StdArc(1, 1, 1.5, 1)); // 从状态0到状态1,输入符号为1,输出符号为1,权重为1.5,转移标识为1 + fst.AddArc(1, fst::StdArc(2, 2, 2.5, 2)); // 从状态1到状态2,输入符号为2,输出符号为2,权重为2.5,转移标识为2 + + // 设置终止状态 + fst.SetFinal(2, 3.5); // 设置状态2为终止状态,权重为3.5 + + // 输出 FST 的文本表示 + fst.Write("example.fst"); + + return 0; +} \ No newline at end of file diff --git a/bin_test/onnx.cc b/bin_test/onnx.cc index e733c46..ab7ca35 100644 --- a/bin_test/onnx.cc +++ b/bin_test/onnx.cc @@ -1,18 +1,13 @@ #include -#include -#include -#include +#include "onnxruntime_cxx_api.h" // NOLINT using namespace std; -using namespace onnxruntime; int main() { // 初始化ONNX Runtime - OrtSessionOptions session_options; - session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL); - session_options.SetExecutionProvider_CPU(true); - OrtSession session(session_options); - - printf("Run ONNX Done..") + Ort::SessionOptions opt = Ort::SessionOptions(); + Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, ""); + opt.SetIntraOpNumThreads(1); + printf("Run ONNX Done..%d,%f\n"); return 0; } \ No newline at end of file diff --git a/cmake-local/gflags.cmake b/cmake-local/gflags.cmake index 1b78c2c..6942454 100644 --- a/cmake-local/gflags.cmake +++ b/cmake-local/gflags.cmake @@ -1,11 +1,3 @@ -FetchContent_Declare(gflags - SOURCE_DIR ${LIB_BASE_DIR}/gflags-src -) - -set(gflags_DIR ${LIB_BASE_DIR}/gflags-build) - -FetchContent_MakeAvailable(gflags) - -include_directories(${gflags_DIR}/include) +find_package(gflags REQUIRED) list(APPEND third_party_libraries gflags) diff --git a/cmake-local/glog.cmake b/cmake-local/glog.cmake index 57eeb35..be2663e 100644 --- a/cmake-local/glog.cmake +++ b/cmake-local/glog.cmake @@ -1,8 +1,2 @@ -FetchContent_Declare(glog - SOURCE_DIR ${LIB_BASE_DIR}/glog-src -) -set(gflags_DIR ${LIB_BASE_DIR}/gflags-build) - -FetchContent_MakeAvailable(glog) - -list(APPEND third_party_libraries glog) \ No newline at end of file +find_package(glog REQUIRED) +list(APPEND third_party_libraries glog::glog) \ No newline at end of file diff --git a/cmake-local/grpc.cmake b/cmake-local/grpc.cmake index 47189fc..6c09e32 100644 --- a/cmake-local/grpc.cmake +++ b/cmake-local/grpc.cmake @@ -14,10 +14,10 @@ if(NOT EXISTS ${grpc_build_dir}) -B ${grpc_build_dir} WORKING_DIRECTORY ${grpc_build_dir}) execute_process( - COMMAND cmake --build . + COMMAND cmake --build . -j4 WORKING_DIRECTORY ${grpc_build_dir}) execute_process( - COMMAND cmake --install . + COMMAND cmake --install . -j6 WORKING_DIRECTORY ${grpc_build_dir}) execute_process( COMMAND cp -r ${LIB_BASE_DIR}/grpc-src/third_party/abseil-cpp/absl ${grpc_build_dir}/include) @@ -32,6 +32,7 @@ include_directories(${grpc_build_dir}/include) # local proto file set(PROTO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bin_grpc") set(grpc_BINARY_DIR "${grpc_build_dir}/bin") + message(${BoldGreen} protoc:${protobuf_BINARY_DIR}/protoc \n grpc_cpp_plugin:${grpc_BINARY_DIR}/grpc_cpp_plugin\n diff --git a/cmake-local/onnx.cmake b/cmake-local/onnx.cmake index 2fdc9b8..abe9219 100644 --- a/cmake-local/onnx.cmake +++ b/cmake-local/onnx.cmake @@ -2,12 +2,10 @@ set(ONNX_VERSION "1.12.0") set(ONNX_URL "https://github.com/microsoft/onnxruntime/releases/download/v${ONNX_VERSION}/onnxruntime-linux-x64-${ONNX_VERSION}.tgz") set(URL_HASH "SHA256=5d503ce8540358b59be26c675e42081be14a3e833a5301926f555451046929c5") FetchContent_Declare(onnxruntime - URL ${ONNX_URL} - URL_HASH ${URL_HASH}# 2022.3.0 on Dec 20, 2022 - ) + SOURCE_DIR ${LIB_BASE_DIR}/onnxruntime-src) + FetchContent_MakeAvailable(onnxruntime) include_directories(${onnxruntime_SOURCE_DIR}/include) link_directories(${onnxruntime_SOURCE_DIR}/lib) -add_definitions(-DUSE_ONNX) -#message(STATUS CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) -#message(STATUS CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) \ No newline at end of file + +list(APPEND third_party_libraries onnxruntime) \ No newline at end of file diff --git a/cmake-local/openfst.cmake b/cmake-local/openfst.cmake new file mode 100644 index 0000000..9c64e25 --- /dev/null +++ b/cmake-local/openfst.cmake @@ -0,0 +1,52 @@ +# We can't build glog with gflags, unless gflags is pre-installed. +# If build glog with pre-installed gflags, there will be conflict. +#message(STATUS "${BoldGreen}glog: ${glog_SOURCE_DIR}${ColourReset}") + +set(openfst_BUILD "${LIB_BASE_DIR}/openfst-build") +if(NOT EXISTS ${openfst_BUILD}) + # install openfst + #./configure --prefix=${openfst_SOURCE_DIR}/build --enable-static --disable-shared --with-pic + execute_process( + COMMAND ./configure --prefix=${openfst_BUILD} + WORKING_DIRECTORY ${LIB_BASE_DIR}/openfst-src) + execute_process( + COMMAND cmake --build . --target install + WORKING_DIRECTORY ${openfst_BUILD}) + execute_process( + COMMAND cmake --install . + WORKING_DIRECTORY ${openfst_BUILD}) +endif() +# We can't build glog with gflags, unless gflags is pre-installed. +# If build glog with pre-installed gflags, there will be conflict. +find_package(gflags) +set(WITH_GFLAGS OFF CACHE BOOL "whether build glog with gflags" FORCE) +find_package(glog) + +if(NOT GRAPH_TOOLS) + set(HAVE_BIN OFF CACHE BOOL "Build the fst binaries" FORCE) + set(HAVE_SCRIPT OFF CACHE BOOL "Build the fstscript" FORCE) +endif() +set(HAVE_COMPACT OFF CACHE BOOL "Build compact" FORCE) +set(HAVE_CONST OFF CACHE BOOL "Build const" FORCE) +set(HAVE_GRM OFF CACHE BOOL "Build grm" FORCE) +set(HAVE_FAR OFF CACHE BOOL "Build far" FORCE) +set(HAVE_PDT OFF CACHE BOOL "Build pdt" FORCE) +set(HAVE_MPDT OFF CACHE BOOL "Build mpdt" FORCE) +set(HAVE_LINEAR OFF CACHE BOOL "Build linear" FORCE) +set(HAVE_LOOKAHEAD OFF CACHE BOOL "Build lookahead" FORCE) +set(HAVE_NGRAM OFF CACHE BOOL "Build ngram" FORCE) +set(HAVE_SPECIAL OFF CACHE BOOL "Build special" FORCE) + +FetchContent_Declare(openfst + SOURCE_DIR ${LIB_BASE_DIR}/openfst-src) +# +FetchContent_MakeAvailable(openfst) +include_directories(${openfst_SOURCE_DIR}/src/include) +set(openfst_BINARY_DIR "${grpc_build_dir}/src/lib") +add_dependencies(fst glog::glog gflags) + +list(APPEND third_party_libraries fst glog::glog gflags) + +#list(APPEND third_party_libraries ) + +# \ No newline at end of file