Skip to content

[build] Add cub library for cuda projects #2819

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

Merged
merged 3 commits into from
Nov 15, 2018
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ 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
11 changes: 11 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ android=false
MATHLIB='ATLAS'
ATLASROOT=`rel2abs ../tools/ATLAS_headers/`
FSTROOT=`rel2abs ../tools/openfst`
CUBROOT=`rel2abs ../tools/cub`

# Save the command line to include in kaldi.mk
cmd_line="$0 $@"
Expand Down Expand Up @@ -955,6 +956,9 @@ do
--fst-root=*)
FSTROOT=`read_dirname $1`;
shift ;;
--cub-root=*)
CUBROOT=`read_dirname $1`;
shift ;;
--clapack-root=*)
CLAPACKROOT=`read_dirname $1`;
shift ;;
Expand Down Expand Up @@ -1092,6 +1096,13 @@ if $double_precision; then
else
echo "DOUBLE_PRECISION = 0" >> kaldi.mk
fi
$use_cuda && echo "Checking cub library in $CUBROOT ..."
if [[ $use_cuda && ! -f $CUBROOT/cub/cub.cuh ]]; then
failure "Could not find file $CUBROOT/cub/cub.cuh:
you may not have installed cub. See ../tools/INSTALL"
else
echo "CUBROOT = $CUBROOT" >> kaldi.mk
fi
echo "Checking OpenFst library in $FSTROOT ..."
if [ ! -f $FSTROOT/include/fst/fst.h ]; then
failure "Could not find file $FSTROOT/include/fst/fst.h:
Expand Down
11 changes: 6 additions & 5 deletions src/makefiles/cuda_32bit.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ ifndef CUDATKDIR
$(error CUDATKDIR not defined.)
endif

CUDA_INCLUDE= -I$(CUDATKDIR)/include
CUDA_FLAGS = -g -Xcompiler -fPIC --verbose --machine 32 -DHAVE_CUDA \
CUDA_INCLUDE= -I$(CUDATKDIR)/include -I$(CUBROOT)
CUDA_FLAGS = -Xcompiler "-fPIC -pthread -isystem $(OPENFSTINC)" --verbose --machine 32 -DHAVE_CUDA \
-ccbin $(CXX) -DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-DCUDA_API_PER_THREAD_DEFAULT_STREAM
-std=c++11 -DCUDA_API_PER_THREAD_DEFAULT_STREAM

CXXFLAGS += -DHAVE_CUDA -I$(CUDATKDIR)/include
LDFLAGS += -L$(CUDATKDIR)/lib -Wl,-rpath=$(CUDATKDIR)/lib
LDLIBS += -lcublas -lcusparse -lcudart -lcurand #LDLIBS : The libs are loaded later than static libs in implicit rule
CUDA_LDFLAGS += -L$(CUDATKDIR)/lib -Wl,-rpath,$(CUDATKDIR)/lib
CUDA_LDLIBS += -lcuda -lcublas -lcusparse -lcudart -lcurand -lnvToolsExt #LDLIBS : The libs are loaded later than static libs in implicit rule
9 changes: 5 additions & 4 deletions src/makefiles/cuda_64bit.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ ifndef CUDATKDIR
$(error CUDATKDIR not defined.)
endif

CUDA_INCLUDE= -I$(CUDATKDIR)/include
CUDA_FLAGS = -g -Xcompiler -fPIC --verbose --machine 64 -DHAVE_CUDA \
CUDA_INCLUDE= -I$(CUDATKDIR)/include -I$(CUBROOT)
CUDA_FLAGS = -Xcompiler "-fPIC -pthread -isystem $(OPENFSTINC)" --verbose --machine 64 -DHAVE_CUDA \
-ccbin $(CXX) -DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-DCUDA_API_PER_THREAD_DEFAULT_STREAM
-std=c++11 -DCUDA_API_PER_THREAD_DEFAULT_STREAM

