From 5888ee8b812d0b81493403ac75f445ae451ca823 Mon Sep 17 00:00:00 2001 From: Vineel Pratap Date: Tue, 5 Jan 2021 19:41:14 -0800 Subject: [PATCH] Fix w2l@anywhere inference build (#930) Summary: - Fix build for inference pipeline Pull Request resolved: https://github.com/facebookresearch/wav2letter/pull/930 Differential Revision: D25783104 Pulled By: vineelpratap fbshipit-source-id: a0024f46ffb335d7cdc83ce0700a889491bc7228 --- .../inference/CMakeLists.txt | 169 +++++++----------- .../{Buildcereal.cmake => BuildCereal.cmake} | 10 +- .../inference/cmake/BuildGoogleTest.cmake | 80 +++++++++ .../inference/cmake/BuildKenlm.cmake | 51 ++++++ .../inference/cmake/FindGMock.cmake | 58 ++++++ .../inference/cmake/Findcereal.cmake | 53 ++++-- .../inference/cmake/Findkenlm.cmake | 95 ++++++++++ .../inference/cmake/TestUtils.cmake | 63 +++++++ .../cmake/streaming_inferenceConfig.cmake | 10 ++ .../{inference => }/examples/AudioToWords.cpp | 4 +- .../{inference => }/examples/AudioToWords.h | 0 .../{inference => }/examples/CMakeLists.txt | 11 +- .../InteractiveStreamingASRExample.cpp | 4 +- .../MultithreadedStreamingASRExample.cpp | 6 +- .../examples/SimpleStreamingASRExample.cpp | 4 +- .../{inference => }/examples/Util.cpp | 2 +- .../inference/{inference => }/examples/Util.h | 0 .../examples/threadpool/COPYING | 0 .../examples/threadpool/ThreadPool.h | 0 .../inference/inference/common/CMakeLists.txt | 4 +- .../inference/decoder/CMakeLists.txt | 7 +- .../inference/inference/decoder/Decoder.cpp | 24 ++- .../inference/inference/module/CMakeLists.txt | 4 +- .../inference/module/feature/CMakeLists.txt | 4 +- .../inference/module/nn/CMakeLists.txt | 16 +- .../module/nn/backend/fbgemm/CMakeLists.txt | 6 +- .../nn/backend/fbgemm/cmake/BuildFbGemm.cmake | 2 +- .../inference/inference/module/nn/nn.h | 2 +- .../inference/test/CMakeLists.txt | 19 ++ .../module => }/test/Conv1dTest.cpp | 0 .../module => }/test/IdentityTest.cpp | 0 .../module => }/test/LayerNormTest.cpp | 2 +- .../module => }/test/LinearTest.cpp | 0 .../module => }/test/LogMelFeatureTest.cpp | 2 +- .../module => }/test/MemoryManagerTest.cpp | 0 .../{inference/module => }/test/ReluTest.cpp | 0 .../module => }/test/ResidualTest.cpp | 2 +- .../module => }/test/TDSBlockTest.cpp | 2 +- .../{inference/module => }/test/TestUtils.h | 3 + .../inference/tools/CMakeLists.txt | 25 +++ .../{ => inference}/tools/README.md | 0 .../tools/StreamingTDSModelConverter.cpp | 9 +- 42 files changed, 566 insertions(+), 187 deletions(-) rename recipes/streaming_convnets/inference/cmake/{Buildcereal.cmake => BuildCereal.cmake} (80%) create mode 100644 recipes/streaming_convnets/inference/cmake/BuildGoogleTest.cmake create mode 100644 recipes/streaming_convnets/inference/cmake/BuildKenlm.cmake create mode 100644 recipes/streaming_convnets/inference/cmake/FindGMock.cmake create mode 100644 recipes/streaming_convnets/inference/cmake/Findkenlm.cmake create mode 100644 recipes/streaming_convnets/inference/cmake/TestUtils.cmake create mode 100644 recipes/streaming_convnets/inference/cmake/streaming_inferenceConfig.cmake rename recipes/streaming_convnets/inference/{inference => }/examples/AudioToWords.cpp (98%) rename recipes/streaming_convnets/inference/{inference => }/examples/AudioToWords.h (100%) rename recipes/streaming_convnets/inference/{inference => }/examples/CMakeLists.txt (91%) rename recipes/streaming_convnets/inference/{inference => }/examples/InteractiveStreamingASRExample.cpp (99%) rename recipes/streaming_convnets/inference/{inference => }/examples/MultithreadedStreamingASRExample.cpp (98%) rename recipes/streaming_convnets/inference/{inference => }/examples/SimpleStreamingASRExample.cpp (99%) rename recipes/streaming_convnets/inference/{inference => }/examples/Util.cpp (98%) rename recipes/streaming_convnets/inference/{inference => }/examples/Util.h (100%) rename recipes/streaming_convnets/inference/{inference => }/examples/threadpool/COPYING (100%) rename recipes/streaming_convnets/inference/{inference => }/examples/threadpool/ThreadPool.h (100%) create mode 100644 recipes/streaming_convnets/inference/test/CMakeLists.txt rename recipes/streaming_convnets/inference/{inference/module => }/test/Conv1dTest.cpp (100%) rename recipes/streaming_convnets/inference/{inference/module => }/test/IdentityTest.cpp (100%) rename recipes/streaming_convnets/inference/{inference/module => }/test/LayerNormTest.cpp (98%) rename recipes/streaming_convnets/inference/{inference/module => }/test/LinearTest.cpp (100%) rename recipes/streaming_convnets/inference/{inference/module => }/test/LogMelFeatureTest.cpp (97%) rename recipes/streaming_convnets/inference/{inference/module => }/test/MemoryManagerTest.cpp (100%) rename recipes/streaming_convnets/inference/{inference/module => }/test/ReluTest.cpp (100%) rename recipes/streaming_convnets/inference/{inference/module => }/test/ResidualTest.cpp (99%) rename recipes/streaming_convnets/inference/{inference/module => }/test/TDSBlockTest.cpp (99%) rename recipes/streaming_convnets/inference/{inference/module => }/test/TestUtils.h (97%) create mode 100644 recipes/streaming_convnets/inference/tools/CMakeLists.txt rename recipes/streaming_convnets/{ => inference}/tools/README.md (100%) rename recipes/streaming_convnets/{ => inference}/tools/StreamingTDSModelConverter.cpp (97%) diff --git a/recipes/streaming_convnets/inference/CMakeLists.txt b/recipes/streaming_convnets/inference/CMakeLists.txt index 0cc4c055..4d589d16 100644 --- a/recipes/streaming_convnets/inference/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/CMakeLists.txt @@ -1,73 +1,72 @@ -cmake_minimum_required(VERSION 3.5.1) +cmake_minimum_required(VERSION 3.10) -project(wav2letter-inference) +# Creates build rules for streaming inference -# Creates build rules for wav2letter inference processing graph. +project(streaming_inference CXX C) -include(GNUInstallDirs) - -option(W2L_INFERENCE_BUILD_TESTS - "Build tests for wav2letter-inference" ON) -option(W2L_INFERENCE_BUILD_EXAMPLES - "Build examples for wav2letter-inference" ON) +option(STREAMING_INFERENCE_BUILD_TESTS + "Build tests for streaming_inference" ON) +option(STREAMING_INFERENCE_BUILD_EXAMPLES + "Build examples for streaming_inference" ON) +option(STREAMING_INFERENCE_BUILD_TOOLS + "Build converter tools for streaming_inference" ON) set(KENLM_MAX_ORDER 6 CACHE STRING "Maximum ngram order for KenLM" ) +#--- Find flashlight --- +find_package(flashlight CONFIG REQUIRED) +if (NOT TARGET flashlight::fl-libraries) + message(FATAL_ERROR "flashlight::fl-libraries must be built for streaming inference") +endif () + # Inference backend names MUST match paths along # inference/module/nn/backend/{backend_name} set(AVAILABLE_INFERENCE_BACKENDS fbgemm) -set(W2L_INFERENCE_BACKEND fbgemm CACHE +set(STREAMING_INFERENCE_BACKEND fbgemm CACHE STRING "Inference backend library" ) set_property( CACHE - W2L_INFERENCE_BACKEND + STREAMING_INFERENCE_BACKEND PROPERTY STRINGS ${AVAILABLE_INFERENCE_BACKENDS} ) + +# C++ 14 is required set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_library(wav2letter-inference "") +add_library(streaming_inference "") list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) -#--- Find gflags --- +#--- Find GFlags --- find_package(gflags REQUIRED) -if (gflags_FOUND) - message(STATUS "gflags found") -else() - message(FATAL_ERROR "gflags not found") -endif() -#--- Download and build Google test --- -# Only if we're not building w2l tests elsewhere, else we'll -# define the same custom target twice with ExternalProject_add -include(BuildGoogleTest) - -#--- Download/build Cereal --- -set(CEREAL_INSTALL_PATH ${CMAKE_CURRENT_LIST_DIR}/cereal) -include(Buildcereal) -# Move cereal headers -install(DIRECTORY ${CEREAL_SOURCE_DIR}/include/cereal - DESTINATION ${CEREAL_INSTALL_PATH} - COMPONENT cereal - FILES_MATCHING - PATTERN "*.hpp" - PATTERN "*.h" - PATTERN ".git" EXCLUDE -) - -install( - FILES - ${CEREAL_SOURCE_DIR}/LICENSE - ${CEREAL_SOURCE_DIR}/README.md - DESTINATION - ${CEREAL_INSTALL_PATH} -) +#--- Find/build Cereal --- +# If cereal is found in a user-defined location, use it rather than +# downloading from source +find_package(cereal) +if (NOT TARGET cereal AND NOT cereal_FOUND) + message(STATUS "cereal NOT found. Will download from source") + set(CEREAL_INSTALL_PATH ${FL_INSTALL_INC_DIR}/cereal) + include(${CMAKE_MODULE_PATH}/BuildCereal.cmake) + # Move cereal headers at install time + install(DIRECTORY ${CEREAL_SOURCE_DIR}/include/cereal + DESTINATION ${CEREAL_INSTALL_PATH} + COMPONENT cereal + FILES_MATCHING + PATTERN "*.hpp" + PATTERN "*.h" + PATTERN ".git" EXCLUDE + ) + install(FILES ${CEREAL_SOURCE_DIR}/LICENSE ${CEREAL_SOURCE_DIR}/README.md + DESTINATION ${CEREAL_INSTALL_PATH} + ) +endif() # ------------------ add subdirectories -------------------- @@ -81,95 +80,51 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/inference/decoder) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/inference/module) # Creates executable targets foreach example. -if (W2L_INFERENCE_BUILD_EXAMPLES) - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/inference/examples) +if (STREAMING_INFERENCE_BUILD_EXAMPLES) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples) endif() # ------------------------ Tests ------------------------ -add_custom_target(inference_tests) - -# Builds a single test source file. -function(build_test SRCFILE) - get_filename_component(target ${SRCFILE} NAME_WE) - set(target inference_${target}) - message(STATUS "Tests: add executable ${target}") - add_executable(${target} ${SRCFILE}) - add_dependencies(wav2letter-inference ${target}) - add_dependencies(${target} gtest) # make sure gtest is built first - add_dependencies(inference_tests ${target}) - target_link_libraries( - ${target} - PRIVATE - ${GTEST_LIBRARIES} - streaming_inference_common - streaming_inference_decoder - streaming_inference_modules - Threads::Threads - ) - target_include_directories( - ${target} - PRIVATE - ${CMAKE_SOURCE_DIR} - ${GTEST_INCLUDE_DIR} - # going up one directory to use #include "inference/*/*.h" - ${wav2letter-inference_SOURCE_DIR} - ${W2L_INFERENCE_TESTS_PATH} - ${cereal_INCLUDE_DIRS} - ) - add_test(${target} ${target}) -endfunction(build_test) - -set(W2L_INFERENCE_TESTS_PATH - ${wav2letter-inference_SOURCE_DIR}/inference/module/test) - -set(W2L_INFERENCE_TESTS_SOURCES - ${W2L_INFERENCE_TESTS_PATH}/Conv1dTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/IdentityTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/LayerNormTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/LinearTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/LogMelFeatureTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/MemoryManagerTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/ReluTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/ResidualTest.cpp - ${W2L_INFERENCE_TESTS_PATH}/TDSBlockTest.cpp -) - -if (W2L_INFERENCE_BUILD_TESTS) - find_package(Threads REQUIRED) +# Creates executable targets foreach example. +if (STREAMING_INFERENCE_BUILD_TESTS) enable_testing() - foreach(SRC_FILE ${W2L_INFERENCE_TESTS_SOURCES}) - build_test(${SRC_FILE}) - endforeach() + include(TestUtils) + # add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test) // FIXME +endif() + +# ------------------------ Tools ------------------------ +if (STREAMING_INFERENCE_BUILD_TOOLS) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools) endif() -# -------------- wav2letter-inference top level target ----------------- +# -------------- streaming_inference top level target ----------------- set_target_properties( - wav2letter-inference + streaming_inference PROPERTIES LINKER_LANGUAGE CXX - CXX_STANDARD 11 + CXX_STANDARD 14 ) target_include_directories( - wav2letter-inference + streaming_inference PUBLIC - ${wav2letter-inference_SOURCE_DIR} + ${streaming_inference_SOURCE_DIR} ) target_link_libraries( - wav2letter-inference + streaming_inference PUBLIC streaming_inference_common streaming_inference_decoder streaming_inference_modules ) -install(TARGETS wav2letter-inference - EXPORT wav2letter-inference-export +install(TARGETS streaming_inference + EXPORT streaming_inference-export LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin - INCLUDES DESTINATION include/wav2letter/inference + INCLUDES DESTINATION include/inference ) diff --git a/recipes/streaming_convnets/inference/cmake/Buildcereal.cmake b/recipes/streaming_convnets/inference/cmake/BuildCereal.cmake similarity index 80% rename from recipes/streaming_convnets/inference/cmake/Buildcereal.cmake rename to recipes/streaming_convnets/inference/cmake/BuildCereal.cmake index 747db712..ade7ccf2 100644 --- a/recipes/streaming_convnets/inference/cmake/Buildcereal.cmake +++ b/recipes/streaming_convnets/inference/cmake/BuildCereal.cmake @@ -1,10 +1,8 @@ -cmake_minimum_required(VERSION 3.5.1) - include(ExternalProject) set(cereal_URL https://github.com/USCiLab/cereal.git) set(cereal_BUILD ${CMAKE_CURRENT_BINARY_DIR}/cereal) -set(cereal_TAG 319ce5f5ee5b76cb80617156bf7c95474a2938b1) # `develop` branch, commit +set(cereal_TAG 02eace19a99ce3cd564ca4e379753d69af08c2c8) # version 1.3.0 # Download Cereal ExternalProject_Add( @@ -18,7 +16,7 @@ ExternalProject_Add( CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=Release -DJUST_INSTALL_CEREAL:BOOL=ON - + ) ExternalProject_Get_Property(cereal source_dir) set(CEREAL_SOURCE_DIR ${source_dir}) @@ -26,9 +24,7 @@ ExternalProject_Get_Property(cereal binary_dir) set(CEREAL_BINARY_DIR ${binary_dir}) # Include dir. dependent on build or install -set(CEREAL_INCLUDE_DIR +set(cereal_INCLUDE_DIRS $ $ # see root CMakeLists.txt ) - - set(cereal_INCLUDE_DIRS ${CEREAL_INCLUDE_DIR}) diff --git a/recipes/streaming_convnets/inference/cmake/BuildGoogleTest.cmake b/recipes/streaming_convnets/inference/cmake/BuildGoogleTest.cmake new file mode 100644 index 00000000..af704226 --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/BuildGoogleTest.cmake @@ -0,0 +1,80 @@ +cmake_minimum_required(VERSION 3.10.0) + +include(ExternalProject) + +set(gtest_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/include) +set(gtest_URL https://github.com/google/googletest.git) +set(gtest_BUILD ${CMAKE_CURRENT_BINARY_DIR}/googletest/) +set(gtest_TAG 703bd9caab50b139428cea1aaff9974ebee5742e) # release 1.10.0 + +if (NOT TARGET gtest) + # Download googletest + ExternalProject_Add( + gtest + PREFIX googletest + GIT_REPOSITORY ${gtest_URL} + GIT_TAG ${gtest_TAG} + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${CMAKE_COMMAND} --build . + INSTALL_COMMAND "" + CMAKE_CACHE_ARGS + -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} + -DCMAKE_BUILD_TYPE:STRING=Release + -DBUILD_GMOCK:BOOL=ON + -DBUILD_GTEST:BOOL=ON + -Dgtest_force_shared_crt:BOOL=OFF + ) +endif () + +ExternalProject_Get_Property(gtest source_dir) +set(GTEST_SOURCE_DIR ${source_dir}) +ExternalProject_Get_Property(gtest binary_dir) +set(GTEST_BINARY_DIR ${binary_dir}) + +if (BUILD_SHARED_LIBS) + set(LIB_TYPE SHARED) +else() + set(LIB_TYPE STATIC) +endif() + +# Library and include dirs +set(GTEST_LIBRARIES + "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}gtest${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" +) +set(GTEST_LIBRARIES_MAIN + "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}gtest_main${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" +) +set(GMOCK_LIBRARIES + "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}gmock${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" +) +set(GMOCK_LIBRARIES_MAIN + "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}gmock_main${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" +) + +set(GTEST_INCLUDE_DIRS ${GTEST_SOURCE_DIR}/googletest/include) +set(GMOCK_INCLUDE_DIRS ${GTEST_SOURCE_DIR}/googlemock/include) +# Make dirs so this can be used as an interface include directory +file(MAKE_DIRECTORY ${GTEST_INCLUDE_DIRS}) +file(MAKE_DIRECTORY ${GMOCK_INCLUDE_DIRS}) + +add_library(GTest::gtest ${LIB_TYPE} IMPORTED) +add_library(GTest::gtest_main ${LIB_TYPE} IMPORTED) +add_library(GTest::gmock ${LIB_TYPE} IMPORTED) +add_library(GTest::gmock_main ${LIB_TYPE} IMPORTED) + +set_target_properties(GTest::gtest PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIRS} + IMPORTED_LOCATION ${GTEST_LIBRARIES} + ) +set_target_properties(GTest::gtest_main PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIRS} + IMPORTED_LOCATION ${GTEST_LIBRARIES_MAIN} + ) +set_target_properties(GTest::gmock PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIRS} + IMPORTED_LOCATION ${GMOCK_LIBRARIES} + ) +set_target_properties(GTest::gmock_main PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIRS} + IMPORTED_LOCATION ${GMOCK_LIBRARIES_MAIN} + ) diff --git a/recipes/streaming_convnets/inference/cmake/BuildKenlm.cmake b/recipes/streaming_convnets/inference/cmake/BuildKenlm.cmake new file mode 100644 index 00000000..d56acfe4 --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/BuildKenlm.cmake @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.10.0) + +# Required for KenLM to read ARPA files in compressed format +find_package(LibLZMA REQUIRED) +find_package(BZip2 REQUIRED) +find_package(ZLIB REQUIRED) + +include(ExternalProject) + +set(kenlm_TEMP_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern/kenlm) +set(kenlm_URL https://github.com/kpu/kenlm.git) +set(kenlm_BUILD ${CMAKE_CURRENT_BINARY_DIR}/kenlm) +set(kenlm_TAG 4a277534fd33da323205e6ec256e8fd0ff6ee6fa) + +if (NOT TARGET kenlm) + # Download kenlm + ExternalProject_Add( + kenlm + PREFIX kenlm + GIT_REPOSITORY ${kenlm_URL} + GIT_TAG ${kenlm_TAG} + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${CMAKE_COMMAND} --build . + CMAKE_CACHE_ARGS + -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH=${kenlm_TEMP_INSTALL_DIR} + ) +endif () + +# Install the install executed at build time +install(DIRECTORY ${kenlm_TEMP_INSTALL_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX}) +install(DIRECTORY ${kenlm_TEMP_INSTALL_DIR}/lib DESTINATION ${CMAKE_INSTALL_PREFIX}) +install(DIRECTORY ${kenlm_TEMP_INSTALL_DIR}/bin DESTINATION ${CMAKE_INSTALL_PREFIX}) + +if (BUILD_SHARED_LIBS) + set(LIB_TYPE SHARED) +else() + set(LIB_TYPE STATIC) +endif() + +# Library and include dirs +set(KENLM_LIBRARIES + "${kenlm_TEMP_INSTALL_DIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}kenlm${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" + "${kenlm_TEMP_INSTALL_DIR}/lib/${CMAKE_${LIB_TYPE}_LIBRARY_PREFIX}kenlm_util${CMAKE_${LIB_TYPE}_LIBRARY_SUFFIX}" + ${LIBLZMA_LIBRARIES} + ${BZIP2_LIBRARIES} + ${ZLIB_LIBRARIES} +) +set(KENLM_INCLUDE_DIRS "${kenlm_TEMP_INSTALL_DIR}/include") +set(KENLM_INCLUDE_DIRS_LM "${kenlm_TEMP_INSTALL_DIR}/include/kenlm") diff --git a/recipes/streaming_convnets/inference/cmake/FindGMock.cmake b/recipes/streaming_convnets/inference/cmake/FindGMock.cmake new file mode 100644 index 00000000..54101dad --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/FindGMock.cmake @@ -0,0 +1,58 @@ +# Find gmock +# +# GMOCK_INCLUDE_DIRS - where to find gmock/gmock.h, etc. +# GMOCK_LIBRARIES - List of libraries when using gmock. +# GMOCK_FOUND - True if gmock found. + +if (GMOCK_INCLUDE_DIRS) + # Already in cache, be silent + set(GMOCK_FIND_QUIETLY TRUE) +endif() + +find_package(GMock CONFIG) +if (NOT TARGET GTest::gmock) + if (NOT GMOCK_ROOT) + set(GMOCK_ROOT ENV{GMOCK_ROOT}) + endif() + + find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h PATHS ${GMOCK_ROOT}) + find_library(GMOCK_MAIN_LIBRARY NAMES gmock_main PATHS ${GMOCK_ROOT}) + find_library(GMOCK_LIBRARIES NAMES gmock PATHS ${GMOCK_ROOT}) + + set(GMOCK_BOTH_LIBRARIES + ${GMOCK_MAIN_LIBRARY} + ${GMOCK_LIBRARIES} + ) + + # handle the QUIETLY and REQUIRED arguments and set GMOCK_FOUND to TRUE if + # all listed variables are TRUE + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + GMock + DEFAULT_MSG + GMOCK_MAIN_LIBRARY + GMOCK_LIBRARIES + GMOCK_LIBRARIES + GMOCK_INCLUDE_DIRS + ) + + mark_as_advanced( + GMOCK_MAIN_LIBRARY + GMOCK_LIBRARIES + LIBGTEST_LIBRARY + GMOCK_LIBRARIES + GMOCK_INCLUDE_DIRS + ) + + add_library(GTest::gmock UNKNOWN IMPORTED) + set_target_properties(GTest::gmock PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIRS} + IMPORTED_LOCATION ${GMOCK_LIBRARIES} + ) + + add_library(GTest::gmock_main UNKNOWN IMPORTED) + set_target_properties(GTest::gmock_main PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIRS} + IMPORTED_LOCATION ${GMOCK_MAIN_LIBRARY} + ) +endif() diff --git a/recipes/streaming_convnets/inference/cmake/Findcereal.cmake b/recipes/streaming_convnets/inference/cmake/Findcereal.cmake index 2e4a2841..520901b3 100644 --- a/recipes/streaming_convnets/inference/cmake/Findcereal.cmake +++ b/recipes/streaming_convnets/inference/cmake/Findcereal.cmake @@ -1,20 +1,43 @@ # Try to find Cereal # -# Sets the following variables: -# CEREAL_FOUND -# CEREAL_INCLUDE_DIRS - directories with Cereal headers -# CEREAL_DEFINITIONS - Cereal compiler flags +# Sets the following imported targets if cereal is found with a config: +# cereal +# +# If cereal is not found with a CMake config, legacy variables are set: +# cereal_FOUND +# cereal_INCLUDE_DIRS - directories with Cereal headers +# cereal_DEFINITIONS - Cereal compiler flags + +find_package(cereal CONFIG) + +if (NOT TARGET cereal) + find_path(cereal_header_paths_tmp + NAMES + cereal.hpp + PATH_SUFFIXES + include + cereal/include + PATHS + ${CEREAL_ROOT_DIR} + ${CEREAL_ROOT_DIR}/include + ${CEREAL_ROOT_DIR}/cereal/include + $ENV{CEREAL_ROOT_DIR} + $ENV{CEREAL_ROOT_DIR}/include + $ENV{CEREAL_ROOT_DIR}/cereal + ) -find_path(CEREAL_INCLUDE_DIR - cereal - HINTS - "$ENV{CEREAL_ROOT}/include" - "/usr/include" - "$ENV{PROGRAMFILES}/cereal/include" -) + get_filename_component(cereal_INCLUDE_DIRS ${cereal_header_paths_tmp} PATH) -set(CEREAL_INCLUDE_DIRS ${CEREAL_INCLUDE_DIR}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(cereal + REQUIRED_VARS cereal_INCLUDE_DIRS + ) -# sets cereal_FOUND value based on validity of CEREAL_INCLUDE_DIRS -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(cereal DEFAULT_MSG CEREAL_INCLUDE_DIRS) + message(STATUS "Found cereal (include: ${cereal_INCLUDE_DIRS})") + mark_as_advanced(cereal_FOUND) + if (cereal_FOUND) + add_library(cereal INTERFACE IMPORTED) + set_target_properties(cereal PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${cereal_INCLUDE_DIRS}") + endif() +endif() diff --git a/recipes/streaming_convnets/inference/cmake/Findkenlm.cmake b/recipes/streaming_convnets/inference/cmake/Findkenlm.cmake new file mode 100644 index 00000000..505346f9 --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/Findkenlm.cmake @@ -0,0 +1,95 @@ +# Try to find the KenLM library +# +# The following variables are optionally searched for defaults +# KENLM_ROOT: Base directory where all KENLM components are found +# +# The following are set after configuration is done: +# KENLM_FOUND +# KENLM_LIBRARIES +# KENLM_INCLUDE_DIRS +# KENLM_INCLUDE_DIRS_LM +# + +message(STATUS "Looking for KenLM") + +# Required for KenLM to read ARPA files in compressed format +find_package(LibLZMA REQUIRED) +find_package(BZip2 REQUIRED) +find_package(ZLIB REQUIRED) + +find_library( + KENLM_LIB + kenlm + HINTS + ${KENLM_ROOT}/lib + ${KENLM_ROOT}/build/lib + PATHS + $ENV{KENLM_ROOT}/lib + $ENV{KENLM_ROOT}/build/lib + ) + +find_library( + KENLM_UTIL_LIB + kenlm_util + HINTS + ${KENLM_ROOT}/lib + ${KENLM_ROOT}/build/lib + PATHS + $ENV{KENLM_ROOT}/lib + $ENV{KENLM_ROOT}/build/lib + ) + +if(KENLM_LIB) + message(STATUS "Using kenlm library found in ${KENLM_LIB}") +else() + message(STATUS "kenlm library not found; if you already have kenlm installed, please set CMAKE_LIBRARY_PATH, KENLM_LIB or KENLM_ROOT environment variable") +endif() + +if(KENLM_UTIL_LIB) + message(STATUS "Using kenlm utils library found in ${KENLM_UTIL_LIB}") +else() + message(STATUS "kenlm utils library not found; if you already have kenlm installed, please set CMAKE_LIBRARY_PATH, KENLM_UTIL_LIB or KENLM_ROOT environment variable") +endif() + +# find a model header, then get the entire include directory. We need to do this because +# cmake consistently confuses other things along this path +find_path(KENLM_MODEL_HEADER + model.hh + PATH_SUFFIXES + kenlm/lm + include/kenlm/lm + HINTS + ${KENLM_ROOT}/lm + ${KENLM_ROOT}/include/kenlm/lm + PATHS + $ENV{KENLM_ROOT}/lm + $ENV{KENLM_ROOT}/include/kenlm/lm + ) + +if(KENLM_MODEL_HEADER) + message(STATUS "kenlm model.hh found in ${KENLM_MODEL_HEADER}") + + get_filename_component(KENLM_INCLUDE_LM ${KENLM_MODEL_HEADER} DIRECTORY) + get_filename_component(KENLM_INCLUDE_DIR ${KENLM_INCLUDE_LM} DIRECTORY) +else() + message(STATUS "kenlm model.hh not found; if you already have kenlm installed, please set CMAKE_INCLUDE_PATH, KENLM_MODEL_HEADER or KENLM_ROOT environment variable") +endif() + +set(KENLM_LIBRARIES + ${KENLM_LIB} + ${KENLM_UTIL_LIB} + ${LIBLZMA_LIBRARIES} + ${BZIP2_LIBRARIES} + ${ZLIB_LIBRARIES} +) +# Some KenLM include paths are relative to [include dir]/kenlm, not just [include dir] (bad) +set(KENLM_INCLUDE_DIRS_LM ${KENLM_INCLUDE_LM}) +set(KENLM_INCLUDE_DIRS ${KENLM_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(kenlm DEFAULT_MSG KENLM_INCLUDE_DIRS KENLM_LIBRARIES) + +if (kenlm_FOUND) + message(STATUS "Found kenlm (include: ${KENLM_INCLUDE_DIRS}, library: ${KENLM_LIBRARIES})") + mark_as_advanced(KENLM_ROOT KENLM_INCLUDE_DIRS KENLM_LIBRARIES) +endif() diff --git a/recipes/streaming_convnets/inference/cmake/TestUtils.cmake b/recipes/streaming_convnets/inference/cmake/TestUtils.cmake new file mode 100644 index 00000000..1742117d --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/TestUtils.cmake @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.5.1) + +set(GTEST_IMPORTED_TARGETS "") + +# Get or find Google Test and Google Mock +find_package(GTest 1.10.0) +if (NOT GTEST_FOUND) + if (NOT TARGET gtest) + message(STATUS "googletest not found - will download and build from source") + # Download and build googletest + include(${CMAKE_MODULE_PATH}/BuildGoogleTest.cmake) # internally sets GTEST_LIBRARIES + list(APPEND GTEST_IMPORTED_TARGETS GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main) + endif() +else() + message(STATUS "gtest found: (include: ${GTEST_INCLUDE_DIRS}, lib: ${GTEST_BOTH_LIBRARIES}") + if (TARGET GTest::GTest) + # We found the differently-named CMake targets from FindGTest + if (NOT TARGET GTest::Main) + message(FATAL_ERROR "Google Test must be built with main") + endif() + list(APPEND GTEST_IMPORTED_TARGETS GTest::GTest GTest::Main) + endif() + if (NOT TARGET GTest::gmock) + find_package(GMock REQUIRED) + message(STATUS "gmock found: (include: ${GMOCK_INCLUDE_DIRS}, lib: ${GMOCK_BOTH_LIBRARIES})") + endif() + list(APPEND GTEST_IMPORTED_TARGETS GTest::gmock GTest::gmock_main) + message(STATUS "Found gtest and gmock on system.") +endif() + +include(GoogleTest) + +function(build_test) + set(options) + set(oneValueArgs SRC) + set(multiValueArgs LIBS PREPROC) + cmake_parse_arguments(build_test "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + get_filename_component(src_name ${build_test_SRC} NAME_WE) + set(target "${src_name}") + add_executable(${target} ${build_test_SRC}) + if (TARGET gtest) + add_dependencies(${target} gtest) # make sure gtest is built first + endif() + target_link_libraries( + ${target} + PUBLIC + ${GTEST_IMPORTED_TARGETS} + ${build_test_LIBS} + ) + target_include_directories( + ${target} + PUBLIC + ${PROJECT_SOURCE_DIR} + ) + target_compile_definitions( + ${target} + PUBLIC + ${build_test_PREPROC} + ) + gtest_add_tests(TARGET ${target}) +endfunction(build_test) diff --git a/recipes/streaming_convnets/inference/cmake/streaming_inferenceConfig.cmake b/recipes/streaming_convnets/inference/cmake/streaming_inferenceConfig.cmake new file mode 100644 index 00000000..25c38969 --- /dev/null +++ b/recipes/streaming_convnets/inference/cmake/streaming_inferenceConfig.cmake @@ -0,0 +1,10 @@ +# - Config file for the streaming_inference package +find_dependency(OpenMP) +find_dependency(kenlm) +find_dependency(Threads) +find_dependency(FFTW3) +if (@FL_LIBRARIES_USE_MKL@) + find_dependency(MKL) +else() + find_dependency(CBLAS) +endif() diff --git a/recipes/streaming_convnets/inference/inference/examples/AudioToWords.cpp b/recipes/streaming_convnets/inference/examples/AudioToWords.cpp similarity index 98% rename from recipes/streaming_convnets/inference/inference/examples/AudioToWords.cpp rename to recipes/streaming_convnets/inference/examples/AudioToWords.cpp index 3844070a..7e3b6322 100644 --- a/recipes/streaming_convnets/inference/inference/examples/AudioToWords.cpp +++ b/recipes/streaming_convnets/inference/examples/AudioToWords.cpp @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -#include "inference/examples/AudioToWords.h" +#include "examples/AudioToWords.h" #include #include +#include "examples/Util.h" #include "inference/common/IOBuffer.h" -#include "inference/examples/Util.h" namespace w2l { namespace streaming { diff --git a/recipes/streaming_convnets/inference/inference/examples/AudioToWords.h b/recipes/streaming_convnets/inference/examples/AudioToWords.h similarity index 100% rename from recipes/streaming_convnets/inference/inference/examples/AudioToWords.h rename to recipes/streaming_convnets/inference/examples/AudioToWords.h diff --git a/recipes/streaming_convnets/inference/inference/examples/CMakeLists.txt b/recipes/streaming_convnets/inference/examples/CMakeLists.txt similarity index 91% rename from recipes/streaming_convnets/inference/inference/examples/CMakeLists.txt rename to recipes/streaming_convnets/inference/examples/CMakeLists.txt index faa0db05..484753f4 100644 --- a/recipes/streaming_convnets/inference/inference/examples/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/examples/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.5.1) +cmake_minimum_required(VERSION 3.10) + project(StreamingInferenceExamples) add_library(StreamingInferenceExamples INTERFACE) @@ -19,14 +20,14 @@ target_include_directories( PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${cereal_INCLUDE_DIRS} - ${wav2letter-inference_SOURCE_DIR} - ${wav2letter++_SOURCE_DIR}/src + ${streaming_inference_SOURCE_DIR} ) target_link_libraries( util_example PUBLIC streaming_inference_common + flashlight::fl-libraries ) # audio_to_words_example library is used by the example executables @@ -38,7 +39,7 @@ target_include_directories( audio_to_words_example PUBLIC ${CMAKE_CURRENT_LIST_DIR} - ${wav2letter-inference_SOURCE_DIR} + ${streaming_inference_SOURCE_DIR} ) target_link_libraries( @@ -47,7 +48,7 @@ target_link_libraries( util_example streaming_inference_modules_nn_backend streaming_inference_decoder - decoder-library + flashlight::fl-libraries Threads::Threads ) diff --git a/recipes/streaming_convnets/inference/inference/examples/InteractiveStreamingASRExample.cpp b/recipes/streaming_convnets/inference/examples/InteractiveStreamingASRExample.cpp similarity index 99% rename from recipes/streaming_convnets/inference/inference/examples/InteractiveStreamingASRExample.cpp rename to recipes/streaming_convnets/inference/examples/InteractiveStreamingASRExample.cpp index 1255918a..c8d7b785 100644 --- a/recipes/streaming_convnets/inference/inference/examples/InteractiveStreamingASRExample.cpp +++ b/recipes/streaming_convnets/inference/examples/InteractiveStreamingASRExample.cpp @@ -71,9 +71,9 @@ #include #include +#include "examples/AudioToWords.h" +#include "examples/Util.h" #include "inference/decoder/Decoder.h" -#include "inference/examples/AudioToWords.h" -#include "inference/examples/Util.h" #include "inference/module/feature/feature.h" #include "inference/module/module.h" #include "inference/module/nn/nn.h" diff --git a/recipes/streaming_convnets/inference/inference/examples/MultithreadedStreamingASRExample.cpp b/recipes/streaming_convnets/inference/examples/MultithreadedStreamingASRExample.cpp similarity index 98% rename from recipes/streaming_convnets/inference/inference/examples/MultithreadedStreamingASRExample.cpp rename to recipes/streaming_convnets/inference/examples/MultithreadedStreamingASRExample.cpp index e9957499..4b80b07b 100644 --- a/recipes/streaming_convnets/inference/inference/examples/MultithreadedStreamingASRExample.cpp +++ b/recipes/streaming_convnets/inference/examples/MultithreadedStreamingASRExample.cpp @@ -51,10 +51,10 @@ #include #include +#include "examples/AudioToWords.h" +#include "examples/Util.h" +#include "examples/threadpool/ThreadPool.h" #include "inference/decoder/Decoder.h" -#include "inference/examples/AudioToWords.h" -#include "inference/examples/Util.h" -#include "inference/examples/threadpool/ThreadPool.h" #include "inference/module/feature/feature.h" #include "inference/module/module.h" #include "inference/module/nn/nn.h" diff --git a/recipes/streaming_convnets/inference/inference/examples/SimpleStreamingASRExample.cpp b/recipes/streaming_convnets/inference/examples/SimpleStreamingASRExample.cpp similarity index 99% rename from recipes/streaming_convnets/inference/inference/examples/SimpleStreamingASRExample.cpp rename to recipes/streaming_convnets/inference/examples/SimpleStreamingASRExample.cpp index 7f00afbd..dbc675ae 100644 --- a/recipes/streaming_convnets/inference/inference/examples/SimpleStreamingASRExample.cpp +++ b/recipes/streaming_convnets/inference/examples/SimpleStreamingASRExample.cpp @@ -73,9 +73,9 @@ #include #include +#include "examples/AudioToWords.h" +#include "examples/Util.h" #include "inference/decoder/Decoder.h" -#include "inference/examples/AudioToWords.h" -#include "inference/examples/Util.h" #include "inference/module/feature/feature.h" #include "inference/module/module.h" #include "inference/module/nn/nn.h" diff --git a/recipes/streaming_convnets/inference/inference/examples/Util.cpp b/recipes/streaming_convnets/inference/examples/Util.cpp similarity index 98% rename from recipes/streaming_convnets/inference/inference/examples/Util.cpp rename to recipes/streaming_convnets/inference/examples/Util.cpp index 3b83b67b..97e77c9d 100644 --- a/recipes/streaming_convnets/inference/inference/examples/Util.cpp +++ b/recipes/streaming_convnets/inference/examples/Util.cpp @@ -6,7 +6,7 @@ * */ -#include "inference/examples/Util.h" +#include "Util.h" #include #include diff --git a/recipes/streaming_convnets/inference/inference/examples/Util.h b/recipes/streaming_convnets/inference/examples/Util.h similarity index 100% rename from recipes/streaming_convnets/inference/inference/examples/Util.h rename to recipes/streaming_convnets/inference/examples/Util.h diff --git a/recipes/streaming_convnets/inference/inference/examples/threadpool/COPYING b/recipes/streaming_convnets/inference/examples/threadpool/COPYING similarity index 100% rename from recipes/streaming_convnets/inference/inference/examples/threadpool/COPYING rename to recipes/streaming_convnets/inference/examples/threadpool/COPYING diff --git a/recipes/streaming_convnets/inference/inference/examples/threadpool/ThreadPool.h b/recipes/streaming_convnets/inference/examples/threadpool/ThreadPool.h similarity index 100% rename from recipes/streaming_convnets/inference/inference/examples/threadpool/ThreadPool.h rename to recipes/streaming_convnets/inference/examples/threadpool/ThreadPool.h diff --git a/recipes/streaming_convnets/inference/inference/common/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/common/CMakeLists.txt index b6bf0d89..f7e7a6de 100644 --- a/recipes/streaming_convnets/inference/inference/common/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/common/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.1) +cmake_minimum_required(VERSION 3.10) add_library(streaming_inference_common ${CMAKE_CURRENT_LIST_DIR}/DataType.cpp @@ -14,5 +14,5 @@ target_include_directories( PUBLIC ${cereal_INCLUDE_DIRS} # going up one directory to use #include "inference/*/*.h" - ${wav2letter-inference_SOURCE_DIR} + ${streaming_inference_SOURCE_DIR} ) diff --git a/recipes/streaming_convnets/inference/inference/decoder/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/decoder/CMakeLists.txt index 92fb4f44..7128bed5 100644 --- a/recipes/streaming_convnets/inference/inference/decoder/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/decoder/CMakeLists.txt @@ -1,21 +1,16 @@ add_library(streaming_inference_decoder INTERFACE) -find_package(kenlm REQUIRED) - target_sources(streaming_inference_decoder INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Decoder.cpp ) -get_target_property(DEC_SOURCES decoder-library INTERFACE_SOURCES) - target_link_libraries( streaming_inference_decoder INTERFACE ${KENLM_LIBRARIES} streaming_inference_common - decoder-library - wav2letter-libraries + flashlight::fl-libraries ) target_compile_definitions( diff --git a/recipes/streaming_convnets/inference/inference/decoder/Decoder.cpp b/recipes/streaming_convnets/inference/inference/decoder/Decoder.cpp index 7c610a2b..366327a1 100644 --- a/recipes/streaming_convnets/inference/inference/decoder/Decoder.cpp +++ b/recipes/streaming_convnets/inference/inference/decoder/Decoder.cpp @@ -19,6 +19,22 @@ #include "flashlight/lib/text/decoder/lm/ZeroLM.h" #include "inference/decoder/Decoder.h" +namespace { +constexpr const char* kBlankToken = "#"; + +std::vector tkn2Idx( + const std::vector& spelling, + const fl::lib::text::Dictionary& tokenDict, + int maxReps) { + std::vector ret; + ret.reserve(spelling.size()); + for (const auto& token : spelling) { + ret.push_back(tokenDict.getIndex(token)); + } + return fl::lib::text::packReplabels(ret, tokenDict, maxReps); +} +} // namespace + namespace w2l { namespace streaming { @@ -41,9 +57,8 @@ DecoderFactory::DecoderFactory( } std::cerr << "[Letters] " << alphabetSize_ << " tokens loaded.\n"; silence_ = letterMap_.getIndex(silenceToken); - blank_ = letterMap_.contains(fl::app::asr::kBlankToken) - ? letterMap_.getIndex(fl::app::asr::kBlankToken) - : -1; + blank_ = + letterMap_.contains(kBlankToken) ? letterMap_.getIndex(kBlankToken) : -1; /* 2. Load word dictionary */ fl::lib::text::LexiconMap lexicon; @@ -83,8 +98,7 @@ DecoderFactory::DecoderFactory( std::tie(dummyState, score) = lm_->score(startState, usrIdx); for (const auto& tokens : it.second) { - auto tokensTensor = - fl::app::asr::tkn2Idx(tokens, letterMap_, repetitionLabel_); + auto tokensTensor = tkn2Idx(tokens, letterMap_, repetitionLabel_); trie_->insert(tokensTensor, usrIdx, score); } } diff --git a/recipes/streaming_convnets/inference/inference/module/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/module/CMakeLists.txt index 5dabf0d8..2483612d 100644 --- a/recipes/streaming_convnets/inference/inference/module/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/module/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.5.1) - # Creates interface library: streaming_inference_modules_nn include(${CMAKE_CURRENT_LIST_DIR}/nn/CMakeLists.txt) include(${CMAKE_CURRENT_LIST_DIR}/feature/CMakeLists.txt) @@ -28,7 +26,7 @@ target_include_directories( streaming_inference_modules INTERFACE # going up one directory to use #include "inference/*/*.h" - ${wav2letter-inference_SOURCE_DIR} + ${streaming_inference_SOURCE_DIR} ${cereal_INCLUDE_DIRS} ${nn_backend_INCLUDE_DIRS} ) diff --git a/recipes/streaming_convnets/inference/inference/module/feature/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/module/feature/CMakeLists.txt index c317c862..2b39fe3f 100644 --- a/recipes/streaming_convnets/inference/inference/module/feature/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/module/feature/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries( PUBLIC ${cereal_LIBRARIES} streaming_inference_common + flashlight::fl-libraries ) target_include_directories( @@ -16,6 +17,5 @@ target_include_directories( PUBLIC ${cereal_INCLUDE_DIRS} # going up one directory to use #include "inference/*/*.h" - ${wav2letter-inference_SOURCE_DIR} - ${wav2letter++_SOURCE_DIR}/src + ${streaming_inference_SOURCE_DIR} ) diff --git a/recipes/streaming_convnets/inference/inference/module/nn/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/module/nn/CMakeLists.txt index a89b7c31..7f84c05f 100644 --- a/recipes/streaming_convnets/inference/inference/module/nn/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/module/nn/CMakeLists.txt @@ -1,20 +1,20 @@ -cmake_minimum_required(VERSION 3.5.1) +cmake_minimum_required(VERSION 3.10) -if (NOT W2L_INFERENCE_BACKEND IN_LIST AVAILABLE_INFERENCE_BACKENDS) - message(FATAL_ERROR "Passed value of W2L_INFERENCE_BACKEND is invalid." +if (NOT STREAMING_INFERENCE_BACKEND IN_LIST AVAILABLE_INFERENCE_BACKENDS) + message(FATAL_ERROR "Passed value of STREAMING_INFERENCE_BACKEND is invalid." " supported values=${AVAILABLE_INFERENCE_BACKENDS}") endif() # Directory of build list for the specified backend set(BACKEND_LIST_PATH - ${CMAKE_CURRENT_LIST_DIR}/backend/${W2L_INFERENCE_BACKEND}/CMakeLists.txt) + ${CMAKE_CURRENT_LIST_DIR}/backend/${STREAMING_INFERENCE_BACKEND}/CMakeLists.txt) # Make sure a path to the valid list exists if (NOT EXISTS ${BACKEND_LIST_PATH}) message(FATAL_ERROR "Inference backend path ${BACKEND_LIST_PATH} does not " "exist. This indicates a problem with the the value of " - "W2L_INFERENCE_BACKEND=${W2L_INFERENCE_BACKEND}. Please ensure " - "${W2L_INFERENCE_BACKEND} is a directory name under " + "STREAMING_INFERENCE_BACKEND=${STREAMING_INFERENCE_BACKEND}. Please ensure " + "${STREAMING_INFERENCE_BACKEND} is a directory name under " "${CMAKE_CURRENT_LIST_DIR}/backend and contains a valid CMakeLists file.") endif () @@ -25,7 +25,7 @@ include(${BACKEND_LIST_PATH}) if (NOT ${BACKEND_FOUND}) message(FATAL_ERROR - "W2L_INFERENCE_BACKEND:${W2L_INFERENCE_BACKEND} is not found.") + "STREAMING_INFERENCE_BACKEND:${STREAMING_INFERENCE_BACKEND} is not found.") endif() add_library(streaming_inference_modules_nn INTERFACE) @@ -47,7 +47,7 @@ target_include_directories( PUBLIC ${cereal_INCLUDE_DIRS} # going up one directory to use #include "inference/*/*.h" - ${wav2letter-inference_SOURCE_DIR}/.. + ${streaming_inference_SOURCE_DIR}/.. ) add_dependencies(streaming_inference_modules_nn_impl cereal) diff --git a/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/CMakeLists.txt b/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/CMakeLists.txt index 74450cc5..d8f13657 100644 --- a/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/CMakeLists.txt +++ b/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.5.1) - list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) include(BuildFbGemm) @@ -14,7 +12,7 @@ set_target_properties( streaming_inference_modules_nn_backend PROPERTIES LINKER_LANGUAGE CXX - CXX_STANDARD 11 + CXX_STANDARD 14 ) add_dependencies(streaming_inference_modules_nn_backend fbgemm) @@ -30,7 +28,7 @@ target_include_directories(streaming_inference_modules_nn_backend PUBLIC ${fbgemm_INCLUDE_DIRS} ${cereal_INCLUDE_DIRS} - ${wav2letter-inference_SOURCE_DIR}/.. + ${streaming_inference_SOURCE_DIR}/.. ) set(BACKEND_FOUND true) diff --git a/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/cmake/BuildFbGemm.cmake b/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/cmake/BuildFbGemm.cmake index 95ad96b7..cb79a913 100644 --- a/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/cmake/BuildFbGemm.cmake +++ b/recipes/streaming_convnets/inference/inference/module/nn/backend/fbgemm/cmake/BuildFbGemm.cmake @@ -1,4 +1,4 @@ -#Download and create a rule to build FG GEMM +# Download and create a rule to build FG GEMM # sets FBGEMM_INCLUDE_DIR and FBGEMM_LIBRARIES include(ExternalProject) diff --git a/recipes/streaming_convnets/inference/inference/module/nn/nn.h b/recipes/streaming_convnets/inference/inference/module/nn/nn.h index b9cdba12..632ad460 100644 --- a/recipes/streaming_convnets/inference/inference/module/nn/nn.h +++ b/recipes/streaming_convnets/inference/inference/module/nn/nn.h @@ -18,6 +18,6 @@ #include "inference/module/nn/TDSBlock.h" // We need to include the backend for the Cereal serirlization implementation. -#if W2L_INFERENCE_BACKEND == fbgemm +#if STREAMING_INFERENCE_BACKEND == fbgemm #include "inference/module/nn/backend/fbgemm/fbgemm.h" #endif diff --git a/recipes/streaming_convnets/inference/test/CMakeLists.txt b/recipes/streaming_convnets/inference/test/CMakeLists.txt new file mode 100644 index 00000000..cb00e193 --- /dev/null +++ b/recipes/streaming_convnets/inference/test/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.10) + +set( + LIBS + streaming_inference_common + streaming_inference_decoder + streaming_inference_modules + Threads::Threads +) + +build_test(SRC Conv1dTest.cpp LIBS ${LIBS}) +build_test(SRC IdentityTest.cpp LIBS ${LIBS}) +build_test(SRC LayerNormTest.cpp LIBS ${LIBS}) +build_test(SRC LinearTest.cpp LIBS ${LIBS}) +build_test(SRC LogMelFeatureTest.cpp LIBS ${LIBS}) +build_test(SRC MemoryManagerTest.cpp LIBS ${LIBS}) +build_test(SRC ReluTest.cpp LIBS ${LIBS}) +build_test(SRC ResidualTest.cpp LIBS ${LIBS}) +build_test(SRC TDSBlockTest.cpp LIBS ${LIBS}) diff --git a/recipes/streaming_convnets/inference/inference/module/test/Conv1dTest.cpp b/recipes/streaming_convnets/inference/test/Conv1dTest.cpp similarity index 100% rename from recipes/streaming_convnets/inference/inference/module/test/Conv1dTest.cpp rename to recipes/streaming_convnets/inference/test/Conv1dTest.cpp diff --git a/recipes/streaming_convnets/inference/inference/module/test/IdentityTest.cpp b/recipes/streaming_convnets/inference/test/IdentityTest.cpp similarity index 100% rename from recipes/streaming_convnets/inference/inference/module/test/IdentityTest.cpp rename to recipes/streaming_convnets/inference/test/IdentityTest.cpp diff --git a/recipes/streaming_convnets/inference/inference/module/test/LayerNormTest.cpp b/recipes/streaming_convnets/inference/test/LayerNormTest.cpp similarity index 98% rename from recipes/streaming_convnets/inference/inference/module/test/LayerNormTest.cpp rename to recipes/streaming_convnets/inference/test/LayerNormTest.cpp index 214c6244..ea679714 100644 --- a/recipes/streaming_convnets/inference/inference/module/test/LayerNormTest.cpp +++ b/recipes/streaming_convnets/inference/test/LayerNormTest.cpp @@ -19,11 +19,11 @@ #include #include +#include "TestUtils.h" #include "inference/common/IOBuffer.h" #include "inference/module/ModuleParameter.h" #include "inference/module/ModuleProcessingState.h" #include "inference/module/nn/LayerNorm.h" -#include "inference/module/test/TestUtils.h" namespace w2l { namespace streaming { diff --git a/recipes/streaming_convnets/inference/inference/module/test/LinearTest.cpp b/recipes/streaming_convnets/inference/test/LinearTest.cpp similarity index 100% rename from recipes/streaming_convnets/inference/inference/module/test/LinearTest.cpp rename to recipes/streaming_convnets/inference/test/LinearTest.cpp diff --git a/recipes/streaming_convnets/inference/inference/module/test/LogMelFeatureTest.cpp b/recipes/streaming_convnets/inference/test/LogMelFeatureTest.cpp similarity index 97% rename from recipes/streaming_convnets/inference/inference/module/test/LogMelFeatureTest.cpp rename to recipes/streaming_convnets/inference/test/LogMelFeatureTest.cpp index 168d4c31..2c37d71d 100644 --- a/recipes/streaming_convnets/inference/inference/module/test/LogMelFeatureTest.cpp +++ b/recipes/streaming_convnets/inference/test/LogMelFeatureTest.cpp @@ -16,8 +16,8 @@ #include #include +#include "TestUtils.h" #include "inference/module/feature/LogMelFeature.h" -#include "inference/module/test/TestUtils.h" namespace w2l { namespace streaming { diff --git a/recipes/streaming_convnets/inference/inference/module/test/MemoryManagerTest.cpp b/recipes/streaming_convnets/inference/test/MemoryManagerTest.cpp similarity index 100% rename from recipes/streaming_convnets/inference/inference/module/test/MemoryManagerTest.cpp rename to recipes/streaming_convnets/inference/test/MemoryManagerTest.cpp diff --git a/recipes/streaming_convnets/inference/inference/module/test/ReluTest.cpp b/recipes/streaming_convnets/inference/test/ReluTest.cpp similarity index 100% rename from recipes/streaming_convnets/inference/inference/module/test/ReluTest.cpp rename to recipes/streaming_convnets/inference/test/ReluTest.cpp diff --git a/recipes/streaming_convnets/inference/inference/module/test/ResidualTest.cpp b/recipes/streaming_convnets/inference/test/ResidualTest.cpp similarity index 99% rename from recipes/streaming_convnets/inference/inference/module/test/ResidualTest.cpp rename to recipes/streaming_convnets/inference/test/ResidualTest.cpp index cbe06bcc..9e899a35 100644 --- a/recipes/streaming_convnets/inference/inference/module/test/ResidualTest.cpp +++ b/recipes/streaming_convnets/inference/test/ResidualTest.cpp @@ -14,13 +14,13 @@ #include #include +#include "TestUtils.h" #include "inference/common/DataType.h" #include "inference/common/IOBuffer.h" #include "inference/module/ModuleParameter.h" #include "inference/module/ModuleProcessingState.h" #include "inference/module/nn/Conv1d.h" #include "inference/module/nn/Residual.h" -#include "inference/module/test/TestUtils.h" namespace w2l { namespace streaming { diff --git a/recipes/streaming_convnets/inference/inference/module/test/TDSBlockTest.cpp b/recipes/streaming_convnets/inference/test/TDSBlockTest.cpp similarity index 99% rename from recipes/streaming_convnets/inference/inference/module/test/TDSBlockTest.cpp rename to recipes/streaming_convnets/inference/test/TDSBlockTest.cpp index 1a6b5459..b137a174 100644 --- a/recipes/streaming_convnets/inference/inference/module/test/TDSBlockTest.cpp +++ b/recipes/streaming_convnets/inference/test/TDSBlockTest.cpp @@ -14,12 +14,12 @@ #include #include +#include "TestUtils.h" #include "inference/common/DataType.h" #include "inference/common/IOBuffer.h" #include "inference/module/ModuleParameter.h" #include "inference/module/ModuleProcessingState.h" #include "inference/module/nn/TDSBlock.h" -#include "inference/module/test/TestUtils.h" namespace w2l { namespace streaming { diff --git a/recipes/streaming_convnets/inference/inference/module/test/TestUtils.h b/recipes/streaming_convnets/inference/test/TestUtils.h similarity index 97% rename from recipes/streaming_convnets/inference/inference/module/test/TestUtils.h rename to recipes/streaming_convnets/inference/test/TestUtils.h index d1e598f5..00298379 100644 --- a/recipes/streaming_convnets/inference/inference/module/test/TestUtils.h +++ b/recipes/streaming_convnets/inference/test/TestUtils.h @@ -4,6 +4,9 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ + +#pragma once + #include #include diff --git a/recipes/streaming_convnets/inference/tools/CMakeLists.txt b/recipes/streaming_convnets/inference/tools/CMakeLists.txt new file mode 100644 index 00000000..99670b95 --- /dev/null +++ b/recipes/streaming_convnets/inference/tools/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) + +add_executable(streaming_tds_model_converter StreamingTDSModelConverter.cpp) + +if (NOT TARGET flashlight::flashlight-app-asr) + message(FATAL_ERROR "flashlight must be build with app/asr for w2l inference tools") +endif () + +if (@FL_USE_CUDA@) + find_dependency(CUDNN 7.1) +endif() + +target_link_libraries( + streaming_tds_model_converter + PRIVATE + streaming_inference_common + streaming_inference_modules + flashlight::flashlight-app-asr +) + +target_include_directories( + streaming_tds_model_converter + PRIVATE + ${PROJECT_SOURCE_DIR} +) diff --git a/recipes/streaming_convnets/tools/README.md b/recipes/streaming_convnets/inference/tools/README.md similarity index 100% rename from recipes/streaming_convnets/tools/README.md rename to recipes/streaming_convnets/inference/tools/README.md diff --git a/recipes/streaming_convnets/tools/StreamingTDSModelConverter.cpp b/recipes/streaming_convnets/inference/tools/StreamingTDSModelConverter.cpp similarity index 97% rename from recipes/streaming_convnets/tools/StreamingTDSModelConverter.cpp rename to recipes/streaming_convnets/inference/tools/StreamingTDSModelConverter.cpp index 42358c64..8b22be4e 100644 --- a/recipes/streaming_convnets/tools/StreamingTDSModelConverter.cpp +++ b/recipes/streaming_convnets/inference/tools/StreamingTDSModelConverter.cpp @@ -174,12 +174,7 @@ int main(int argc, char** argv) { LOG(INFO) << "Gflags after parsing \n" << serializeGflags("; "); /* ===================== Create Dictionary ===================== */ - auto dictPath = fl::lib::pathsConcat(FLAGS_tokensdir, FLAGS_tokens); - if (dictPath.empty() || !fileExists(dictPath)) { - throw std::runtime_error( - "Invalid dictionary filepath specified " + dictPath); - } - text::Dictionary tokenDict(dictPath); + text::Dictionary tokenDict(FLAGS_tokens); for (int64_t r = 1; r <= FLAGS_replabel; ++r) { tokenDict.addEntry("<" + std::to_string(r) + ">"); } @@ -198,7 +193,7 @@ int main(int argc, char** argv) { LOG(FATAL) << "This script currently support only mfsc features"; } - auto lines = getFileContent(fl::lib::pathsConcat(FLAGS_archdir, FLAGS_arch)); + auto lines = getFileContent(FLAGS_arch); auto streamingModule = std::make_shared(); auto params = network->params();