Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[src,build] Add minimal example to demonstrate pybind11 binding #3668

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

<!--
WARNING: THE KALDI ISSUE TRACKER IS **ONLY** USED FOR KALDI DEVELOPMENT!

If you have a question about using Kaldi, please use the kald-help discussion group:

https://groups.google.com/forum/#!forum/kaldi-help

Instructions for joining are available at: http://kaldi-asr.org/forums.html
-->
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-proposal-discussion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Feature proposal or discussion
about: Suggest an idea for Kaldi
title: ''
labels: discussion
assignees: ''

---

<!--
WARNING: THE KALDI ISSUE TRACKER IS **ONLY** USED FOR KALDI DEVELOPMENT!

If you have a question about using Kaldi, please use the kald-help discussion group:

https://groups.google.com/forum/#!forum/kaldi-help

Instructions for joining are available at: http://kaldi-asr.org/forums.html
-->
21 changes: 17 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ GSYMS
/src/kaldi.mk.bak

# /egs/
/egs/*/s*/mfcc
/egs/*/s*/plp
/egs/*/s*/exp
/egs/*/s*/data
/egs/*/*/mfcc
/egs/*/*/plp
/egs/*/*/exp
/egs/*/*/data
/egs/*/*/wav
/egs/*/*/enhan

# /tools/
/tools/pocolm/
/tools/ATLAS/
/tools/atlas3.8.3.tar.gz
/tools/irstlm/
/tools/mitlm/
/tools/openfst
/tools/openfst-1.3.2.tar.gz
/tools/openfst-1.3.2/
Expand Down Expand Up @@ -143,3 +147,12 @@ GSYMS
/tools/mmseg-1.3.0.tar.gz
/tools/mmseg-1.3.0/
/kaldiwin_vs*
/tools/cub-1.8.0.zip
/tools/cub-1.8.0/
/tools/cub
/tools/python/

# These CMakeLists.txt files are all genareted on the fly at the moment.
# They are added here to avoid accidently checkin.
/src/**/CMakeLists.txt
/build*
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ script:
# for the explanation why extra switches needed for clang with ccache.
- CXX="ccache clang++-3.8 -Qunused-arguments -fcolor-diagnostics -Wno-tautological-compare"
CFLAGS=""
LDFLAGS="-llapack"
LDFLAGS="-llapack -Wl,-fuse-ld=gold"
INCDIRS="$XROOT/usr/include"
LIBDIRS="$XROOT/usr/lib"
tools/extras/travis_script.sh
Expand Down
195 changes: 195 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
cmake_minimum_required(VERSION 3.5)
project(kaldi)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(GNUInstallDirs)
include(Utils)
include(third_party/get_third_party)

message(STATUS "Running gen_cmake_skeleton.py")
execute_process(COMMAND python
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/gen_cmake_skeleton.py"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"--quiet"
)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INSTALL_MESSAGE LAZY) # hide "-- Up-to-date: ..."
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
message(FATAL_ERROR "DLL is not supported currently")
elseif(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib")
endif()
endif()

set(MATHLIB "OpenBLAS" CACHE STRING "OpenBLAS|MKL|Accelerate")
option(KALDI_BUILD_EXE "If disabled, will make add_kaldi_executable a no-op" ON)
option(KALDI_BUILD_TEST "If disabled, will make add_kaldi_test_executable a no-op" ON)
option(KALDI_USE_PATCH_NUMBER "Use MAJOR.MINOR.PATCH format, otherwise MAJOR.MINOR" OFF)

link_libraries(${CMAKE_DL_LIBS})

find_package(Threads)
link_libraries(Threads::Threads)

if(MATHLIB STREQUAL "OpenBLAS")
set(BLA_VENDOR "OpenBLAS")
find_package(LAPACK REQUIRED)
add_definitions(-DHAVE_CLAPACK=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tools/CLAPACK)
link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
elseif(MATHLIB STREQUAL "MKL")
set(BLA_VENDOR "Intel10_64lp")
# find_package(BLAS REQUIRED)
normalize_env_path(ENV{MKLROOT})
find_package(LAPACK REQUIRED)
add_definitions(-DHAVE_MKL=1)
include_directories($ENV{MKLROOT}/include) # TODO: maybe not use env, idk, find_package doesnt handle includes...
link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
elseif(MATHLIB STREQUAL "Accelerate")
set(BLA_VENDOR "Apple")
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
add_definitions(-DHAVE_CLAPACK=1)
link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
else()
message(FATAL_ERROR "${MATHLIB} is not tested and supported, you are on your own now.")
endif()

if(MSVC)
# Added in source, but we actually should do it in build script, whatever...
# add_definitions(-DWIN32_LEAN_AND_MEAN=1)

add_compile_options(/permissive- /FS /wd4819 /EHsc /bigobj)

# some warnings related with fst
add_compile_options(/wd4018 /wd4244 /wd4267 /wd4291 /wd4305)

set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "")
if(NOT DEFINED ENV{CUDAHOSTCXX})
set(ENV{CUDAHOSTCXX} ${CMAKE_CXX_COMPILER})
endif()
if(NOT DEFINED CUDA_HOST_COMPILER)
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
endif()
endif()

