Commit 3d664abd authored by Artur Wojcik's avatar Artur Wojcik Committed by Robert Kimball

[ONNX] Link nGraph statically against Protocol Buffers (#1419)

* onnx: pull Protobuf 3.5.x from GitHub
Signed-off-by: 's avatarArtur Wojcik <artur.wojcik@intel.com>

* onnx: fix Travis build configuration issue
Signed-off-by: 's avatarArtur Wojcik <artur.wojcik@intel.com>

* onnx: additional fixes for Travis
Signed-off-by: 's avatarArtur Wojcik <artur.wojcik@intel.com>

* onnx: update documentation - build requirements for MacOS
Signed-off-by: 's avatarArtur Wojcik <artur.wojcik@intel.com>

* onnx: update documentation - build requirements for Ubuntu
Signed-off-by: 's avatarArtur Wojcik <artur.wojcik@intel.com>
parent 3de2051e
...@@ -11,11 +11,13 @@ RUN apt-get update && apt-get install -y \ ...@@ -11,11 +11,13 @@ RUN apt-get update && apt-get install -y \
clang-format-3.9 \ clang-format-3.9 \
git \ git \
curl \ curl \
protobuf-compiler \
libprotoc-dev \
zlib1g \ zlib1g \
zlib1g-dev \ zlib1g-dev \
libtinfo-dev && \ libtinfo-dev \
unzip \
autoconf \
automake \
libtool && \
apt-get clean autoclean && apt-get autoremove -y apt-get clean autoclean && apt-get autoremove -y
# Python dependencies # Python dependencies
......
...@@ -91,6 +91,10 @@ option(NGRAPH_DISTRIBUTED_ENABLE "Add distributed mode to the CPU backend" FALSE ...@@ -91,6 +91,10 @@ 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)
option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" FALSE) option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" FALSE)
if (NGRAPH_ONNX_IMPORT_ENABLE)
option(NGRAPH_USE_SYSTEM_PROTOBUF "Use system provided Protobuf shared object" FALSE)
endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Installation logic... # Installation logic...
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
...@@ -208,13 +212,18 @@ set(NGRAPH_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/ngraph) ...@@ -208,13 +212,18 @@ set(NGRAPH_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/ngraph)
set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external) set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external)
if (NGRAPH_ONNX_IMPORT_ENABLE)
find_package(Protobuf 2.6.1 REQUIRED)
endif()
if(NOT DEFINED EXTERNAL_PROJECTS_ROOT) if(NOT DEFINED EXTERNAL_PROJECTS_ROOT)
set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR}) set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR})
endif() endif()
if (NGRAPH_ONNX_IMPORT_ENABLE)
if (NOT NGRAPH_USE_SYSTEM_PROTOBUF)
include (cmake/external_protobuf.cmake)
else()
find_package(Protobuf 2.6.1 REQUIRED)
endif()
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) include(cmake/external_eigen.cmake)
......
# ******************************************************************************
# 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.
# ******************************************************************************
# Enable ExternalProject CMake module
include(ExternalProject)
#------------------------------------------------------------------------------
# Download and install Google Protobuf ...
#------------------------------------------------------------------------------
set(PROTOBUF_GIT_REPO_URL https://github.com/google/protobuf.git)
set(PROTOBUF_GIT_BRANCH origin/3.5.x)
# The 'BUILD_BYPRODUCTS' arguments was introduced in CMake 3.2.
if (${CMAKE_VERSION} VERSION_LESS 3.2)
ExternalProject_Add(
ext_protobuf
PREFIX protobuf
GIT_REPOSITORY ${PROTOBUF_GIT_REPO_URL}
GIT_TAG ${PROTOBUF_GIT_BRANCH}
INSTALL_COMMAND ""
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ./autogen.sh && ./configure --disable-shared CXXFLAGS=-fPIC
BUILD_COMMAND ${MAKE}
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf"
EXCLUDE_FROM_ALL TRUE
)
else()
if (${CMAKE_VERSION} VERSION_LESS 3.6)
ExternalProject_Add(
ext_protobuf
PREFIX ext_protobuf
GIT_REPOSITORY ${PROTOBUF_GIT_REPO_URL}
GIT_TAG ${PROTOBUF_GIT_BRANCH}
INSTALL_COMMAND ""
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ./autogen.sh && ./configure --disable-shared CXXFLAGS=-fPIC
BUILD_COMMAND ${MAKE}
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/protobuf/src/src/.libs/libprotobuf.a"
EXCLUDE_FROM_ALL TRUE
)
else()
# To speed things up prefer 'shallow copy' for CMake 3.6 and later
ExternalProject_Add(
ext_protobuf
PREFIX ext_protobuf
GIT_REPOSITORY ${PROTOBUF_GIT_REPO_URL}
GIT_TAG ${PROTOBUF_GIT_BRANCH}
GIT_SHALLOW TRUE
INSTALL_COMMAND ""
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ./autogen.sh && ./configure --disable-shared CXXFLAGS=-fPIC
BUILD_COMMAND ${MAKE}
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf/src"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/protobuf"
BUILD_BYPRODUCTS "${EXTERNAL_PROJECTS_ROOT}/protobuf/src/src/.libs/libprotobuf.a"
EXCLUDE_FROM_ALL TRUE
)
endif()
endif()
# -----------------------------------------------------------------------------
ExternalProject_Get_Property(ext_protobuf SOURCE_DIR BINARY_DIR)
# -----------------------------------------------------------------------------
# Use the interface of FindProtobuf.cmake
# -----------------------------------------------------------------------------
set(Protobuf_SRC_ROOT_FOLDER ${SOURCE_DIR})
set(Protobuf_PROTOC_EXECUTABLE ${Protobuf_SRC_ROOT_FOLDER}/src/protoc)
set(Protobuf_INCLUDE_DIR ${Protobuf_SRC_ROOT_FOLDER}/src)
set(Protobuf_LIBRARY ${Protobuf_SRC_ROOT_FOLDER}/src/.libs/libprotobuf.a)
set(Protobuf_LIBRARIES ${Protobuf_LIBRARY})
if (NOT TARGET protobuf::libprotobuf)
add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
set_target_properties(protobuf::libprotobuf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}"
IMPORTED_LOCATION "${Protobuf_LIBRARY}")
add_dependencies(protobuf::libprotobuf ext_protobuf)
endif()
if (NOT TARGET protobuf::protoc)
add_executable(protobuf::protoc IMPORTED)
set_target_properties(protobuf::protoc PROPERTIES
IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}")
add_dependencies(protobuf::protoc ext_protobuf)
endif()
...@@ -20,7 +20,7 @@ with the following packages and prerequisites: ...@@ -20,7 +20,7 @@ with the following packages and prerequisites:
:escape: ~ :escape: ~
CentOS 7.4 64-bit, GCC 4.8, CMake 3.4.3, supported, ``wget zlib-devel ncurses-libs ncurses-devel patch diffutils gcc-c++ make git perl-Data-Dumper`` CentOS 7.4 64-bit, GCC 4.8, CMake 3.4.3, supported, ``wget zlib-devel ncurses-libs ncurses-devel patch diffutils gcc-c++ make git perl-Data-Dumper``
Ubuntu 16.04 or 18.04 (LTS) 64-bit, Clang 3.9, CMake 3.5.1 + GNU Make, supported, ``build-essential cmake clang-3.9 clang-format-3.9 git curl zlib1g zlib1g-dev libtinfo-dev`` Ubuntu 16.04 or 18.04 (LTS) 64-bit, Clang 3.9, CMake 3.5.1 + GNU Make, supported, ``build-essential cmake clang-3.9 clang-format-3.9 git curl zlib1g zlib1g-dev libtinfo-dev unzip autoconf automake libtool``
Clear Linux\* OS for Intel Architecture, Clang 5.0.1, CMake 3.10.2, experimental, bundles ``machine-learning-basic dev-utils python3-basic python-basic-dev`` Clear Linux\* OS for Intel Architecture, Clang 5.0.1, CMake 3.10.2, experimental, bundles ``machine-learning-basic dev-utils python3-basic python-basic-dev``
Other configurations may work, but should be considered experimental with Other configurations may work, but should be considered experimental with
...@@ -183,7 +183,7 @@ according to those conventions. These scripts require the command ...@@ -183,7 +183,7 @@ according to those conventions. These scripts require the command
.. code-block:: bash .. code-block:: bash
$ brew install llvm@3.9 $ brew install llvm@3.9 automake
$ mkdir -p $HOME/bin $ mkdir -p $HOME/bin
$ ln -s /usr/local/opt/llvm@3.9/bin/clang-format $HOME/bin/clang-format-3.9 $ ln -s /usr/local/opt/llvm@3.9/bin/clang-format $HOME/bin/clang-format-3.9
$ echo 'export PATH=$HOME/bin:$PATH' >> $HOME/.bash_profile $ echo 'export PATH=$HOME/bin:$PATH' >> $HOME/.bash_profile
......
...@@ -23,7 +23,7 @@ if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/onnx.proto") ...@@ -23,7 +23,7 @@ if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/onnx.proto")
endif() endif()
add_custom_command(OUTPUT onnx.pb.cc onnx.pb.h add_custom_command(OUTPUT onnx.pb.cc onnx.pb.h
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx.proto COMMAND protobuf::protoc --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/onnx.proto
DEPENDS onnx.proto) DEPENDS onnx.proto)
add_library(onnx_import_interface OBJECT add_library(onnx_import_interface OBJECT
...@@ -49,12 +49,18 @@ add_library(onnx_import STATIC ...@@ -49,12 +49,18 @@ add_library(onnx_import STATIC
add_dependencies(onnx_import onnx_import_interface) add_dependencies(onnx_import onnx_import_interface)
if (NOT NGRAPH_USE_SYSTEM_PROTOBUF)
add_dependencies(onnx_import_interface protobuf::libprotobuf)
add_dependencies(onnx_import protobuf::libprotobuf)
endif()
set_property(TARGET onnx_import PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET onnx_import PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(onnx_import PUBLIC ${CMAKE_CURRENT_BINARY_DIR} PRIVATE ${NGRAPH_INCLUDE_PATH}) target_include_directories(onnx_import PUBLIC ${CMAKE_CURRENT_BINARY_DIR} PRIVATE ${NGRAPH_INCLUDE_PATH} ${Protobuf_INCLUDE_DIR})
target_link_libraries(onnx_import PRIVATE ${PROTOBUF_LIBRARIES}) target_link_libraries(onnx_import PRIVATE ${Protobuf_LIBRARIES})
set_property(TARGET onnx_import_interface PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET onnx_import_interface PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(onnx_import_interface PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${NGRAPH_INCLUDE_PATH}) target_include_directories(onnx_import_interface PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
${NGRAPH_INCLUDE_PATH} ${Protobuf_INCLUDE_DIR})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$") if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
target_compile_options(onnx_import PRIVATE -Wno-undef -Wno-reserved-id-macro -Wno-switch-enum target_compile_options(onnx_import PRIVATE -Wno-undef -Wno-reserved-id-macro -Wno-switch-enum
......
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