Initial top-level ONNX support (#1987)
authorАндрей Тищенко/AI Tools Lab /SRR/Staff Engineer/삼성전자 <a.tischenko@partner.samsung.com>
Tue, 30 Oct 2018 13:29:56 +0000 (16:29 +0300)
committerРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Tue, 30 Oct 2018 13:29:56 +0000 (16:29 +0300)
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
cmake/packages/ONNXProto/CMakeLists.txt [new file with mode: 0644]
cmake/packages/ONNXProtoConfig.cmake [new file with mode: 0644]
cmake/packages/ONNXSourceConfig.cmake [new file with mode: 0644]

index b1955b7..cb2ef2a 100644 (file)
@@ -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 (file)
index 0000000..b37fc3b
--- /dev/null
@@ -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 (file)
index 0000000..32e8556
--- /dev/null
@@ -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 (file)
index 0000000..5115c2f
--- /dev/null
@@ -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()