diff options
author | Daya S Khudia <dskhudia@fb.com> | 2018-10-13 01:48:13 +0300 |
---|---|---|
committer | Daya S Khudia <dskhudia@fb.com> | 2018-10-31 00:56:00 +0300 |
commit | e85b5a12254fa47ca6b56236489253a68fd32104 (patch) | |
tree | d62190c53913c65e136fb26dc89bfab38144e2c3 /cmake |
Initial commit
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/DownloadASMJIT.cmake | 16 | ||||
-rw-r--r-- | cmake/modules/DownloadCPUINFO.cmake | 16 | ||||
-rw-r--r-- | cmake/modules/DownloadGTEST.cmake | 16 | ||||
-rw-r--r-- | cmake/modules/FindMKL.cmake | 270 |
4 files changed, 318 insertions, 0 deletions
diff --git a/cmake/modules/DownloadASMJIT.cmake b/cmake/modules/DownloadASMJIT.cmake new file mode 100644 index 0000000..6e6a6f9 --- /dev/null +++ b/cmake/modules/DownloadASMJIT.cmake @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.7 FATAL_ERROR) + +project(asmjit-download NONE) + +include(ExternalProject) + +ExternalProject_Add(asmjit + GIT_REPOSITORY https://github.com/asmjit/asmjit + GIT_TAG master + SOURCE_DIR "${FBGEMM_THIRDPARTY_DIR}/asmjit" + BINARY_DIR "${FBGEMM_BINARY_DIR}/asmjit" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/cmake/modules/DownloadCPUINFO.cmake b/cmake/modules/DownloadCPUINFO.cmake new file mode 100644 index 0000000..730ecbf --- /dev/null +++ b/cmake/modules/DownloadCPUINFO.cmake @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.7 FATAL_ERROR) + +project(cpuinfo-download NONE) + +include(ExternalProject) + +ExternalProject_Add(cpuinfo + GIT_REPOSITORY https://github.com/pytorch/cpuinfo + GIT_TAG master + SOURCE_DIR "${FBGEMM_THIRDPARTY_DIR}/cpuinfo" + BINARY_DIR "${FBGEMM_BINARY_DIR}/cpuinfo" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/cmake/modules/DownloadGTEST.cmake b/cmake/modules/DownloadGTEST.cmake new file mode 100644 index 0000000..b0a56f8 --- /dev/null +++ b/cmake/modules/DownloadGTEST.cmake @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.7 FATAL_ERROR) + +project(googletest-download NONE) + +include(ExternalProject) + +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG 0fc5466dbb9e623029b1ada539717d10bd45e99e + SOURCE_DIR "${FBGEMM_THIRDPARTY_DIR}/googletest" + BINARY_DIR "${FBGEMM_BINARY_DIR}/googletest" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/cmake/modules/FindMKL.cmake b/cmake/modules/FindMKL.cmake new file mode 100644 index 0000000..6b38af7 --- /dev/null +++ b/cmake/modules/FindMKL.cmake @@ -0,0 +1,270 @@ +# - Find INTEL MKL library +# This module finds the Intel Mkl libraries. +# Note: This file is a modified version of pytorch/cmake/Modules/FindMKL.cmake +# +# This module sets the following variables: +# MKL_FOUND - set to true if a library implementing the CBLAS interface is found +# MKL_VERSION - best guess +# MKL_INCLUDE_DIR - path to include dir. +# MKL_LIBRARIES - list of libraries for base mkl + +# Do nothing if MKL_FOUND was set before! +IF (NOT MKL_FOUND) + +SET(MKL_VERSION) +SET(MKL_INCLUDE_DIR) +SET(MKL_LIBRARIES) + +# Includes +INCLUDE(CheckTypeSize) +INCLUDE(CheckFunctionExists) + +# Intel Compiler Suite +SET(INTEL_COMPILER_DIR "/opt/intel" CACHE STRING + "Root directory of the Intel Compiler Suite (contains ipp, mkl, etc.)") +SET(INTEL_MKL_DIR "/opt/intel/mkl" CACHE STRING + "Root directory of the Intel MKL (standalone)") +SET(INTEL_MKL_SEQUENTIAL OFF CACHE BOOL + "Force using the sequential (non threaded) libraries") + +# Checks +CHECK_TYPE_SIZE("void*" SIZE_OF_VOIDP) +IF ("${SIZE_OF_VOIDP}" EQUAL 8) + SET(mklvers "intel64") + SET(iccvers "intel64") + SET(mkl64s "_lp64") +ELSE ("${SIZE_OF_VOIDP}" EQUAL 8) + SET(mklvers "32") + SET(iccvers "ia32") + SET(mkl64s) +ENDIF ("${SIZE_OF_VOIDP}" EQUAL 8) +IF(CMAKE_COMPILER_IS_GNUCC) + SET(mklthreads "mkl_gnu_thread" "mkl_intel_thread") + SET(mklifaces "intel" "gf") + SET(mklrtls "gomp" "iomp5") +ELSE(CMAKE_COMPILER_IS_GNUCC) + SET(mklthreads "mkl_intel_thread") + SET(mklifaces "intel") + SET(mklrtls "iomp5" "guide") + IF (MSVC) + SET(mklrtls "libiomp5md") + ENDIF (MSVC) +ENDIF (CMAKE_COMPILER_IS_GNUCC) + +# Kernel libraries dynamically loaded +SET(mklseq) + + +# Paths +SET(saved_CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}) +SET(saved_CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}) +IF(WIN32) + # Set default MKLRoot for Windows + IF($ENV{MKLProductDir}) + SET(INTEL_COMPILER_DIR $ENV{MKLProductDir}) + ELSE() + SET(INTEL_COMPILER_DIR + "C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows") + ENDIF() + # Change mklvers and iccvers when we are using MSVC instead of ICC + IF(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + SET(mklvers "${mklvers}_win") + SET(iccvers "${iccvers}_win") + ENDIF() +ENDIF(WIN32) +IF (EXISTS ${INTEL_COMPILER_DIR}) + # TODO: diagnostic if dir does not exist + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${INTEL_COMPILER_DIR}/lib/${iccvers}") + IF(MSVC) + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${INTEL_COMPILER_DIR}/compiler/lib/${iccvers}") + ENDIF() + IF (NOT EXISTS ${INTEL_MKL_DIR}) + SET(INTEL_MKL_DIR "${INTEL_COMPILER_DIR}/mkl") + ENDIF() +ENDIF() +IF (EXISTS ${INTEL_MKL_DIR}) + # TODO: diagnostic if dir does not exist + SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} + "${INTEL_MKL_DIR}/include") + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${INTEL_MKL_DIR}/lib/${mklvers}") + IF (MSVC) + SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} + "${INTEL_MKL_DIR}/lib/${iccvers}") + ENDIF() +ENDIF() + +# Try linking multiple libs +MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags) + # This macro checks for the existence of the combination of libraries given by _list. + # If the combination is found, this macro checks whether we can link against that library + # combination using the name of a routine given by _name using the linker + # flags given by _flags. If the combination of libraries is found and passes + # the link test, LIBRARIES is set to the list of complete library paths that + # have been found. Otherwise, LIBRARIES is set to FALSE. + # N.B. _prefix is the prefix applied to the names of all cached variables that + # are generated internally and marked advanced by this macro. + SET(_prefix "${LIBRARIES}") + # start checking + SET(_libraries_work TRUE) + SET(${LIBRARIES}) + SET(_combined_name) + SET(_paths) + SET(__list) + FOREACH(_elem ${_list}) + IF(__list) + SET(__list "${__list} - ${_elem}") + ELSE(__list) + SET(__list "${_elem}") + ENDIF(__list) + ENDFOREACH(_elem) + MESSAGE(STATUS "Checking for [${__list}]") + FOREACH(_library ${_list}) + SET(_combined_name ${_combined_name}_${_library}) + IF(_libraries_work) + IF(${_library} STREQUAL "gomp") + FIND_PACKAGE(OpenMP) + IF(OPENMP_FOUND) + SET(${_prefix}_${_library}_LIBRARY ${OpenMP_C_FLAGS}) + ENDIF(OPENMP_FOUND) + ELSE(${_library} STREQUAL "gomp") + FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library}) + ENDIF(${_library} STREQUAL "gomp") + MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY) + SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) + SET(_libraries_work ${${_prefix}_${_library}_LIBRARY}) + IF(${_prefix}_${_library}_LIBRARY) + MESSAGE(STATUS " Library ${_library}: ${${_prefix}_${_library}_LIBRARY}") + ELSE(${_prefix}_${_library}_LIBRARY) + MESSAGE(STATUS " Library ${_library}: not found") + ENDIF(${_prefix}_${_library}_LIBRARY) + ENDIF(_libraries_work) + ENDFOREACH(_library ${_list}) + # Test this combination of libraries. + IF(_libraries_work) + SET(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) + SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}") + CHECK_FUNCTION_EXISTS(${_name} ${_prefix}${_combined_name}_WORKS) + SET(CMAKE_REQUIRED_LIBRARIES) + MARK_AS_ADVANCED(${_prefix}${_combined_name}_WORKS) + SET(_libraries_work ${${_prefix}${_combined_name}_WORKS}) + ENDIF(_libraries_work) + # Fin + IF(_libraries_work) + ELSE (_libraries_work) + SET(${LIBRARIES}) + MARK_AS_ADVANCED(${LIBRARIES}) + ENDIF(_libraries_work) +ENDMACRO(CHECK_ALL_LIBRARIES) + +IF(WIN32) + SET(mkl_m "") + SET(mkl_pthread "") +ELSE(WIN32) + SET(mkl_m "m") + SET(mkl_pthread "pthread") +ENDIF(WIN32) + +IF(UNIX AND NOT APPLE) + SET(mkl_dl "${CMAKE_DL_LIBS}") +ELSE(UNIX AND NOT APPLE) + SET(mkl_dl "") +ENDIF(UNIX AND NOT APPLE) + +# Check for version 10/11 +IF (NOT MKL_LIBRARIES) + SET(MKL_VERSION 1011) +ENDIF (NOT MKL_LIBRARIES) +FOREACH(mklrtl ${mklrtls} "") + FOREACH(mkliface ${mklifaces}) + FOREACH(mkl64 ${mkl64s} "") + FOREACH(mklthread ${mklthreads}) + IF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL) + CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm + "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};${mkl_pthread};${mkl_m};${mkl_dl}" "") + ENDIF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL) + ENDFOREACH(mklthread) + ENDFOREACH(mkl64) + ENDFOREACH(mkliface) +ENDFOREACH(mklrtl) +FOREACH(mklrtl ${mklrtls} "") + FOREACH(mkliface ${mklifaces}) + FOREACH(mkl64 ${mkl64s} "") + IF (NOT MKL_LIBRARIES) + CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm + "mkl_${mkliface}${mkl64};mkl_sequential;mkl_core;${mkl_m};${mkl_dl}" "") + IF (MKL_LIBRARIES) + SET(mklseq "_sequential") + ENDIF (MKL_LIBRARIES) + ENDIF (NOT MKL_LIBRARIES) + ENDFOREACH(mkl64) + ENDFOREACH(mkliface) +ENDFOREACH(mklrtl) +FOREACH(mklrtl ${mklrtls} "") + FOREACH(mkliface ${mklifaces}) + FOREACH(mkl64 ${mkl64s} "") + FOREACH(mklthread ${mklthreads}) + IF (NOT MKL_LIBRARIES) + CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm + "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m};${mkl_dl}" "") + ENDIF (NOT MKL_LIBRARIES) + ENDFOREACH(mklthread) + ENDFOREACH(mkl64) + ENDFOREACH(mkliface) +ENDFOREACH(mklrtl) + +# Check for older versions +IF (NOT MKL_LIBRARIES) + SET(MKL_VERSION 900) + CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm + "mkl;guide;pthread;m" "") +ENDIF (NOT MKL_LIBRARIES) + +# Include files +IF (MKL_LIBRARIES) + FIND_PATH(MKL_INCLUDE_DIR "mkl_cblas.h") + MARK_AS_ADVANCED(MKL_INCLUDE_DIR) +ENDIF (MKL_LIBRARIES) + +# LibIRC: intel compiler always links this; +# gcc does not; but mkl kernels sometimes need it. +IF (MKL_LIBRARIES) + IF (CMAKE_COMPILER_IS_GNUCC) + FIND_LIBRARY(MKL_KERNEL_libirc "irc") + ELSEIF (CMAKE_C_COMPILER_ID AND NOT CMAKE_C_COMPILER_ID STREQUAL "Intel") + FIND_LIBRARY(MKL_KERNEL_libirc "irc") + ENDIF (CMAKE_COMPILER_IS_GNUCC) + MARK_AS_ADVANCED(MKL_KERNEL_libirc) + IF (MKL_KERNEL_libirc) + SET(MKL_LIBRARIES ${MKL_LIBRARIES} ${MKL_KERNEL_libirc}) + ENDIF (MKL_KERNEL_libirc) +ENDIF (MKL_LIBRARIES) + +# Final +SET(CMAKE_LIBRARY_PATH ${saved_CMAKE_LIBRARY_PATH}) +SET(CMAKE_INCLUDE_PATH ${saved_CMAKE_INCLUDE_PATH}) +IF (MKL_LIBRARIES AND MKL_INCLUDE_DIR) + SET(MKL_FOUND TRUE) + set(MKL_cmake_included true) +ELSE (MKL_LIBRARIES AND MKL_INCLUDE_DIR) + SET(MKL_FOUND FALSE) + SET(MKL_VERSION) +ENDIF (MKL_LIBRARIES AND MKL_INCLUDE_DIR) + +# Standard termination +IF(NOT MKL_FOUND AND MKL_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "MKL library not found. Please specify library location") +ENDIF(NOT MKL_FOUND AND MKL_FIND_REQUIRED) +IF(NOT MKL_FIND_QUIETLY) + IF(MKL_FOUND) + MESSAGE(STATUS "MKL library found") + ELSE(MKL_FOUND) + MESSAGE(STATUS "MKL library not found") + return() + ENDIF(MKL_FOUND) +ENDIF(NOT MKL_FIND_QUIETLY) + +# Do nothing if MKL_FOUND was set before! +ENDIF (NOT MKL_FOUND) |