From 80a0c9db9681bf4aabce1472f9e8fadad76d6498 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A2=D0=B8=D1=89?= =?utf8?q?=D0=B5=D0=BD=D0=BA=D0=BE/AI=20Tools=20Lab=20/SRR/Staff=20Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 30 Oct 2018 16:29:56 +0300 Subject: [PATCH] Initial top-level ONNX support (#1987) CMake changes were done to allow ONNX downloading and onnx.proto compiling. Signed-off-by: Andrew V. Tischenko a.tischenko@partner.samsung.com --- CMakeLists.txt | 3 +++ cmake/packages/ONNXProto/CMakeLists.txt | 6 ++++++ cmake/packages/ONNXProtoConfig.cmake | 25 +++++++++++++++++++++++++ cmake/packages/ONNXSourceConfig.cmake | 17 +++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 cmake/packages/ONNXProto/CMakeLists.txt create mode 100644 cmake/packages/ONNXProtoConfig.cmake create mode 100644 cmake/packages/ONNXSourceConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b1955b7..cb2ef2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,9 @@ option(DOWNLOAD_GFLAGS "Download GFlags source" OFF) option(DOWNLOAD_FLATBUFFERS "Download FlatBuffers source" ON) option(DOWNLOAD_TENSORFLOW "Download TensorFlow source" ON) option(DOWNLOAD_CAFFE "Download Caffe source" ON) +# TODO: we need protoc version 2.6 and higher but server has 2.5 only +# that's why we can't compile onnx.proto +option(DOWNLOAD_ONNX "Download ONNX source" OFF) option(BUILD_GTEST "Download and build Google Test" ON) diff --git a/cmake/packages/ONNXProto/CMakeLists.txt b/cmake/packages/ONNXProto/CMakeLists.txt new file mode 100644 index 0000000..b37fc3b --- /dev/null +++ b/cmake/packages/ONNXProto/CMakeLists.txt @@ -0,0 +1,6 @@ +Protobuf_Generate(ONNX_PROTO "${CMAKE_CURRENT_BINARY_DIR}/generated" + "${ONNXSource_DIR}" "onnx/onnx.proto") + +add_library(onnxproto SHARED ${ONNX_PROTO_SOURCES}) +target_include_directories(onnxproto PUBLIC ${ONNX_PROTO_INCLUDE_DIRS}) +target_link_libraries(onnxproto libprotobuf) diff --git a/cmake/packages/ONNXProtoConfig.cmake b/cmake/packages/ONNXProtoConfig.cmake new file mode 100644 index 0000000..32e8556 --- /dev/null +++ b/cmake/packages/ONNXProtoConfig.cmake @@ -0,0 +1,25 @@ +function(_ONNXProto_import) + nncc_find_package(ONNXSource QUIET) + + if(NOT ONNXSource_FOUND) + set(ONNXProto_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT ONNXSource_FOUND) + + nncc_find_package(Protobuf QUIET) + + if(NOT Protobuf_FOUND) + set(ONNXProto_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Protobuf_FOUND) + + if(NOT TARGET onnxproto) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/ONNXProto" onnxproto) + endif(NOT TARGET onnxproto) + + message(STATUS "Found ONNX: TRUE") + set(ONNXProto_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXProto_import) + +_ONNXProto_import() diff --git a/cmake/packages/ONNXSourceConfig.cmake b/cmake/packages/ONNXSourceConfig.cmake new file mode 100644 index 0000000..5115c2f --- /dev/null +++ b/cmake/packages/ONNXSourceConfig.cmake @@ -0,0 +1,17 @@ +function(_ONNXSource_import) + if(NOT DOWNLOAD_ONNX) + set(ONNXSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_ONNX) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(ONNX_URL https://github.com/onnx/onnx/archive/v1.3.0.zip) + ExternalSource_Download(ONNX ${ONNX_URL}) + + set(ONNXSource_DIR ${ONNX_SOURCE_DIR} PARENT_SCOPE) + set(ONNXSource_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXSource_import) + +_ONNXSource_import() -- 2.7.4