Unverified Commit eef750df authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Modernize cmake usage (#1032)

* Update cmake files to more modern approach

* disable building libraries that are not required

* handle more build cases

* add versions to backend libs. add start of package target.

* add create_backend to backends

* temporary workaround to tbb not linking correctly with gcc

* install codegen lib

* force tbb to link to the cpu backend so that it is available for codegen

* fix clang build error

* fix warning for codegen build

* update cuda header paths

* change error message for opening backend shared library

* set lib path
parent b8e28555
...@@ -21,7 +21,11 @@ NGRAPH_GET_VERSION_LABEL() ...@@ -21,7 +21,11 @@ NGRAPH_GET_VERSION_LABEL()
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" NGRAPH_VERSION_SHORT "${NGRAPH_VERSION_LABEL}") string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" NGRAPH_VERSION_SHORT "${NGRAPH_VERSION_LABEL}")
string(REGEX MATCH "([0-9]+)\.([0-9]+)" NGRAPH_API_VERSION "${NGRAPH_VERSION_LABEL}") string(REGEX MATCH "([0-9]+)\.([0-9]+)" NGRAPH_API_VERSION "${NGRAPH_VERSION_LABEL}")
set(NGRAPH_VERSION "${NGRAPH_VERSION_LABEL}") string(REGEX MATCH "[^v](.*)" NGRAPH_VERSION "${NGRAPH_VERSION_LABEL}")
string(REPLACE "." ";" NGRAPH_VERSION_PARTS "${NGRAPH_VERSION_SHORT}")
list(GET NGRAPH_VERSION_PARTS 0 NGRAPH_VERSION_MAJOR)
list(GET NGRAPH_VERSION_PARTS 1 NGRAPH_VERSION_MINOR)
list(GET NGRAPH_VERSION_PARTS 2 NGRAPH_VERSION_PATCH)
configure_file(VERSION.in VERSION) configure_file(VERSION.in VERSION)
message(STATUS "NGRAPH_VERSION ${NGRAPH_VERSION}") message(STATUS "NGRAPH_VERSION ${NGRAPH_VERSION}")
...@@ -81,6 +85,7 @@ option(NGRAPH_UNIT_TEST_ENABLE "Control the building of unit tests" TRUE) ...@@ -81,6 +85,7 @@ option(NGRAPH_UNIT_TEST_ENABLE "Control the building of unit tests" TRUE)
option(NGRAPH_TOOLS_ENABLE "Control the building of tool" TRUE) option(NGRAPH_TOOLS_ENABLE "Control the building of tool" TRUE)
option(NGRAPH_CPU_ENABLE "Control the building of the CPU backend" TRUE) option(NGRAPH_CPU_ENABLE "Control the building of the CPU backend" TRUE)
option(NGRAPH_GPU_ENABLE "Control the building of the GPU backend" FALSE) option(NGRAPH_GPU_ENABLE "Control the building of the GPU backend" FALSE)
option(NGRAPH_INTERPRETER_ENABLE "Control the building of the INTERPRETER backend" TRUE)
option(NGRAPH_DISTRIBUTED_ENABLE "Add distributed mode to the CPU backend" FALSE) option(NGRAPH_DISTRIBUTED_ENABLE "Add distributed mode to the CPU backend" FALSE)
option(NGRAPH_DEBUG_ENABLE "Enable output for NGRAPH_DEBUG statements" FALSE) option(NGRAPH_DEBUG_ENABLE "Enable output for NGRAPH_DEBUG statements" FALSE)
...@@ -108,6 +113,7 @@ message (STATUS "To Override use: cmake -DNGRAPH_INSTALL_PREFIX=/foo") ...@@ -108,6 +113,7 @@ message (STATUS "To Override use: cmake -DNGRAPH_INSTALL_PREFIX=/foo")
set(NGRAPH_INSTALL_LIB "${CMAKE_INSTALL_PREFIX}/lib") set(NGRAPH_INSTALL_LIB "${CMAKE_INSTALL_PREFIX}/lib")
set(NGRAPH_INSTALL_INCLUDE "${CMAKE_INSTALL_PREFIX}/include") set(NGRAPH_INSTALL_INCLUDE "${CMAKE_INSTALL_PREFIX}/include")
set(NGRAPH_INSTALL_DOC "${CMAKE_INSTALL_PREFIX}/doc") set(NGRAPH_INSTALL_DOC "${CMAKE_INSTALL_PREFIX}/doc")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Compiler-specific logic... # Compiler-specific logic...
...@@ -157,7 +163,10 @@ endif() ...@@ -157,7 +163,10 @@ endif()
include(unit_test_control) include(unit_test_control)
set(UNIT_TEST_CONFIG_LIST "" CACHE INTERNAL "") set(UNIT_TEST_CONFIG_LIST "" CACHE INTERNAL "")
unit_test_control(BACKEND INTERPRETER MANIFEST src/ngraph/runtime/interpreter/unit_test.manifest)
if (NGRAPH_INTERPRETER_ENABLE)
unit_test_control(BACKEND INTERPRETER MANIFEST src/ngraph/runtime/interpreter/unit_test.manifest)
endif()
# Set true if CPU backend is built by default # Set true if CPU backend is built by default
if (NGRAPH_CPU_ENABLE) if (NGRAPH_CPU_ENABLE)
...@@ -165,31 +174,12 @@ if (NGRAPH_CPU_ENABLE) ...@@ -165,31 +174,12 @@ if (NGRAPH_CPU_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_CPU_ENABLE") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_CPU_ENABLE")
endif() endif()
if (NOT DEFINED NGRAPH_TBB_ENABLE) if (NGRAPH_GPU_ENABLE)
set(NGRAPH_TBB_ENABLE ${NGRAPH_CPU_ENABLE}) unit_test_control(BACKEND GPU MANIFEST src/ngraph/runtime/gpu/unit_test.manifest)
endif() endif()
#----------------------------------------------------------------------------------------------- if (NOT DEFINED NGRAPH_TBB_ENABLE)
# GPU support set(NGRAPH_TBB_ENABLE ${NGRAPH_CPU_ENABLE})
#-----------------------------------------------------------------------------------------------
# Setup CUDA and cuDNN if NGRAPH_GPU_ENABLE=TRUE
if(NGRAPH_GPU_ENABLE)
find_package(CUDA 8 REQUIRED)
message(STATUS "GPU Backend Enabled")
set(NGRAPH_GPU_ENABLE TRUE)
find_package(CUDNN 7 REQUIRED)
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR} ${LLVM_INCLUDE_DIR})
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0 AND
CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER)
message(FATAL_ERROR
"CUDA 8.0 is not compatible with GCC version >= 6.\n"
"Please select a correct compiler version\n"
)
endif()
unit_test_control(BACKEND GPU MANIFEST src/ngraph/runtime/gpu/unit_test.manifest)
elseif(NGRAPH_GPU_ENABLE)
message(FATAL_ERROR "GPU was required but CUDA library was not found")
endif() endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
...@@ -199,45 +189,26 @@ if(NGRAPH_DEBUG_ENABLE) ...@@ -199,45 +189,26 @@ if(NGRAPH_DEBUG_ENABLE)
add_definitions(-DNGRAPH_DEBUG_ENABLE) add_definitions(-DNGRAPH_DEBUG_ENABLE)
endif() endif()
#-----------------------------------------------------------------------------------------------
# distributed support
#-----------------------------------------------------------------------------------------------
if(NGRAPH_DISTRIBUTED_ENABLE)
find_package(MPI REQUIRED)
add_definitions(-DNGRAPH_DISTRIBUTED)
endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# External projects install directory # External projects install directory
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Root for external installs, when using `make`, e.g.
# ${EXTERNAL_PROJECTS_ROOT}
# ├── eigen
# │   ├── include
# │   │   └── eigen3 <-- ${EIGEN_INCLUDE_DIR}
# │   │   ├── Eigen
# │ ...
# │
# └── mkldnn
# ├── include <-- ${MKLDNN_INCLUDE_DIR}
# │   ├── mkldnn.h
# │ ...
# ├── lib <-- ${MKLDNN_LIB_DIR}
# │   ├── libiomp5.so
# ...
set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external) set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external)
# The following 'add_subdirectory' call: if(NOT DEFINED EXTERNAL_PROJECTS_ROOT)
# - defines the 'libgtest' target. set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR})
# - defines the 'GTEST_INCLUDE_DIR' cmake variable. endif()
add_subdirectory(third-party) include(cmake/external_gtest.cmake)
include(cmake/external_json.cmake)
include(cmake/external_eigen.cmake)
include(cmake/external_mkldnn.cmake)
if (NGRAPH_USE_PREBUILT_LLVM OR DEFINED LLVM_TARBALL_URL)
include(cmake/external_llvm_prebuilt.cmake)
else()
include(cmake/external_llvm.cmake)
endif()
include(cmake/external_tbb.cmake)
# The following 'add_subdirectory' call:
# - defines the 'ngraph' library target.
# - defines the 'NGRAPH_INCLUDE_DIR' cmake variable.
# - defines the 'NGRAPH_VERSION' cmake variable.
# - install-related targets.
add_subdirectory(src) add_subdirectory(src)
if (NGRAPH_UNIT_TEST_ENABLE) if (NGRAPH_UNIT_TEST_ENABLE)
......
...@@ -20,14 +20,15 @@ include(ExternalProject) ...@@ -20,14 +20,15 @@ include(ExternalProject)
set(EIGEN_GIT_TAG patched) set(EIGEN_GIT_TAG patched)
set(EIGEN_GIT_URL https://github.com/NervanaSystems/eigen) set(EIGEN_GIT_URL https://github.com/NervanaSystems/eigen)
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
# Download Eigen # Download Eigen
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
# The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2. # The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2.
if (${CMAKE_VERSION} VERSION_LESS 3.2) if (${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add( ExternalProject_Add(
ext_eigen ext_eigen
PREFIX eigen
GIT_REPOSITORY ${EIGEN_GIT_URL} GIT_REPOSITORY ${EIGEN_GIT_URL}
GIT_TAG ${EIGEN_GIT_TAG} GIT_TAG ${EIGEN_GIT_TAG}
UPDATE_COMMAND "" UPDATE_COMMAND ""
...@@ -40,10 +41,12 @@ if (${CMAKE_VERSION} VERSION_LESS 3.2) ...@@ -40,10 +41,12 @@ if (${CMAKE_VERSION} VERSION_LESS 3.2)
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/src" SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/build" BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen" INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen"
EXCLUDE_FROM_ALL TRUE
) )
else() else()
ExternalProject_Add( ExternalProject_Add(
ext_eigen ext_eigen
PREFIX eigen
GIT_REPOSITORY ${EIGEN_GIT_URL} GIT_REPOSITORY ${EIGEN_GIT_URL}
GIT_TAG ${EIGEN_GIT_TAG} GIT_TAG ${EIGEN_GIT_TAG}
UPDATE_COMMAND "" UPDATE_COMMAND ""
...@@ -57,9 +60,13 @@ else() ...@@ -57,9 +60,13 @@ else()
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/build" BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen" INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/eigen/src/Eigen/Core" BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/eigen/src/Eigen/Core"
EXCLUDE_FROM_ALL TRUE
) )
endif() endif()
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
set(EIGEN_INCLUDE_DIR "${EXTERNAL_PROJECTS_ROOT}/eigen/src" PARENT_SCOPE) ExternalProject_Get_Property(ext_eigen SOURCE_DIR)
add_library(libeigen INTERFACE)
target_include_directories(libeigen SYSTEM INTERFACE ${SOURCE_DIR})
add_dependencies(libeigen ext_eigen)
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
# Enable ExternalProject CMake module # Enable ExternalProject CMake module
include(ExternalProject) include(ExternalProject)
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
# Download and install GoogleTest ... # Download and install GoogleTest ...
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
SET(GTEST_GIT_REPO_URL https://github.com/google/googletest.git) SET(GTEST_GIT_REPO_URL https://github.com/google/googletest.git)
SET(GTEST_GIT_LABEL release-1.8.0) SET(GTEST_GIT_LABEL release-1.8.0)
...@@ -28,28 +28,35 @@ SET(GTEST_GIT_LABEL release-1.8.0) ...@@ -28,28 +28,35 @@ SET(GTEST_GIT_LABEL release-1.8.0)
if (${CMAKE_VERSION} VERSION_LESS 3.2) if (${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add( ExternalProject_Add(
ext_gtest ext_gtest
PREFIX gtest
GIT_REPOSITORY ${GTEST_GIT_REPO_URL} GIT_REPOSITORY ${GTEST_GIT_REPO_URL}
GIT_TAG ${GTEST_GIT_LABEL} GIT_TAG ${GTEST_GIT_LABEL}
# Disable install step # Disable install step
INSTALL_COMMAND "" INSTALL_COMMAND ""
UPDATE_COMMAND "" UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_FLAGS="-fPIC" CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS="-fPIC"
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/tmp" TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/stamp" STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/download" DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/src" SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/build" BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest" INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest"
EXCLUDE_FROM_ALL TRUE
) )
else() else()
ExternalProject_Add( ExternalProject_Add(
ext_gtest ext_gtest
PREFIX gtest
GIT_REPOSITORY ${GTEST_GIT_REPO_URL} GIT_REPOSITORY ${GTEST_GIT_REPO_URL}
GIT_TAG ${GTEST_GIT_LABEL} GIT_TAG ${GTEST_GIT_LABEL}
# Disable install step # Disable install step
INSTALL_COMMAND "" INSTALL_COMMAND ""
UPDATE_COMMAND "" UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_FLAGS="-fPIC" CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS="-fPIC"
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/tmp" TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/stamp" STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/download" DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/download"
...@@ -57,23 +64,15 @@ else() ...@@ -57,23 +64,15 @@ else()
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/build" BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest" INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/gtest/build/googlemock/gtest/libgtest.a" BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/gtest/build/googlemock/gtest/libgtest.a"
EXCLUDE_FROM_ALL TRUE
) )
endif() endif()
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
get_filename_component( ExternalProject_Get_Property(ext_gtest SOURCE_DIR BINARY_DIR)
GTEST_INCLUDE_DIR
"${EXTERNAL_PROJECTS_ROOT}/gtest/src/googletest/include"
ABSOLUTE)
set(GTEST_INCLUDE_DIR "${GTEST_INCLUDE_DIR}" PARENT_SCOPE)
# Create a libgtest target to be used as a dependency by test programs add_library(libgtest INTERFACE)
add_library(libgtest IMPORTED STATIC GLOBAL)
add_dependencies(libgtest ext_gtest) add_dependencies(libgtest ext_gtest)
target_include_directories(libgtest SYSTEM INTERFACE ${SOURCE_DIR}/googletest/include)
# Set libgtest properties target_link_libraries(libgtest INTERFACE ${BINARY_DIR}/googlemock/gtest/libgtest.a)
set_target_properties(libgtest PROPERTIES
"IMPORTED_LOCATION" "${EXTERNAL_PROJECTS_ROOT}/gtest/build/googlemock/gtest/libgtest.a"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
)
...@@ -28,6 +28,7 @@ SET(JSON_GIT_LABEL v3.1.1) ...@@ -28,6 +28,7 @@ SET(JSON_GIT_LABEL v3.1.1)
if (${CMAKE_VERSION} VERSION_LESS 3.2) if (${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add( ExternalProject_Add(
ext_json ext_json
PREFIX json
GIT_REPOSITORY ${JSON_GIT_REPO_URL} GIT_REPOSITORY ${JSON_GIT_REPO_URL}
GIT_TAG ${JSON_GIT_LABEL} GIT_TAG ${JSON_GIT_LABEL}
# Disable install step # Disable install step
...@@ -37,10 +38,12 @@ if (${CMAKE_VERSION} VERSION_LESS 3.2) ...@@ -37,10 +38,12 @@ if (${CMAKE_VERSION} VERSION_LESS 3.2)
# cmake does not allow calling cmake functions so we call a cmake script in the Module # cmake does not allow calling cmake functions so we call a cmake script in the Module
# directory. # directory.
PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/patch_json.cmake PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/patch_json.cmake
EXCLUDE_FROM_ALL TRUE
) )
else() else()
ExternalProject_Add( ExternalProject_Add(
ext_json ext_json
PREFIX json
GIT_REPOSITORY ${JSON_GIT_REPO_URL} GIT_REPOSITORY ${JSON_GIT_REPO_URL}
GIT_TAG ${JSON_GIT_LABEL} GIT_TAG ${JSON_GIT_LABEL}
# Disable install step # Disable install step
...@@ -50,13 +53,13 @@ else() ...@@ -50,13 +53,13 @@ else()
# cmake does not allow calling cmake functions so we call a cmake script in the Module # cmake does not allow calling cmake functions so we call a cmake script in the Module
# directory. # directory.
PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/patch_json.cmake PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/patch_json.cmake
EXCLUDE_FROM_ALL TRUE
) )
endif() endif()
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
get_filename_component( ExternalProject_Get_Property(ext_json SOURCE_DIR)
JSON_INCLUDE_DIR add_library(libjson INTERFACE)
"${EXTERNAL_PROJECTS_ROOT}/ext_json-prefix/src/ext_json/include" target_include_directories(libjson SYSTEM INTERFACE ${SOURCE_DIR}/include)
ABSOLUTE) add_dependencies(libjson ext_json)
set(JSON_INCLUDE_DIR "${JSON_INCLUDE_DIR}" PARENT_SCOPE)
This diff is collapsed.
...@@ -16,128 +16,126 @@ ...@@ -16,128 +16,126 @@
include(ExternalProject) include(ExternalProject)
if (NGRAPH_CPU_ENABLE AND (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") OR (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) message(STATUS "Fetching LLVM from llvm.org")
message(FATAL_ERROR "The NGRAPH_USE_PREBUILT_LLVM option is not supported on this platform.")
endif()
if (NGRAPH_CPU_ENABLE) find_package(ZLIB REQUIRED)
message(STATUS "Fetching LLVM from llvm.org")
# Override default LLVM binaries # Override default LLVM binaries
if(NOT DEFINED LLVM_TARBALL_URL) if(NOT DEFINED LLVM_TARBALL_URL)
set(LLVM_TARBALL_URL http://releases.llvm.org/5.0.1/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz) set(LLVM_TARBALL_URL http://releases.llvm.org/5.0.1/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz)
endif() endif()
if(NOT DEFINED LLVM_SHA1_HASH) if(NOT DEFINED LLVM_SHA1_HASH)
set(LLVM_SHA1_HASH 2fddf9a90b182fa594786be6923e58f5ead71e9c) set(LLVM_SHA1_HASH 2fddf9a90b182fa594786be6923e58f5ead71e9c)
endif() endif()
# The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2. # The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2.
if(${CMAKE_VERSION} VERSION_LESS 3.2) if(${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add( ExternalProject_Add(
ext_llvm ext_llvm
URL ${LLVM_TARBALL_URL} URL ${LLVM_TARBALL_URL}
URL_HASH SHA1=${LLVM_SHA1_HASH} URL_HASH SHA1=${LLVM_SHA1_HASH}
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND "" INSTALL_COMMAND ""
UPDATE_COMMAND "" UPDATE_COMMAND ""
) EXCLUDE_FROM_ALL TRUE
else() )
ExternalProject_Add( else()
ext_llvm ExternalProject_Add(
URL ${LLVM_TARBALL_URL} ext_llvm
URL_HASH SHA1=${LLVM_SHA1_HASH} URL ${LLVM_TARBALL_URL}
CONFIGURE_COMMAND "" URL_HASH SHA1=${LLVM_SHA1_HASH}
BUILD_COMMAND "" CONFIGURE_COMMAND ""
INSTALL_COMMAND "" BUILD_COMMAND ""
UPDATE_COMMAND "" INSTALL_COMMAND ""
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/ext_llvm-prefix/src/ext_llvm/lib/libLLVMCore.a" UPDATE_COMMAND ""
) BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/ext_llvm-prefix/src/ext_llvm/lib/libLLVMCore.a"
endif() EXCLUDE_FROM_ALL TRUE
)
endif()
ExternalProject_Get_Property(ext_llvm source_dir) ExternalProject_Get_Property(ext_llvm SOURCE_DIR)
set(LLVM_INCLUDE_DIR "${source_dir}/include" PARENT_SCOPE)
set(LLVM_INCLUDE_DIR "${source_dir}/include") # used by other external projects in current scope
set(LLVM_LIB_DIR "${source_dir}/lib" PARENT_SCOPE)
set(LLVM_LINK_LIBS set(LLVM_LINK_LIBS
clangTooling ${SOURCE_DIR}/lib/libclangTooling.a
clangFrontendTool ${SOURCE_DIR}/lib/libclangFrontendTool.a
clangFrontend ${SOURCE_DIR}/lib/libclangFrontend.a
clangDriver ${SOURCE_DIR}/lib/libclangDriver.a
clangSerialization ${SOURCE_DIR}/lib/libclangSerialization.a
clangCodeGen ${SOURCE_DIR}/lib/libclangCodeGen.a
clangParse ${SOURCE_DIR}/lib/libclangParse.a
clangSema ${SOURCE_DIR}/lib/libclangSema.a
clangStaticAnalyzerFrontend ${SOURCE_DIR}/lib/libclangStaticAnalyzerFrontend.a
clangStaticAnalyzerCheckers ${SOURCE_DIR}/lib/libclangStaticAnalyzerCheckers.a
clangStaticAnalyzerCore ${SOURCE_DIR}/lib/libclangStaticAnalyzerCore.a
clangAnalysis ${SOURCE_DIR}/lib/libclangAnalysis.a
clangARCMigrate ${SOURCE_DIR}/lib/libclangARCMigrate.a
clangRewriteFrontend ${SOURCE_DIR}/lib/libclangRewriteFrontend.a
clangEdit ${SOURCE_DIR}/lib/libclangEdit.a
clangAST ${SOURCE_DIR}/lib/libclangAST.a
clangLex ${SOURCE_DIR}/lib/libclangLex.a
clangBasic ${SOURCE_DIR}/lib/libclangBasic.a
LLVMLTO ${SOURCE_DIR}/lib/libLLVMLTO.a
LLVMPasses ${SOURCE_DIR}/lib/libLLVMPasses.a
LLVMObjCARCOpts ${SOURCE_DIR}/lib/libLLVMObjCARCOpts.a
LLVMSymbolize ${SOURCE_DIR}/lib/libLLVMSymbolize.a
LLVMDebugInfoPDB ${SOURCE_DIR}/lib/libLLVMDebugInfoPDB.a
LLVMDebugInfoDWARF ${SOURCE_DIR}/lib/libLLVMDebugInfoDWARF.a
LLVMMIRParser ${SOURCE_DIR}/lib/libLLVMMIRParser.a
LLVMCoverage ${SOURCE_DIR}/lib/libLLVMCoverage.a
LLVMTableGen ${SOURCE_DIR}/lib/libLLVMTableGen.a
LLVMDlltoolDriver ${SOURCE_DIR}/lib/libLLVMDlltoolDriver.a
LLVMOrcJIT ${SOURCE_DIR}/lib/libLLVMOrcJIT.a
LLVMObjectYAML ${SOURCE_DIR}/lib/libLLVMObjectYAML.a
LLVMLibDriver ${SOURCE_DIR}/lib/libLLVMLibDriver.a
LLVMOption ${SOURCE_DIR}/lib/libLLVMOption.a
LLVMX86Disassembler ${SOURCE_DIR}/lib/libLLVMX86Disassembler.a
LLVMX86AsmParser ${SOURCE_DIR}/lib/libLLVMX86AsmParser.a
LLVMX86CodeGen ${SOURCE_DIR}/lib/libLLVMX86CodeGen.a
LLVMGlobalISel ${SOURCE_DIR}/lib/libLLVMGlobalISel.a
LLVMSelectionDAG ${SOURCE_DIR}/lib/libLLVMSelectionDAG.a
LLVMAsmPrinter ${SOURCE_DIR}/lib/libLLVMAsmPrinter.a
LLVMDebugInfoCodeView ${SOURCE_DIR}/lib/libLLVMDebugInfoCodeView.a
LLVMDebugInfoMSF ${SOURCE_DIR}/lib/libLLVMDebugInfoMSF.a
LLVMX86Desc ${SOURCE_DIR}/lib/libLLVMX86Desc.a
LLVMMCDisassembler ${SOURCE_DIR}/lib/libLLVMMCDisassembler.a
LLVMX86Info ${SOURCE_DIR}/lib/libLLVMX86Info.a
LLVMX86AsmPrinter ${SOURCE_DIR}/lib/libLLVMX86AsmPrinter.a
LLVMX86Utils ${SOURCE_DIR}/lib/libLLVMX86Utils.a
LLVMMCJIT ${SOURCE_DIR}/lib/libLLVMMCJIT.a
LLVMLineEditor ${SOURCE_DIR}/lib/libLLVMLineEditor.a
LLVMInterpreter ${SOURCE_DIR}/lib/libLLVMInterpreter.a
LLVMExecutionEngine ${SOURCE_DIR}/lib/libLLVMExecutionEngine.a
LLVMRuntimeDyld ${SOURCE_DIR}/lib/libLLVMRuntimeDyld.a
LLVMCodeGen ${SOURCE_DIR}/lib/libLLVMCodeGen.a
LLVMTarget ${SOURCE_DIR}/lib/libLLVMTarget.a
LLVMCoroutines ${SOURCE_DIR}/lib/libLLVMCoroutines.a
LLVMipo ${SOURCE_DIR}/lib/libLLVMipo.a
LLVMInstrumentation ${SOURCE_DIR}/lib/libLLVMInstrumentation.a
LLVMVectorize ${SOURCE_DIR}/lib/libLLVMVectorize.a
LLVMScalarOpts ${SOURCE_DIR}/lib/libLLVMScalarOpts.a
LLVMLinker ${SOURCE_DIR}/lib/libLLVMLinker.a
LLVMIRReader ${SOURCE_DIR}/lib/libLLVMIRReader.a
LLVMAsmParser ${SOURCE_DIR}/lib/libLLVMAsmParser.a
LLVMInstCombine ${SOURCE_DIR}/lib/libLLVMInstCombine.a
LLVMTransformUtils ${SOURCE_DIR}/lib/libLLVMTransformUtils.a
LLVMBitWriter ${SOURCE_DIR}/lib/libLLVMBitWriter.a
LLVMAnalysis ${SOURCE_DIR}/lib/libLLVMAnalysis.a
LLVMProfileData ${SOURCE_DIR}/lib/libLLVMProfileData.a
LLVMObject ${SOURCE_DIR}/lib/libLLVMObject.a
LLVMMCParser ${SOURCE_DIR}/lib/libLLVMMCParser.a
LLVMMC ${SOURCE_DIR}/lib/libLLVMMC.a
LLVMBitReader ${SOURCE_DIR}/lib/libLLVMBitReader.a
LLVMCore ${SOURCE_DIR}/lib/libLLVMCore.a
LLVMBinaryFormat ${SOURCE_DIR}/lib/libLLVMBinaryFormat.a
LLVMSupport ${SOURCE_DIR}/lib/libLLVMSupport.a
LLVMDemangle ${SOURCE_DIR}/lib/libLLVMDemangle.a
tinfo tinfo
z z
m m
PARENT_SCOPE) )
endif() add_library(libllvm INTERFACE)
target_include_directories(libllvm SYSTEM INTERFACE ${SOURCE_DIR}/include)
target_link_libraries(libllvm INTERFACE ${LLVM_LINK_LIBS})
...@@ -16,83 +16,96 @@ ...@@ -16,83 +16,96 @@
include(ExternalProject) include(ExternalProject)
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
# Fetch and install MKL-DNN # Fetch and install MKL-DNN
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
if(NGRAPH_CPU_ENABLE) if(MKLDNN_INCLUDE_DIR AND MKLDNN_LIB_DIR)
# User provided mkl-dnn ExternalProject_Add(
if(MKLDNN_INCLUDE_DIR AND MKLDNN_LIB_DIR) ext_mkldnn
ExternalProject_Add( DOWNLOAD_COMMAND ""
ext_mkldnn UPDATE_COMMAND ""
DOWNLOAD_COMMAND "" CONFIGURE_COMMAND ""
UPDATE_COMMAND "" BUILD_COMMAND ""
CONFIGURE_COMMAND "" INSTALL_COMMAND ""
BUILD_COMMAND "" )
INSTALL_COMMAND "" add_library(libmkldnn INTERFACE)
) target_include_directories(libmkldnn SYSTEM INTERFACE ${MKLDNN_INCLUDE_DIR})
return() target_link_libraries(libmkldnn INTERFACE
endif() ${MKLDNN_LIB_DIR}/libmkldnn.so
${MKLDNN_LIB_DIR}/libmklml_intel.so
set(MKLDNN_GIT_REPO_URL https://github.com/intel/mkl-dnn) ${MKLDNN_LIB_DIR}/libiomp5.so
set(MKLDNN_GIT_TAG "0e7ca73") )
# The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2. install(DIRECTORY ${MKLDNN_LIB_DIR}/ DESTINATION ${NGRAPH_INSTALL_LIB})
if(${CMAKE_VERSION} VERSION_LESS 3.2) return()
ExternalProject_Add( endif()
ext_mkldnn
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
)
else()
ExternalProject_Add(
ext_mkldnn
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/mkldnn/include/mkldnn.hpp"
)
endif()
ExternalProject_Get_Property(ext_mkldnn source_dir binary_dir) set(MKLDNN_GIT_REPO_URL https://github.com/intel/mkl-dnn)
set(MKLDNN_GIT_TAG "0e7ca73")
ExternalProject_Add_Step( # The 'BUILD_BYPRODUCTS' argument was introduced in CMake 3.2.
if(${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add(
ext_mkldnn ext_mkldnn
PrepareMKL GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
COMMAND ${source_dir}/scripts/prepare_mkl.sh GIT_TAG ${MKLDNN_GIT_TAG}
DEPENDEES download UPDATE_COMMAND ""
DEPENDERS configure # Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
EXCLUDE_FROM_ALL TRUE
) )
else()
ExternalProject_Add(
ext_mkldnn
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/mkldnn/include/mkldnn.hpp"
EXCLUDE_FROM_ALL TRUE
)
endif()
ExternalProject_Get_Property(ext_mkldnn source_dir binary_dir)
set(MKLDNN_INCLUDE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/include" PARENT_SCOPE) ExternalProject_Add_Step(
set(MKLDNN_LIB_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib" PARENT_SCOPE) ext_mkldnn
PrepareMKL
COMMAND ${source_dir}/scripts/prepare_mkl.sh
DEPENDEES download
DEPENDERS configure
)
endif() add_library(libmkldnn INTERFACE)
target_include_directories(libmkldnn SYSTEM INTERFACE ${EXTERNAL_PROJECTS_ROOT}/mkldnn/include)
target_link_libraries(libmkldnn INTERFACE
${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/libmkldnn.so
${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/libmklml_intel.so
${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/libiomp5.so
)
install(DIRECTORY ${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/ DESTINATION ${NGRAPH_INSTALL_LIB})
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
# Fetch and configure TBB # Fetch and configure TBB
#---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------
if(NGRAPH_TBB_ENABLE) if(NGRAPH_TBB_ENABLE)
set(TBB_GIT_REPO_URL https://github.com/01org/tbb) set(TBB_GIT_REPO_URL https://github.com/01org/tbb)
...@@ -28,5 +28,5 @@ if(NGRAPH_TBB_ENABLE) ...@@ -28,5 +28,5 @@ if(NGRAPH_TBB_ENABLE)
execute_process(COMMAND "${CMAKE_COMMAND}" --build . execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tbb") WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tbb")
set(TBB_ROOT ${CMAKE_CURRENT_BINARY_DIR}/tbb/tbb-src PARENT_SCOPE) set(TBB_ROOT ${CMAKE_CURRENT_BINARY_DIR}/tbb/tbb-src)
endif() endif()
...@@ -14,55 +14,9 @@ ...@@ -14,55 +14,9 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(MKLDNN_INCLUDE_DIR)
link_directories(${MKLDNN_LIB_DIR})
endif()
if (NGRAPH_CPU_ENABLE) if (NGRAPH_CPU_ENABLE)
add_subdirectory(abc)
set(HEADER_SEARCH_DEFINES add_subdirectory(abc_operator)
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\"" add_subdirectory(mnist_mlp)
) add_subdirectory(update)
# abc
set (ABC_SRC
${PROJECT_SOURCE_DIR}/doc/examples/abc.cpp
)
set_source_files_properties(${ABC_SRC} PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
add_executable(abc ${ABC_SRC})
add_dependencies(abc ngraph)
target_link_libraries(abc ngraph)
# abc_op
set (ABC_OP_SRC
${PROJECT_SOURCE_DIR}/doc/examples/abc_operator.cpp
)
set_source_files_properties(${ABC_OP_SRC} PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
add_executable(abc_op ${ABC_OP_SRC})
add_dependencies(abc_op ngraph)
target_link_libraries(abc_op ngraph)
# update
set (UPDATE_SRC
${PROJECT_SOURCE_DIR}/doc/examples/update.cpp
)
set_source_files_properties(${UPDATE_SRC} PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
add_executable(update ${UPDATE_SRC})
add_dependencies(update ngraph)
target_link_libraries(update ngraph)
# mnist_mlp
set(MNIST_SRC
${PROJECT_SOURCE_DIR}/doc/examples/mnist_loader.cpp
${PROJECT_SOURCE_DIR}/doc/examples/mnist_mlp.cpp
)
set_source_files_properties(${MNIST_SRC} PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
add_executable(mnist_mlp ${MNIST_SRC})
add_dependencies(mnist_mlp ngraph)
target_link_libraries(mnist_mlp ngraph)
endif() endif()
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
add_executable(abc abc.cpp)
add_dependencies(abc ngraph cpu_backend)
target_link_libraries(abc ngraph cpu_backend)
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
add_executable(abc_op abc_operator.cpp)
add_dependencies(abc_op ngraph cpu_backend)
target_link_libraries(abc_op ngraph cpu_backend)
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
add_executable(mnist_mlp mnist_loader.cpp mnist_mlp.cpp)
add_dependencies(mnist_mlp ngraph cpu_backend)
target_link_libraries(mnist_mlp ngraph cpu_backend)
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
add_executable(update update.cpp)
add_dependencies(update ngraph cpu_backend)
target_link_libraries(update ngraph cpu_backend)
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIN_NGRAPH_LIBRARY") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIN_NGRAPH_LIBRARY")
include_directories(ngraph)
add_subdirectory(resource) add_subdirectory(resource)
add_subdirectory(ngraph) add_subdirectory(ngraph)
......
This diff is collapsed.
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
set(SRC
code_writer.cpp
compiler.cpp
execution_engine.cpp
)
# LLVM binary builds are typically built without RTTI
# The built-in headers are in a version-specific directory
# This must be kept in sync with the LLVM + Clang version in use
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_FLAGS "-fno-rtti")
get_target_property(MKLDNN_INCLUDE_DIR libmkldnn INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(EIGEN_INCLUDE_DIR libeigen INTERFACE_INCLUDE_DIRECTORIES)
set(HEADER_SEARCH_DEFINES
"EIGEN_HEADERS_PATH=\"${EIGEN_INCLUDE_DIR}\""
"MKLDNN_HEADERS_PATH=\"${MKLDNN_INCLUDE_DIR}\""
"CLANG_BUILTIN_HEADERS_PATH=\"${LLVM_LIB_DIR}/clang/5.0.1/include\""
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\""
"INSTALLED_HEADERS_PATH=\"${CMAKE_INSTALL_PREFIX}/include\""
)
if(NGRAPH_DISTRIBUTED_ENABLE)
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
string(REPLACE ";" "\\;" MPI_C_INCLUDE_PATH "${MPI_C_INCLUDE_PATH}")
add_definitions("-DMPI_HEADER_PATH=\"${MPI_C_INCLUDE_PATH}\"")
add_definitions(-DNGRAPH_DISTRIBUTED)
endif()
if(NGRAPH_GPU_ENABLE)
find_package(CUDA 8 REQUIRED)
find_package(CUDNN 7 REQUIRED)
list(APPEND HEADER_SEARCH_DEFINES "CUDA_HEADER_PATHS=\"${CUDA_INCLUDE_DIRS}\"")
list(APPEND HEADER_SEARCH_DEFINES "CUDNN_HEADER_PATHS=\"${CUDNN_INCLUDE_DIRS}\"")
endif()
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
# Generate the resource file containing all headers used by the codegen compiler
add_custom_target(header_resource
resource_generator --output ${CMAKE_BINARY_DIR}/header_resource.hpp --base codegen
DEPENDS resource_generator ext_eigen ext_llvm ext_mkldnn
BYPRODUCTS
)
# The conditional is a hack. I want to use EXCLUDE_FROM_ALL and OPTIONAL but that does not
# seem to be working for me.
if (NGRAPH_CPU_ENABLE OR NGRAPH_GPU_ENABLE)
add_library(codegen SHARED ${SRC})
set_target_properties(codegen PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
add_dependencies(codegen header_resource)
target_include_directories(codegen SYSTEM PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(codegen PRIVATE libllvm)
target_link_libraries(codegen PUBLIC libmkldnn libeigen pthread dl)
install(TARGETS codegen DESTINATION ${NGRAPH_INSTALL_LIB})
endif()
...@@ -273,7 +273,6 @@ void codegen::StaticCompiler::add_header_search_path(const string& p) ...@@ -273,7 +273,6 @@ void codegen::StaticCompiler::add_header_search_path(const string& p)
} }
} }
} }
std::unique_ptr<codegen::Module> std::unique_ptr<codegen::Module>
codegen::StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& m_compiler_action, codegen::StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& m_compiler_action,
const string& source) const string& source)
......
...@@ -14,17 +14,12 @@ ...@@ -14,17 +14,12 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(NOT DEFINED EXTERNAL_PROJECTS_ROOT) add_subdirectory(interpreter)
set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR})
if (NGRAPH_CPU_ENABLE)
add_subdirectory(cpu)
endif() endif()
include( ../cmake/external_gtest.cmake ) if (NGRAPH_GPU_ENABLE)
include( ../cmake/external_json.cmake ) add_subdirectory(gpu)
include( ../cmake/external_eigen.cmake )
include( ../cmake/external_mkldnn.cmake )
if (NGRAPH_USE_PREBUILT_LLVM OR DEFINED LLVM_TARBALL_URL)
include( ../cmake/external_llvm_prebuilt.cmake )
else()
include( ../cmake/external_llvm.cmake )
endif() endif()
include( ../cmake/external_tbb.cmake )
...@@ -42,8 +42,11 @@ runtime::Backend::~Backend() ...@@ -42,8 +42,11 @@ runtime::Backend::~Backend()
void* runtime::Backend::open_shared_library(const string& type) void* runtime::Backend::open_shared_library(const string& type)
{ {
string ext = SHARED_LIB_EXT;
string ver = LIBRARY_VERSION;
void* handle = nullptr; void* handle = nullptr;
string name = "lib" + to_lower(type) + "_backend.so"; string name = "lib" + to_lower(type) + "_backend" + ext;
handle = dlopen(name.c_str(), RTLD_NOW | RTLD_GLOBAL); handle = dlopen(name.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (handle) if (handle)
{ {
...@@ -60,7 +63,7 @@ void* runtime::Backend::open_shared_library(const string& type) ...@@ -60,7 +63,7 @@ void* runtime::Backend::open_shared_library(const string& type)
else else
{ {
string err = dlerror(); string err = dlerror();
throw runtime_error("Failed to find Backend library '" + name + "'\n" + err); throw runtime_error("Library open for Backend '" + name + "' failed with error:\n" + err);
} }
return handle; return handle;
} }
......
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
set(SRC
cpu_backend.cpp
cpu_call_frame.cpp
cpu_emitter.cpp
cpu_external_function.cpp
cpu_kernel_emitters.cpp
cpu_kernel_utils.cpp
cpu_kernels.cpp
cpu_layout_descriptor.cpp
cpu_tensor_view_wrapper.cpp
cpu_tensor_view.cpp
cpu_tracing.cpp
kernel/eigen_thread_pool.cpp
kernel/pad.cpp
kernel/reduce_max.cpp
kernel/reduce_sum.cpp
kernel/reshape.cpp
mkldnn_emitter.cpp
mkldnn_invoke.cpp
mkldnn_utils.cpp
op/batch_norm_relu.cpp
op/conv_bias.cpp
op/conv_relu.cpp
op/convert_layout.cpp
op/lstm.cpp
op/matmul_bias.cpp
op/max_pool_with_indices.cpp
op/rnn.cpp
op/sigmoid_mul.cpp
op/sigmoid.cpp
pass/cpu_assignment.cpp
pass/cpu_concat_inputs.cpp
pass/cpu_fusion.cpp
pass/cpu_layout.cpp
pass/cpu_post_layout_optimizations.cpp
pass/cpu_rnn_fusion.cpp
pass/cpu_rnn_mat_fusion.cpp
pass/cpu_shuffle_folding.cpp
pass/cpu_workspace_insertion.cpp
)
if (NGRAPH_TBB_ENABLE)
include(${TBB_ROOT}/cmake/TBBBuild.cmake)
tbb_build(TBB_ROOT ${TBB_ROOT} MAKE_ARGS tbb_build_dir=${CMAKE_CURRENT_BINARY_DIR}/tbb_build
tbb_build_prefix=tbb CONFIG_DIR TBB_DIR)
find_package(TBB REQUIRED tbb)
if (NOT TBB_FOUND)
message(FATAL_ERROR "TBB is needed by the CPU backend and was not found")
else()
message(STATUS "Found TBB and imported target ${TBB_IMPORTED_TARGETS}")
endif()
set_source_files_properties(cpu_external_function.cpp
PROPERTIES COMPILE_DEFINITIONS "NGRAPH_TBB_ENABLE")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tbb_build/tbb_release/
DESTINATION ${NGRAPH_INSTALL_LIB}
FILES_MATCHING REGEX "/libtbb${CMAKE_SHARED_LIBRARY_SUFFIX}(\\.[0-9]+)*$"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tbb_build/tbb_debug/
DESTINATION ${NGRAPH_INSTALL_LIB}
FILES_MATCHING REGEX "/libtbb_debug${CMAKE_SHARED_LIBRARY_SUFFIX}(\\.[0-9]+)*$"
)
add_library(libtbb INTERFACE)
target_link_libraries(libtbb INTERFACE
${CMAKE_CURRENT_BINARY_DIR}/tbb_build/tbb_release/libtbb${CMAKE_SHARED_LIBRARY_SUFFIX}
)
target_include_directories(libtbb SYSTEM INTERFACE ${TBB_ROOT}/include)
endif()
if (NGRAPH_CPU_ENABLE)
set(NGRAPH_CPU_DEBUGINFO_ENABLE 0 CACHE STRING "Enable debuginfo in the CPU backend")
add_library(cpu_backend SHARED ${SRC})
set_target_properties(cpu_backend PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
if(NGRAPH_DISTRIBUTED_ENABLE)
find_package(MPI REQUIRED)
add_definitions(-DNGRAPH_DISTRIBUTED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
target_link_libraries(cpu_backend PRIVATE ${MPI_CXX_LIBRARIES})
endif()
target_link_libraries(cpu_backend PUBLIC ngraph codegen libmkldnn libeigen libjson libtbb)
target_include_directories(cpu_backend SYSTEM PUBLIC libmkldnn)
install(TARGETS cpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
endif()
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "ngraph/runtime/cpu/cpu_backend.hpp" #include <tbb/tbb_stddef.h>
#include "ngraph/graph_util.hpp" #include "ngraph/graph_util.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp" #include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp" #include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp" #include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
...@@ -24,14 +26,13 @@ ...@@ -24,14 +26,13 @@
using namespace ngraph; using namespace ngraph;
using namespace std; using namespace std;
static bool static_init() extern "C" void create_backend()
{ {
// Force TBB to link to the backend
tbb::TBB_runtime_interface_version();
runtime::Backend::register_backend("CPU", make_shared<runtime::cpu::CPU_Backend>()); runtime::Backend::register_backend("CPU", make_shared<runtime::cpu::CPU_Backend>());
return true;
}; };
bool runtime::cpu::CPU_Backend::init = static_init();
shared_ptr<runtime::cpu::CPU_CallFrame> runtime::cpu::CPU_Backend::make_call_frame( shared_ptr<runtime::cpu::CPU_CallFrame> runtime::cpu::CPU_Backend::make_call_frame(
const shared_ptr<runtime::cpu::CPU_ExternalFunction>& external_function) const shared_ptr<runtime::cpu::CPU_ExternalFunction>& external_function)
{ {
......
...@@ -66,7 +66,6 @@ namespace ngraph ...@@ -66,7 +66,6 @@ namespace ngraph
}; };
std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map; std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map;
static bool init;
}; };
} }
} }
......
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIRS})
# Add sources for the GPU backend
# and all its dependencies
set(SRC
cuda_emitter.cpp
cudnn_emitter.cpp
gpu_backend.cpp
gpu_call_frame.cpp
gpu_cuda_context_manager.cpp
gpu_cuda_function_builder.cpp
gpu_cuda_function_pool.cpp
gpu_cuda_kernel_builder.cpp
gpu_cuda_kernel_emitters.cpp
gpu_emitter.cpp
gpu_external_function.cpp
gpu_invoke.cpp
gpu_kernel_emitters.cpp
gpu_memory_manager.cpp
gpu_primitive_emitter.cpp
gpu_runtime_context.cpp
gpu_tensor_view_wrapper.cpp
gpu_tensor_view.cpp
gpu_util.cpp
type_info.cpp
)
if (NGRAPH_GPU_ENABLE)
add_library(gpu_backend SHARED ${SRC})
set_target_properties(gpu_backend PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
target_link_libraries(gpu_backend PUBLIC ngraph codegen)
find_library(CUDA_nvrtc_LIBRARY nvrtc /usr/local/cuda/lib64)
find_library(CUDA_cuda_LIBRARY cuda /usr/local/cuda/lib64/stubs)
find_package(CUDA 8 REQUIRED)
find_package(CUDNN 7 REQUIRED)
target_include_directories(gpu_backend SYSTEM PUBLIC ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
target_link_libraries(gpu_backend PUBLIC
${CUDA_cuda_LIBRARY}
${CUDA_nvrtc_LIBRARY}
${CUDA_LIBRARIES}
${CUDA_CUBLAS_LIBRARIES}
${CUDNN_LIBRARIES})
install(TARGETS gpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
endif()
...@@ -23,14 +23,11 @@ ...@@ -23,14 +23,11 @@
using namespace ngraph; using namespace ngraph;
using namespace std; using namespace std;
static bool static_init() extern "C" void create_backend()
{ {
runtime::Backend::register_backend("GPU", make_shared<runtime::gpu::GPU_Backend>()); runtime::Backend::register_backend("GPU", make_shared<runtime::gpu::GPU_Backend>());
return true;
}; };
bool runtime::gpu::GPU_Backend::init = static_init();
shared_ptr<runtime::gpu::GPU_CallFrame> runtime::gpu::GPU_Backend::make_call_frame( shared_ptr<runtime::gpu::GPU_CallFrame> runtime::gpu::GPU_Backend::make_call_frame(
const shared_ptr<GPU_ExternalFunction>& external_function) const shared_ptr<GPU_ExternalFunction>& external_function)
{ {
......
...@@ -63,7 +63,6 @@ namespace ngraph ...@@ -63,7 +63,6 @@ namespace ngraph
}; };
std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map; std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map;
static bool init;
}; };
} }
} }
......
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
if(NGRAPH_DISTRIBUTED_ENABLE)
find_package(MPI REQUIRED)
add_definitions(-DNGRAPH_DISTRIBUTED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
link_libraries(${MPI_CXX_LIBRARIES})
endif()
if (NGRAPH_INTERPRETER_ENABLE)
add_library(interpreter_backend SHARED int_backend.cpp)
set_target_properties(interpreter_backend PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
target_link_libraries(interpreter_backend PUBLIC ngraph)
install(TARGETS interpreter_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
endif()
...@@ -29,15 +29,12 @@ using namespace ngraph; ...@@ -29,15 +29,12 @@ using namespace ngraph;
using descriptor::layout::DenseTensorViewLayout; using descriptor::layout::DenseTensorViewLayout;
static bool static_init() extern "C" void create_backend()
{ {
runtime::Backend::register_backend("INTERPRETER", runtime::Backend::register_backend("INTERPRETER",
make_shared<runtime::interpreter::INTBackend>()); make_shared<runtime::interpreter::INTBackend>());
return true;
}; };
bool runtime::interpreter::INTBackend::init = static_init();
shared_ptr<runtime::TensorView> shared_ptr<runtime::TensorView>
runtime::interpreter::INTBackend::create_tensor(const element::Type& type, const Shape& shape) runtime::interpreter::INTBackend::create_tensor(const element::Type& type, const Shape& shape)
{ {
......
...@@ -158,7 +158,6 @@ private: ...@@ -158,7 +158,6 @@ private:
std::unordered_map<const Node*, stopwatch> m_timer_map; std::unordered_map<const Node*, stopwatch> m_timer_map;
}; };
std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map; std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map;
static bool init;
static void perform_nan_check(const std::vector<std::shared_ptr<HostTensorView>>&, static void perform_nan_check(const std::vector<std::shared_ptr<HostTensorView>>&,
const Node* op = nullptr); const Node* op = nullptr);
......
...@@ -14,28 +14,42 @@ ...@@ -14,28 +14,42 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if (NGRAPH_CPU_ENABLE) set (SRC
set (SRC main.cpp
main.cpp util.cpp
util.cpp uncomment.cpp
uncomment.cpp header_rewrite.cpp
header_rewrite.cpp )
)
get_target_property(MKLDNN_INCLUDE_DIR libmkldnn INTERFACE_INCLUDE_DIRECTORIES)
add_executable(resource_generator ${SRC}) get_target_property(EIGEN_INCLUDE_DIR libeigen INTERFACE_INCLUDE_DIRECTORIES)
add_dependencies(resource_generator ext_llvm ext_eigen ext_mkldnn) get_target_property(LLVM_INCLUDE_DIR libllvm INTERFACE_INCLUDE_DIRECTORIES)
set(CLANG_INCLUDE_DIR ${LLVM_INCLUDE_DIR}/../lib/clang/5.0.1/include)
set(HEADER_SEARCH_DEFINES get_filename_component(CLANG_INCLUDE_DIR ${CLANG_INCLUDE_DIR} ABSOLUTE)
"EIGEN_HEADERS_PATH=\"${EIGEN_INCLUDE_DIR}\""
"MKLDNN_HEADERS_PATH=\"${MKLDNN_INCLUDE_DIR}\"" set(HEADER_SEARCH_DEFINES
"CLANG_BUILTIN_HEADERS_PATH=\"${LLVM_LIB_DIR}/clang/5.0.1/include\"" "EIGEN_HEADERS_PATH=\"${EIGEN_INCLUDE_DIR}\""
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\"" "MKLDNN_HEADERS_PATH=\"${MKLDNN_INCLUDE_DIR}\""
) "CLANG_BUILTIN_HEADERS_PATH=\"${CLANG_INCLUDE_DIR}\""
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\""
if(NGRAPH_TBB_ENABLE) )
list(APPEND HEADER_SEARCH_DEFINES "TBB_HEADERS_PATH=\"${TBB_ROOT}/include\"")
set(HEADER_SEARCH_DEFINES ${HEADER_SEARCH_DEFINES} "NGRAPH_TBB_ENABLE") if(NGRAPH_TBB_ENABLE)
endif() list(APPEND HEADER_SEARCH_DEFINES "TBB_HEADERS_PATH=\"${TBB_ROOT}/include\"")
list(APPEND HEADER_SEARCH_DEFINES "NGRAPH_TBB_ENABLE")
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}") endif()
if (NGRAPH_GPU_ENABLE)
find_package(CUDA 8 REQUIRED)
find_package(CUDNN 7 REQUIRED)
set_property(SOURCE codegen/compiler.cpp APPEND_STRING PROPERTY COMPILE_DEFINITIONS
"CUDA_HEADER_PATHS=\"${CUDA_INCLUDE_DIRS}\";")
set_property(SOURCE codegen/compiler.cpp APPEND_STRING PROPERTY COMPILE_DEFINITIONS
"CUDNN_HEADER_PATHS=\"${CUDNN_INCLUDE_DIRS}\";")
endif() endif()
add_executable(resource_generator EXCLUDE_FROM_ALL ${SRC})
add_dependencies(resource_generator ext_llvm ext_eigen ext_mkldnn)
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
...@@ -14,25 +14,7 @@ ...@@ -14,25 +14,7 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(MKLDNN_INCLUDE_DIR)
link_directories(${MKLDNN_LIB_DIR})
endif()
if (NGRAPH_CPU_ENABLE) if (NGRAPH_CPU_ENABLE)
set (SRC add_executable(compile_benchmark compile_benchmark.cpp)
compile_benchmark.cpp target_link_libraries(compile_benchmark ngraph cpu_backend)
${PROJECT_SOURCE_DIR}/test/util/benchmark.cpp
)
add_executable(compile_benchmark ${SRC})
add_dependencies(compile_benchmark ngraph)
set(HEADER_SEARCH_DEFINES
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\""
)
target_link_libraries(compile_benchmark ngraph)
include_directories("${PROJECT_SOURCE_DIR}/test")
set_source_files_properties(compile_benchmark.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
endif() endif()
...@@ -25,7 +25,7 @@ if (NGRAPH_CPU_ENABLE) ...@@ -25,7 +25,7 @@ if (NGRAPH_CPU_ENABLE)
) )
add_executable(nbench ${SRC}) add_executable(nbench ${SRC})
add_dependencies(nbench ngraph) add_dependencies(nbench ngraph cpu_backend)
set(HEADER_SEARCH_DEFINES set(HEADER_SEARCH_DEFINES
"NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\"" "NGRAPH_HEADERS_PATH=\"${NGRAPH_INCLUDE_PATH}\""
......
...@@ -14,17 +14,6 @@ ...@@ -14,17 +14,6 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
if(MKLDNN_INCLUDE_DIR) add_executable(reserialize reserialize.cpp)
link_directories(${MKLDNN_LIB_DIR}) add_dependencies(reserialize ngraph)
endif() target_link_libraries(reserialize ngraph)
if (NGRAPH_CPU_ENABLE)
set (SRC
reserialize.cpp
)
add_executable(reserialize ${SRC})
add_dependencies(reserialize ngraph)
target_link_libraries(reserialize ngraph)
endif()
...@@ -14,17 +14,8 @@ ...@@ -14,17 +14,8 @@
# limitations under the License. # limitations under the License.
# ****************************************************************************** # ******************************************************************************
include_directories( set(SRC
SYSTEM
${GTEST_INCLUDE_DIR}
${EIGEN_INCLUDE_DIR}
)
set (SRC
backend_api.cpp
algebraic_simplification.cpp algebraic_simplification.cpp
backend_debug_api.cpp
builder.cpp
builder_autobroadcast.cpp builder_autobroadcast.cpp
build_graph.cpp build_graph.cpp
copy.cpp copy.cpp
...@@ -54,53 +45,22 @@ set (SRC ...@@ -54,53 +45,22 @@ set (SRC
zero_dim_tensor_elimination.cpp zero_dim_tensor_elimination.cpp
) )
if (NGRAPH_INTERPRETER_ENABLE)
set(SRC ${SRC} backend_debug_api.cpp builder.cpp backend_api.cpp)
endif()
add_subdirectory(models) add_subdirectory(models)
add_subdirectory(files) add_subdirectory(files)
add_subdirectory(util) add_subdirectory(util)
#================================================================================================ if(NGRAPH_CPU_ENABLE)
# To auto generate a suite of unit tests for a backend add a line like this
# set(BACKEND_NAMES ${BACKEND_NAMES} "BACKEND_NAME_GOES_HERE")
# and replace BACKEND_NAME_GOES_HERE with your backend name.
# The code for the unit test suite is in test/backend_test.in.cpp
#================================================================================================
# TODO add interpreter back to unit tests when it works
set(BACKEND_NAMES ${BACKEND_NAMES} "INTERPRETER")
if(MKLDNN_INCLUDE_DIR)
include_directories(SYSTEM ${MKLDNN_INCLUDE_DIR})
link_directories(${MKLDNN_LIB_DIR})
set(SRC ${SRC} mkldnn.cpp)
endif()
if(NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR)
include_directories(SYSTEM ${LLVM_INCLUDE_DIR})
link_directories(${LLVM_LIB_DIR})
set(SRC ${SRC} backend_performance.cpp codegen.cpp cpu_fusion.cpp cpu_test.cpp) set(SRC ${SRC} backend_performance.cpp codegen.cpp cpu_fusion.cpp cpu_test.cpp)
set(BACKEND_NAMES ${BACKEND_NAMES} "CPU")
endif() endif()
if(NGRAPH_GPU_ENABLE AND LLVM_INCLUDE_DIR) if(NGRAPH_GPU_ENABLE)
include_directories(SYSTEM ${LLVM_INCLUDE_DIR} ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
link_directories(${LLVM_LIB_DIR})
link_directories(${CUDA_LIBRARIES})
link_directories(${CUDA_CUBLAS_LIBRARIES})
link_directories(${CUDNN_LIBRARIES})
set(SRC ${SRC} cudnn.cpp gpu_test.cpp) set(SRC ${SRC} cudnn.cpp gpu_test.cpp)
# Disabled for testing
set(BACKEND_NAMES ${BACKEND_NAMES} "GPU")
endif() endif()
if(NGRAPH_DISTRIBUTED_ENABLE AND MPI_C_INCLUDE_PATH)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
foreach(BACKEND_NAME ${BACKEND_NAMES})
configure_file(distributed.cpp distributed_${BACKEND_NAME}.cpp)
set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/distributed_${BACKEND_NAME}.cpp)
endforeach()
endif()
foreach(TEST_CONFIG ${UNIT_TEST_CONFIG_LIST}) foreach(TEST_CONFIG ${UNIT_TEST_CONFIG_LIST})
string(FIND ${TEST_CONFIG} "@" OFFSET) string(FIND ${TEST_CONFIG} "@" OFFSET)
string(SUBSTRING ${TEST_CONFIG} 0 ${OFFSET} BACKEND_NAME) string(SUBSTRING ${TEST_CONFIG} 0 ${OFFSET} BACKEND_NAME)
...@@ -111,6 +71,10 @@ foreach(TEST_CONFIG ${UNIT_TEST_CONFIG_LIST}) ...@@ -111,6 +71,10 @@ foreach(TEST_CONFIG ${UNIT_TEST_CONFIG_LIST})
configure_file(convolution_test.in.cpp convolution_test_${BACKEND_NAME}.cpp) configure_file(convolution_test.in.cpp convolution_test_${BACKEND_NAME}.cpp)
set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/backend_test_${BACKEND_NAME}.cpp) set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/backend_test_${BACKEND_NAME}.cpp)
set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/convolution_test_${BACKEND_NAME}.cpp) set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/convolution_test_${BACKEND_NAME}.cpp)
if(NGRAPH_DISTRIBUTED_ENABLE)
configure_file(distributed.cpp distributed_${BACKEND_NAME}.cpp)
set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/distributed_${BACKEND_NAME}.cpp)
endif()
# Some---but not all---autodiff tests go through multiple iterations with # Some---but not all---autodiff tests go through multiple iterations with
# different random seeds. On the CPU backend this is currently very slow # different random seeds. On the CPU backend this is currently very slow
...@@ -139,35 +103,37 @@ if(NGRAPH_ADDRESS_SANITIZER) ...@@ -139,35 +103,37 @@ if(NGRAPH_ADDRESS_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
endif() endif()
if(NGRAPH_DISTRIBUTED_ENABLE)
find_package(MPI REQUIRED)
add_definitions(-DNGRAPH_DISTRIBUTED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
link_libraries(${MPI_CXX_LIBRARIES})
endif()
add_executable(unit-test ${SRC}) add_executable(unit-test ${SRC})
target_link_libraries(unit-test ngraph_test_util) target_link_libraries(unit-test ngraph_test_util)
add_dependencies(unit-test ngraph_test_util) target_link_libraries(unit-test ngraph libgtest libjson pthread)
target_link_libraries(unit-test ${CMAKE_DL_LIBS})
if(MPI_C_INCLUDE_PATH) if (NGRAPH_CPU_ENABLE)
target_link_libraries(unit-test ${MPI_CXX_LIBRARIES}) # The INTERPRETER backend is required for graph_partition, convolution, and backwards unit tests
target_link_libraries(unit-test cpu_backend interpreter_backend)
endif() endif()
if(MKLDNN_INCLUDE_DIR) if (NGRAPH_TBB_ENABLE)
target_link_libraries(unit-test mkldnn) add_definitions(-DNGRAPH_TBB_ENABLE)
add_dependencies(unit-test ext_mkldnn)
endif() endif()
if(LLVM_INCLUDE_DIR) if (NGRAPH_INTERPRETER_ENABLE)
target_link_libraries(unit-test ${LLVM_LINK_LIBS}) add_definitions(-DNGRAPH_INTERPRETER_ENABLE)
add_dependencies(unit-test ext_llvm) target_link_libraries(unit-test interpreter_backend)
endif() endif()
if(CUDA_INCLUDE_DIRS) if (NGRAPH_GPU_ENABLE)
find_library(CUDA_NVRTC_LIBRARY nvrtc /usr/local/cuda/lib64) target_link_libraries(unit-test gpu_backend)
target_link_libraries(unit-test ${CUDA_NVRTC_LIBRARY} ${CUDA_LIBRARIES} ${CUDNN_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES})
endif() endif()
target_link_libraries(unit-test ngraph libgtest pthread)
target_link_libraries(unit-test ${CMAKE_DL_LIBS})
add_dependencies(unit-test ngraph libgtest ext_json)
include_directories(SYSTEM ${JSON_INCLUDE_DIR})
add_custom_target(style-check add_custom_target(style-check
COMMAND ${PROJECT_SOURCE_DIR}/maint/check-code-format.sh COMMAND ${PROJECT_SOURCE_DIR}/maint/check-code-format.sh
) )
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "ngraph/log.hpp" #include "ngraph/log.hpp"
#include "ngraph/op/concat.hpp" #include "ngraph/op/concat.hpp"
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/serializer.hpp" #include "ngraph/serializer.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
#include "util/benchmark.hpp" #include "util/benchmark.hpp"
......
...@@ -4859,6 +4859,7 @@ NGRAPH_TEST(${BACKEND_NAME}, numeric_double_inf) ...@@ -4859,6 +4859,7 @@ NGRAPH_TEST(${BACKEND_NAME}, numeric_double_inf)
EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result)); EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
} }
#ifdef NGRAPH_TBB_ENABLE
NGRAPH_TEST(${BACKEND_NAME}, abc_tbb) NGRAPH_TEST(${BACKEND_NAME}, abc_tbb)
{ {
// Force TBB flow graph generation in the CPU backend // Force TBB flow graph generation in the CPU backend
...@@ -4904,6 +4905,7 @@ NGRAPH_TEST(${BACKEND_NAME}, abc_tbb) ...@@ -4904,6 +4905,7 @@ NGRAPH_TEST(${BACKEND_NAME}, abc_tbb)
unsetenv("NGRAPH_CPU_USE_TBB"); unsetenv("NGRAPH_CPU_USE_TBB");
} }
} }
#endif // NGRAPH_TBB_ENABLE
// //
// The unit tests for ReduceWindow follow exactly what we test for MaxPool---but they use ReduceWindow to do it. // The unit tests for ReduceWindow follow exactly what we test for MaxPool---but they use ReduceWindow to do it.
......
/*******************************************************************************
* Copyright 2017-2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/ngraph.hpp" #include "ngraph/ngraph.hpp"
......
...@@ -500,7 +500,6 @@ TEST(graph_partition, hybrid_multi_middle_nodes) ...@@ -500,7 +500,6 @@ TEST(graph_partition, hybrid_multi_middle_nodes)
EXPECT_EQ(read_vector<float>(r), EXPECT_EQ(read_vector<float>(r),
(test::NDArray<float, 2>({{210, 288}, {378, 480}})).get_vector()); (test::NDArray<float, 2>({{210, 288}, {378, 480}})).get_vector());
} }
#endif
TEST(graph_partition, hybrid_no_split) TEST(graph_partition, hybrid_no_split)
{ {
...@@ -526,3 +525,5 @@ TEST(graph_partition, hybrid_no_split) ...@@ -526,3 +525,5 @@ TEST(graph_partition, hybrid_no_split)
backend->call(f, {c}, {a, b}); backend->call(f, {c}, {a, b});
EXPECT_EQ(read_vector<float>(c), (test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()); EXPECT_EQ(read_vector<float>(c), (test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector());
} }
#endif
...@@ -45,6 +45,7 @@ T get_or_default(nlohmann::json& j, const std::string& key, const T& default_val ...@@ -45,6 +45,7 @@ T get_or_default(nlohmann::json& j, const std::string& key, const T& default_val
return rc; return rc;
} }
#if defined(NGRAPH_INTERPRETER_ENABLE)
TEST(serialize, main) TEST(serialize, main)
{ {
// First create "f(A,B,C) = (A+B)*C". // First create "f(A,B,C) = (A+B)*C".
...@@ -102,6 +103,7 @@ TEST(serialize, main) ...@@ -102,6 +103,7 @@ TEST(serialize, main)
backend->call(sfunc, {result}, {x, z, y}); backend->call(sfunc, {result}, {x, z, y});
EXPECT_EQ((vector<float>{200, 288, 392, 512}), read_vector<float>(result)); EXPECT_EQ((vector<float>{200, 288, 392, 512}), read_vector<float>(result));
} }
#endif
TEST(serialize, existing_models) TEST(serialize, existing_models)
{ {
......
...@@ -101,11 +101,13 @@ void test_read_write(const vector<T>& x) ...@@ -101,11 +101,13 @@ void test_read_write(const vector<T>& x)
ASSERT_EQ(result1, result2); ASSERT_EQ(result1, result2);
} }
#if defined(NGRAPH_INTERPRETER_ENABLE)
TEST(tensor, read_write) TEST(tensor, read_write)
{ {
test_read_write<float>({1.0, 3.0, 5.0}); test_read_write<float>({1.0, 3.0, 5.0});
test_read_write<int64_t>({-1, 2, 4}); test_read_write<int64_t>({-1, 2, 4});
} }
#endif
TEST(tensor, output_flag) TEST(tensor, output_flag)
{ {
......
...@@ -143,6 +143,7 @@ TEST(util, contains) ...@@ -143,6 +143,7 @@ TEST(util, contains)
EXPECT_FALSE(contains(v1, 8)); EXPECT_FALSE(contains(v1, 8));
} }
#if defined(NGRAPH_INTERPRETER_ENABLE)
TEST(util, all_close) TEST(util, all_close)
{ {
auto backend = runtime::Backend::create("INTERPRETER"); auto backend = runtime::Backend::create("INTERPRETER");
...@@ -165,6 +166,7 @@ TEST(util, all_close) ...@@ -165,6 +166,7 @@ TEST(util, all_close)
EXPECT_FALSE(ngraph::test::all_close<float>(c, a, .05f, 0)); EXPECT_FALSE(ngraph::test::all_close<float>(c, a, .05f, 0));
EXPECT_TRUE(ngraph::test::all_close<float>(c, a, .11f, 0)); EXPECT_TRUE(ngraph::test::all_close<float>(c, a, .11f, 0));
} }
#endif
TEST(util, traverse_functions) TEST(util, traverse_functions)
{ {
......
...@@ -30,6 +30,7 @@ include_directories( ...@@ -30,6 +30,7 @@ include_directories(
) )
add_library(ngraph_test_util SHARED ${SRC}) add_library(ngraph_test_util SHARED ${SRC})
set_target_properties(ngraph_test_util PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
target_link_libraries(ngraph_test_util ngraph libgtest) target_link_libraries(ngraph_test_util ngraph libgtest)
add_dependencies(ngraph_test_util ngraph libgtest) add_dependencies(ngraph_test_util ngraph libgtest)
......
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