Commit b3f0a474 authored by Artur Wojcik's avatar Artur Wojcik Committed by Michał Karzyński

onnx [1]: add importer cmakes (#1145)

* onnx: add importer cmakes
* onnx: use file(DOWNLOAD ...) command to download onnx.proto
* onnx: add Protobuf minimal required version
parent e4db82ec
......@@ -89,6 +89,7 @@ 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_DEBUG_ENABLE "Enable output for NGRAPH_DEBUG statements" FALSE)
option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" FALSE)
#-----------------------------------------------------------------------------------------------
# Installation logic...
......@@ -205,6 +206,10 @@ set(NGRAPH_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/ngraph)
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)
set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR})
endif()
......
......@@ -143,6 +143,8 @@ set (SRC
cpio.cpp
)
add_subdirectory(frontend)
message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}/op)
file(GLOB OPS "${CMAKE_CURRENT_SOURCE_DIR}/op/" "${CMAKE_CURRENT_SOURCE_DIR}/op/*.hpp")
foreach(OP ${OPS})
......@@ -180,6 +182,10 @@ add_definitions("-DLIBRARY_VERSION=\"${NGRAPH_VERSION}\"")
set_target_properties(ngraph PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
target_link_libraries(ngraph PUBLIC libjson)
if (NGRAPH_ONNX_IMPORT_ENABLE)
add_dependencies(ngraph onnx_import)
endif()
if (NOT APPLE)
set_property(TARGET ngraph APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--rpath,$ORIGIN")
......@@ -204,6 +210,11 @@ endif()
target_include_directories(ngraph PUBLIC "${NGRAPH_INCLUDE_PATH}")
target_link_libraries(ngraph PUBLIC dl pthread)
if (NGRAPH_ONNX_IMPORT_ENABLE)
target_sources(ngraph PRIVATE $<TARGET_OBJECTS:onnx_import_interface>)
target_link_libraries(ngraph PRIVATE onnx_import)
endif()
#-----------------------------------------------------------------------------------------------
# Installation logic...
#-----------------------------------------------------------------------------------------------
......
# ******************************************************************************
# 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_ONNX_IMPORT_ENABLE)
add_subdirectory(onnx_import)
endif()
# ******************************************************************************
# Copyright (c) 2017-2018 Intel Copyright
#
# 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 application 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(ONNX_SOURCE_URL "https://raw.githubusercontent.com/onnx/onnx/v1.1.2/onnx/onnx.proto")
set_source_files_properties(onnx.pb.h onnx.pb.cc PROPERTIES GENERATED TRUE)
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/onnx.proto")
file(DOWNLOAD ${ONNX_SOURCE_URL} ${CMAKE_CURRENT_BINARY_DIR}/onnx.proto)
endif()
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
DEPENDS onnx.proto)
add_library(onnx_import_interface OBJECT
onnx.pb.h
onnx.proto)
add_library(onnx_import STATIC
onnx.pb.cc)
add_dependencies(onnx_import onnx_import_interface)
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_link_libraries(onnx_import PRIVATE ${PROTOBUF_LIBRARIES})
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})
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
target_compile_options(onnx_import PRIVATE -Wno-undef -Wno-reserved-id-macro -Wno-switch-enum
-Wno-extended-offsetof -Wno-zero-as-null-pointer-constant -Wno-shorten-64-to-32 -Wno-unused-macros
-Wno-missing-variable-declarations -Wno-unused-private-field)
endif()
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