Skip to content

Commit

Permalink
Merge branch 'inf_build' of github.com:facebookresearch/wav2letter in…
Browse files Browse the repository at this point in the history
…to inf_build
  • Loading branch information
Vineel Pratap committed Jan 5, 2021
2 parents 403feb6 + 12c84e5 commit 898e8f4
Show file tree
Hide file tree
Showing 108 changed files with 29,273 additions and 109 deletions.
95 changes: 54 additions & 41 deletions recipes/streaming_convnets/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
cmake_minimum_required(VERSION 3.10)

# Creates build rules for wav2letter inference
# Creates build rules for streaming inference

include(GNUInstallDirs)
project(streaming_inference CXX C)

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 convertor 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)

project(wav2letter-inference)

add_library(wav2letter-inference "")
add_library(streaming_inference "")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

Expand Down Expand Up @@ -81,23 +89,23 @@ 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)
if (STREAMING_INFERENCE_BUILD_EXAMPLES)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples)
endif()

# ------------------------ Tests ------------------------

add_custom_target(inference_tests)
add_custom_target(streaming_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(streaming_inference ${target})
add_dependencies(${target} gtest) # make sure gtest is built first
add_dependencies(inference_tests ${target})
add_dependencies(streaming_inference_tests ${target})
target_link_libraries(
${target}
PRIVATE
Expand All @@ -113,63 +121,68 @@ function(build_test SRCFILE)
${CMAKE_SOURCE_DIR}
${GTEST_INCLUDE_DIR}
# going up one directory to use #include "inference/*/*.h"
${wav2letter-inference_SOURCE_DIR}
${W2L_INFERENCE_TESTS_PATH}
${streaming_inference_SOURCE_DIR}
${STREAMING_INFERENCE_TESTS_PATH}
${cereal_INCLUDE_DIRS}
)
add_test(${target} ${target})
endfunction(build_test)

set(W2L_INFERENCE_TESTS_PATH
${wav2letter-inference_SOURCE_DIR}/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
set(STREAMING_INFERENCE_TESTS_PATH
${streaming_inference_SOURCE_DIR}/test)

set(STREAMING_INFERENCE_TESTS_SOURCES
${STREAMING_INFERENCE_TESTS_PATH}/Conv1dTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/IdentityTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/LayerNormTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/LinearTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/LogMelFeatureTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/MemoryManagerTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/ReluTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/ResidualTest.cpp
${STREAMING_INFERENCE_TESTS_PATH}/TDSBlockTest.cpp
)

if (W2L_INFERENCE_BUILD_TESTS)
if (STREAMING_INFERENCE_BUILD_TESTS)
find_package(Threads REQUIRED)
enable_testing()
foreach(SRC_FILE ${W2L_INFERENCE_TESTS_SOURCES})
foreach(SRC_FILE ${STREAMING_INFERENCE_TESTS_SOURCES})
build_test(${SRC_FILE})
endforeach()
endif()

# -------------- wav2letter-inference top level target -----------------
# ------------------------ Tools ------------------------
if (STREAMING_INFERENCE_BUILD_TOOLS)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools)
endif()

# -------------- 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
)
24 changes: 24 additions & 0 deletions recipes/streaming_convnets/inference/cereal/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2014, Randolph Voorhies, Shane Grant
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 changes: 85 additions & 0 deletions recipes/streaming_convnets/inference/cereal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
cereal - A C++11 library for serialization
==========================================

<img src="http://uscilab.github.io/cereal/assets/img/cerealboxside.png" align="right"/><p>cereal is a header-only C++11 serialization library. cereal takes arbitrary data types and reversibly turns them into different representations, such as compact binary encodings, XML, or JSON. cereal was designed to be fast, light-weight, and easy to extend - it has no external dependencies and can be easily bundled with other code or used standalone.</p>

### cereal has great documentation

Looking for more information on how cereal works and its documentation? Visit [cereal's web page](http://USCiLab.github.com/cereal) to get the latest information.

### cereal is easy to use

Installation and use of of cereal is fully documented on the [main web page](http://USCiLab.github.com/cereal), but this is a quick and dirty version:

* Download cereal and place the headers somewhere your code can see them
* Write serialization functions for your custom types or use the built in support for the standard library cereal provides
* Use the serialization archives to load and save data

```cpp
#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/binary.hpp>
#include <fstream>

struct MyRecord
{
uint8_t x, y;
float z;

template <class Archive>
void serialize( Archive & ar )
{
ar( x, y, z );
}
};

struct SomeData
{
int32_t id;
std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data;

template <class Archive>
void save( Archive & ar ) const
{
ar( data );
}

template <class Archive>
void load( Archive & ar )
{
static int32_t idGen = 0;
id = idGen++;
ar( data );
}
};

int main()
{
std::ofstream os("out.cereal", std::ios::binary);
cereal::BinaryOutputArchive archive( os );

SomeData myData;
archive( myData );

return 0;
}
```

### cereal has a mailing list

Either get in touch over <a href="mailto:[email protected]">email</a> or [on the web](https://groups.google.com/forum/#!forum/cerealcpp).



## cereal has a permissive license

cereal is licensed under the [BSD license](http://opensource.org/licenses/BSD-3-Clause).

## cereal build status

* develop : [![Build Status](https://travis-ci.org/USCiLab/cereal.png?branch=develop)](https://travis-ci.org/USCiLab/cereal)
[![Build status](https://ci.appveyor.com/api/projects/status/91aou6smj36or0vb/branch/develop?svg=true)](https://ci.appveyor.com/project/AzothAmmo/cereal/branch/develop)

---

Were you looking for the Haskell cereal? Go <a href="https://github.com/GaloisInc/cereal">here</a>.
Loading

0 comments on commit 898e8f4

Please sign in to comment.