2017-01-04 17:40:56 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
2016-12-05 00:42:00 +00:00
|
|
|
|
2016-12-20 22:00:43 +00:00
|
|
|
project(Caffe2 CXX C)
|
2016-12-05 00:42:00 +00:00
|
|
|
|
|
|
|
|
# TODO(bwasti): versioning
|
|
|
|
|
|
2017-01-04 18:46:37 +00:00
|
|
|
# We want CMake to GLOB everything every time.
|
|
|
|
|
execute_process(COMMAND find "${PROJECT_SOURCE_DIR}" -name "CMakeLists.txt" -exec touch {} \;)
|
|
|
|
|
|
2016-12-05 00:42:00 +00:00
|
|
|
# Useful functions.
|
|
|
|
|
function (exclude OUTPUT INPUT)
|
|
|
|
|
set(EXCLUDES ${ARGN})
|
|
|
|
|
foreach(EXCLUDE ${EXCLUDES})
|
|
|
|
|
list(REMOVE_ITEM INPUT "${EXCLUDE}")
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${OUTPUT} ${INPUT} PARENT_SCOPE)
|
|
|
|
|
endfunction(exclude)
|
|
|
|
|
|
|
|
|
|
function (prepend OUTPUT PREPEND)
|
|
|
|
|
set(OUT "")
|
|
|
|
|
foreach(ITEM ${ARGN})
|
|
|
|
|
list(APPEND OUT "${PREPEND}${ITEM}")
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${OUTPUT} ${OUT} PARENT_SCOPE)
|
|
|
|
|
endfunction(prepend)
|
|
|
|
|
|
2016-12-06 16:39:15 +00:00
|
|
|
# ---[ CMake scripts + modules
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
|
|
|
|
|
2017-01-12 00:51:02 +00:00
|
|
|
enable_testing()
|
|
|
|
|
|
2016-12-06 16:39:15 +00:00
|
|
|
# External projects
|
|
|
|
|
include(ExternalProject)
|
|
|
|
|
|
|
|
|
|
include(cmake/Utils.cmake)
|
2017-01-05 00:44:55 +00:00
|
|
|
include(cmake/Summary.cmake)
|
2016-12-06 16:39:15 +00:00
|
|
|
|
|
|
|
|
# options
|
2017-01-05 00:40:26 +00:00
|
|
|
option(USE_THREADS "Use Threads" ON)
|
2016-12-12 17:29:00 +00:00
|
|
|
option(USE_NERVANA_GPU "Use Nervana GPU backend" OFF)
|
2017-01-04 07:16:50 +00:00
|
|
|
option(USE_GLOG "Use GLOG" ON)
|
|
|
|
|
option(USE_GFLAGS "Use GFLAGS" ON)
|
2016-12-12 17:29:00 +00:00
|
|
|
option(USE_LMDB "Use LMDB" ON)
|
|
|
|
|
option(USE_LEVELDB "Use LMDB" ON)
|
2017-02-13 17:42:48 +00:00
|
|
|
option(USE_NCCL "Use NCCL" ON)
|
2017-03-27 15:42:36 +00:00
|
|
|
option(USE_NNPACK "Use NNPACK" ON)
|
2016-12-12 17:29:00 +00:00
|
|
|
option(USE_OPENCV "Use openCV" ON)
|
2017-01-04 23:46:43 +00:00
|
|
|
option(USE_CUDA "Use Cuda" ON)
|
2017-02-28 18:15:08 +00:00
|
|
|
option(USE_CNMEM "Use CNMEM" OFF)
|
2017-01-12 00:51:02 +00:00
|
|
|
option(USE_ZMQ "Use ZMQ" OFF)
|
|
|
|
|
option(USE_ROCKSDB "Use RocksDB" ON)
|
|
|
|
|
option(USE_REDIS "Use Redis" OFF)
|
2017-01-04 22:52:15 +00:00
|
|
|
option(USE_MPI "Use MPI" ON)
|
2017-03-24 15:19:13 +00:00
|
|
|
option(USE_GLOO "Use Gloo" ON)
|
2016-12-12 17:29:00 +00:00
|
|
|
option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON)
|
2017-01-04 17:44:47 +00:00
|
|
|
option(USE_OPENMP "Use OpenMP for parallel code" ON)
|
2017-01-05 00:40:26 +00:00
|
|
|
option(BUILD_PYTHON "Build python binaries" ON)
|
2017-01-28 21:18:40 +00:00
|
|
|
option(BUILD_BINARY "Build c++ binary executives" ON)
|
2016-12-06 16:39:15 +00:00
|
|
|
|
2017-01-04 22:52:15 +00:00
|
|
|
# options that do not affect the main binaries, but affects testing binaries
|
|
|
|
|
option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" ON)
|
|
|
|
|
|
2017-01-30 17:39:25 +00:00
|
|
|
# options that takes in strings instead of on and off statemens.
|
|
|
|
|
option(CAFFE2_CPU_FLAGS "Flags to specify CPU features." "")
|
|
|
|
|
|
2017-01-09 18:49:51 +00:00
|
|
|
# Set default build type
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
|
message(STATUS "Build type not set - defaulting to Release")
|
|
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build from: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2016-12-06 16:39:15 +00:00
|
|
|
# ---[ Dependencies
|
|
|
|
|
include(cmake/Dependencies.cmake)
|
|
|
|
|
|
2017-01-05 05:52:59 +00:00
|
|
|
# ---[ Misc checks to cope with various compiler modes
|
|
|
|
|
include(cmake/MiscCheck.cmake)
|
|
|
|
|
|
2017-03-15 18:31:55 +00:00
|
|
|
# ---[ Set link flag, handle additional deps for gcc 4.8 and above
|
2017-03-17 22:01:55 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8.0 AND NOT ANDROID)
|
2017-01-12 00:51:02 +00:00
|
|
|
message(STATUS "GCC ${CMAKE_CXX_COMPILER_VERSION}: Adding gcc and gcc_s libs to link line")
|
|
|
|
|
list(APPEND Caffe2_DEPENDENCY_LIBS gcc_s gcc)
|
2016-12-12 17:29:00 +00:00
|
|
|
endif()
|
|
|
|
|
|
2016-12-21 14:14:04 +00:00
|
|
|
# ---[ Set output directories
|
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "binaries")
|
|
|
|
|
|
2017-01-05 04:36:11 +00:00
|
|
|
# ---[ Build flags
|
Re-apply windows diff D4657831
Summary:
(Note: previous revert was due to a race condition between D4657831 and
D4659953 that I failed to catch.)
After this, we should have contbuild guarding the Windows build both with
and without CUDA.
This includes a series of changes that are needed to make Windows build,
specifically:
(1) Various flags that are needed in the cmake system, specially dealing
with /MD, /MT, cuda, cudnn, whole static linking, etc.
(2) Contbuild scripts based on appveyo.
(3) For Windows build, note that one will need to use "cmake --build" to
build stuff so that the build type is consistent between configuration and
actual build. see scripts\build_windows.bat for details.
(4) In logging.h, ERROR is already defined by Windows. I don't have a good
solution now, and as a result, LOG(ERROR) on windows is going to be
LOG(INFO).
(5) variable length array is not supported by MSVC (and it is not part of
C++ standard). As a result I replaced them with vectors.
(6) sched.h is not available on Windows, so akyrola 's awesome simple
async net might encounter some slowdown due to no affinity setting on
Windows.
(7) MSVC has a bug that does not work very well with template calls inide
a templated function call, which is a known issue that should be fixed in
MSVC 2017. However for now this means changes to conv_op_impl.h and
recurrent_net_op.h. No actual functionalities are changed.
(8) std host function calls are not supported in CUDA8+MSVC, so I changed
lp_pool (and maybe a few others) to use cuda device functions.
(9) The current Scale and Axpy has heavy templating that does not work
well with MSVC. As a result I reverted azzolini 's changes to the Scale
and Axpy interface, moved the fixed-length version to ScaleFixedSize and
AxpyFixedSize.
(10) CUDA + MSVC does not deal with Eigen well, so I guarded all Eigen
parts to only the non-CUDA part.
(11) In conclusion, it is fun but painful to deal with visual c++.
Differential Revision: D4666745
fbshipit-source-id: 3c9035083067bdb19a16d9c345c1ce66b6a86600
2017-03-07 18:56:26 +00:00
|
|
|
if(NOT MSVC)
|
2017-02-13 17:42:48 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
|
Re-apply windows diff D4657831
Summary:
(Note: previous revert was due to a race condition between D4657831 and
D4659953 that I failed to catch.)
After this, we should have contbuild guarding the Windows build both with
and without CUDA.
This includes a series of changes that are needed to make Windows build,
specifically:
(1) Various flags that are needed in the cmake system, specially dealing
with /MD, /MT, cuda, cudnn, whole static linking, etc.
(2) Contbuild scripts based on appveyo.
(3) For Windows build, note that one will need to use "cmake --build" to
build stuff so that the build type is consistent between configuration and
actual build. see scripts\build_windows.bat for details.
(4) In logging.h, ERROR is already defined by Windows. I don't have a good
solution now, and as a result, LOG(ERROR) on windows is going to be
LOG(INFO).
(5) variable length array is not supported by MSVC (and it is not part of
C++ standard). As a result I replaced them with vectors.
(6) sched.h is not available on Windows, so akyrola 's awesome simple
async net might encounter some slowdown due to no affinity setting on
Windows.
(7) MSVC has a bug that does not work very well with template calls inide
a templated function call, which is a known issue that should be fixed in
MSVC 2017. However for now this means changes to conv_op_impl.h and
recurrent_net_op.h. No actual functionalities are changed.
(8) std host function calls are not supported in CUDA8+MSVC, so I changed
lp_pool (and maybe a few others) to use cuda device functions.
(9) The current Scale and Axpy has heavy templating that does not work
well with MSVC. As a result I reverted azzolini 's changes to the Scale
and Axpy interface, moved the fixed-length version to ScaleFixedSize and
AxpyFixedSize.
(10) CUDA + MSVC does not deal with Eigen well, so I guarded all Eigen
parts to only the non-CUDA part.
(11) In conclusion, it is fun but painful to deal with visual c++.
Differential Revision: D4666745
fbshipit-source-id: 3c9035083067bdb19a16d9c345c1ce66b6a86600
2017-03-07 18:56:26 +00:00
|
|
|
else()
|
|
|
|
|
if (NOT ${BUILD_SHARED_LIBS})
|
|
|
|
|
foreach(flag_var
|
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
|
|
|
if(${flag_var} MATCHES "/MD")
|
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
|
|
|
|
endif(${flag_var} MATCHES "/MD")
|
|
|
|
|
endforeach(flag_var)
|
|
|
|
|
endif()
|
2017-02-13 17:42:48 +00:00
|
|
|
endif()
|
2017-01-05 04:36:11 +00:00
|
|
|
|
2017-01-30 17:39:25 +00:00
|
|
|
if (CAFFE2_CPU_FLAGS)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_CPU_FLAGS}")
|
|
|
|
|
endif()
|
|
|
|
|
|
2017-01-12 00:51:02 +00:00
|
|
|
# ---[ Include path needed for proto
|
2017-01-26 22:29:51 +00:00
|
|
|
include_directories(BEFORE ${PROJECT_BINARY_DIR})
|
2017-01-12 00:51:02 +00:00
|
|
|
|
2016-12-12 17:29:00 +00:00
|
|
|
# ---[ Third party builds.
|
2017-01-26 22:29:51 +00:00
|
|
|
include_directories(${PROJECT_SOURCE_DIR})
|
2016-12-05 00:42:00 +00:00
|
|
|
|
2016-12-12 17:29:00 +00:00
|
|
|
# ---[ Old caffe protobuf.
|
2016-12-05 00:42:00 +00:00
|
|
|
add_subdirectory(caffe/proto)
|
|
|
|
|
|
2016-12-12 17:29:00 +00:00
|
|
|
# ---[ Main build
|
2016-12-05 00:42:00 +00:00
|
|
|
add_subdirectory(caffe2)
|
2016-12-08 18:23:04 +00:00
|
|
|
|
|
|
|
|
# ---[ Copy all python files to build directory
|
2017-01-05 00:40:26 +00:00
|
|
|
if (BUILD_PYTHON)
|
2017-01-22 21:28:20 +00:00
|
|
|
# Generate and create all needed __init__.py files, if they aren't already
|
|
|
|
|
# present in the current source tree.
|
|
|
|
|
message(STATUS "Automatically generating missing __init__.py files.")
|
|
|
|
|
caffe_autogen_init_py_files()
|
|
|
|
|
|
2017-01-23 17:44:23 +00:00
|
|
|
# Create a custom target that copies all python files.
|
|
|
|
|
file(GLOB_RECURSE PYTHON_SRCS RELATIVE ${PROJECT_SOURCE_DIR}
|
|
|
|
|
"${PROJECT_SOURCE_DIR}/caffe2/*.py")
|
|
|
|
|
add_custom_target(python_copy_files ALL)
|
|
|
|
|
foreach(python_src ${PYTHON_SRCS})
|
|
|
|
|
get_filename_component(dir ${python_src} DIRECTORY)
|
|
|
|
|
add_custom_command(
|
|
|
|
|
TARGET python_copy_files PRE_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${PROJECT_SOURCE_DIR}/${python_src} ${CMAKE_BINARY_DIR}/${dir})
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2017-01-22 21:28:20 +00:00
|
|
|
# Install commands
|
2017-01-05 00:40:26 +00:00
|
|
|
# Pick up static python files
|
2017-01-22 21:28:20 +00:00
|
|
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
|
2017-01-05 00:40:26 +00:00
|
|
|
FILES_MATCHING PATTERN "*.py")
|
|
|
|
|
# Caffe proto files
|
|
|
|
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION ${CMAKE_INSTALL_PREFIX}
|
|
|
|
|
FILES_MATCHING PATTERN "*.py")
|
|
|
|
|
# Caffe2 proto files
|
|
|
|
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
|
|
|
|
|
FILES_MATCHING PATTERN "*.py")
|
|
|
|
|
endif()
|
2016-12-21 14:14:04 +00:00
|
|
|
|
2017-01-05 00:44:55 +00:00
|
|
|
Caffe2_print_configuration_summary()
|