Skip to content

Commit

Permalink
inf_build
Browse files Browse the repository at this point in the history
  • Loading branch information
Vineel Pratap committed Jan 5, 2021
1 parent 64e54f8 commit 2399848
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 14 deletions.
22 changes: 11 additions & 11 deletions recipes/streaming_convnets/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.10)

project(wav2letter-inference)

# Creates build rules for wav2letter inference processing graph.
# Creates build rules for wav2letter inference

include(GNUInstallDirs)

Expand Down Expand Up @@ -31,16 +29,18 @@ set_property(
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(wav2letter-inference)

add_library(wav2letter-inference "")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

#--- Find gflags ---
find_package(gflags REQUIRED)
if (gflags_FOUND)
message(STATUS "gflags found")
#--- Find GFlags ---
find_package(GFLAGS REQUIRED)
if (GFLAGS_FOUND)
message(STATUS "GFLAGS found")
else()
message(FATAL_ERROR "gflags not found")
message(FATAL_ERROR "GFLAGS not found")
endif()

#--- Download and build Google test ---
Expand Down Expand Up @@ -82,7 +82,7 @@ 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)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples)
endif()

# ------------------------ Tests ------------------------
Expand Down Expand Up @@ -121,7 +121,7 @@ function(build_test SRCFILE)
endfunction(build_test)

set(W2L_INFERENCE_TESTS_PATH
${wav2letter-inference_SOURCE_DIR}/inference/module/test)
${wav2letter-inference_SOURCE_DIR}/test)

set(W2L_INFERENCE_TESTS_SOURCES
${W2L_INFERENCE_TESTS_PATH}/Conv1dTest.cpp
Expand Down
44 changes: 44 additions & 0 deletions recipes/streaming_convnets/inference/cmake/BuildGoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.5.1)

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 . --config Release
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
-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})

# Library and include dirs
set(GTEST_LIBRARIES
"${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

set(GTEST_INCLUDE_DIR
${GTEST_SOURCE_DIR}/googletest/include
${GTEST_SOURCE_DIR}/googlemock/include
)
83 changes: 83 additions & 0 deletions recipes/streaming_convnets/inference/cmake/Findkenlm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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")

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(FATAL_ERROR "kenlm library not found; 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(FATAL_ERROR "kenlm utils library not found; 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}")
else()
message(FATAL_ERROR "kenlm model.hh not found; please set CMAKE_INCLUDE_PATH, KENLM_MODEL_HEADER or KENLM_ROOT environment variable")
endif()
get_filename_component(KENLM_INCLUDE_LM ${KENLM_MODEL_HEADER} DIRECTORY)
get_filename_component(KENLM_INCLUDE_DIR ${KENLM_INCLUDE_LM} DIRECTORY)

set(KENLM_LIBRARIES ${KENLM_LIB} ${KENLM_UTIL_LIB})
# 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()
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ target_sources(streaming_inference_decoder
${CMAKE_CURRENT_LIST_DIR}/Decoder.cpp
)

get_target_property(DEC_SOURCES decoder-library INTERFACE_SOURCES)
if (NOT TARGET flashlight::fl-libraries)
message(FATAL_ERROR "flashight::fl-libraries must be built for inference")
endif ()

target_link_libraries(
streaming_inference_decoder
INTERFACE
${KENLM_LIBRARIES}
streaming_inference_common
decoder-library
wav2letter-libraries
flashight::fl-libraries
)

target_compile_definitions(
Expand Down
18 changes: 18 additions & 0 deletions recipes/streaming_convnets/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.10)

add_executable(
StreamingTDSModelConverter
StreamingTDSModelConverter.cpp
)

target_include_directories(
StreamingTDSModelConverter
PRIVATE
${PROJECT_SOURCE_DIR}
)

target_link_libraries(
StreamingTDSModelConverter
PRIVATE
flashlight::flashlight-app-asr
)

0 comments on commit 2399848

Please sign in to comment.