faiss-1.5.0版在cuda9.0(1080Ti)、cuda9.2(TitanV)上的編譯

背景

不支持conda安裝cuda9.2版本的faiss。faiss-1.5.1版本編譯不成功。

步驟

  1. 下載faiss-1.5.0版本,解壓并重命名為faiss
  2. 運(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

  1. 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
  1. 執(zhí)行
make install
  1. 安裝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
  1. 編譯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
  1. 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的路徑試試

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 5.2 Mac OS安裝說明 譯者:Python 文檔協(xié)作翻譯小組,原文:Mac OS Installation ...
    布客飛龍閱讀 2,119評(píng)論 0 6
  • tensorflow前前后后裝過幾十次,每次裝cuda&cuDNN都很麻煩,決定整理一下踩過的坑和安裝流程,記錄可...
    wong11閱讀 7,693評(píng)論 2 7
  • 第一章:編譯和安裝SCons第二章:簡(jiǎn)單編譯第三章:編譯相關(guān)的一些事情第四章:編譯和鏈接庫(kù)文件第五章:節(jié)點(diǎn)對(duì)象第六...
    仙靈兒閱讀 12,345評(píng)論 0 3
  • 提起老舍,我們都會(huì)想起他那凝練著很濃的北京風(fēng)味的筆觸。老舍先生是一位地道的北京人,而他所寫的《想北平》中,也有著最...
    創(chuàng)由心閱讀 350評(píng)論 0 3
  • 今早我說請(qǐng)假了。爸爸出差那么久,我們終于自由了,媽媽把日子都安排好了。他爸問,你打算干嘛呢?我說你都要出差那么久了...
    abdec69fff26閱讀 368評(píng)論 0 0

友情鏈接更多精彩內(nèi)容