Commit 7621d5ab authored by Sang Ik Lee's avatar Sang Ik Lee Committed by Robert Kimball

Silee2/subdirectories (#2420)

* CMake: Only add subdirectories if needed.
CMake: Disable TBB on Windows.

* CMake: mkl-dnn is only needed for CPU backend.

* CMake: Check dependency between options.

* CMake: Eigen is only needed for CPU or GENERIC_CPU backend.

* Enable TBB on Windows.

* Disable tools unit test if nGraph tools are disabled.
parent 00447a8e
...@@ -343,20 +343,38 @@ endif() ...@@ -343,20 +343,38 @@ endif()
include(cmake/external_gtest.cmake) include(cmake/external_gtest.cmake)
include(cmake/external_json.cmake) include(cmake/external_json.cmake)
include(cmake/external_eigen.cmake) if(NGRAPH_CPU_ENABLE OR NGRAPH_GENERIC_CPU_ENABLE)
include(cmake/external_mkldnn.cmake) include(cmake/external_eigen.cmake)
include(cmake/external_cldnn.cmake) endif()
if(NGRAPH_CPU_ENABLE)
if (NGRAPH_USE_PREBUILT_LLVM OR DEFINED LLVM_TARBALL_URL) include(cmake/external_mkldnn.cmake)
include(cmake/external_llvm_prebuilt.cmake) endif()
elseif (NOT NGRAPH_DEX_ONLY OR NOT MSVS) if(NGRAPH_INTELGPU_ENABLE)
include(cmake/external_llvm.cmake) include(cmake/external_cldnn.cmake)
endif() endif()
if (WIN32 OR APPLE) if ((NGRAPH_GPU_ENABLE OR NGRAPH_CPU_ENABLE) AND NOT NGRAPH_DEX_ONLY)
include(cmake/external_tbb_prebuilt.cmake) set(NGRAPH_CODEGEN_ENABLE TRUE)
else() else()
include(cmake/external_tbb.cmake) set(NGRAPH_CODEGEN_ENABLE FALSE)
endif()
if(NGRAPH_CODEGEN_ENABLE)
if (NGRAPH_USE_PREBUILT_LLVM OR DEFINED LLVM_TARBALL_URL)
include(cmake/external_llvm_prebuilt.cmake)
elseif (NOT MSVS)
include(cmake/external_llvm.cmake)
else()
message(FATAL_ERROR "CODEGEN not support on Windows!")
endif()
endif()
if(NGRAPH_TBB_ENABLE)
if (WIN32 OR APPLE)
include(cmake/external_tbb_prebuilt.cmake)
else()
include(cmake/external_tbb.cmake)
endif()
endif() endif()
if (NGRAPH_DISTRIBUTED_MLSL_ENABLE) if (NGRAPH_DISTRIBUTED_MLSL_ENABLE)
......
...@@ -14,88 +14,90 @@ ...@@ -14,88 +14,90 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(NOT NGRAPH_CODEGEN_ENABLE)
return()
endif()
if ((NGRAPH_GPU_ENABLE OR NGRAPH_CPU_ENABLE) AND NOT NGRAPH_DEX_ONLY) if (DEFINED NGRAPH_USE_CXX_ABI AND NGRAPH_USE_PREBUILT_LLVM)
if (DEFINED NGRAPH_USE_CXX_ABI AND NGRAPH_USE_PREBUILT_LLVM) message(FATAL_ERROR "Unable to use NGRAPH_USE_PREBUILT_LLVM with NGRAPH_USE_CXX_ABI")
message(FATAL_ERROR "Unable to use NGRAPH_USE_PREBUILT_LLVM with NGRAPH_USE_CXX_ABI") endif()
endif()
set(SRC set(SRC
compiler.cpp compiler.cpp
execution_engine.cpp execution_engine.cpp
) )
add_library(codegen SHARED ${SRC}) add_library(codegen SHARED ${SRC})
# LLVM binary builds are typically built without RTTI # LLVM binary builds are typically built without RTTI
# The built-in headers are in a version-specific directory # The built-in headers are in a version-specific directory
# This must be kept in sync with the LLVM + Clang version in use # This must be kept in sync with the LLVM + Clang version in use
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_FLAGS "-fno-rtti") set_source_files_properties(compiler.cpp PROPERTIES COMPILE_FLAGS "-fno-rtti")
get_target_property(LLVM_LIB_DIR libllvm INTERFACE_INCLUDE_DIRECTORIES) get_target_property(LLVM_LIB_DIR libllvm INTERFACE_INCLUDE_DIRECTORIES)
# find_file(HEADER_1 cmath HINTS /usr/include/c++/7) # find_file(HEADER_1 cmath HINTS /usr/include/c++/7)
get_filename_component(LLVM_LIB_DIR ${LLVM_LIB_DIR}/../lib/clang/5.0.2/include ABSOLUTE) get_filename_component(LLVM_LIB_DIR ${LLVM_LIB_DIR}/../lib/clang/5.0.2/include ABSOLUTE)
if(NGRAPH_CPU_ENABLE) if(NGRAPH_CPU_ENABLE)
get_target_property(MKLDNN_INCLUDE_DIR libmkldnn INTERFACE_INCLUDE_DIRECTORIES) get_target_property(MKLDNN_INCLUDE_DIR libmkldnn INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(EIGEN_INCLUDE_DIR libeigen INTERFACE_INCLUDE_DIRECTORIES) get_target_property(EIGEN_INCLUDE_DIR libeigen INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND HEADER_SEARCH_DEFINES EIGEN_HEADERS_PATH="${EIGEN_INCLUDE_DIR}") list(APPEND HEADER_SEARCH_DEFINES EIGEN_HEADERS_PATH="${EIGEN_INCLUDE_DIR}")
list(APPEND HEADER_SEARCH_DEFINES MKLDNN_HEADERS_PATH="${MKLDNN_INCLUDE_DIR}") list(APPEND HEADER_SEARCH_DEFINES MKLDNN_HEADERS_PATH="${MKLDNN_INCLUDE_DIR}")
endif() endif()
list(APPEND HEADER_SEARCH_DEFINES CLANG_BUILTIN_HEADERS_PATH="${LLVM_LIB_DIR}") list(APPEND HEADER_SEARCH_DEFINES CLANG_BUILTIN_HEADERS_PATH="${LLVM_LIB_DIR}")
list(APPEND HEADER_SEARCH_DEFINES NGRAPH_HEADERS_PATH="${NGRAPH_INCLUDE_PATH}") list(APPEND HEADER_SEARCH_DEFINES NGRAPH_HEADERS_PATH="${NGRAPH_INCLUDE_PATH}")
if(NGRAPH_DISTRIBUTED_ENABLE) if(NGRAPH_DISTRIBUTED_ENABLE)
if (NGRAPH_DISTRIBUTED_MLSL_ENABLE) if (NGRAPH_DISTRIBUTED_MLSL_ENABLE)
get_target_property(MLSL_INCLUDE_DIR libmlsl INTERFACE_INCLUDE_DIRECTORIES) get_target_property(MLSL_INCLUDE_DIR libmlsl INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND HEADER_SEARCH_DEFINES MLSL_HEADER_PATH="${MLSL_INCLUDE_DIR}") list(APPEND HEADER_SEARCH_DEFINES MLSL_HEADER_PATH="${MLSL_INCLUDE_DIR}")
elseif(NGRAPH_DISTRIBUTED_OMPI_ENABLE) elseif(NGRAPH_DISTRIBUTED_OMPI_ENABLE)
find_package(MPI REQUIRED) find_package(MPI REQUIRED)
add_definitions(-DMPI_HEADER_PATH="${MPI_PATH}") add_definitions(-DMPI_HEADER_PATH="${MPI_PATH}")
else() else()
message(FATAL_ERROR "Distributed Library not supported/mentioned") message(FATAL_ERROR "Distributed Library not supported/mentioned")
endif()
endif() endif()
endif()
if(NGRAPH_GPU_ENABLE) if(NGRAPH_GPU_ENABLE)
find_package(CUDA 8 REQUIRED) find_package(CUDA 8 REQUIRED)
find_package(CUDNN 7 REQUIRED) find_package(CUDNN 7 REQUIRED)
list(APPEND HEADER_SEARCH_DEFINES CUDA_HEADER_PATHS="${CUDA_INCLUDE_DIRS}") list(APPEND HEADER_SEARCH_DEFINES CUDA_HEADER_PATHS="${CUDA_INCLUDE_DIRS}")
list(APPEND HEADER_SEARCH_DEFINES CUDNN_HEADER_PATHS="${CUDNN_INCLUDE_DIRS}") list(APPEND HEADER_SEARCH_DEFINES CUDNN_HEADER_PATHS="${CUDNN_INCLUDE_DIRS}")
endif() endif()
if(NGRAPH_TBB_ENABLE) if(NGRAPH_TBB_ENABLE)
list(APPEND HEADER_SEARCH_DEFINES TBB_HEADERS_PATH="${TBB_ROOT}/include") list(APPEND HEADER_SEARCH_DEFINES TBB_HEADERS_PATH="${TBB_ROOT}/include")
endif() endif()
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}") set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
# Generate the resource file containing all headers used by the codegen compiler # Generate the resource file containing all headers used by the codegen compiler
add_custom_target(header_resource add_custom_target(header_resource
resource_generator --output ${CMAKE_BINARY_DIR}/header_resource.hpp --base codegen resource_generator --output ${CMAKE_BINARY_DIR}/header_resource.hpp --base codegen
DEPENDS resource_generator ext_llvm DEPENDS resource_generator ext_llvm
BYPRODUCTS BYPRODUCTS
) )
if (NGRAPH_CPU_ENABLE) if (NGRAPH_CPU_ENABLE)
add_dependencies(header_resource ext_eigen ext_mkldnn) add_dependencies(header_resource ext_eigen ext_mkldnn)
endif() endif()
if(NGRAPH_LIB_VERSIONING_ENABLE) if(NGRAPH_LIB_VERSIONING_ENABLE)
set_target_properties(codegen PROPERTIES set_target_properties(codegen PROPERTIES
VERSION ${NGRAPH_VERSION} VERSION ${NGRAPH_VERSION}
SOVERSION ${NGRAPH_API_VERSION}) SOVERSION ${NGRAPH_API_VERSION})
endif() endif()
add_dependencies(codegen header_resource) add_dependencies(codegen header_resource)
if (NGRAPH_CPU_ENABLE) if (NGRAPH_CPU_ENABLE)
add_dependencies(codegen libmkldnn libeigen) add_dependencies(codegen libmkldnn libeigen)
if(LINUX) if(LINUX)
# --exclude-libs=ALL prevents symbols from statically-linked libraries (LLVM, in this case) # --exclude-libs=ALL prevents symbols from statically-linked libraries (LLVM, in this case)
# from being automatically exported # from being automatically exported
set_property(TARGET codegen APPEND PROPERTY LINK_FLAGS "-Wl,--exclude-libs=ALL") set_property(TARGET codegen APPEND PROPERTY LINK_FLAGS "-Wl,--exclude-libs=ALL")
endif()
endif() endif()
target_include_directories(codegen SYSTEM PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(codegen PRIVATE libllvm ngraph)
install(TARGETS codegen DESTINATION ${NGRAPH_INSTALL_LIB})
endif() endif()
target_include_directories(codegen SYSTEM PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(codegen PRIVATE libllvm ngraph)
install(TARGETS codegen DESTINATION ${NGRAPH_INSTALL_LIB})
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(NOT NGRAPH_CODEGEN_ENABLE)
return()
endif()
set (SRC set (SRC
main.cpp main.cpp
util.cpp util.cpp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment