Skip to content

Commit

Permalink
Updates for vcpkg CUDA port version 1 (flashlight#384)
Browse files Browse the repository at this point in the history
Summary:
- Only link `fl-libraries` to the FL core if building tests - there are some uses in core tests - https://git.io/JL955
- Fix a dependent option issue with `FL_BUILD_CONTRIB`
- Remove Opus dependency -- `libogg` actually contains all of the opus symbols we need
- Don't install directories containing "tutorial"
- Consolidate gflags/glog locating
- More documentation tweaks and improvements

Pull Request resolved: flashlight#384

Test Plan: CI, devfair build + test, vcpkg build with my fork

Reviewed By: tlikhomanenko

Differential Revision: D25726638

Pulled By: jacobkahn

fbshipit-source-id: 97de3966c150ca98840eb03c36f3f931dea5f70e
  • Loading branch information
jacobkahn authored and facebook-github-bot committed Dec 29, 2020
1 parent fb28bd5 commit 0948e97
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 136 deletions.
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ option(FL_BUILD_SCRIPTS "Build internal scripts for wav2letter++" OFF)
option(FL_BUILD_RECIPES "Build recipes" ON)
option(FL_BUILD_STANDALONE "Build standalone installation" ON)
option(FL_BUILD_LIBRARIES "Build flashlight libraries" ON)
cmake_dependent_option(FL_BUILD_CORE "Build flashlight core" ON "FL_BUILD_LIBRARIES" OFF)
cmake_dependent_option(FL_BUILD_APPS "Build flashlight apps" ON "FL_BUILD_CORE" OFF)
option(FL_BUILD_CORE "Build flashlight core" ON)
cmake_dependent_option(FL_BUILD_CONTRIB
"Build and link additional flashlight contrib assets." ON
"FL_BUILD_CORE" OFF)
cmake_dependent_option(FL_BUILD_APPS
"Build flashlight apps" ON
"FL_BUILD_CORE;FL_BUILD_CONTRIB;FL_BUILD_LIBRARIES" OFF)

# Flashlight backend
set(FL_BACKEND "CUDA" CACHE STRING "Backend with which to build flashlight")
Expand Down Expand Up @@ -96,7 +101,8 @@ if (FL_BUILD_TESTS)
endif ()

# ------------------------ flashlight Libraries ------------------------
if (FL_BUILD_LIBRARIES)
# FIXME: libraries are required to build core tests - https://git.io/JL955
if (FL_BUILD_LIBRARIES OR (FL_BUILD_CORE AND FL_BUILD_TESTS))
message(STATUS "Will build flashlight libraries.")

option(FL_LIBRARIES_USE_CUDA "Use CUDA in flashlight libraries build" ON)
Expand Down Expand Up @@ -135,8 +141,10 @@ if (FL_BUILD_CORE)
CXX_STANDARD 14
)

# Link libraries to flashlight core
target_link_libraries(flashlight PUBLIC fl-libraries)
# FIXME: libraries are required to build core tests - https://git.io/JL955
if (FL_BUILD_LIBRARIES OR (FL_BUILD_CORE AND FL_BUILD_TESTS))
target_link_libraries(flashlight PUBLIC fl-libraries)
endif()

# ------------------------ Global External Dependencies ------------------------
# ArrayFire
Expand Down Expand Up @@ -253,6 +261,7 @@ endif() # if FL_BUILD_CORE

# --------------------------- Apps ---------------------------
if (FL_BUILD_APPS)
message(STATUS "Will build Flashlight applications.")
set(FL_APPS_DIR "${FL_ROOT_DIR}/app")
include(${FL_APPS_DIR}/CMakeLists.txt)
endif()
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ from the Facebook AI Research Speech team and the creators of Torch and
Deep Speech. Its core features include:
- Just-in-time kernel compilation with modern C++ with the [ArrayFire](https://github.com/arrayfire/arrayfire)
tensor library.
- CUDA, CPU, and OpenCL (coming soon) backends for GPU and CPU training.
- CUDA and CPU backends for GPU and CPU training.
- An emphasis on efficiency and scale.

Native support in C++ and simple extensibility makes Flashlight a powerful research framework that's *hackable to its core* and enables fast iteration on new experimental setups and algorithms without sacrificing performance. In a single repository, Flashlight provides [applications](https://github.com/facebookresearch/flashlight/tree/master/flashlight/app) for research across multiple domains:
- [Automatic speech recognition](https://github.com/facebookresearch/flashlight/tree/master/flashlight/app/asr) (the [wav2letter](https://github.com/facebookresearch/wav2letter/) project) — [Documentation](flashlight/app/asr) | [Tutorial](flashlight/app/asr/tutorial)
- [Image classification](flashlight/app/imgclass)
- [Language modeling](flashlight/app/lm)
- Image segmentation (coming soon)


### Project Layout
Expand Down Expand Up @@ -98,6 +97,7 @@ D.backward(); // populates A.grad() along with gradients for B, C, and D.
</details>

## Building and Installing
[**Install with `vcpkg`**](#library-installation-with-vcpkg) | [**Build from Source**](#building-from-source) | [**Build from Source with `vcpkg`**](#from-source-build-with-vcpkg) | [**Building Your Own Project with Flashlight**](#building-your-own-project-with-flashlight)

### Requirements
At minimum, compilation requires:
Expand Down Expand Up @@ -132,8 +132,6 @@ Flashlight [app binaries](flashlight/app) are also built for the selected featur

[Integrating Flashlight into your own project](#with-a-vcpkg-flashlight-installation) with is simple using `vcpkg`'s [CMake toolchain integration](https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/#cmake).

CPU and OpenCL support for Flashlight with `vcpkg` are coming soon.

#### From-Source Build with `vcpkg`

To build Flashlight from source using dependencies installed with `vcpkg`, install [`CUDA` >= 9.2](https://developer.nvidia.com/cuda-downloads), [`cuDNN`](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html), [`NCCL`](https://docs.nvidia.com/deeplearning/nccl/install-guide/index.html), and [Intel MKL](https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html), then build the rest of the dependencies for the CUDA backend based on which Flashlight features you'd like to build:
Expand Down Expand Up @@ -361,7 +359,7 @@ The Flashlight CMake build accepts the following build options (prefixed with `-
</tbody>
</table></div>

### Building your Own Project with Flashlight
### Building Your Own Project with Flashlight
Flashlight is most-easily linked to using CMake. Flashlight exports the following CMake targets when installed:
- `flashlight::fl-libraries` — contains flashlight libraries headers and symbols.
- `flashlight::flashlight` — contains flashlight libraries as well as the flashlight core autograd and neural network library.
Expand Down
3 changes: 0 additions & 3 deletions cmake/BuildSndFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.10.0)
# SndFile must be built with encoder libs
find_package(Ogg REQUIRED)
find_package(Vorbis REQUIRED)
find_package(Opus REQUIRED)
find_package(FLAC REQUIRED)

include(ExternalProject)
Expand Down Expand Up @@ -61,13 +60,11 @@ get_target_property(VORBIS_LIB Vorbis::vorbis IMPORTED_LOCATION)
get_target_property(VORBIS_ENC_LIB Vorbis::vorbisenc IMPORTED_LOCATION)
get_target_property(FLAC_LIB FLAC::FLAC IMPORTED_LOCATION)
get_target_property(OGG_LIB Ogg::ogg IMPORTED_LOCATION)
get_target_property(OPUS_LIB Opus::opus IMPORTED_LOCATION)
list(APPEND SNDFILE_DEP_LIBRARIES
${VORBIS_LIB}
${VORBIS_ENC_LIB}
${FLAC_LIB}
${OGG_LIB}
${OPUS_LIB}
)

add_library(SndFile::sndfile ${LIB_TYPE} IMPORTED)
Expand Down
65 changes: 0 additions & 65 deletions cmake/FindOpus.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions cmake/FindSndFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ if (NOT TARGET SndFile::sndfile)
# find_dependency() - we need them for creating a new IMPORTED target
find_package(Ogg REQUIRED)
find_package(Vorbis REQUIRED)
find_package(Opus REQUIRED)
find_package(FLAC REQUIRED)

find_path(
Expand Down Expand Up @@ -67,13 +66,11 @@ if (NOT TARGET SndFile::sndfile)
get_target_property(VORBIS_ENC_LIB Vorbis::vorbisenc IMPORTED_LOCATION)
get_target_property(FLAC_LIB FLAC::FLAC IMPORTED_LOCATION)
get_target_property(OGG_LIB Ogg::ogg IMPORTED_LOCATION)
get_target_property(OPUS_LIB Opus::opus IMPORTED_LOCATION)
list(APPEND SNDFILE_DEP_LIBRARIES
${VORBIS_LIB}
${VORBIS_ENC_LIB}
${FLAC_LIB}
${OGG_LIB}
${OPUS_LIB}
)

add_library(SndFile::sndfile UNKNOWN IMPORTED)
Expand Down
1 change: 1 addition & 0 deletions cmake/InternalUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function(setup_install_headers HEADER_DIR DEST_DIR)
PATTERN "tests" EXCLUDE
PATTERN "backend" EXCLUDE
PATTERN "examples" EXCLUDE
PATTERN "tutorial" EXCLUDE
PATTERN "third_party" EXCLUDE
PATTERN "experimental" EXCLUDE
PATTERN "plugincompiler" EXCLUDE
Expand Down
17 changes: 17 additions & 0 deletions flashlight/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ cmake_dependent_option(FL_BUILD_APP_ASR "Build asr task for flashlight" ON "FL_B
cmake_dependent_option(FL_BUILD_APP_IMGCLASS "Build image classification app" ON "FL_BUILD_CORE;FL_BUILD_CONTRIB;FL_BUILD_APPS" OFF)
cmake_dependent_option(FL_BUILD_APP_LM "Build lm task for flashlight" ON "FL_BUILD_CORE;FL_BUILD_CONTRIB;FL_BUILD_APPS" OFF)

# Find GLog
find_package(GLOG REQUIRED)
if (GLOG_FOUND)
message(STATUS "GLOG found")
else()
message(FATAL_ERROR "GLOG not found")
endif()

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

if (FL_BUILD_APP_ASR)
message(STATUS "Building flashlight ASR app")
if (NOT FL_BUILD_DISTRIBUTED)
Expand All @@ -16,6 +32,7 @@ if (FL_BUILD_APP_ASR)
endif ()

if (FL_BUILD_APP_IMGCLASS)
message(STATUS "Building flashlight imgclass app")
if (NOT FL_BUILD_DISTRIBUTED)
message(FATAL_ERROR "FL_BUILD_DISTRIBUTED must be enabled for image classification")
endif()
Expand Down
16 changes: 0 additions & 16 deletions flashlight/app/asr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ add_library(
""
)

# Find GLog
find_package(GLOG REQUIRED)
if (GLOG_FOUND)
message(STATUS "GLOG found")
else()
message(FATAL_ERROR "GLOG not found")
endif()

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

target_link_libraries(
flashlight-app-asr
PUBLIC
Expand Down
1 change: 0 additions & 1 deletion flashlight/app/asr/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if (FL_BUILD_STANDALONE)
setup_install_find_module(${CMAKE_MODULE_PATH}/FindSndFile.cmake)
setup_install_find_module(${CMAKE_MODULE_PATH}/FindOgg.cmake)
setup_install_find_module(${CMAKE_MODULE_PATH}/FindVorbis.cmake)
setup_install_find_module(${CMAKE_MODULE_PATH}/FindOpus.cmake)
setup_install_find_module(${CMAKE_MODULE_PATH}/FindFLAC.cmake)
endif()

Expand Down
16 changes: 0 additions & 16 deletions flashlight/app/imgclass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ add_library(
""
)

# Find GLog
find_package(GLOG REQUIRED)
if (GLOG_FOUND)
message(STATUS "GLOG found")
else()
message(FATAL_ERROR "GLOG not found")
endif()

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

target_link_libraries(
flashlight-app-imgclass
PUBLIC
Expand Down
18 changes: 1 addition & 17 deletions flashlight/app/lm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
cmake_minimum_required(VERSION 3.10)

# ------------------------- Library -------------------------
add_library(
flashlight-app-lm
""
)

# ------------------------ Global External Dependencies ------------------------
# Find gflags
find_package(GLOG REQUIRED)
if (GLOG_FOUND)
message(STATUS "GLOG found")
else()
message(FATAL_ERROR "GLOG not found")
endif()

find_package(gflags REQUIRED)
if (gflags_FOUND)
message(STATUS "gflags found")
else()
message(FATAL_ERROR "gflags not found")
endif()

target_sources(
flashlight-app-lm
PRIVATE
Expand All @@ -43,6 +26,7 @@ target_include_directories(
${GLOG_INCLUDE_DIRS}
${gflags_INCLUDE_DIRS}
)

# ------------------------ Components ------------------------

# Common
Expand Down
5 changes: 0 additions & 5 deletions flashlight/fl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ if (FL_BUILD_DISTRIBUTED)
endif ()

# -------------------------------- Components --------------------------------

# Build and link resources from `flashlight/contrib`.
cmake_dependent_option(FL_BUILD_CONTRIB
"Build and link additional flashlight contrib resources." ON
"FL_BUILD_CORE" OFF)
if (FL_BUILD_CONTRIB)
message(STATUS "Will build flashlight contrib assets.")
include(${FL_CORE_COMPONENT_SRC_DIR}/contrib/CMakeLists.txt)
Expand Down

0 comments on commit 0948e97

Please sign in to comment.