[nnc] Refactoring cmake build system (#2844)
authorРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Mon, 14 Jan 2019 16:57:04 +0000 (19:57 +0300)
committerEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Mon, 14 Jan 2019 16:57:04 +0000 (19:57 +0300)
* make separate config and utils files
* refactoring CMakeLists in other components

Signed-off-by: Roman Rusyaev <r.rusyaev@samsung.com>
28 files changed:
contrib/nnc/CMakeLists.txt
contrib/nnc/cmake/config.cmake [new file with mode: 0644]
contrib/nnc/cmake/soft_backend.cmake [deleted file]
contrib/nnc/cmake/utils.cmake [new file with mode: 0644]
contrib/nnc/core/CMakeLists.txt
contrib/nnc/driver/Driver.cpp
contrib/nnc/pass/CMakeLists.txt
contrib/nnc/passes/CMakeLists.txt
contrib/nnc/passes/acl_soft_backend/CMakeLists.txt
contrib/nnc/passes/caffe2_frontend/CMakeLists.txt
contrib/nnc/passes/caffe_frontend/CMakeLists.txt
contrib/nnc/passes/common_frontend/CMakeLists.txt
contrib/nnc/passes/interpreter/CMakeLists.txt
contrib/nnc/passes/onnx_frontend/CMakeLists.txt
contrib/nnc/passes/soft_backend/CMakeLists.txt
contrib/nnc/passes/tflite_frontend/CMakeLists.txt
contrib/nnc/support/CMakeLists.txt
contrib/nnc/tests/import/CMakeLists.txt
contrib/nnc/tests/soft_backend/CMakeLists.txt
contrib/nnc/unittests/CMakeLists.txt
contrib/nnc/unittests/acl_backend/CMakeLists.txt
contrib/nnc/unittests/caffe2_frontend/CMakeLists.txt
contrib/nnc/unittests/caffe_frontend/CMakeLists.txt
contrib/nnc/unittests/core/CMakeLists.txt
contrib/nnc/unittests/pass/CMakeLists.txt
contrib/nnc/unittests/soft_backend/CMakeLists.txt
contrib/nnc/unittests/support/CMakeLists.txt
contrib/nnc/unittests/tflite_frontend/CMakeLists.txt

index 1e5393c..b56c519 100644 (file)
-project(nnc)
-
-list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
-include(soft_backend)
-
-set(DRIVER_SOURCES driver/main.cpp driver/Driver.cpp)
-set(OPTIONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/driver/Options.cpp)
-
-# add interface header files
-include_directories(include)
-
-#
-# Variables that uses inside compiler via configure_file
-#
-###
-set(NNC_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}) # root path of installation directory
-set(NNC_INSTALL_LIB_PATH ${NNC_INSTALL_PATH}/lib) # directory that contains other directories with shared library
-
-# nnc executable
-add_executable(nnc ${DRIVER_SOURCES} ${OPTIONS_SRC})
-target_link_libraries(nnc PRIVATE nnc_support nnc_pass)
-
-# install nnc
-install(TARGETS nnc DESTINATION ${NNC_INSTALL_PATH}/bin)
-# TODO when we upgrade our cmake to version 3.8 we'll need to use BUILD_RPATH
-# variable instead of CMAKE_BUILD_WITH_INSTALL_RPATH here
-set_target_properties(nnc PROPERTIES INSTALL_RPATH "${NNC_INSTALL_LIB_PATH}")
-set_target_properties(nnc PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
-set_target_properties(nnc PROPERTIES CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
-
 set(NNC_ROOT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(NNC_ROOT_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
-#
-# find necessary packages
-#
-find_package(HDF5 COMPONENTS CXX QUIET)
-# defines if hdf5 package was found
-if(HDF5_FOUND)
-  set(NNC_HDF5_SUPPORTED ON)
-else()
-  set(NNC_HDF5_SUPPORTED OFF)
-endif()
-
-# We need protobuf and pytorch sources to generate caffe2.pb.h and caffe2.pb.cc
-nncc_find_package(PytorchSource QUIET)
-nncc_find_package(Protobuf QUIET)
-if (Protobuf_FOUND AND PytorchSource_FOUND)
-  set(NNC_FRONTEND_CAFFE2_ENABLED ON)
-else()
-  set(NNC_FRONTEND_CAFFE2_ENABLED OFF)
-endif()
-
-# Try to get compiled caffe proto and return if not successful
-# Note: this creates a target called "caffeproto" that contains compiled caffe.proto sources,
-#       and after linking with it caffe.pb.h will be available as "caffe/proto/caffe.pb.h"
-nncc_find_package(CaffeProto QUIET)
-if (CaffeProto_FOUND)
-  set(NNC_FRONTEND_CAFFE_ENABLED ON)
-else()
-  set(NNC_FRONTEND_CAFFE_ENABLED OFF)
-endif()
-
-# Try to get the compiled onnx proto and return if not successful.
-# Note: this creates a target called "onnxproto" and after linking with it
-#       onnx.pb.h will be available as "onnx/onnx.pb.h"
-nncc_find_package(ONNXProto QUIET)
-if (ONNXProto_FOUND)
-  set(NNC_FRONTEND_ONNX_ENABLED ON)
-else()
-  set(NNC_FRONTEND_ONNX_ENABLED OFF)
-endif()
+list(APPEND CMAKE_MODULE_PATH ${NNC_ROOT_SRC_DIR}/cmake)
 
-# We need flatbuffer for tflite frontend
-nncc_find_package(FlatBuffers QUIET)
-if (FlatBuffers_FOUND)
-  set(NNC_FRONTEND_TFLITE_ENABLED ON)
-else()
-  set(NNC_FRONTEND_TFLITE_ENABLED OFF)
-endif()
-###
-
-#
-# functions
-#
-function(install_nnc_library LIB)
-  install(TARGETS ${LIB} DESTINATION ${NNC_INSTALL_LIB_PATH})
-  # set external RPATHs
-  set_target_properties(${LIB} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
-  # use paths from build directoris
-  set_target_properties(${LIB} PROPERTIES CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
-  # set RPATH to core part of nnc
-  set_target_properties(${LIB} PROPERTIES INSTALL_RPATH ${NNC_INSTALL_LIB_PATH})
-endfunction()
+include(config)
+include(utils)
 
-function(add_nnc_library)
-  add_library(${ARGV})
+# configure file that contains extern definitions
+configure_file(${NNC_ROOT_SRC_DIR}/include/Definitions.h.in
+        ${NNC_ROOT_BIN_DIR}/include/Definitions.h)
 
-  get_target_property(LIBS nnc LINK_LIBRARIES)
-  list(APPEND LIBS ${ARGV0})
-  set_target_properties(nnc PROPERTIES LINK_LIBRARIES "${LIBS}")
-endfunction()
-#
-# end functions
-#
+# add interface header files
+include_directories(${NNC_ROOT_SRC_DIR}/include)
+include_directories(${NNC_ROOT_BIN_DIR}/include)
 
-#
-# Used by unit tests
-#
-set(NNC_SOFT_BACKEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/soft_backend)
-set(NNC_ACL_BACKEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/acl_soft_backend)
-set(NNC_INTERPRETER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/interpreter)
-set(NNC_CAFFE_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/caffe_frontend)
-set(NNC_CAFFE2_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/caffe2_frontend)
-set(NNC_TFLITE_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/tflite_frontend)
-set(NNC_ONNX_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/onnx_frontend)
-set(NNC_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core)
-set(NNC_SUPPORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/support)
+# target for compiler executable
+add_executable(${NNC_TARGET_EXECUTABLE} ${NNC_DRIVER_DIR}/main.cpp ${NNC_DRIVER_DIR}/Driver.cpp ${OPTIONS_SRC})
 
-# configure file that contains extern definitions
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/Definitions.h.in
-        ${CMAKE_CURRENT_BINARY_DIR}/include/Definitions.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
+# install compiler
+nnc_install_executable(${NNC_TARGET_EXECUTABLE})
 
 add_subdirectory(support)
 add_subdirectory(core)
 add_subdirectory(pass)
 add_subdirectory(passes)
-add_subdirectory(unittests)
-add_subdirectory(utils)
+if(NNC_ENABLE_UNITTEST)
+  add_subdirectory(unittests)
+endif()
 add_subdirectory(tests)
-
+add_subdirectory(utils)
diff --git a/contrib/nnc/cmake/config.cmake b/contrib/nnc/cmake/config.cmake
new file mode 100644 (file)
index 0000000..e5f9faa
--- /dev/null
@@ -0,0 +1,88 @@
+#
+# definition of directories of all nnc component
+#
+set(NNC_DRIVER_DIR ${NNC_ROOT_SRC_DIR}/driver)
+set(NNC_SOFT_BACKEND_DIR ${NNC_ROOT_SRC_DIR}/passes/soft_backend)
+set(NNC_ACL_BACKEND_DIR ${NNC_ROOT_SRC_DIR}/passes/acl_soft_backend)
+set(NNC_INTERPRETER_DIR ${NNC_ROOT_SRC_DIR}/passes/interpreter)
+set(NNC_CAFFE_FRONTEND_DIR ${NNC_ROOT_SRC_DIR}/passes/caffe_frontend)
+set(NNC_CAFFE2_FRONTEND_DIR ${NNC_ROOT_SRC_DIR}/passes/caffe2_frontend)
+set(NNC_TFLITE_FRONTEND_DIR ${NNC_ROOT_SRC_DIR}/passes/tflite_frontend)
+set(NNC_ONNX_FRONTEND_DIR ${NNC_ROOT_SRC_DIR}/passes/onnx_frontend)
+set(NNC_CORE_DIR ${NNC_ROOT_SRC_DIR}/core)
+set(NNC_SUPPORT_DIR ${NNC_ROOT_SRC_DIR}/support)
+set(NNC_PASS_DIR ${NNC_ROOT_SRC_DIR}/pass)
+
+set(OPTIONS_SRC ${NNC_DRIVER_DIR}/Options.cpp)
+
+#
+# Other additional useful cmake variables
+#
+set(NNC_ENABLE_UNITTEST ${ENABLE_TEST})
+set(NNC_TARGET_EXECUTABLE nnc) # nnc main target
+
+set(NNC_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}) # root path of installation directory
+set(NNC_INSTALL_BIN_PATH ${NNC_INSTALL_PATH}/bin)
+set(NNC_INSTALL_LIB_PATH ${NNC_INSTALL_PATH}/lib) # directory that contains other directories with shared library
+
+#
+# find necessary packages
+#
+find_package(HDF5 COMPONENTS CXX QUIET)
+# defines if hdf5 package was found
+if(HDF5_FOUND)
+  set(NNC_HDF5_SUPPORTED ON)
+else()
+  message(WARNING "HDF5 not found, functionality of some nnc components will be disabled")
+  set(NNC_HDF5_SUPPORTED OFF)
+endif()
+
+# We need protobuf and pytorch sources to generate caffe2.pb.h and caffe2.pb.cc
+nncc_find_package(PytorchSource QUIET)
+nncc_find_package(Protobuf QUIET)
+if(Protobuf_FOUND AND PytorchSource_FOUND)
+  set(NNC_FRONTEND_CAFFE2_ENABLED ON)
+else()
+  if(NOT Protobuf_FOUND)
+    message(WARNING "Protobuf not found, nnc caffe2 frontend will not be available")
+  endif()
+  if(NOT PytorchSource_FOUND)
+    message(WARNING "PyTorch not found, nnc caffe2 frontend will not be available")
+  endif()
+  set(NNC_FRONTEND_CAFFE2_ENABLED OFF)
+endif()
+
+# Try to get compiled caffe proto and return if not successful
+# Note: this creates a target called "caffeproto" that contains compiled caffe.proto sources,
+#       and after linking with it caffe.pb.h will be available as "caffe/proto/caffe.pb.h"
+nncc_find_package(CaffeProto QUIET)
+if (CaffeProto_FOUND)
+  set(NNC_FRONTEND_CAFFE_ENABLED ON)
+else()
+  message(WARNING "Caffeproto library was not found, nnc caffe frontend will not be available")
+  set(NNC_FRONTEND_CAFFE_ENABLED OFF)
+endif()
+
+# Try to get the compiled onnx proto and return if not successful.
+# Note: this creates a target called "onnxproto" and after linking with it
+#       onnx.pb.h will be available as "onnx/onnx.pb.h"
+set(NNC_FRONTEND_ONNX_ENABLED OFF)
+nncc_find_package(ONNXProto QUIET)
+if (ONNXProto_FOUND)
+  nncc_find_package(ONNXSource)
+  if (${ONNXSource_FOUND})
+    set(NNC_FRONTEND_ONNX_ENABLED ON)
+  endif()
+endif()
+if(NOT NNC_FRONTEND_ONNX_ENABLED)
+  message(WARNING "nnc onnx frontend will not be available")
+endif()
+
+# We need flatbuffer for tflite frontend
+nncc_find_package(FlatBuffers QUIET)
+if (FlatBuffers_FOUND)
+  set(NNC_FRONTEND_TFLITE_ENABLED ON)
+else()
+  message(WARNING "FlatBuffers not found, nnc tflite frontend will not be available")
+  set(NNC_FRONTEND_TFLITE_ENABLED OFF)
+endif()
diff --git a/contrib/nnc/cmake/soft_backend.cmake b/contrib/nnc/cmake/soft_backend.cmake
deleted file mode 100644 (file)
index ccabc07..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-function(make_generated_sources DEF_SOURCES OUT_DIR GEN_SOURCES)
-    set(GEN_OUT "")
-    foreach(file IN LISTS DEF_SOURCES)
-        get_filename_component(file_name ${file} NAME_WE)
-        set(out_file "${OUT_DIR}/${file_name}.generated.h")
-        list(APPEND GEN_OUT "${out_file}")
-        add_custom_command(
-                OUTPUT  ${out_file}
-                COMMAND def2src ${OUT_DIR} ${file}
-                DEPENDS def2src ${file}
-        )
-    endforeach()
-    set(${GEN_SOURCES} ${GEN_OUT} PARENT_SCOPE)
-endfunction(make_generated_sources)
-
diff --git a/contrib/nnc/cmake/utils.cmake b/contrib/nnc/cmake/utils.cmake
new file mode 100644 (file)
index 0000000..bed8593
--- /dev/null
@@ -0,0 +1,57 @@
+# generate sources files by *.def files for soft backend
+function(nnc_make_generated_sources DEF_SOURCES OUT_DIR GEN_SOURCES)
+    set(GEN_OUT "")
+    foreach(file IN LISTS DEF_SOURCES)
+        get_filename_component(file_name ${file} NAME_WE)
+        set(out_file "${OUT_DIR}/${file_name}.generated.h")
+        list(APPEND GEN_OUT "${out_file}")
+        add_custom_command(
+                OUTPUT  ${out_file}
+                COMMAND def2src ${OUT_DIR} ${file}
+                DEPENDS def2src ${file}
+        )
+    endforeach()
+    set(${GEN_SOURCES} ${GEN_OUT} PARENT_SCOPE)
+endfunction()
+
+function(nnc_set_installation_properties TARG)
+  # TODO when we upgrade our cmake to version 3.8 we'll need to use
+  #      BUILD_RPATH variable instead of CMAKE_BUILD_WITH_INSTALL_RPATH here
+
+  # set external RPATHs
+  set_target_properties(${TARG} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+  # use paths from build directoris
+  set_target_properties(${TARG} PROPERTIES CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+  # set RPATH to core part of nnc
+  set_target_properties(${TARG} PROPERTIES INSTALL_RPATH ${NNC_INSTALL_LIB_PATH})
+endfunction()
+
+# install nnc libraries
+function(nnc_install_library LIB)
+  install(TARGETS ${LIB} DESTINATION ${NNC_INSTALL_LIB_PATH})
+  nnc_set_installation_properties(${LIB})
+endfunction()
+
+# install nnc executable
+function(nnc_install_executable BIN)
+  install(TARGETS ${BIN} DESTINATION ${NNC_INSTALL_BIN_PATH})
+  nnc_set_installation_properties(${BIN})
+endfunction()
+
+# add nnc library as target
+function(nnc_add_library)
+  add_library(${ARGV})
+
+  get_target_property(LIBS ${NNC_TARGET_EXECUTABLE} LINK_LIBRARIES)
+  if(LIBS MATCHES NOTFOUND)
+    set(LIBS "")
+  endif()
+  list(APPEND LIBS ${ARGV0})
+  set_target_properties(${NNC_TARGET_EXECUTABLE} PROPERTIES LINK_LIBRARIES "${LIBS}")
+endfunction()
+
+# function to add nnc unit test
+function(nnc_add_unit_test)
+  add_nncc_test(${ARGV})
+  add_dependencies(nnc_unit_tests ${ARGV0})
+endfunction()
index 5936137..12bb9b6 100644 (file)
@@ -31,7 +31,7 @@ if(Protobuf_FOUND)
             modelIR/proto
             model_ir.proto)
 
-    add_nncc_library(model_ir_proto STATIC ${MODEL_IR_PROTO_SOURCES})
+    add_library(model_ir_proto STATIC ${MODEL_IR_PROTO_SOURCES})
     target_link_libraries(model_ir_proto PUBLIC libprotobuf)
     target_include_directories(model_ir_proto PUBLIC ${MODEL_IR_PROTO_INCLUDE_DIRS})
     set_target_properties(model_ir_proto PROPERTIES POSITION_INDEPENDENT_CODE ON)
@@ -40,14 +40,14 @@ if(Protobuf_FOUND)
     set(SERIALIZER_SOURCES "modelIR/Serializer.cpp"
                            "modelIR/Deserializer.cpp")
 
-    add_nncc_library(nnc_core SHARED ${SOURCES} ${SERIALIZER_SOURCES})
+    add_library(nnc_core SHARED ${SOURCES} ${SERIALIZER_SOURCES})
     target_link_libraries(nnc_core PUBLIC model_ir_proto)
 else()
     message(WARNING "Protobuf not found, NNC serialization not available")
-    add_nncc_library(nnc_core SHARED ${SOURCES})
+    add_library(nnc_core SHARED ${SOURCES})
 endif()
 
 set_target_properties(nnc_core PROPERTIES LINKER_LANGUAGE CXX)
 
 # install nnc core library
-install_nnc_library(nnc_core)
+nnc_install_library(nnc_core)
index ee57a3a..28c73fe 100644 (file)
@@ -51,16 +51,16 @@ static std::string getFrontendOptionsString() {
   std::string res;
 
   if (!cli::caffeFrontend.isDisabled())
-    res += " '" + cli::caffeFrontend.getNames()[0] + "' ";
+    res += "'" + cli::caffeFrontend.getNames()[0] + "' ";
 
   if (!cli::caffe2Frontend.isDisabled())
-    res += " '" + cli::caffe2Frontend.getNames()[0] + "' ";
+    res += "'" + cli::caffe2Frontend.getNames()[0] + "' ";
 
   if (!cli::onnxFrontend.isDisabled())
-    res += " '" + cli::onnxFrontend.getNames()[0] + "' ";
+    res += "'" + cli::onnxFrontend.getNames()[0] + "' ";
 
   if (!cli::tflFrontend.isDisabled())
-    res += " '" + cli::tflFrontend.getNames()[0] + "' ";
+    res += "'" + cli::tflFrontend.getNames()[0] + "'";
 
   return res;
 }
@@ -95,9 +95,7 @@ void Driver::registerBackendPass() {
 
   std::unique_ptr<Pass> pass;
 
-  if (cli::target == NNC_TARGET_ARM_CPP) {
-    pass = std::move(std::unique_ptr<Pass>(new CPPCodeGenerator()));
-  } else if (cli::target == NNC_TARGET_X86_CPP) {
+  if (cli::target == NNC_TARGET_ARM_CPP || cli::target == NNC_TARGET_X86_CPP) {
     pass = std::move(std::unique_ptr<Pass>(new CPPCodeGenerator()));
   } else if (cli::target == NNC_TARGET_ARM_GPU_CPP) {
     pass = std::move(std::unique_ptr<Pass>(new AclCppCodeGenerator()));
index 8a5094a..2bd7780 100644 (file)
@@ -1,4 +1,4 @@
 set(PASS_MANAGER_SRC PassManager.cpp)
 
-add_library(nnc_pass STATIC ${PASS_MANAGER_SRC})
+nnc_add_library(nnc_pass STATIC ${PASS_MANAGER_SRC})
 set_target_properties(nnc_pass PROPERTIES LINKER_LANGUAGE CXX)
index 0c93a45..74a46dd 100644 (file)
@@ -8,10 +8,18 @@ add_executable(def2src ${DEF_CONV})
 # FRONTENDs
 #
 add_subdirectory(common_frontend)
-add_subdirectory(tflite_frontend)
-add_subdirectory(caffe_frontend)
-add_subdirectory(onnx_frontend)
-add_subdirectory(caffe2_frontend)
+if(NNC_FRONTEND_TFLITE_ENABLED)
+  add_subdirectory(tflite_frontend)
+endif()
+if(NNC_FRONTEND_CAFFE_ENABLED)
+  add_subdirectory(caffe_frontend)
+endif()
+if(NNC_FRONTEND_ONNX_ENABLED)
+  add_subdirectory(onnx_frontend)
+endif()
+if(NNC_FRONTEND_CAFFE2_ENABLED)
+  add_subdirectory(caffe2_frontend)
+endif()
 
 #
 # BACKENDs
index 1f61d6d..a9691f2 100644 (file)
@@ -2,12 +2,12 @@ set(ACL_SOFT_BACKEND_CPP_SOURCES AclCppGenerator.cpp AclCppOpGenerator.cpp
     ArtifactGeneratorCppCode.cpp ArtifactGeneratorCppDecl.cpp ArtifactModel.cpp)
 
 file(GLOB_RECURSE ACL_IN_SOURCES "*.in")
-make_generated_sources("${ACL_IN_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} ACL_GENERATED_SOURCES)
+nnc_make_generated_sources("${ACL_IN_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} ACL_GENERATED_SOURCES)
 
-add_nnc_library(acl_soft_backend_cpp SHARED ${ACL_SOFT_BACKEND_CPP_SOURCES} ${ACL_GENERATED_SOURCES})
+nnc_add_library(acl_soft_backend_cpp SHARED ${ACL_SOFT_BACKEND_CPP_SOURCES} ${ACL_GENERATED_SOURCES})
 target_include_directories(acl_soft_backend_cpp PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 target_link_libraries(acl_soft_backend_cpp PRIVATE nnc_support)
 target_link_libraries(acl_soft_backend_cpp PRIVATE nnc_core)
 
 # install soft backend c++ library
-install_nnc_library(acl_soft_backend_cpp)
+nnc_install_library(acl_soft_backend_cpp)
index 161ab4f..f4553d9 100644 (file)
@@ -1,7 +1,3 @@
-if (NOT NNC_FRONTEND_CAFFE2_ENABLED)
-  return ()
-endif()
-
 ###################
 # Caffe2 proto    #
 ###################
index ae223bb..18a9942 100644 (file)
@@ -1,10 +1,6 @@
 ###################
 # Caffe importer  #
 ###################
-if (NOT NNC_FRONTEND_CAFFE_ENABLED)
-  return ()
-endif()
-
 file(GLOB caffe_importer_sources *.cpp)
 file(GLOB caffe_importer_headers *.h)
 
index 46fd692..5c25580 100644 (file)
@@ -12,7 +12,7 @@ target_link_libraries(nn_import_common PRIVATE nnc_core nnc_support)
 # This library depends on other frontends to provide uniform interface for those who use frontends
 #
 set(IMPORTER_SOURCES NNImporter.cpp)
-add_nnc_library(nn_importer SHARED ${IMPORTER_SOURCES})
+nnc_add_library(nn_importer SHARED ${IMPORTER_SOURCES})
 target_include_directories(nn_importer PRIVATE
         ${NNC_CAFFE_FRONTEND_DIR}
         ${NNC_CAFFE2_FRONTEND_DIR}
@@ -33,4 +33,4 @@ if (NNC_FRONTEND_ONNX_ENABLED)
 endif()
 
 # install frontend library
-install_nnc_library(nn_importer)
+nnc_install_library(nn_importer)
index 26b1c64..ddc06c9 100644 (file)
@@ -1,5 +1,5 @@
 file(GLOB_RECURSE interp_src ./*.cpp ./*.h)
-add_nnc_library(nnc_interpreter SHARED ${interp_src})
+nnc_add_library(nnc_interpreter SHARED ${interp_src})
 target_link_libraries(nnc_interpreter PRIVATE nnc_core nnc_support)
 
 if(NNC_HDF5_SUPPORTED)
@@ -8,4 +8,4 @@ if(NNC_HDF5_SUPPORTED)
 endif(NNC_HDF5_SUPPORTED)
 
 # install interpreter library
-install_nnc_library(nnc_interpreter)
\ No newline at end of file
+nnc_install_library(nnc_interpreter)
index 6e623c1..b26faf6 100644 (file)
@@ -1,30 +1,19 @@
-if (NOT NNC_FRONTEND_ONNX_ENABLED)
-  return ()
-endif(NOT NNC_FRONTEND_ONNX_ENABLED)
+###################
+# ONNX importer #
+###################
 
-if(TARGET onnxproto)
+file(GLOB onnx_importer_headers *.h)
+file(GLOB onnx_importer_sources *.cpp)
 
-  nncc_find_package(ONNXSource)
-  if (NOT ${ONNXSource_FOUND})
-    return()
-  endif()
-  ###################
-  # ONNX importer #
-  ###################
+add_library(onnx_importer STATIC ${onnx_importer_sources}
+                                 ${onnx_importer_headers})
+set_target_properties(onnx_importer PROPERTIES POSITION_INDEPENDENT_CODE ON)
 
-  file(GLOB onnx_importer_headers *.h)
-  file(GLOB onnx_importer_sources *.cpp)
+target_link_libraries(onnx_importer PUBLIC onnxproto)
+target_link_libraries(onnx_importer PRIVATE nn_import_common)
+target_link_libraries(onnx_importer PRIVATE nnc_support)
+target_link_libraries(onnx_importer PRIVATE nnc_core)
+add_definitions (-DONNX_NAMESPACE=onnx)
 
-  add_library(onnx_importer STATIC ${onnx_importer_sources}
-                                   ${onnx_importer_headers})
-  set_target_properties(onnx_importer PROPERTIES POSITION_INDEPENDENT_CODE ON)
-
-  target_link_libraries(onnx_importer PUBLIC onnxproto)
-  target_link_libraries(onnx_importer PRIVATE nn_import_common)
-  target_link_libraries(onnx_importer PRIVATE nnc_support)
-  target_link_libraries(onnx_importer PRIVATE nnc_core)
-  add_definitions (-DONNX_NAMESPACE=onnx)
-
-  get_target_property(INCLUDE_DIRS onnxproto INCLUDE_DIRECTORIES)
-  target_include_directories(onnx_importer PRIVATE ${INCLUDE_DIRS} ${ONNXSource_DIR})
-endif(TARGET onnxproto)
+get_target_property(INCLUDE_DIRS onnxproto INCLUDE_DIRECTORIES)
+target_include_directories(onnx_importer PRIVATE ${INCLUDE_DIRS} ${ONNXSource_DIR})
index e5c0b6c..2ecc219 100644 (file)
@@ -4,7 +4,7 @@ set(SOFT_BACKEND_C_SOURCES CGenerator.cpp)
 
 file(GLOB_RECURSE SOFT_DEF_SOURCES "*.def")
 
-make_generated_sources("${SOFT_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} SOFT_GENERATED_SOURCES)
+nnc_make_generated_sources("${SOFT_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} SOFT_GENERATED_SOURCES)
 
 add_library(soft_backend_common STATIC ${SOFT_BACKEND_COMMON_SOURCES})
 set_property(TARGET soft_backend_common PROPERTY POSITION_INDEPENDENT_CODE ON)
@@ -13,7 +13,7 @@ target_link_libraries(soft_backend_common PRIVATE nnc_support)
 target_link_libraries(soft_backend_common PRIVATE nnc_core)
 
 function(make_soft_backend NAME)
-    add_nnc_library(${NAME} SHARED ${ARGN} ${SOFT_GENERATED_SOURCES})
+    nnc_add_library(${NAME} SHARED ${ARGN} ${SOFT_GENERATED_SOURCES})
     target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 
     target_link_libraries(${NAME} PRIVATE soft_backend_common)
@@ -21,7 +21,7 @@ function(make_soft_backend NAME)
     target_link_libraries(${NAME} PRIVATE nnc_core)
 
     # install soft backend c++ library
-    install_nnc_library(${NAME})
+    nnc_install_library(${NAME})
 endfunction(make_soft_backend)
 
 make_soft_backend(soft_backend_cpp ${SOFT_BACKEND_CPP_SOURCES})
index d55bba6..6e8b50c 100644 (file)
@@ -1,7 +1,3 @@
-if (NOT NNC_FRONTEND_TFLITE_ENABLED)
-  return ()
-endif()
-
 ###################
 # SCHEMA          #
 ###################
@@ -14,7 +10,7 @@ FlatBuffers_Generate(FB_GEN
                      ${CMAKE_CURRENT_SOURCE_DIR}/schema
                      schema.fbs)
 
-add_nncc_library(tflite_schema STATIC ${FB_GEN_SOURCES})
+add_library(tflite_schema STATIC ${FB_GEN_SOURCES})
 target_link_libraries(tflite_schema PUBLIC flatbuffers)
 target_include_directories(tflite_schema PUBLIC ${FB_GEN_INCLUDE_DIRS})
 
index f4b4188..ccfd8ac 100644 (file)
@@ -3,6 +3,6 @@ set(SUPPORT_SOURCES
         CLOptionChecker.cpp
         ProtobufHelper.cpp)
 
-add_library(nnc_support STATIC ${SUPPORT_SOURCES})
+nnc_add_library(nnc_support STATIC ${SUPPORT_SOURCES})
 set_target_properties(nnc_support PROPERTIES LINKER_LANGUAGE CXX)
 set_target_properties(nnc_support PROPERTIES POSITION_INDEPENDENT_CODE ON)
index cf1667b..9ed636f 100644 (file)
@@ -9,13 +9,13 @@
 # These executables are not executed anywhere because it is not yet decided
 # how to store large files (in this case, files with models), and how to run all system tests.
 # As soon as it is decided, model files should be added, as well as the code that runs the tests.
-if (TARGET tflite_importer)
+if(NNC_FRONTEND_TFLITE_ENABLED)
   add_executable(system_test_import_tflite tflite.cpp ${OPTIONS_SRC})
   target_link_libraries(system_test_import_tflite PRIVATE nnc_support tflite_importer)
   target_include_directories(system_test_import_tflite PRIVATE ${NNC_TFLITE_FRONTEND_DIR})
 endif()
 
-if (TARGET caffe_importer)
+if(NNC_FRONTEND_CAFFE_ENABLED)
   add_executable(system_test_import_caffe caffe.cpp ${OPTIONS_SRC})
   target_link_libraries(system_test_import_caffe PRIVATE nnc_support caffe_importer)
   target_include_directories(system_test_import_caffe PRIVATE ${NNC_CAFFE_FRONTEND_DIR})
index 47783a1..325dcb7 100644 (file)
@@ -1,6 +1,6 @@
 file(GLOB_RECURSE SOFT_TEST_DEF_SOURCES *.def)
 
-make_generated_sources("${SOFT_TEST_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} SOFT_TEST_GENERATED_SOURCES)
+nnc_make_generated_sources("${SOFT_TEST_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} SOFT_TEST_GENERATED_SOURCES)
 
 add_executable(nnc_system_soft_backend_cpp_compile CompileCPP.cpp ${OPTIONS_SRC} ${SOFT_TEST_GENERATED_SOURCES})
 target_link_libraries(nnc_system_soft_backend_cpp_compile PRIVATE nnc_support soft_backend_cpp nnc_core)
index 26c9415..7d61e4e 100644 (file)
@@ -1,22 +1,18 @@
 # Dummy target to build all nnc unit tests
-if(ENABLE_TEST)
-  add_custom_target(nnc_unit_tests)
-  add_custom_target(nnc_check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS nnc_unit_tests)
-endif()
-
-# function to add nnc unit test
-function(add_nnc_unit_test)
-  if(ENABLE_TEST)
-    add_nncc_test(${ARGV})
-    add_dependencies(nnc_unit_tests ${ARGV0})
-  endif()
-endfunction()
+add_custom_target(nnc_unit_tests)
+add_custom_target(nnc_check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS nnc_unit_tests)
 
 add_subdirectory(pass)
 add_subdirectory(core)
 add_subdirectory(soft_backend)
 add_subdirectory(acl_backend)
 add_subdirectory(support)
-add_subdirectory(caffe_frontend)
-add_subdirectory(caffe2_frontend)
-add_subdirectory(tflite_frontend)
+if(NNC_FRONTEND_CAFFE_ENABLED)
+  add_subdirectory(caffe_frontend)
+endif()
+if(NNC_FRONTEND_CAFFE2_ENABLED)
+  add_subdirectory(caffe2_frontend)
+endif()
+if(NNC_FRONTEND_TFLITE_ENABLED)
+  add_subdirectory(tflite_frontend)
+endif()
index 012ae37..32435f0 100644 (file)
@@ -1,11 +1,9 @@
 set(ACL_CPP_BACKEND_UTEST_SOURCES DOMToText.cpp MIRToDOM.cpp)
 
 file(GLOB_RECURSE ACL_IN_SOURCES "${NNC_ACL_BACKEND_DIR}/*.in")
-make_generated_sources("${ACL_IN_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} ACL_GENERATED_SOURCES)
+nnc_make_generated_sources("${ACL_IN_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} ACL_GENERATED_SOURCES)
 
-add_nnc_unit_test(nnc_acl_cpp_backend_test ${ACL_CPP_BACKEND_UTEST_SOURCES} ${OPTIONS_SRC} ${ACL_GENERATED_SOURCES})
+nnc_add_unit_test(nnc_acl_cpp_backend_test ${ACL_CPP_BACKEND_UTEST_SOURCES} ${OPTIONS_SRC} ${ACL_GENERATED_SOURCES})
 
-if (TARGET nnc_acl_cpp_backend_test)
-    nncc_target_link_libraries(nnc_acl_cpp_backend_test nnc_core nnc_support acl_soft_backend_cpp)
-    target_include_directories(nnc_acl_cpp_backend_test PRIVATE ${NNC_ACL_BACKEND_DIR} ${CMAKE_CURRENT_BINARY_DIR})
-endif()
+nncc_target_link_libraries(nnc_acl_cpp_backend_test nnc_core nnc_support acl_soft_backend_cpp)
+target_include_directories(nnc_acl_cpp_backend_test PRIVATE ${NNC_ACL_BACKEND_DIR} ${CMAKE_CURRENT_BINARY_DIR})
index 488a9f7..4261ba9 100644 (file)
@@ -7,11 +7,9 @@ execute_process(
         RESULT_VARIABLE test_create_failed
 )
 
-if (NNC_FRONTEND_CAFFE2_ENABLED AND NOT ${test_create_failed})
+if (NOT ${test_create_failed})
   add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}")
-  add_nnc_unit_test(nnc_caffe2_frontend_test ${TESTS} ${OPTIONS_SRC})
-  if (TARGET nnc_caffe2_frontend_test)
-    nncc_target_link_libraries(nnc_caffe2_frontend_test caffe2_importer nnc_support nnc_core)
-    target_include_directories(nnc_caffe2_frontend_test PRIVATE ${NNC_CAFFE2_FRONTEND_DIR})
-  endif()
+  nnc_add_unit_test(nnc_caffe2_frontend_test ${TESTS} ${OPTIONS_SRC})
+  nncc_target_link_libraries(nnc_caffe2_frontend_test caffe2_importer nnc_support nnc_core)
+  target_include_directories(nnc_caffe2_frontend_test PRIVATE ${NNC_CAFFE2_FRONTEND_DIR})
 endif()
index f70eec2..c73f0b0 100644 (file)
@@ -1,10 +1,6 @@
 file(GLOB_RECURSE TESTS "*.cpp")
 
-if (NNC_FRONTEND_CAFFE_ENABLED)
-  add_definitions(-DTEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test_data/")
-  add_nnc_unit_test(nnc_caffe_frontend_test ${TESTS} ${OPTIONS_SRC})
-  if (TARGET nnc_caffe_frontend_test)
-    nncc_target_link_libraries(nnc_caffe_frontend_test caffe_importer nnc_support nnc_core)
-    target_include_directories(nnc_caffe_frontend_test PRIVATE ${NNC_CAFFE_FRONTEND_DIR})
-  endif()
-endif()
+add_definitions(-DTEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test_data/")
+nnc_add_unit_test(nnc_caffe_frontend_test ${TESTS} ${OPTIONS_SRC})
+nncc_target_link_libraries(nnc_caffe_frontend_test caffe_importer nnc_support nnc_core)
+target_include_directories(nnc_caffe_frontend_test PRIVATE ${NNC_CAFFE_FRONTEND_DIR})
index d2e786b..9d37231 100644 (file)
@@ -10,11 +10,9 @@ nncc_find_package(Protobuf QUIET)
 if(Protobuf_FOUND)
   set(SERIALIZER_TESTS "serializer.cpp"
                        "deserializer.cpp")
-  add_nnc_unit_test(nnc_core_test ${TESTS} ${SERIALIZER_TESTS})
+  nnc_add_unit_test(nnc_core_test ${TESTS} ${SERIALIZER_TESTS})
 else()
-  add_nnc_unit_test(nnc_core_test ${TESTS})
+  nnc_add_unit_test(nnc_core_test ${TESTS})
 endif()
 
-if (TARGET nnc_core_test)
-  nncc_target_link_libraries(nnc_core_test nnc_core)
-endif()
+nncc_target_link_libraries(nnc_core_test nnc_core)
index 5f75d53..efecc93 100644 (file)
@@ -1,6 +1,4 @@
 file(GLOB_RECURSE TEST_SOURCES "*.cpp")
 
-add_nnc_unit_test(nnc_pass_test ${TEST_SOURCES} ${OPTIONS_SRC})
-if (TARGET nnc_pass_test)
-  nncc_target_link_libraries(nnc_pass_test nnc_support nnc_core)
-endif()
+nnc_add_unit_test(nnc_pass_test ${TEST_SOURCES} ${OPTIONS_SRC})
+nncc_target_link_libraries(nnc_pass_test nnc_support nnc_core)
index dc42081..4956597 100644 (file)
@@ -1,20 +1,16 @@
 file(GLOB_RECURSE CPU_CPP_DEF_SOURCES "${NNC_SOFT_BACKEND_DIR}/*.def")
-make_generated_sources("${CPU_CPP_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} CPU_CPP_GENERATED_SOURCES)
+nnc_make_generated_sources("${CPU_CPP_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} CPU_CPP_GENERATED_SOURCES)
 
 set(CPU_CPP_BACKEND_OP_SOURCES CPPOperations.cpp)
 set(CPU_CPP_BACKEND_GN_SOURCES ${NNC_SOFT_BACKEND_DIR}/CPPGenerator.cpp Generator.cpp ${CPU_CPP_GENERATED_SOURCES})
 set(CPU_CPP_BACKEND_MA_SOURCES ModelAnalyzer.cpp)
 set(CPU_CPP_BACKEND_HT_SOURCES CPPHeaderTypes.cpp)
 
-add_nnc_unit_test(nnc_cpu_cpp_backend_ops_test ${CPU_CPP_BACKEND_OP_SOURCES} ${CPU_BACKEND_CPP_OP_SOURCES} ${OPTIONS_SRC} ${SOFT_DEF_SOURCES})
-if (TARGET nnc_cpu_cpp_backend_ops_test)
-  nncc_target_link_libraries(nnc_cpu_cpp_backend_ops_test nnc_support nnc_interpreter nnc_core soft_backend_common)
-  target_include_directories(nnc_cpu_cpp_backend_ops_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${NNC_SOFT_BACKEND_DIR})
-endif()
+nnc_add_unit_test(nnc_cpu_cpp_backend_ops_test ${CPU_CPP_BACKEND_OP_SOURCES} ${CPU_BACKEND_CPP_OP_SOURCES} ${OPTIONS_SRC} ${SOFT_DEF_SOURCES})
+nncc_target_link_libraries(nnc_cpu_cpp_backend_ops_test nnc_support nnc_interpreter nnc_core soft_backend_common)
+target_include_directories(nnc_cpu_cpp_backend_ops_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${NNC_SOFT_BACKEND_DIR})
 
-add_nnc_unit_test(nnc_cpu_cpp_backend_general_test ${CPU_CPP_BACKEND_GN_SOURCES} ${CPU_CPP_BACKEND_HT_SOURCES}
+nnc_add_unit_test(nnc_cpu_cpp_backend_general_test ${CPU_CPP_BACKEND_GN_SOURCES} ${CPU_CPP_BACKEND_HT_SOURCES}
                   ${CPU_CPP_BACKEND_MA_SOURCES} ${OPTIONS_SRC} ${SOFT_DEF_SOURCES})
-if (TARGET nnc_cpu_cpp_backend_general_test)
-  nncc_target_link_libraries(nnc_cpu_cpp_backend_general_test nnc_support nnc_core soft_backend_common)
-  target_include_directories(nnc_cpu_cpp_backend_general_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${NNC_SOFT_BACKEND_DIR})
-endif()
+nncc_target_link_libraries(nnc_cpu_cpp_backend_general_test nnc_support nnc_core soft_backend_common)
+target_include_directories(nnc_cpu_cpp_backend_general_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${NNC_SOFT_BACKEND_DIR})
index 020dcfd..d236159 100644 (file)
@@ -1,4 +1,4 @@
 set(CL_SOURCES ${NNC_SUPPORT_DIR}/CommandLine.cpp)
 set(CL_TESTS CommandLineTest.cpp)
 
-add_nnc_unit_test(nnc_support_commandline_test ${CL_TESTS} ${CL_SOURCES})
+nnc_add_unit_test(nnc_support_commandline_test ${CL_TESTS} ${CL_SOURCES})
index c0f4b61..dc3db15 100644 (file)
@@ -8,11 +8,9 @@ execute_process(
         RESULT_VARIABLE test_create_failed
 )
 
-if (NNC_FRONTEND_TFLITE_ENABLED AND NOT ${test_create_failed})
+if (NOT ${test_create_failed})
   add_definitions(-DTFLITE_TEST_DIR="${CMAKE_CURRENT_BINARY_DIR}/")
-  add_nnc_unit_test(nnc_tflite_frontend_test ${TESTS} ${OPTIONS_SRC})
-  if (TARGET nnc_tflite_frontend_test)
-    nncc_target_link_libraries(nnc_tflite_frontend_test tflite_importer nnc_support nnc_core )
-    target_include_directories(nnc_tflite_frontend_test PRIVATE ${NNC_TFLITE_FRONTEND_DIR})
-  endif()
+  nnc_add_unit_test(nnc_tflite_frontend_test ${TESTS} ${OPTIONS_SRC})
+  nncc_target_link_libraries(nnc_tflite_frontend_test tflite_importer nnc_support nnc_core )
+  target_include_directories(nnc_tflite_frontend_test PRIVATE ${NNC_TFLITE_FRONTEND_DIR})
 endif()