Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ _site
*.sublime-workspace
*.sublime-project

# Eclipse Project settings
*.*project


# CMake generated files
*.gen.cmake
72 changes: 72 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 2.8)
project( Caffe )

### Build Options ##########################################################################

option(BUILD_PYTHON "Build Python wrapper" OFF)
option(BUILD_MATLAB "Build Matlab wrapper" OFF)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_SHARED_LIBS "Build SHARED libs if ON and STATIC otherwise" OFF)

if(NOT BLAS)
set(BLAS atlas)
endif()

if(NOT CUDA_TEST_DEVICE)
set(CUDA_TEST_DEVICE -1)
endif()

# Install Prefix
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install path" FORCE )
endif()

### Configuration ###########################################################################

# Enable CTest from top build directory
enable_testing()

# Compiler Flags
set(CMAKE_CXX_COMPILER_FLAGS ${CMAKE_CXX_COMPILER_FLAGS} -Wall)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC)
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O3)

# Include Directories
set(${PROJECT_NAME}_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include)
include_directories(${${PROJECT_NAME}_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/src)

# CMake module path for custom module finding
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeScripts)

# CUDA is required globally
find_package(CUDA 5.5 REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})


### Subdirectories ##########################################################################

add_subdirectory(src/gtest)
add_subdirectory(src/caffe)
add_subdirectory(tools)

if(BUILD_EXAMPLES)
message(STATUS "Examples enabled")
add_subdirectory(examples)
endif()

if(BUILD_PYTHON)
message(STATUS "Python enabled")
add_subdirectory(python)
endif()

if(BUILD_MATLAB)
message(STATUS "Matlab enabled")
add_subdirectory(matlab)
endif()

### Install #################################################################################

# Install Includes
file(GLOB folders ${${PROJECT_NAME}_INCLUDE_DIRS}/*)
install(DIRECTORY ${folders} DESTINATION include)
62 changes: 62 additions & 0 deletions CMakeScripts/FindAtlas.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Find the Atlas (and Lapack) libraries
#
# The following variables are optionally searched for defaults
# Atlas_ROOT_DIR: Base directory where all Atlas components are found
#
# The following are set after configuration is done:
# Atlas_FOUND
# Atlas_INCLUDE_DIRS
# Atlas_LIBRARIES
# Atlas_LIBRARYRARY_DIRS

set(Atlas_INCLUDE_SEARCH_PATHS
/usr/include/atlas
/usr/include/atlas-base
$ENV{Atlas_ROOT_DIR}
$ENV{Atlas_ROOT_DIR}/include
)

set(Atlas_LIB_SEARCH_PATHS
/usr/lib/atlas
/usr/lib/atlas-base
$ENV{Atlas_ROOT_DIR}
$ENV{Atlas_ROOT_DIR}/lib
)

find_path(Atlas_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Atlas_INCLUDE_SEARCH_PATHS})
find_path(Atlas_CLAPACK_INCLUDE_DIR NAMES clapack.h PATHS ${Atlas_INCLUDE_SEARCH_PATHS})
find_library(Atlas_CBLAS_LIBRARY NAMES ptcblas_r ptcblas cblas_r cblas PATHS ${Atlas_LIB_SEARCH_PATHS})
find_library(Atlas_BLAS_LIBRARY NAMES atlas_r atlas PATHS ${Atlas_LIB_SEARCH_PATHS})
find_library(Atlas_LAPACK_LIBRARY NAMES alapack_r alapack lapack_atlas PATHS ${Atlas_LIB_SEARCH_PATHS})

set(LOOKED_FOR

Atlas_CBLAS_INCLUDE_DIR
Atlas_CLAPACK_INCLUDE_DIR

Atlas_CBLAS_LIBRARY
Atlas_BLAS_LIBRARY
Atlas_LAPACK_LIBRARY
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Atlas DEFAULT_MSG ${LOOKED_FOR})

if(ATLAS_FOUND)

mark_as_advanced(${LOOKED_FOR})

set(Atlas_INCLUDE_DIR
${Atlas_CBLAS_INCLUDE_DIR}
${Atlas_CLAPACK_INCLUDE_DIR}
)

set(Atlas_LIBRARIES
${Atlas_LAPACK_LIBRARY}
${Atlas_CBLAS_LIBRARY}
${Atlas_BLAS_LIBRARY}
)

endif(ATLAS_FOUND)


48 changes: 48 additions & 0 deletions CMakeScripts/FindGlog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# - Try to find Glog
#
# The following variables are optionally searched for defaults
# GLOG_ROOT_DIR: Base directory where all GLOG components are found
#
# The following are set after configuration is done:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
# GLOG_LIBRARYRARY_DIRS

include(FindPackageHandleStandardArgs)

set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")

if(WIN32)
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR}/src/windows)
else()
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR})
endif()

if(MSVC)
find_library(GLOG_LIBRARY_RELEASE libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Release)

find_library(GLOG_LIBRARY_DEBUG libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Debug)

set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG})
else()
find_library(GLOG_LIBRARY glog
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES
lib
lib64)
endif()

find_package_handle_standard_args(GLOG DEFAULT_MSG
GLOG_INCLUDE_DIR GLOG_LIBRARY)

if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
endif()
37 changes: 37 additions & 0 deletions CMakeScripts/FindLevelDB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# - Find LevelDB
#
# LEVELDB_INCLUDE - Where to find leveldb/db.h
# LEVELDB_LIBS - List of libraries when using LevelDB.
# LEVELDB_FOUND - True if LevelDB found.

get_filename_component(module_file_path ${CMAKE_CURRENT_LIST_FILE} PATH)

# Look for the header file.
find_path(LEVELDB_INCLUDE NAMES leveldb/db.h PATHS $ENV{LEVELDB_ROOT}/include /opt/local/include /usr/local/include /usr/include DOC "Path in which the file leveldb/db.h is located." )
mark_as_advanced(LEVELDB_INCLUDE)

# Look for the library.
# Does this work on UNIX systems? (LINUX)
find_library(LEVELDB_LIBS NAMES leveldb PATHS /usr/lib $ENV{LEVELDB_ROOT}/lib DOC "Path to leveldb library." )
mark_as_advanced(LEVELDB_LIBS)

# Copy the results to the output variables.
if (LEVELDB_INCLUDE AND LEVELDB_LIBS)
message(STATUS "Found leveldb in ${LEVELDB_INCLUDE} ${LEVELDB_LIBS}")
set(LEVELDB_FOUND 1)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_LIBRARY ${LEVELDB_LIBS} pthread)
set(CMAKE_REQUIRED_INCLUDES ${LEVELDB_INCLUDE})
else ()
set(LEVELDB_FOUND 0)
endif ()

# Report the results.
if (NOT LEVELDB_FOUND)
set(LEVELDB_DIR_MESSAGE "LEVELDB was not found. Make sure LEVELDB_LIBS and LEVELDB_INCLUDE are set.")
if (LEVELDB_FIND_REQUIRED)
message(FATAL_ERROR "${LEVELDB_DIR_MESSAGE}")
elseif (NOT LEVELDB_FIND_QUIETLY)
message(STATUS "${LEVELDB_DIR_MESSAGE}")
endif ()
endif ()
113 changes: 113 additions & 0 deletions CMakeScripts/FindMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# - Find Intel MKL
# Find the MKL libraries
#
# Options:
#
# MKL_STATAIC : use static linking
# MKL_MULTI_THREADED: use multi-threading
# MKL_SDL : Single Dynamic Library interface
#
# This module defines the following variables:
#
# MKL_FOUND : True if MKL_INCLUDE_DIR are found
# MKL_INCLUDE_DIR : where to find mkl.h, etc.
# MKL_INCLUDE_DIRS : set when MKL_INCLUDE_DIR found
# MKL_LIBRARIES : the library to link against.


include(FindPackageHandleStandardArgs)

set(INTEL_ROOT "/opt/intel" CACHE PATH "Folder contains intel libs")
set(MKL_ROOT ${INTEL_ROOT}/mkl CACHE PATH "Folder contains MKL")

# Find include dir
find_path(MKL_INCLUDE_DIR mkl.h
PATHS ${MKL_ROOT}/include)

# Find include directory
# There is no include folder under linux
if(WIN32)
find_path(INTEL_INCLUDE_DIR omp.h
PATHS ${INTEL_ROOT}/include)
set(MKL_INCLUDE_DIR ${MKL_INCLUDE_DIR} ${INTEL_INCLUDE_DIR})
endif()

# Find libraries

# Handle suffix
set(_MKL_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})

if(WIN32)
if(MKL_STATAIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES _dll.lib)
endif()
else()
if(MKL_STATAIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
endif()
endif()


# MKL is composed by four layers: Interface, Threading, Computational and RTL

if(MKL_SDL)
find_library(MKL_LIBRARY mkl_rt
PATHS ${MKL_ROOT}/lib/ia32/)

set(MKL_MINIMAL_LIBRARY ${MKL_LIBRARY})
else()
######################### Interface layer #######################
if(WIN32)
set(MKL_INTERFACE_LIBNAME mkl_intel_c)
else()
set(MKL_INTERFACE_LIBNAME mkl_intel)
endif()

find_library(MKL_INTERFACE_LIBRARY ${MKL_INTERFACE_LIBNAME}
PATHS ${MKL_ROOT}/lib/ia32/)

######################## Threading layer ########################
if(MKL_MULTI_THREADED)
set(MKL_THREADING_LIBNAME mkl_intel_thread)
else()
set(MKL_THREADING_LIBNAME mkl_sequential)
endif()

find_library(MKL_THREADING_LIBRARY ${MKL_THREADING_LIBNAME}
PATHS ${MKL_ROOT}/lib/ia32/)

####################### Computational layer #####################
find_library(MKL_CORE_LIBRARY mkl_core
PATHS ${MKL_ROOT}/lib/ia32/)
find_library(MKL_FFT_LIBRARY mkl_cdft_core
PATHS ${MKL_ROOT}/lib/ia32/)
find_library(MKL_SCALAPACK_LIBRARY mkl_scalapack_core
PATHS ${MKL_ROOT}/lib/ia32/)

############################ RTL layer ##########################
if(WIN32)
set(MKL_RTL_LIBNAME libiomp5md)
else()
set(MKL_RTL_LIBNAME libiomp5)
endif()
find_library(MKL_RTL_LIBRARY ${MKL_RTL_LIBNAME}
PATHS ${INTEL_RTL_ROOT}/lib)

set(MKL_LIBRARY ${MKL_INTERFACE_LIBRARY} ${MKL_THREADING_LIBRARY} ${MKL_CORE_LIBRARY} ${MKL_FFT_LIBRARY} ${MKL_SCALAPACK_LIBRARY} ${MKL_RTL_LIBRARY})
set(MKL_MINIMAL_LIBRARY ${MKL_INTERFACE_LIBRARY} ${MKL_THREADING_LIBRARY} ${MKL_CORE_LIBRARY} ${MKL_RTL_LIBRARY})
endif()

set(CMAKE_FIND_LIBRARY_SUFFIXES ${_MKL_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})

find_package_handle_standard_args(MKL DEFAULT_MSG
MKL_INCLUDE_DIR MKL_LIBRARY MKL_MINIMAL_LIBRARY)

if(MKL_FOUND)
set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
set(MKL_LIBRARIES ${MKL_LIBRARY})
set(MKL_MINIMAL_LIBRARIES ${MKL_LIBRARY})
endif()
Loading