CXXFLAGS += -DHAVE_CUDA -I$(CUDATKDIR)/include
CUDA_LDFLAGS += -L$(CUDATKDIR)/lib64 -Wl,-rpath,$(CUDATKDIR)/lib64
CUDA_LDLIBS += -lcublas -lcusparse -lcudart -lcurand #LDLIBS : The libs are loaded later than static libs in implicit rule
CUDA_LDLIBS += -lcuda -lcublas -lcusparse -lcudart -lcurand -lnvToolsExt #LDLIBS : The libs are loaded later than static libs in implicit rule
16 changes: 14 additions & 2 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CC = gcc # used for sph2pipe
# Note: OpenFst requires a relatively recent C++ compiler with C++11 support,
# e.g. g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3.
OPENFST_VERSION ?= 1.6.7
CUB_VERSION ?= 1.8.0

# Default features configured for OpenFST; can be overridden in the make command line.
OPENFST_CONFIGURE ?= --enable-static --enable-shared --enable-far --enable-ngram-fsts
Expand All @@ -18,7 +19,7 @@ ifeq ("$(shell expr $(OPENFST_VER_NUM) \< 10600)","1")
Supported versions: >= 1.6.0)
endif

all: check_required_programs sph2pipe sclite openfst
all: check_required_programs sph2pipe sclite openfst cub
@echo -e "\n\n"
@echo "Warning: IRSTLM is not installed by default anymore. If you need IRSTLM"
@echo "Warning: use the script extras/install_irstlm.sh"
Expand Down Expand Up @@ -49,6 +50,9 @@ distclean:
rm -rf openfst-$(OPENFST_VERSION).tar.gz
rm -f openfst
rm -rf libsndfile-1.0.25{,.tar.gz} BeamformIt-3.51{,.tgz}
rm -f cub-$(CUB_VERSION).zip
rm -rf cub-$(CUB_VERSION)
rm -f cub


.PHONY: openfst # so target will be made even though "openfst" exists.
Expand Down Expand Up @@ -119,7 +123,7 @@ sph2pipe_v2.5/sph2pipe: | sph2pipe_v2.5
$(CC) -o sph2pipe *.c -lm

sph2pipe_v2.5: sph2pipe_v2.5.tar.gz
tar xzf sph2pipe_v2.5.tar.gz
tar --no-same-owner -xzf sph2pipe_v2.5.tar.gz

sph2pipe_v2.5.tar.gz:
wget -T 10 -t 3 http://www.openslr.org/resources/3/sph2pipe_v2.5.tar.gz || \
Expand Down Expand Up @@ -149,3 +153,11 @@ openblas_compiled:
cd OpenBLAS; sed 's:# FCOMMON_OPT = -frecursive:FCOMMON_OPT = -frecursive:' < Makefile.rule >tmp && mv tmp Makefile.rule
# $(MAKE) PREFIX=`pwd`/OpenBLAS/install FC=gfortran $(fortran_opt) DEBUG=1 USE_THREAD=1 NUM_THREADS=64 -C OpenBLAS all install
$(MAKE) PREFIX=`pwd`/OpenBLAS/install FC=gfortran $(fortran_opt) DEBUG=1 USE_THREAD=0 -C OpenBLAS all install


.PHONY: cub
cub:
wget -T 10 -t 3 -O cub-$(CUB_VERSION).zip https://github.com/NVlabs/cub/archive/$(CUB_VERSION).zip
unzip -oq cub-$(CUB_VERSION).zip
rm -f cub
ln -s cub-$(CUB_VERSION) cub
1 change: 1 addition & 0 deletions tools/extras/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ echo "Building tools..." [Time: $(date)]
runvx cd tools
runvx make -j$MAXPAR openfst "$CCC" CXXFLAGS="$CF" \
OPENFST_CONFIGURE="--disable-static --enable-shared --disable-bin --disable-dependency-tracking"
runvx make -j$MAXPAR cub "$CCC" CXXFLAGS="$CF"
cd ..

runvx cd src
Expand Down