[C/C++ 인공지능][linux][cuda] flashlight


Flashlight: Fast, Flexible Machine Learning in C++

Quickstart | Installation | Documentation

CircleCI Documentation Status Docker Image Build Status Join the chat at https://gitter.im/flashlight-ml/community


Docker Image for CUDA backend Docker Image for CPU backend

Install CUDA backend with vcpkg Install CPU backend with vcpkg

Flashlight is a fast, flexible machine learning library written entirely in C++ 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 tensor library.
  • 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 apps for research across multiple domains:

Project Layout

Flashlight is broken down into a few parts:

  • flashlight/lib contains kernels and standalone utilities for sequence losses, beam search decoding, text processing, and more.
  • flashlight/fl is the core neural network library using the ArrayFire tensor library.
  • flashlight/app are applications of the core library to machine learning across domains.
  • `flashlight/pkg are packages built on top of Flashlight and ArrayFire for specific purposes (Domain libraries for speech, vision, and text, and Halide extensions).


First, build and install Flashlight and link it to your own project.

Sequential forms a sequence of Flashlight Modules for chaining computation.

Implementing a simple convnet is easy.

See the MNIST example for a full tutorial including a training loop and dataset abstractions.

Variable is the base Flashlight tensor that operates on ArrayFire arrays. Tape-based Automatic differentiation in Flashlight is simple and works as you'd expect.

Autograd Example

Building and Installing

Install with vcpkg | With Docker | From Source | From Source with vcpkg | Build Your Project with Flashlight


At minimum, compilation requires:

  • A C++ compiler with good C++17 support (e.g. gcc/g++ >= 7)
  • CMake — version 3.10 or later, and make
  • A Linux-based operating system.

See the full dependency list for more details if building from source.

Instructions for building/installing Python bindings can be found here.

Flashlight Build Setups

Flashlight can be broken down into several components as described above. Each component can be incrementally built by specifying the correct build options.

There are two ways to work with Flashlight:

  1. As an installed library that you link to with your own project. This is best for building standalone applications dependent on Flashlight.
  2. With in-source development where the Flashlight project source is changed and rebuilt. This is best if customizing/hacking the core framework or the Flashlight-provided app binaries.

Flashlight can be built in one of two ways:

  1. With vcpkg, a C++ package manager.
  2. From source by installing dependencies as needed.

Installing Flashlight with vcpkg

Library Installation with vcpkg

Flashlight is most-easily built and installed with vcpkg. Both the CUDA and CPU backends are supported with vcpkg. For either backend, first install Intel MKL. For the CUDA backend, install CUDA >= 9.2cuDNN, and NCCL. Then, after installing vcpkg, install the libraries and core with:

./vcpkg/vcpkg install flashlight-cuda # CUDA backend, OR
./vcpkg/vcpkg install flashlight-cpu  # CPU backend

To install Flashlight apps, check the features available for installation by running ./vcpkg search flashlight-cuda or ./vcpkg search flashlight-cpu. Each app is a "feature": for example, ./vcpkg install flashlight-cuda[asr] installs the ASR app with the CUDA backend.

Below is the currently-supported list of features (for each of flashlight-cuda and flashlight-cpu):

flashlight-{cuda/cpu}[lib]      # Flashlight libraries
flashlight-{cuda/cpu}[nn]       # Flashlight neural net library
flashlight-{cuda/cpu}[asr]      # Flashlight speech recognition app
flashlight-{cuda/cpu}[lm]       # Flashlight language modeling app
flashlight-{cuda/cpu}[imgclass] # Flashlight image classification app

Flashlight app binaries are also built for the selected features and are installed into the vcpkg install tree's tools directory.

Integrating Flashlight into your own project with is simple using vcpkg's CMake toolchain integration.

From-Source Build with vcpkg

First, install the dependencies for your backend of choice using vcpkg (click to expand the below):

Installing CUDA Backend Dependencies with vcpkg
Installing CPU Backend Dependencies with vcpkg
Build Using the vcpkg Toolchain File

To build Flashlight from source with these dependencies, clone the repository:

git clone https://github.com/flashlight/flashlight.git && cd flashlight
mkdir -p build && cd build

Then, build from source using vcpkg's CMake toolchain:

cmake .. \
    -DCMAKE_TOOLCHAIN_FILE=[path to your vcpkg clone]/scripts/buildsystems/vcpkg.cmake
make -j$(nproc)
make install -j$(nproc) # only if you want to install Flashlight for external use

To build a subset of Flashlight's features, see the build options below.

Building from Source

To build from source, first install the below dependencies. Most are available with your system's local package manager.

Some dependencies marked below are downloaded and installed automatically if not found on the local system. FL_BUILD_STANDALONE determines this behavior — if disabled, dependencies won't be downloaded and built when building Flashlight.

Once all dependencies are installed, clone the repository:

git clone https://github.com/flashlight/flashlight.git && cd flashlight
mkdir -p build && cd build

Then build all Flashlight components with:

cmake .. -DCMAKE_BUILD_TYPE=Release -DFL_BACKEND=[backend] [...build options]
make -j$(nproc)
make install

Setting the MKLROOT environment variable (export MKLROOT=/opt/intel/oneapi/mkl/latest or export MKLROOT=/opt/intel/mkl on most Linux-based systems) can help CMake find Intel MKL if not initially found.

To build a smaller subset of Flashlight features/apps, see the build options below for a complete list of options.

To install Flashlight in a custom directory, use CMake's CMAKE_INSTALL_PREFIX argument. Flashlight libraries can be built as shared libraries using CMake's BUILD_SHARED_LIBS argument.

Flashlight uses modern CMake and IMPORTED targets for most dependencies. If a dependency isn't found, passing -D<package>_DIR to your cmake command or exporting <package>_DIR as an environment variable equal to the path to <package>Config.cmake can help locate dependencies on your system. See the documentation for more details. If CMake is failing to locate a package, check to see if a corresponding issue has already been created before creating your own.


Dependencies marked with * are automatically downloaded and built from source if not found on the system. Setting FL_BUILD_STANDALONE to OFF disables this behavior.

Dependencies marked with ^ are required if building with distributed training enabled (FL_BUILD_DISTRIBUTED — see the build options below). Distributed training is required for all apps.

Dependencies marked with  are installable via vcpkg. See the instructions for installing those dependencies above for doing a Flashlight from-source build.

Component Backend Dependencies
Audio library (fl_lib_audio) CUDA CUDA >= 9.2, CUB*† (if CUDA < 11)
CPU A BLAS library (Intel MKL >= 2018, OpenBLAS†, etc)
core Any ArrayFire >= 3.7.3†, an MPI library^(OpenMPI†, etc),  cereal*† >= 1.3.0, stb*†
CUDA CUDA >= 9.2, NCCL^, cuDNN
CPU oneDNN† >= 2.0, gloo (with MPI)*^†
Runtime package (fl_pkg_runtime) Any Google Glog†, Gflags
Speech package (fl_pkg_speech) Any libsndfile*† >= 10.0.28, a BLAS library (Intel MKL >= 2018, OpenBLAS†, etc)
app: imgclass Any -
app: objdet Any -
app: lm Any -
tests Any Google Test (gtest, with gmock)*† >= 1.10.0

Build Options

The Flashlight CMake build accepts the following build options (prefixed with -D when running CMake from the command line):

Name Options Default Value Description
FL_BACKEND CUDA, CPU, OPENCL CUDA Backend with which to build all components.
FL_BUILD_STANDALONE ON, OFF ON Downloads/builds some dependencies if not found.
FL_BUILD_ALL_LIBS ON, OFF OFF Build all the Flashlight libraries.
FL_BUILD_LIB_SET ON, OFF OFF Build the Flashlight set library.
FL_BUILD_LIB_SEQUENCE ON, OFF OFF Build the Flashlight sequence library.
FL_BUILD_LIB_AUDIO ON, OFF OFF Build the Flashlight audio library.
FL_BUILD_LIB_COMMON ON, OFF OFF Build the Flashlight common library.
FL_BUILD_LIB_TEXT ON, OFF OFF Build the Flashlight text library.
FL_BUILD_CORE ON, OFF ON Build the Flashlight neural net library.
FL_BUILD_DISTRIBUTED ON, OFF ON Build with distributed training; required for apps.
FL_BUILD_CONTRIB ON, OFF ON Build contrib APIs subject to breaking changes.
FL_BUILD_ALL_PKGS ON, OFF OFF Defines default value for every pkg (see below).
FL_BUILD_PKG_VISION ON, OFF FL_BUILD_ALL_PKGS Build the flashlight vision package
FL_BUILD_PKG_TEXT ON, OFF FL_BUILD_ALL_PKGS Build the flashlight text package
FL_BUILD_PKG_SPEECH ON, OFF FL_BUILD_ALL_PKGS Build the flashlight speech package
FL_BUILD_PKG_HALIDE ON, OFF FL_BUILD_ALL_PKGS Build the flashlight halide package
FL_BUILD_ALL_APPS ON, OFF OFF Defines default value for every app (see below).
FL_BUILD_APP_ASR ON, OFF FL_BUILD_ALL_APPS Build the automatic speech recognition app.
FL_BUILD_APP_IMGCLASS ON, OFF FL_BUILD_ALL_APPS Build the image classification app.
FL_BUILD_APP_OBJDET ON, OFF FL_BUILD_ALL_APPS Build automatic speech recognition app tools.
FL_BUILD_APP_LM ON, OFF FL_BUILD_ALL_APPS Build the language modeling app.
FL_BUILD_APP_ASR_TOOLS ON, OFF FL_BUILD_APP_ASR Build automatic speech recognition app tools.
FL_BUILD_EXPERIMENTAL ON, OFF OFF Build experimental components.
CMAKE_BUILD_TYPE See docs. Debug See the CMake documentation.
CMAKE_INSTALL_PREFIX [Directory] See docs. See the CMake documentation.

Building Your Own Project with Flashlight

Flashlight is most-easily linked to using CMake. Flashlight exports the following CMake targets when installed:

  • flashlight::fl_lib_common — contains flashlight libraries for common headers and symbols used throughout flashlight.
  • flashlight::fl_lib_set — contains flashlight libraries for headers and symbols pertaining to sets.
  • flashlight::fl_lib_sequence — contains flashlight libraries for headers and symbols pertaining to sequences.
  • flashlight::fl_lib_audio — contains flashlight libraries for headers and symbols pertaining to audio.
  • flashlight::fl_lib_text — contains flashlight libraries for headers and symbols pertaining to text.
  • flashlight::flashlight — contains flashlight libraries as well as the flashlight core autograd and neural network library.
  • flashlight::fl_pkg_runtime — contains flashlight core as well as common utilities for training (logging / flags / distributed utils).
  • flashlight::fl_pkg_vision — contains flashlight core as well as common utilities for vision pipelines.
  • flashlight::fl_pkg_text — contains flashlight core as well as common utilities for dealing with text data.
  • flashlight::fl_pkg_speech — contains flashlight core as well as common utilities for dealing with speech data.
  • flashlight::fl_pkg_halide — contains flashlight core and extentions to easily interface with halide.

Given a simple project.cpp file that includes and links to Flashlight:

#include <iostream>

#include <arrayfire.h>
#include <flashlight/fl/flashlight.h>

int main() {
 fl::Variable v(af::constant(1, 1), true);
 auto result = v + 10;
 std::cout << "Hello World!" << std::endl;
 af::print("Array value is ", result.array()); // 11.000
 return 0;

The following CMake configuration links Flashlight and sets include directories:

cmake_minimum_required(VERSION 3.10)

add_executable(myProject project.cpp)

find_package(flashlight CONFIG REQUIRED)
target_link_libraries(myProject PRIVATE flashlight::flashlight)

With a vcpkg Flashlight Installation

If you installed Flashlight with vcpkg, the above CMake configuration for myProject can be built by running:

cd project && mkdir build && cd build
cmake .. \
  -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg clone]/scripts/buildsystems/vcpkg.cmake \
make -j$(nproc)

With a From-Source Flashlight Installation

If using a from-source installation of Flashlight, Flashlight will be found automatically by CMake:

cd project && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

If Flashlight is installed in a custom location using a CMAKE_INSTALL_PREFIX, passing -Dflashlight_DIR=[install prefix]/share/flashlight/cmake as an argument to your cmake command can help CMake find Flashlight.

Building and Running Flashlight with Docker

Flashlight and its dependencies can also be built with the provided Dockerfiles — see the accompanying Docker documentation for more information.

Contributing and Contact

Contact: vineelkpratap@fb.comawni@fb.comjacobkahn@fb.comqiantong@fb.comantares@fb.compadentomasello@fb.comjcai@fb.comgab@fb.comvitaliy888@fb.comlocronan@fb.com

Flashlight is being very actively developed. See CONTRIBUTING for more on how to help out.


Some of Flashlight's code is derived from arrayfire-ml.


Flashlight is under an MIT license. See LICENSE for more information.


[출처] https://github.com/flashlight/flashlight





본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
226 [C/C++][tensorflow 1.x] windows C lib : [Tensorflow] How to Install Tensorflow for C API file 졸리운_곰 2021.11.19 0
225 [C/C++][tensorflow] tensorflovw 1.x version 텐서플로우 C 예제 file 졸리운_곰 2021.11.19 1
224 [Visual Studio][boost c++] [C++] boost 설치 및 visual studio 설정 file 졸리운_곰 2021.11.18 0
223 [리눅스 마스터][linux, UNIX] 전설의 라인 에디트 Man page — ED 사용법 졸리운_곰 2021.11.18 0
222 [리눅스 마스터][linux, UNIX] [편집][shell] ed (line editer) 사용예 졸리운_곰 2021.11.17 0
221 [C/C++][gnuplot][수학][MFC] Windows 환경의 C++ 언어에서 gnuplot을 사용한 그래프 출력 2 file 졸리운_곰 2021.11.12 0
220 [C/C++][gnuplot][수학][MFC] Windows 환경의 C++ 언어에서 gnuplot을 사용한 그래프 출력 file 졸리운_곰 2021.11.12 2
» [C/C++ 인공지능][linux][cuda] flashlight file 졸리운_곰 2021.11.09 2
218 [C/C++] C++ Basic Input/Output 졸리운_곰 2021.11.06 4
217 [C/C++] Console Input/Output Functions in C file 졸리운_곰 2021.11.05 0
216 [C/C++ 프로그래밍] CMake 예제 졸리운_곰 2021.11.04 5
215 C/C++의 만년, 패키지 매니저 file 졸리운_곰 2021.11.04 2
214 [docker][도커] 로컬 개발환경 Docker 사용하기 file 졸리운_곰 2021.10.16 2
213 [unix][linux][compiler] Yacc와 Lex 시작하기 file 졸리운_곰 2021.09.08 2
212 [Docker][도커] docker 이미지 및 컨테이너 관리 명령어 정리 file 졸리운_곰 2021.08.29 5
211 [docker][도커] 컨테이너 시작, 중지, 재시작 졸리운_곰 2021.08.29 1
210 [Visual Studio 2019] Visual Studio로 Linux 원격 개발하기(Ubuntu 설치부터 SSH 서버접속까지) file 졸리운_곰 2021.08.29 4
209 [unix][emacs] 이맥스와 함께하는 개발환경 . emacs 튜토리얼 file 졸리운_곰 2021.08.18 6
208 [DOCKER] 도커_컨테이너 생성, 시작, 정지 file 졸리운_곰 2021.08.15 2
207 [쿠버네티스][Kubernetes] Helm 사용법 file 졸리운_곰 2021.07.19 4
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED