背景
不支持conda安裝cuda9.2版本的faiss。faiss-1.5.1版本編譯不成功。
步驟
- 下載faiss-1.5.0版本,解壓并重命名為faiss
- 運(yùn)行
./configure --prefix=/home/cyh/faiss_build/ --with-cuda=/usr/local/cuda-9.2 --with-python=python3
# prefix: build的路徑
# with-cuda: 安裝cuda的路徑
# with-python: 指定python版本
得到makefile.inc
cuda9.0的makefile.inc
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD+Patents license found in the
# LICENSE file in the root directory of this source tree.
CXX = g++ -std=c++11
CXXCPP = g++ -std=c++11 -E
# TODO: Investigate the LAPACKE wrapper for LAPACK, which defines the correct
# type for FORTRAN integers.
CPPFLAGS = -DFINTEGER=int
CXXFLAGS = -fPIC -fopenmp -m64 -Wno-sign-compare -g -O3 -Wall -Wextra
CPUFLAGS = -msse4 -mpopcnt
LDFLAGS = -fopenmp
LIBS = -lopenblas
PYTHONCFLAGS = -I/usr/include/python3.5m -I/usr/include/python3.5m -I/home/cyh/.local/lib/python3.5/site-packages/numpy/core/include
NVCC = /usr/local/cuda-9.0/bin/nvcc
NVCCLDFLAGS = -L/usr/local/cuda-9.0/lib64
NVCCLIBS = -lcudart -lcublas -lcuda
CUDAROOT = /usr/local/cuda-9.0
CUDACFLAGS = -I/usr/local/cuda-9.0/include
NVCCFLAGS = -I $(CUDAROOT)/targets/x86_64-linux/include/ \
-Xcompiler -fPIC \
-Xcudafe --diag_suppress=unrecognized_attribute \
-gencode arch=compute_35,code="compute_35" \
-gencode arch=compute_52,code="compute_52" \
-gencode arch=compute_60,code="compute_60" \
-gencode arch=compute_61,code="compute_61" \
-lineinfo \
-ccbin $(CXX) -DFAISS_USE_FLOAT16
OS = $(shell uname -s)
SHAREDEXT = so
SHAREDFLAGS = -shared
ifeq ($(OS),Darwin)
SHAREDEXT = dylib
SHAREDFLAGS = -dynamiclib -undefined dynamic_lookup
endif
MKDIR_P = /bin/mkdir -p
PYTHON = python3
SWIG = swig
prefix ?= /home/cyh/faiss_build
exec_prefix ?= ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
cuda9.2的makefile.inc,可以看出NVCC和CUDA的相關(guān)變量都為空。
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD+Patents license found in the
# LICENSE file in the root directory of this source tree.
CXX = g++ -std=c++11
CXXCPP = g++ -std=c++11 -E
# TODO: Investigate the LAPACKE wrapper for LAPACK, which defines the correct
# type for FORTRAN integers.
CPPFLAGS = -DFINTEGER=int
CXXFLAGS = -fPIC -fopenmp -m64 -Wno-sign-compare -g -O3 -Wall -Wextra
CPUFLAGS = -msse4 -mpopcnt
LDFLAGS = -fopenmp
LIBS = -lopenblas
PYTHONCFLAGS = -I/usr/include/python3.5m -I/usr/include/python3.5m -I/home/cyh/.local/lib/python3.5/site-packages/numpy/core/include
NVCC =
NVCCLDFLAGS =
NVCCLIBS =
CUDAROOT =
CUDACFLAGS =
NVCCFLAGS = -I $(CUDAROOT)/targets/x86_64-linux/include/ \
-Xcompiler -fPIC \
-Xcudafe --diag_suppress=unrecognized_attribute \
-gencode arch=compute_35,code="compute_35" \
-gencode arch=compute_52,code="compute_52" \
-gencode arch=compute_60,code="compute_60" \
-gencode arch=compute_61,code="compute_61" \
-lineinfo \
-ccbin $(CXX) -DFAISS_USE_FLOAT16
OS = $(shell uname -s)
SHAREDEXT = so
SHAREDFLAGS = -shared
ifeq ($(OS),Darwin)
SHAREDEXT = dylib
SHAREDFLAGS = -dynamiclib -undefined dynamic_lookup
endif
MKDIR_P = /bin/mkdir -p
PYTHON = python3
SWIG =
prefix ?= /home/cyh/faiss_build
exec_prefix ?= ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
- cuda9.0直接運(yùn)行
make -j
cuda9.2需要修改makefile.inc為
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD+Patents license found in the
# LICENSE file in the root directory of this source tree.
CXX = g++ -std=c++11
CXXCPP = g++ -std=c++11 -E
# TODO: Investigate the LAPACKE wrapper for LAPACK, which defines the correct
# type for FORTRAN integers.
CPPFLAGS = -DFINTEGER=int
CXXFLAGS = -fPIC -fopenmp -m64 -Wno-sign-compare -g -O3 -Wall -Wextra
CPUFLAGS = -msse4 -mpopcnt
LDFLAGS = -fopenmp
LIBS = -lopenblas
PYTHONCFLAGS = -I/usr/include/python3.5m -I/usr/include/python3.5m -I/home/cyh/faiss_build/include/faiss
NVCC = /usr/local/cuda-9.2/bin/nvcc
NVCCLDFLAGS = -L/usr/local/cuda-9.2/lib64
NVCCLIBS = -lcudart -lcublas -lcuda
CUDAROOT = /usr/local/cuda-9.2
CUDACFLAGS = -I/usr/local/cuda-9.2/include
NVCCFLAGS = -I $(CUDAROOT)/targets/x86_64-linux/include/ \
-Xcompiler -fPIC \
-Xcudafe --diag_suppress=unrecognized_attribute \
-gencode arch=compute_35,code="compute_35" \
-gencode arch=compute_52,code="compute_52" \
-gencode arch=compute_60,code="compute_60" \
-gencode arch=compute_61,code="compute_61" \
-gencode arch=compute_70,code="compute_70" \
-lineinfo \
-ccbin $(CXX) -DFAISS_USE_FLOAT16
OS = $(shell uname -s)
SHAREDEXT = so
SHAREDFLAGS = -shared
ifeq ($(OS),Darwin)
SHAREDEXT = dylib
SHAREDFLAGS = -dynamiclib -undefined dynamic_lookup
endif
MKDIR_P = /bin/mkdir -p
PYTHON = python3
SWIG =
prefix ?= /home/cyh/faiss_build
exec_prefix ?= ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
其中,cuda9.2需要改的部分:
NVCC = /usr/local/cuda-9.2/bin/nvcc
NVCCLDFLAGS = -L/usr/local/cuda-9.2/lib64
NVCCLIBS = -lcudart -lcublas -lcuda
CUDAROOT = /usr/local/cuda-9.2
CUDACFLAGS = -I/usr/local/cuda-9.2/include
NVCCFLAGS = -I $(CUDAROOT)/targets/x86_64-linux/include/ \
TitanV需要增加一行,增加計(jì)算能力
-gencode arch=compute_70,code="compute_70" \
然后再執(zhí)行
make -j
- 執(zhí)行
make install
- 安裝python版本
如果需要更改python版本faiss安裝路徑,更改faiss/python/Makefile
install: build
$(PYTHON) setup.py install --prefix=/home/cyh/.local
# 增加 --perfix 安裝路徑
然后執(zhí)行
make py
如果找不到xxx.h,更改makefile.inc中的PYTHONCFLAGS為
PYTHONCFLAGS = -I/usr/include/python3.5m -I/usr/include/python3.5m -I/home/cyh/faiss_build/include/faiss
# -I/home/cyh/faiss_build/include/faiss: -I$(faiss的build路徑)/include/faiss
- 編譯gpu相關(guān)組件
faiss/gpu/Makefile的48行少了一個(gè)\,更改為:
48 GpuIndexBinaryFlat.o \
執(zhí)行
make -j
測(cè)試gpu,進(jìn)入faiss/gpu/test
make demo_ivfpq_indexing_gpu
- python的gpu版本
進(jìn)入faiss/python
make _swigfaiss_gpu.so
測(cè)試
python -c "import _swigfaiss_gpu"
如果編譯沒有報(bào)錯(cuò),但是import報(bào)錯(cuò)了,可以關(guān)掉conda的路徑試試