Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add initial cmake support * update cmake, add cmake instructions to INSTALL * update findopenmp and INSTALL * change FindOpenBLAS.cmake to cater for macports - change cblas.h to openblas_config.h since macports does not ship cblas.h with openblas. * revise INSTALL for cmake
- Loading branch information
Showing
9 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
cmake_minimum_required(VERSION 2.8.7) | ||
|
||
# faiss project | ||
project(faiss C CXX) | ||
|
||
option(BUILD_TUTORIAL "Build tutorials" ON) | ||
option(BUILD_TEST "Build tests" ON) | ||
option(BUILD_WITH_GPU "Build faiss with gpu (cuda) support" ON) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) | ||
|
||
# OpenMP | ||
find_package(OpenMP REQUIRED) | ||
|
||
# openblas | ||
find_package(OpenBLAS REQUIRED) | ||
include_directories(${OpenBLAS_INCLUDE_DIR}) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -m64 -Wall -g -O3 -msse4 -mpopcnt -fopenmp -Wno-sign-compare") | ||
add_definitions(-DFINTEGER=int) | ||
|
||
# specify output bin_path and lib_path | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
|
||
# specify header and cpp files | ||
file(GLOB faiss_cpu_headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | ||
file(GLOB faiss_cpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
set(faiss_lib faiss) | ||
add_library(${faiss_lib} STATIC ${faiss_cpu_headers} ${faiss_cpu_cpp}) | ||
target_link_libraries(${faiss_lib} ${OpenMP_CXX_FLAGS} ${OpenBLAS_LIB}) | ||
|
||
# build gpu lib | ||
if(BUILD_WITH_GPU) | ||
include(cmake/Cuda.cmake) | ||
add_subdirectory(gpu) | ||
endif(BUILD_WITH_GPU) | ||
|
||
# build tutorial examples | ||
if(BUILD_TUTORIAL) | ||
add_subdirectory(tutorial) | ||
endif(BUILD_TUTORIAL) | ||
|
||
# build tests | ||
if(BUILD_TEST) | ||
add_subdirectory(tests) | ||
endif(BUILD_TEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# configure cuda | ||
|
||
find_package(CUDA QUIET REQUIRED) | ||
if(CUDA_FOUND) | ||
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS}) | ||
list(APPEND CUDA_LINKER_LIBS ${CUDA_CUDART_LIBRARY} ${CUDA_curand_LIBRARY} ${CUDA_CUBLAS_LIBRARIES}) | ||
else(CUDA_FOUND) | ||
message(STATUS "Could not locate cuda, disabling cuda support.") | ||
set(BUILD_WITH_GPU OFF) | ||
return() | ||
endif(CUDA_FOUND) | ||
|
||
# set cuda flags | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_35;-std=c++11;-DVERBOSE;-g;-lineinfo;-Xcompiler;-ggdb") | ||
else() | ||
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_35;-std=c++11;-DVERBOSE;-O3;-DNDEBUG;-Xcompiler;-DNDEBU") | ||
endif() | ||
set(CUDA_PROPAGATE_HOST_FLAGS OFF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
|
||
SET(Open_BLAS_INCLUDE_SEARCH_PATHS | ||
/usr/include | ||
/usr/include/openblas | ||
/usr/include/openblas-base | ||
/usr/local/include | ||
/usr/local/include/openblas | ||
/usr/local/include/openblas-base | ||
/opt/OpenBLAS/include | ||
/opt/local/include | ||
$ENV{OpenBLAS_HOME} | ||
$ENV{OpenBLAS_HOME}/include | ||
) | ||
|
||
SET(Open_BLAS_LIB_SEARCH_PATHS | ||
/lib/ | ||
/lib/openblas-base | ||
/lib64/ | ||
/usr/lib | ||
/usr/lib/openblas-base | ||
/usr/lib64 | ||
/usr/local/lib | ||
/usr/local/lib64 | ||
/opt/OpenBLAS/lib | ||
/opt/local/lib | ||
$ENV{OpenBLAS}cd | ||
$ENV{OpenBLAS}/lib | ||
$ENV{OpenBLAS_HOME} | ||
$ENV{OpenBLAS_HOME}/lib | ||
) | ||
|
||
FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES openblas_config.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS}) | ||
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS}) | ||
|
||
SET(OpenBLAS_FOUND ON) | ||
|
||
# Check include files | ||
IF(NOT OpenBLAS_INCLUDE_DIR) | ||
SET(OpenBLAS_FOUND OFF) | ||
MESSAGE(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off") | ||
ENDIF() | ||
|
||
# Check libraries | ||
IF(NOT OpenBLAS_LIB) | ||
SET(OpenBLAS_FOUND OFF) | ||
MESSAGE(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off") | ||
ENDIF() | ||
|
||
IF (OpenBLAS_FOUND) | ||
IF (NOT OpenBLAS_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}") | ||
MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") | ||
ENDIF (NOT OpenBLAS_FIND_QUIETLY) | ||
ELSE (OpenBLAS_FOUND) | ||
IF (OpenBLAS_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find OpenBLAS") | ||
ENDIF (OpenBLAS_FIND_REQUIRED) | ||
ENDIF (OpenBLAS_FOUND) | ||
|
||
MARK_AS_ADVANCED( | ||
OpenBLAS_INCLUDE_DIR | ||
OpenBLAS_LIB | ||
OpenBLAS | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# specify header and cpp files | ||
file(GLOB_RECURSE faiss_gpu_headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | ||
file(GLOB_RECURSE faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
file(GLOB_RECURSE faiss_gpu_cuh ${CMAKE_CURRENT_SOURCE_DIR}/*.cuh) | ||
file(GLOB_RECURSE faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/*.cu) | ||
|
||
set(faiss_lib_gpu gpufaiss) | ||
|
||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/demo_ivfpq_indexing_gpu.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TestGpuIndexFlat.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TestGpuIndexIVFFlat.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TestGpuIndexIVFPQ.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TestUtils.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/test/TestGpuSelect.cu) | ||
list(REMOVE_ITEM faiss_gpu_headers ${CMAKE_CURRENT_SOURCE_DIR}/test/TestUtils.h) | ||
list(REMOVE_ITEM faiss_gpu_headers ${CMAKE_CURRENT_SOURCE_DIR}/perf/IndexWrapper.h) | ||
list(REMOVE_ITEM faiss_gpu_headers ${CMAKE_CURRENT_SOURCE_DIR}/perf/IndexWrapper-inl.h) | ||
list(REMOVE_ITEM faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/perf/CompareFlat.cu) | ||
list(REMOVE_ITEM faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/perf/CompareIVFFlat.cu) | ||
list(REMOVE_ITEM faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/perf/CompareIVFPQ.cu) | ||
list(REMOVE_ITEM faiss_gpu_cu ${CMAKE_CURRENT_SOURCE_DIR}/perf/CompareIVFPQGrid.cu) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/perf/PerfClustering.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/perf/PerfIVFPQAdd.cpp) | ||
list(REMOVE_ITEM faiss_gpu_cpp ${CMAKE_CURRENT_SOURCE_DIR}/perf/WriteIndex.cpp) | ||
|
||
cuda_add_library(${faiss_lib_gpu} STATIC ${faiss_gpu_headers} ${faiss_gpu_cpp} ${faiss_gpu_cuh} ${faiss_gpu_cu}) | ||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
list(APPEND srcs | ||
${CMAKE_CURRENT_SOURCE_DIR}/demo_ivfpq_indexing_gpu.cpp) | ||
|
||
foreach(source ${srcs}) | ||
get_filename_component(name ${source} NAME_WE) | ||
add_executable(${name} ${source}) | ||
target_link_libraries(${name} ${faiss_lib_gpu} ${faiss_lib} ${CUDA_LINKER_LIBS}) | ||
endforeach(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
file(GLOB srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
# Build each source file independently | ||
include_directories(../../) # faiss root directory | ||
|
||
# gtest | ||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
||
foreach(source ${srcs}) | ||
get_filename_component(name ${source} NAME_WE) | ||
|
||
# target | ||
add_executable(${name} ${source}) | ||
target_link_libraries(${name} ${faiss_lib} ${OpenBLAS_LIB} ${GTEST_BOTH_LIBRARIES}) | ||
|
||
# Install | ||
install(TARGETS ${name} DESTINATION test) | ||
endforeach(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
file(GLOB srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
# Build each source file independently | ||
include_directories(../../../) # faiss root directory | ||
|
||
foreach(source ${srcs}) | ||
get_filename_component(name ${source} NAME_WE) | ||
|
||
# target | ||
add_executable(${name} ${source}) | ||
target_link_libraries(${name} ${faiss_lib}) | ||
|
||
# Install | ||
install(TARGETS ${name} DESTINATION bin) | ||
endforeach(source) |