find_package(CUDA)
if(CUDA_FOUND)
set(CUB_ROOT_DIR "${PROJECT_SOURCE_DIR}/tools/cub")

set(CUDA_PROPAGATE_HOST_FLAGS ON)
set(KALDI_CUDA_NVCC_FLAGS "--default-stream=per-thread;-std=c++${CMAKE_CXX_STANDARD}")
if(MSVC)
list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler /permissive-,/FS,/wd4819,/EHsc,/bigobj")
list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler /wd4018,/wd4244,/wd4267,/wd4291,/wd4305")
if(BUILD_SHARED_LIBS)
list(APPEND CUDA_NVCC_FLAGS_RELEASE -Xcompiler /MD)
list(APPEND CUDA_NVCC_FLAGS_DEBUG -Xcompiler /MDd)
endif()
else()
# list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler -std=c++${CMAKE_CXX_STANDARD}")
list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler -fPIC")
endif()
set(CUDA_NVCC_FLAGS ${KALDI_CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS})

add_definitions(-DHAVE_CUDA=1)
add_definitions(-DCUDA_API_PER_THREAD_DEFAULT_STREAM=1)
include_directories(${CUDA_INCLUDE_DIRS})
link_libraries(
${CUDA_LIBRARIES}
${CUDA_CUDA_LIBRARY}
${CUDA_CUBLAS_LIBRARIES}
${CUDA_CUFFT_LIBRARIES}
${CUDA_curand_LIBRARY}
${CUDA_cusolver_LIBRARY}
${CUDA_cusparse_LIBRARY})

find_package(NvToolExt REQUIRED)
include_directories(${NvToolExt_INCLUDE_DIR})
link_libraries(${NvToolExt_LIBRARIES})

find_package(CUB REQUIRED)
include_directories(${CUB_INCLUDE_DIR})
endif()

add_definitions(-DKALDI_NO_PORTAUDIO=1)

include(VersionHelper)
get_version() # this will set KALDI_VERSION and KALDI_PATCH_NUMBER
if(${KALDI_USE_PATCH_NUMBER})
set(KALDI_VERSION "${KALDI_VERSION}.${KALDI_PATCH_NUMBER}")
endif()

get_third_party(openfst)
set(OPENFST_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/openfst)
include(third_party/openfst_lib_target)
link_libraries(fst)

# add all native libraries
add_subdirectory(src/base) # NOTE, we need to patch the target with version from outside
set_property(TARGET kaldi-base PROPERTY COMPILE_DEFINITIONS "KALDI_VERSION=\"${KALDI_VERSION}\"")
add_subdirectory(src/matrix)
add_subdirectory(src/cudamatrix)
add_subdirectory(src/util)
add_subdirectory(src/feat)
add_subdirectory(src/tree)
add_subdirectory(src/gmm)
add_subdirectory(src/transform)
add_subdirectory(src/sgmm2)
add_subdirectory(src/fstext)
add_subdirectory(src/hmm)
add_subdirectory(src/lm)
add_subdirectory(src/decoder)
add_subdirectory(src/lat)
add_subdirectory(src/nnet)
add_subdirectory(src/nnet2)
add_subdirectory(src/nnet3)
add_subdirectory(src/rnnlm)
add_subdirectory(src/chain)
add_subdirectory(src/ivector)
add_subdirectory(src/online)
add_subdirectory(src/online2)
add_subdirectory(src/kws)

add_subdirectory(src/itf)

# add all cuda libraries
if(CUDA_FOUND)
add_subdirectory(src/cudafeat)
add_subdirectory(src/cudadecoder)
endif()

# add all native executables
add_subdirectory(src/gmmbin)
add_subdirectory(src/featbin)
add_subdirectory(src/onlinebin)

# add all cuda executables
if(CUDA_FOUND)
add_subdirectory(src/cudafeatbin)
add_subdirectory(src/cudadecoderbin)
endif()

include(CMakePackageConfigHelpers)
# maybe we should put this into subfolder?
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/kaldi-config.cmake.in
${CMAKE_BINARY_DIR}/cmake/kaldi-config.cmake
INSTALL_DESTINATION lib/cmake/kaldi
)
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/cmake/kaldi-config-version.cmake
VERSION ${KALDI_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_BINARY_DIR}/cmake/kaldi-config.cmake ${CMAKE_BINARY_DIR}/cmake/kaldi-config-version.cmake
DESTINATION lib/cmake/kaldi
)
install(EXPORT kaldi-targets DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/kaldi)
17 changes: 12 additions & 5 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
This is the official Kaldi INSTALL. Look also at INSTALL.md for the git mirror installation.
[for native Windows install, see windows/INSTALL]
[Option 1 in the following does not apply to native Windows install, see windows/INSTALL or following Option 2]

(1)
go to tools/ and follow INSTALL instructions there.
Option 1 (bash + makefile):

(2)
go to src/ and follow INSTALL instructions there.
Steps:
(1)
go to tools/ and follow INSTALL instructions there.

(2)
go to src/ and follow INSTALL instructions there.

Option 2 (cmake):

Go to cmake/ and follow INSTALL.md instructions there.
Note, it may not be well tested and some features are missing currently.
Loading