diff options
Diffstat (limited to 'infra/nncc')
85 files changed, 2398 insertions, 0 deletions
diff --git a/infra/nncc/3rdparty/.gitignore b/infra/nncc/3rdparty/.gitignore new file mode 100644 index 000000000..c3d773e35 --- /dev/null +++ b/infra/nncc/3rdparty/.gitignore @@ -0,0 +1 @@ +URL.local diff --git a/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.default b/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.default new file mode 100644 index 000000000..1fff1b4f3 --- /dev/null +++ b/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.default @@ -0,0 +1 @@ +https://bitbucket.org/eigen/eigen/get/fd6845384b86.tar.gz diff --git a/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.info b/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.info new file mode 100644 index 000000000..8e7a3c2f0 --- /dev/null +++ b/infra/nncc/3rdparty/Eigen/fd6845384b86/URL.info @@ -0,0 +1,3 @@ +This URL originates from TensorFlow 1.12 + +Please check https://github.com/tensorflow/tensorflow/blob/v1.12.0/tensorflow/workspace.bzl#L121 diff --git a/infra/nncc/CMakeLists.txt b/infra/nncc/CMakeLists.txt new file mode 100644 index 000000000..12b840636 --- /dev/null +++ b/infra/nncc/CMakeLists.txt @@ -0,0 +1,144 @@ +cmake_minimum_required(VERSION 3.1) + +project(nncc) + +enable_testing() + +set(CMAKE_CXX_STANDARD 11) + +# This feature works with CMake 3.5.2 or later. However, using previous versions does not produce +# an error. We are still officially using CMake 3.1.0, but put this code for the sake of semantic +# support in various development tools. +# Todo: Someday, CMake needs to be updated to 3.7.2 or later to take advantage of improvements +# such as `cmake-server`. +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(NNCC_PROJECT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." CACHE + INTERNAL "Where to find nncc top-level source directory" +) + +set(NNCC_EXTERNALS_DIR + "${NNCC_PROJECT_SOURCE_DIR}/externals" CACHE + INTERNAL "Where to download external dependencies" +) +set(NNCC_OVERLAY_DIR "${CMAKE_BINARY_DIR}/overlay" CACHE + INTERNAL "Where locally built external dependencies are installed") + +# This allows find_package to access configurations installed inside overlay +list(APPEND CMAKE_PREFIX_PATH "${NNCC_OVERLAY_DIR}") + +macro(nncc_include PREFIX) + include("${NNCC_PROJECT_SOURCE_DIR}/infra/nncc/cmake/modules/${PREFIX}.cmake") +endmacro(nncc_include) + +macro(nncc_find_package PREFIX) + find_package(${PREFIX} CONFIG NO_DEFAULT_PATH + PATHS ${NNCC_PROJECT_SOURCE_DIR}/infra/nncc/cmake/packages + ${ARGN} + ) +endmacro(nncc_find_package) + +# nncc_find_resource(NAME) will update the following variables +# +# NAME_FOUND +# NAME_DIR +# +# TODO Explain how to add a resource in README.md +function(nncc_find_resource NAME) + set(RESOURCE_DIR "${NNCC_PROJECT_SOURCE_DIR}/res/${NAME}") + + if(NOT IS_DIRECTORY ${RESOURCE_DIR}) + set(${NAME}_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT IS_DIRECTORY ${RESOURCE_DIR}) + + set(${NAME}_DIR ${RESOURCE_DIR} PARENT_SCOPE) + set(${NAME}_FOUND TRUE PARENT_SCOPE) +endfunction(nncc_find_resource) + +### +### CMake configuration +### +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Type of build" FORCE) +endif(NOT CMAKE_BUILD_TYPE) +message(STATUS "Use '${CMAKE_BUILD_TYPE}' configuration") + +# Prefer -pthread to -lpthread for find_package(Threads ...) +# +# std::thread code compiled only with -lpthread emits the following runtime error (on GCC 4.8.4) +# +# terminate called after throwing an instance of 'std::system_error' +# what(): Enable multithreading to use std::thread: Operation not permitted +# +set(THREADS_PREFER_PTHREAD_FLAG TRUE) + +### +### Configuration +### +option(DOWNLOAD_PROTOBUF "Download Protocol Buffer source" ON) +option(BUILD_PROTOBUF "Locally build Protocol Buffer from the downloaded source" ON) +option(DOWNLOAD_EIGEN "Download Eigen source" ON) +option(DOWNLOAD_FARMHASH "Download farmhash source" ON) +option(DOWNLOAD_GEMMLOWP "Download GEMM low precesion library source" ON) +option(DOWNLOAD_NEON2SSE "Download NEON2SSE library source" ON) +option(DOWNLOAD_GFLAGS "Download GFlags source" OFF) +option(DOWNLOAD_FLATBUFFERS "Download FlatBuffers source" ON) +option(BUILD_FLATBUFFERS "Locally build Flatbuffers from the downloaded source" ON) +option(DOWNLOAD_TENSORFLOW "Download TensorFlow source" ON) +option(DOWNLOAD_CAFFE "Download Caffe source" ON) +option(DOWNLOAD_PYTORCH "Download Pytorch source" ON) +option(DOWNLOAD_ONNX "Download ONNX source" ON) +option(DOWNLOAD_ABSEIL "Download Abseil-cpp source" ON) + +option(DOWNLOAD_GTEST "Download Google Test source" ON) +option(BUILD_GTEST "Build Google Test from the downloaded source" ON) + +nncc_find_package(GTest QUIET) + +option(ENABLE_TEST "Build Tests using Google Test" ${GTest_FOUND}) + +if(${ENABLE_TEST} AND NOT ${GTest_FOUND}) + message(FATAL_ERROR "Google Test is required to enable test") +endif(${ENABLE_TEST} AND NOT ${GTest_FOUND}) + +option(ENABLE_COVERAGE "Build for coverage test" OFF) +if(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST}) + message(FATAL_ERROR "Test should be enabled to measure test coverage") +endif(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST}) + +if(${ENABLE_TEST}) + include(CTest) +endif(${ENABLE_TEST}) + +option(ENABLE_CONTRIB_BUILD "Build incubating projects under contrib/" ON) +option(ENABLE_STRICT_BUILD "Treat warning as error" OFF) + +### +### Target +### +add_library(nncc_common INTERFACE) +if(ENABLE_STRICT_BUILD) + # TODO Remove -Wno-reoder + target_compile_options(nncc_common INTERFACE -Werror -Wall -Wextra -Wno-reorder) +endif(ENABLE_STRICT_BUILD) + +add_library(nncc_coverage INTERFACE) +if(ENABLE_COVERAGE) + target_compile_options(nncc_coverage INTERFACE -g -O0 -fprofile-arcs -ftest-coverage) + target_link_libraries(nncc_coverage INTERFACE gcov) +endif(ENABLE_COVERAGE) + +### +### Function +### +# TODO Remove this nncc_include +nncc_include(OptionalTargetTools) +nncc_include(add_subdirectories) + +### +### Components +### +if(ENABLE_CONTRIB_BUILD) + add_subdirectory("${NNCC_PROJECT_SOURCE_DIR}/compiler" "${CMAKE_BINARY_DIR}/compiler") +endif(ENABLE_CONTRIB_BUILD) diff --git a/infra/nncc/cmake/modules/Asserts.cmake b/infra/nncc/cmake/modules/Asserts.cmake new file mode 100644 index 000000000..e40097e31 --- /dev/null +++ b/infra/nncc/cmake/modules/Asserts.cmake @@ -0,0 +1,8 @@ +# AssertTarget(t) stops the build if target "t" does not exist. +function(AssertTarget TGT) + if(TARGET ${TGT}) + return() + endif(TARGET ${TGT}) + + message(FATAL_ERROR "${TGT} target does not exist") +endfunction(AssertTarget TGT) diff --git a/infra/nncc/cmake/modules/ExternalProjectTools.cmake b/infra/nncc/cmake/modules/ExternalProjectTools.cmake new file mode 100644 index 000000000..11446c051 --- /dev/null +++ b/infra/nncc/cmake/modules/ExternalProjectTools.cmake @@ -0,0 +1,3 @@ +macro(add_extdirectory DIR TAG) + add_subdirectory(${DIR} "${CMAKE_BINARY_DIR}/externals/${TAG}") +endmacro(add_extdirectory) diff --git a/infra/nncc/cmake/modules/ExternalSourceTools.cmake b/infra/nncc/cmake/modules/ExternalSourceTools.cmake new file mode 100644 index 000000000..3baaeba8e --- /dev/null +++ b/infra/nncc/cmake/modules/ExternalSourceTools.cmake @@ -0,0 +1,97 @@ +# +# ExternalSource_Download(VAR ...) +# +function(ExternalSource_Download PREFIX) + include(CMakeParseArguments) + nncc_include(StampTools) + + cmake_parse_arguments(ARG "" "DIRNAME;URL;CHECKSUM" "" ${ARGN}) + + # Configure URL + if(ARG_URL) + set(URL ${ARG_URL}) + else() + # Use the first unparsed argument as URL (for backward compatibility) + list(GET ARG_UNPARSED_ARGUMENTS 0 URL) + endif(ARG_URL) + + # Configure DIRNAME + if(NOT ARG_DIRNAME) + # Use PREFIX as DIRNAME (for backward compatibility) + set(DIRNAME ${PREFIX}) + else() + set(DIRNAME ${ARG_DIRNAME}) + endif(NOT ARG_DIRNAME) + + get_filename_component(FILENAME ${URL} NAME) + + set(CACHE_DIR "${NNCC_EXTERNALS_DIR}") + set(OUT_DIR "${CACHE_DIR}/${DIRNAME}") + set(TMP_DIR "${CACHE_DIR}/${DIRNAME}-tmp") + + set(DOWNLOAD_PATH "${CACHE_DIR}/${DIRNAME}-${FILENAME}") + set(STAMP_PATH "${CACHE_DIR}/${DIRNAME}.stamp") + + if(NOT EXISTS "${CACHE_DIR}") + file(MAKE_DIRECTORY "${CACHE_DIR}") + endif(NOT EXISTS "${CACHE_DIR}") + + # Compare URL in STAMP file and the given URL + Stamp_Check(URL_CHECK "${STAMP_PATH}" "${URL}") + + if(NOT URL_CHECK) + file(REMOVE "${STAMP_PATH}") + file(REMOVE_RECURSE "${OUT_DIR}") + file(REMOVE_RECURSE "${TMP_DIR}") + + file(MAKE_DIRECTORY "${TMP_DIR}") + + message("-- Download ${PREFIX} from ${URL}") + file(DOWNLOAD ${URL} "${DOWNLOAD_PATH}" SHOW_PROGRESS) + message("-- Download ${PREFIX} from ${URL} - done") + + # Verify checksum + if(ARG_CHECKSUM) + message(STATUS "Verify ${PREFIX} archive") + string(REPLACE "=" ";" CHECKSUM_SPEC "${ARG_CHECKSUM}") + + list(GET CHECKSUM_SPEC 0 CHECKSUM_ALG) + list(GET CHECKSUM_SPEC 1 CHECKSUM_VAL) + string(STRIP "${CHECKSUM_VAL}" CHECKSUM_VAL) + + set(EXPECTED_CHECKSUM ${CHECKSUM_VAL}) + file(${CHECKSUM_ALG} "${DOWNLOAD_PATH}" OBTAINED_CHECKSUM) + + if(NOT (EXPECTED_CHECKSUM STREQUAL OBTAINED_CHECKSUM)) + message(STATUS "CHECKSUM MISMATCH") + message(STATUS " expected: ${EXPECTED_CHECKSUM}") + message(STATUS " obtained: ${OBTAINED_CHECKSUM}") + message(FATAL_ERROR "Verify ${PREFIX} archive - fail") + endif(NOT (EXPECTED_CHECKSUM STREQUAL OBTAINED_CHECKSUM)) + + message(STATUS "Verify ${PREFIX} archive - done") + endif(ARG_CHECKSUM) + + message("-- Extract ${PREFIX}") + execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${DOWNLOAD_PATH}" + WORKING_DIRECTORY "${TMP_DIR}") + file(REMOVE "${DOWNLOAD_PATH}") + message("-- Extract ${PREFIX} - done") + + message("-- Cleanup ${PREFIX}") + file(GLOB contents "${TMP_DIR}/*") + list(LENGTH contents n) + if(NOT n EQUAL 1 OR NOT IS_DIRECTORY "${contents}") + set(contents "${TMP_DIR}") + endif() + + get_filename_component(contents ${contents} ABSOLUTE) + + file(RENAME ${contents} "${OUT_DIR}") + file(REMOVE_RECURSE "${TMP_DIR}") + file(WRITE "${STAMP_PATH}" "${URL}") + message("-- Cleanup ${PREFIX} - done") + endif() + + set(${PREFIX}_SOURCE_DIR "${OUT_DIR}" PARENT_SCOPE) +endfunction(ExternalSource_Download) diff --git a/infra/nncc/cmake/modules/ListFile.cmake b/infra/nncc/cmake/modules/ListFile.cmake new file mode 100644 index 000000000..aee0d162a --- /dev/null +++ b/infra/nncc/cmake/modules/ListFile.cmake @@ -0,0 +1,12 @@ +# Read a file and create a list variable +# +# HOW TO USE +# +# ListFile_Read("A.txt" A_LIST) +# +function(ListFile_Read FILENAME VARNAME) + file(READ ${FILENAME} content) + # Reference: http://public.kitware.com/pipermail/cmake/2007-May/014236.html + STRING(REGEX REPLACE "\n" ";" content "${content}") + set(${VARNAME} ${content} PARENT_SCOPE) +endfunction(ListFile_Read) diff --git a/infra/nncc/cmake/modules/OptionTools.cmake b/infra/nncc/cmake/modules/OptionTools.cmake new file mode 100644 index 000000000..0ca50f7c3 --- /dev/null +++ b/infra/nncc/cmake/modules/OptionTools.cmake @@ -0,0 +1,9 @@ +function(envoption PREFIX DEFAULT_VALUE) + set(VALUE ${DEFAULT_VALUE}) + + if(DEFINED ENV{${PREFIX}}) + set(VALUE $ENV{${PREFIX}}) + endif() + + set(${PREFIX} ${VALUE} PARENT_SCOPE) +endfunction(envoption) diff --git a/infra/nncc/cmake/modules/OptionalTargetTools.cmake b/infra/nncc/cmake/modules/OptionalTargetTools.cmake new file mode 100644 index 000000000..8bf2c37ef --- /dev/null +++ b/infra/nncc/cmake/modules/OptionalTargetTools.cmake @@ -0,0 +1,5 @@ +macro(optional_target_link_libraries NAME) + if(TARGET ${NAME}) + target_link_libraries(${NAME} ${ARGN}) + endif(TARGET ${NAME}) +endmacro(optional_target_link_libraries) diff --git a/infra/nncc/cmake/modules/StampTools.cmake b/infra/nncc/cmake/modules/StampTools.cmake new file mode 100644 index 000000000..d38e033ff --- /dev/null +++ b/infra/nncc/cmake/modules/StampTools.cmake @@ -0,0 +1,18 @@ +# Stamp_Check(VARNAME PATH CONTENT) +# Stamp_Check sets VARNAME as TRUE if a file exists at "PATH", and its content is same as "CONTENT" +# Stamp_Check sets VARNAME as FALSE otherwise +function(Stamp_Check VARNAME PATH EXPECTED_CONTENT) + if(NOT EXISTS "${PATH}") + set(${VARNAME} FALSE PARENT_SCOPE) + return() + endif(NOT EXISTS "${PATH}") + + file(READ ${PATH} OBTAINED_CONTENT) + + if(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT) + set(${VARNAME} FALSE PARENT_SCOPE) + return() + endif(NOT EXPECTED_CONTENT STREQUAL OBTAINED_CONTENT) + + set(${VARNAME} TRUE PARENT_SCOPE) +endfunction(Stamp_Check) diff --git a/infra/nncc/cmake/modules/TargetRequire.cmake b/infra/nncc/cmake/modules/TargetRequire.cmake new file mode 100644 index 000000000..801600dd9 --- /dev/null +++ b/infra/nncc/cmake/modules/TargetRequire.cmake @@ -0,0 +1,45 @@ +# TargetRequire_Check(NAME t1 t2 t3 ...) +# +# TargetRequire_Check(NAME ...) sets "NAME" as TRUE if all the required targets are +# available, and FALSE otherwise. +function(TargetRequire_Check VARNAME) + set(${VARNAME} TRUE PARENT_SCOPE) + foreach(REQUIRED_TARGET IN ITEMS ${ARGN}) + if(NOT TARGET ${REQUIRED_TARGET}) + set(${VARNAME} FALSE PARENT_SCOPE) + return() + endif(NOT TARGET ${REQUIRED_TARGET}) + endforeach(REQUIRED_TARGET) +endfunction(TargetRequire_Check) + +# TargetRequire_Assert(t1 t2 t3 ...) +# +# TargetRequire_Assert(...) stops CMake immediately if there is a target required but unavailable. +function(TargetRequire_Assert) + unset(MISSING_TARGETS) + + foreach(REQUIRED_TARGET IN ITEMS ${ARGN}) + if(NOT TARGET ${REQUIRED_TARGET}) + list(APPEND MISSING_TARGETS ${REQUIRED_TARGET}) + endif(NOT TARGET ${REQUIRED_TARGET}) + endforeach(REQUIRED_TARGET) + + list(LENGTH MISSING_TARGETS MISSING_COUNT) + + if(NOT MISSING_COUNT EQUAL 0) + message(FATAL_ERROR "${MISSING_TARGETS} are required, but unavailable") + endif(NOT MISSING_COUNT EQUAL 0) +endfunction(TargetRequire_Assert) + +# TargetRequire_Return(t1 t2 t3 ...) +# +# TargetRequire_Return(...) returns immediately if there is a target required but unavailable. +# +# NOTE "macro" is inevitable to make "return" inside affect the caller. +macro(TargetRequire_Return) + foreach(REQUIRED_TARGET IN ITEMS ${ARGN}) + if(NOT TARGET ${REQUIRED_TARGET}) + return() + endif(NOT TARGET ${REQUIRED_TARGET}) + endforeach(REQUIRED_TARGET) +endmacro(TargetRequire_Return) diff --git a/infra/nncc/cmake/modules/ThirdPartyTools.cmake b/infra/nncc/cmake/modules/ThirdPartyTools.cmake new file mode 100644 index 000000000..8fbeacf6e --- /dev/null +++ b/infra/nncc/cmake/modules/ThirdPartyTools.cmake @@ -0,0 +1,42 @@ +function(ThirdParty_URL VARNAME) + # PACKAGE (mandatory) + # VERSION (mandatory) + # ENV ... (optional, for backward compatibility) + + include(CMakeParseArguments) + + cmake_parse_arguments(ARG "" "PACKAGE;VERSION;ENV" "" ${ARGN}) + + if(NOT ARG_PACKAGE) + message(FATAL_ERROR "PACKAGE is missing") + endif(NOT ARG_PACKAGE) + + if(NOT ARG_VERSION) + message(FATAL_ERROR "VERSION is missing") + endif(NOT ARG_VERSION) + + set(PACKAGE_INFO_DIR "${NNCC_PROJECT_SOURCE_DIR}/infra/nncc/3rdparty/${ARG_PACKAGE}/${ARG_VERSION}") + set(PACKAGE_URL_FILE "${PACKAGE_INFO_DIR}/URL.default") + set(PACKAGE_URL_LOCAL_FILE "${PACKAGE_INFO_DIR}/URL.local") + + if(NOT EXISTS "${PACKAGE_URL_FILE}") + message(FATAL_ERROR "URL file does not exist") + endif() + + # Read URL from "[PACKAGE NAME]/[PACKAGE VERSION]/URL.default" + file(STRINGS "${PACKAGE_URL_FILE}" VALUE) + + # Read URL from "[PACKAGE NAME]/[PACAKGE VERSION]/URL.local" (if it exists) + if(EXISTS "${PACKAGE_URL_LOCAL_FILE}") + file(STRINGS "${PACKAGE_URL_LOCAL_FILE}" VALUE) + endif() + + # Read URL from process environment (if ENV option is specified) + if(ARG_ENV) + if(DEFINED ENV{${ARG_ENV}}) + set(VALUE $ENV{${ARG_ENV}}) + endif() + endif(ARG_ENV) + + set("${VARNAME}" "${VALUE}" PARENT_SCOPE) +endfunction(ThirdParty_URL) diff --git a/infra/nncc/cmake/modules/add_subdirectories.cmake b/infra/nncc/cmake/modules/add_subdirectories.cmake new file mode 100644 index 000000000..06b7c768d --- /dev/null +++ b/infra/nncc/cmake/modules/add_subdirectories.cmake @@ -0,0 +1,27 @@ +function(list_subdirectories OUTPUT_VARIABLE) + cmake_parse_arguments(ARG "" "" "EXCLUDES" ${ARGN}) + + file(GLOB PROJECT_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "*/CMakeLists.txt") + + foreach(PROJECT_FILE IN ITEMS ${PROJECT_FILES}) + get_filename_component(PROJECT_DIR ${PROJECT_FILE} DIRECTORY) + list(FIND ARG_EXCLUDES ${PROJECT_DIR} PROJECT_INDEX) + if(${PROJECT_INDEX} EQUAL -1) + list(APPEND PROJECT_LIST ${PROJECT_DIR}) + endif(${PROJECT_INDEX} EQUAL -1) + endforeach(PROJECT_FILE) + + set(${OUTPUT_VARIABLE} ${PROJECT_LIST} PARENT_SCOPE) +endfunction(list_subdirectories) + +function(add_subdirectories) + cmake_parse_arguments(ARG "" "" "EXCLUDES" ${ARGN}) + + list_subdirectories(PROJECT_DIRS EXCLUDES ${ARG_EXCLUDES}) + + foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS}) + add_subdirectory(${PROJECT_DIR}) + endforeach(PROJECT_DIR) +endfunction(add_subdirectories) diff --git a/infra/nncc/cmake/packages/AbseilConfig.cmake b/infra/nncc/cmake/packages/AbseilConfig.cmake new file mode 100644 index 000000000..4c731008a --- /dev/null +++ b/infra/nncc/cmake/packages/AbseilConfig.cmake @@ -0,0 +1,37 @@ +function(_Abseil_import) + nncc_find_package(AbseilSource QUIET) + + if(NOT AbseilSource_FOUND) + message("Abseil: NOT FOUND (Cannot access source)") + set(Abseil_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT AbseilSource_FOUND) + + if(NOT TARGET abseil) + nncc_include(ExternalProjectTools) + + # NOTE Turn off abseil testing + set(BUILD_TESTING OFF) + add_extdirectory("${AbseilSource_DIR}" ABSEIL) + + add_library(abseil INTERFACE) + target_link_libraries(abseil INTERFACE + # From "Available Abseil CMake Public Targets" in CMake/README.md + absl::base + absl::algorithm + absl::container + absl::debugging + absl::memory + absl::meta + absl::numeric + absl::strings + absl::synchronization + absl::time + absl::utility + ) + endif(NOT TARGET abseil) + + set(Abseil_FOUND TRUE PARENT_SCOPE) +endfunction(_Abseil_import) + +_Abseil_import() diff --git a/infra/nncc/cmake/packages/AbseilSourceConfig.cmake b/infra/nncc/cmake/packages/AbseilSourceConfig.cmake new file mode 100644 index 000000000..d980ac653 --- /dev/null +++ b/infra/nncc/cmake/packages/AbseilSourceConfig.cmake @@ -0,0 +1,24 @@ +function(_AbseilSource_import) + if(NOT DOWNLOAD_ABSEIL) + set(AbseilSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_ABSEIL) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # NOTE TensorFlow 1.12 downloads abseil from the following URL + # - https://github.com/abseil/abseil-cpp/archive/48cd2c3f351ff188bc85684b84a91b6e6d17d896.tar.gz + # + # The last change of "48cd2c3f351" was commited on 2018.09.27 + # + # Let's use the latest released version (2018-12 release) + envoption(ABSEIL_URL https://github.com/abseil/abseil-cpp/archive/20181200.tar.gz) + + ExternalSource_Download(ABSEIL ${ABSEIL_URL}) + + set(AbseilSource_DIR ${ABSEIL_SOURCE_DIR} PARENT_SCOPE) + set(AbseilSource_FOUND TRUE PARENT_SCOPE) +endfunction(_AbseilSource_import) + +_AbseilSource_import() diff --git a/infra/nncc/cmake/packages/Caffe/CMakeLists.txt b/infra/nncc/cmake/packages/Caffe/CMakeLists.txt new file mode 100644 index 000000000..51b723edd --- /dev/null +++ b/infra/nncc/cmake/packages/Caffe/CMakeLists.txt @@ -0,0 +1,15 @@ +file(GLOB CORE_SOURCES "${CaffeSource_DIR}/src/caffe/*.cpp" "${CaffeSource_DIR}/src/caffe/util/*.cpp") +file(GLOB LAYER_SOURCES "${CaffeSource_DIR}/src/caffe/layers/*.cpp") + +add_library(caffe SHARED ${CORE_SOURCES} ${LAYER_SOURCES}) +target_compile_definitions(caffe PUBLIC CPU_ONLY) +target_include_directories(caffe PUBLIC ${CaffeSource_DIR}/include) +target_include_directories(caffe PRIVATE ${Boost_INCLUDE_DIRS}) +target_include_directories(caffe PRIVATE ${HDF5_INCLUDE_DIRS}) +target_include_directories(caffe PRIVATE ${Atlas_INCLUDE_DIRS}) +target_link_libraries(caffe caffeproto) +target_link_libraries(caffe glog) +target_link_libraries(caffe gflags) +target_link_libraries(caffe ${Boost_LIBRARIES}) +target_link_libraries(caffe ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}) +target_link_libraries(caffe ${Atlas_LIBRARIES}) diff --git a/infra/nncc/cmake/packages/CaffeConfig.cmake b/infra/nncc/cmake/packages/CaffeConfig.cmake new file mode 100644 index 000000000..7b5eb2f2e --- /dev/null +++ b/infra/nncc/cmake/packages/CaffeConfig.cmake @@ -0,0 +1,62 @@ +function(_Caffe_import) + nncc_find_package(CaffeSource QUIET) + + if(NOT CaffeSource_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT CaffeSource_FOUND) + + nncc_find_package(CaffeProto QUIET) + + if(NOT CaffeProto_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + find_package(Boost 1.54 COMPONENTS system thread filesystem QUIET) + + if(NOT Boost_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + find_package(HDF5 COMPONENTS HL QUIET) + + if(NOT HDF5_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + list(APPEND CMAKE_MODULE_PATH ${CaffeSource_DIR}/cmake/Modules) + + find_package(Atlas QUIET) + + if(NOT ATLAS_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + nncc_find_package(GLog QUIET) + + if(NOT GLog_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + nncc_find_package(GFlags QUIET) + + if(NOT GFlags_FOUND) + set(Caffe_FOUND FALSE PARENT_SCOPE) + return() + endif() + + if(NOT TARGET caffe) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/Caffe" caffe) + message(STATUS "Found Caffe: TRUE") + endif(NOT TARGET caffe) + + set(Caffe_FOUND TRUE PARENT_SCOPE) +endfunction(_Caffe_import) + +_Caffe_import() diff --git a/infra/nncc/cmake/packages/CaffeProto/CMakeLists.txt b/infra/nncc/cmake/packages/CaffeProto/CMakeLists.txt new file mode 100644 index 000000000..f9f8724a0 --- /dev/null +++ b/infra/nncc/cmake/packages/CaffeProto/CMakeLists.txt @@ -0,0 +1,6 @@ +Protobuf_Generate(CAFFE_PROTO "${CMAKE_CURRENT_BINARY_DIR}/generated/caffe" "${CaffeSource_DIR}/src" "caffe/proto/caffe.proto") + +add_library(caffeproto STATIC ${CAFFE_PROTO_SOURCES}) +set_target_properties(caffeproto PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(caffeproto PUBLIC ${CAFFE_PROTO_INCLUDE_DIRS}) +target_link_libraries(caffeproto libprotobuf) diff --git a/infra/nncc/cmake/packages/CaffeProtoConfig.cmake b/infra/nncc/cmake/packages/CaffeProtoConfig.cmake new file mode 100644 index 000000000..33c239509 --- /dev/null +++ b/infra/nncc/cmake/packages/CaffeProtoConfig.cmake @@ -0,0 +1,24 @@ +function(_CaffeProto_import) + nncc_find_package(CaffeSource QUIET) + + if(NOT CaffeSource_FOUND) + set(CaffeProto_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT CaffeSource_FOUND) + + nncc_find_package(Protobuf QUIET) + + if(NOT Protobuf_FOUND) + set(CaffeProto_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Protobuf_FOUND) + + if(NOT TARGET caffeproto) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/CaffeProto" caffeproto) + endif(NOT TARGET caffeproto) + + set(CaffeProto_FOUND TRUE PARENT_SCOPE) +endfunction(_CaffeProto_import) + +_CaffeProto_import() diff --git a/infra/nncc/cmake/packages/CaffeSourceConfig.cmake b/infra/nncc/cmake/packages/CaffeSourceConfig.cmake new file mode 100644 index 000000000..91d334235 --- /dev/null +++ b/infra/nncc/cmake/packages/CaffeSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_CaffeSource_import) + if(NOT DOWNLOAD_CAFFE) + set(CaffeSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_CAFFE) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(CAFFE_URL https://github.com/BVLC/caffe/archive/1.0.tar.gz) + + ExternalSource_Download(CAFFE ${CAFFE_URL}) + + set(CaffeSource_DIR ${CAFFE_SOURCE_DIR} PARENT_SCOPE) + set(CaffeSource_FOUND ${DOWNLOAD_CAFFE} PARENT_SCOPE) +endfunction(_CaffeSource_import) + +_CaffeSource_import() diff --git a/infra/nncc/cmake/packages/EigenConfig.cmake b/infra/nncc/cmake/packages/EigenConfig.cmake new file mode 100644 index 000000000..ac5164f68 --- /dev/null +++ b/infra/nncc/cmake/packages/EigenConfig.cmake @@ -0,0 +1,17 @@ +function(_Eigen_import) + nncc_find_package(EigenSource QUIET) + + if(NOT EigenSource_FOUND) + set(Eigen_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT EigenSource_FOUND) + + if(NOT TARGET eigen) + add_library(eigen INTERFACE) + target_include_directories(eigen INTERFACE "${EigenSource_DIR}") + endif(NOT TARGET eigen) + + set(EigenSource_FOUND TRUE PARENT_SCOPE) +endfunction(_Eigen_import) + +_Eigen_import() diff --git a/infra/nncc/cmake/packages/EigenSource-fd6845384b86Config.cmake b/infra/nncc/cmake/packages/EigenSource-fd6845384b86Config.cmake new file mode 100644 index 000000000..bf0f94d29 --- /dev/null +++ b/infra/nncc/cmake/packages/EigenSource-fd6845384b86Config.cmake @@ -0,0 +1,26 @@ +# find_package rejects version with commit number. Commit ID is appended to the package name +# as a workaround. +# +# TODO Find a better way +function(_import) + if(NOT DOWNLOAD_EIGEN) + set(EigenSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_EIGEN) + + nncc_include(ExternalSourceTools) + nncc_include(ThirdPartyTools) + + ThirdParty_URL(EIGEN_URL PACKAGE Eigen VERSION fd6845384b86) + + ExternalSource_Download(EIGEN + DIRNAME EIGEN-fd6845384b86 + CHECKSUM MD5=4c884968ede816a84c70e2cd2c81de8d + ${EIGEN_URL} + ) + + set(EigenSource_DIR ${EIGEN_SOURCE_DIR} PARENT_SCOPE) + set(EigenSource-fd6845384b86_FOUND TRUE PARENT_SCOPE) +endfunction(_import) + +_import() diff --git a/infra/nncc/cmake/packages/EigenSourceConfig.cmake b/infra/nncc/cmake/packages/EigenSourceConfig.cmake new file mode 100644 index 000000000..f87f53304 --- /dev/null +++ b/infra/nncc/cmake/packages/EigenSourceConfig.cmake @@ -0,0 +1,19 @@ +function(_EigenSource_import) + if(NOT DOWNLOAD_EIGEN) + set(EigenSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_EIGEN) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # NOTE The following URL comes from TensorFlow 1.7 + envoption(EIGEN_URL https://bitbucket.org/eigen/eigen/get/2355b229ea4c.tar.gz) + + ExternalSource_Download(EIGEN ${EIGEN_URL}) + + set(EigenSource_DIR ${EIGEN_SOURCE_DIR} PARENT_SCOPE) + set(EigenSource_FOUND TRUE PARENT_SCOPE) +endfunction(_EigenSource_import) + +_EigenSource_import() diff --git a/infra/nncc/cmake/packages/Farmhash/CMakeLists.txt b/infra/nncc/cmake/packages/Farmhash/CMakeLists.txt new file mode 100644 index 000000000..3da57a498 --- /dev/null +++ b/infra/nncc/cmake/packages/Farmhash/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(farmhash "${FarmhashSource_DIR}/src/farmhash.cc") +set_target_properties(farmhash PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(farmhash PUBLIC "${FarmhashSource_DIR}/src") diff --git a/infra/nncc/cmake/packages/FarmhashConfig.cmake b/infra/nncc/cmake/packages/FarmhashConfig.cmake new file mode 100644 index 000000000..68f3d7c49 --- /dev/null +++ b/infra/nncc/cmake/packages/FarmhashConfig.cmake @@ -0,0 +1,17 @@ +function(_Farmhash_import) + nncc_find_package(FarmhashSource QUIET) + + if(NOT FarmhashSource_FOUND) + set(Farmhash_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT FarmhashSource_FOUND) + + if(NOT TARGET farmhash) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/Farmhash" farmhash) + endif(NOT TARGET farmhash) + + set(Farmhash_FOUND TRUE PARENT_SCOPE) +endfunction(_Farmhash_import) + +_Farmhash_import() diff --git a/infra/nncc/cmake/packages/FarmhashSourceConfig.cmake b/infra/nncc/cmake/packages/FarmhashSourceConfig.cmake new file mode 100644 index 000000000..207909fab --- /dev/null +++ b/infra/nncc/cmake/packages/FarmhashSourceConfig.cmake @@ -0,0 +1,19 @@ +function(_FarmhashSource_import) + if(NOT DOWNLOAD_FARMHASH) + set(FarmhashSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_FARMHASH) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # NOTE TensorFlow 1.7 downloads farmhash from the following URL + envoption(FARMHASH_URL https://github.com/google/farmhash/archive/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz) + + ExternalSource_Download(FARMHASH ${FARMHASH_URL}) + + set(FarmhashSource_DIR ${FARMHASH_SOURCE_DIR} PARENT_SCOPE) + set(FarmhashSource_FOUND TRUE PARENT_SCOPE) +endfunction(_FarmhashSource_import) + +_FarmhashSource_import() diff --git a/infra/nncc/cmake/packages/FlatBuffersConfig.cmake b/infra/nncc/cmake/packages/FlatBuffersConfig.cmake new file mode 100644 index 000000000..45511ca5e --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersConfig.cmake @@ -0,0 +1,135 @@ +function(_FlatBuffers_import) + find_package(Flatbuffers QUIET) + set(FlatBuffers_FOUND ${Flatbuffers_FOUND} PARENT_SCOPE) +endfunction(_FlatBuffers_import) + +function(_FlatBuffers_build) + if(NOT BUILD_FLATBUFFERS) + return() + endif(NOT BUILD_FLATBUFFERS) + + nncc_find_package(FlatBuffersSource EXACT 1.10 QUIET) + + if(NOT FlatBuffersSource_FOUND) + # Source is not available + return() + endif(NOT FlatBuffersSource_FOUND) + + # TODO Introduce helper functions + set(FLATBUFFERS_BUILD "${CMAKE_BINARY_DIR}/externals/FLATBUFFERS/build") + set(FLATBUFFERS_INSTALL "${NNCC_OVERLAY_DIR}") + + set(STAMP_PATH "${FLATBUFFERS_INSTALL}/FLATBUFFERS.stamp") + set(LOG_PATH "${FLATBUFFERS_INSTALL}/FLATBUFFERS.log") + + if(EXISTS ${STAMP_PATH}) + return() + endif(EXISTS ${STAMP_PATH}) + + message(STATUS "Build Flatbuffers from ${FlatBuffersSource_DIR}") + + file(MAKE_DIRECTORY ${FLATBUFFERS_BUILD}) + file(MAKE_DIRECTORY ${FLATBUFFERS_INSTALL}) + + # NOTE Do NOT retry Flatbuffers build once it fails + file(WRITE "${STAMP_PATH}") + + execute_process(COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${FLATBUFFERS_INSTALL} + -DCMAKE_BUILD_TYPE=Release + ${FlatBuffersSource_DIR} + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${FLATBUFFERS_BUILD} + RESULT_VARIABLE BUILD_EXITCODE) + + execute_process(COMMAND ${CMAKE_COMMAND} --build . -- install + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${FLATBUFFERS_BUILD} + RESULT_VARIABLE INSTALL_EXITCODE) + + if(BUILD_EXITCODE EQUAL 0 AND INSTALL_EXITCODE EQUAL 0) + message(STATUS "Succeeded in building Flatbuffers") + else() + message(FATAL_ERROR "Fail to build Flatbuffers (check '${LOG_PATH}' for details)") + endif(BUILD_EXITCODE EQUAL 0 AND INSTALL_EXITCODE EQUAL 0) +endfunction(_FlatBuffers_build) + +_FlatBuffers_build() +_FlatBuffers_import() + +if(FlatBuffers_FOUND) + if(NOT TARGET flatbuffers) + add_library(flatbuffers INTERFACE) + target_link_libraries(flatbuffers INTERFACE flatbuffers::flatbuffers) + message(STATUS "Found FlatBuffers: TRUE") + endif(NOT TARGET flatbuffers) + + function(FlatBuffers_Generate PREFIX OUTPUT_DIR SCHEMA_DIR) + get_filename_component(abs_output_dir ${OUTPUT_DIR} ABSOLUTE) + get_filename_component(abs_schema_dir ${SCHEMA_DIR} ABSOLUTE) + + foreach(schema ${ARGN}) + get_filename_component(schema_fn "${schema}" NAME) + get_filename_component(dir "${schema}" DIRECTORY) + + get_filename_component(schema_fn_we "${schema_fn}" NAME_WE) + + list(APPEND SCHEMA_FILES "${abs_schema_dir}/${schema}") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${schema_fn_we}_generated.h") + endforeach() + + add_custom_command(OUTPUT ${OUTPUT_FILES} + COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}" + COMMAND "$<TARGET_FILE:flatbuffers::flatc>" -c --no-includes + --no-union-value-namespacing + --gen-object-api -o "${abs_output_dir}" + ${SCHEMA_FILES} + DEPENDS flatbuffers::flatc) + + set(${PREFIX}_SOURCES ${OUTPUT_FILES} PARENT_SCOPE) + set(${PREFIX}_INCLUDE_DIRS ${abs_output_dir} PARENT_SCOPE) + endfunction(FlatBuffers_Generate) + + function(FlatBuffers_Target TGT) + set(oneValueArgs OUTPUT_DIR SCHEMA_DIR) + set(multiValueArgs SCHEMA_FILES) + cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + get_filename_component(abs_output_dir ${ARG_OUTPUT_DIR} ABSOLUTE) + get_filename_component(abs_schema_dir ${ARG_SCHEMA_DIR} ABSOLUTE) + + # Let's reset list variables before using them + # NOTE THIS DOES NOT AFFECT parent scope + unset(SCHEMA_FILES) + unset(OUTPUT_FILES) + + foreach(schema ${ARG_SCHEMA_FILES}) + get_filename_component(schema_fn "${schema}" NAME) + get_filename_component(dir "${schema}" DIRECTORY) + + get_filename_component(schema_fn_we "${schema_fn}" NAME_WE) + + list(APPEND SCHEMA_FILES "${abs_schema_dir}/${schema}") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${schema_fn_we}_generated.h") + endforeach() + + # Generate headers + add_custom_command(OUTPUT ${OUTPUT_FILES} + COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}" + COMMAND "$<TARGET_FILE:flatbuffers::flatc>" -c --no-includes + --no-union-value-namespacing + --gen-object-api -o "${abs_output_dir}" + ${SCHEMA_FILES} + DEPENDS ${SCHEMA_FILES} + COMMENT "Generate '${TGT}' headers") + + # NOTE This header-only library is deliberately declared as STATIC library + # to avoid possible scope issues related with generated files + add_library(${TGT} STATIC ${OUTPUT_FILES}) + set_target_properties(${TGT} PROPERTIES LINKER_LANGUAGE CXX) + target_include_directories(${TGT} PUBLIC "${ARG_OUTPUT_DIR}") + target_link_libraries(${TGT} PUBLIC flatbuffers) + endfunction(FlatBuffers_Target) +endif(FlatBuffers_FOUND) diff --git a/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfig.cmake b/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfig.cmake new file mode 100644 index 000000000..c5f4dc9b7 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_FlatBuffersSource_import) + if(NOT DOWNLOAD_FLATBUFFERS) + set(FlatBuffersSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_FLATBUFFERS) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(FLATBUFFERS_1_10_URL https://github.com/google/flatbuffers/archive/v1.10.0.tar.gz) + + ExternalSource_Download(FLATBUFFERS DIRNAME FLATBUFFERS-1.10 ${FLATBUFFERS_1_10_URL}) + + set(FlatBuffersSource_DIR ${FLATBUFFERS_SOURCE_DIR} PARENT_SCOPE) + set(FlatBuffersSource_FOUND TRUE PARENT_SCOPE) +endfunction(_FlatBuffersSource_import) + +_FlatBuffersSource_import() diff --git a/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfigVersion.cmake b/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfigVersion.cmake new file mode 100644 index 000000000..6585f21d5 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSource-1.10/FlatBuffersSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.10") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfig.cmake b/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfig.cmake new file mode 100644 index 000000000..46935b9f7 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_FlatBuffersSource_import) + if(NOT DOWNLOAD_FLATBUFFERS) + set(FlatBuffersSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_FLATBUFFERS) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(FLATBUFFERS_1_8_URL https://github.com/google/flatbuffers/archive/v1.8.0.tar.gz) + + ExternalSource_Download(FLATBUFFERS DIRNAME FLATBUFFERS-1.8 ${FLATBUFFERS_1_8_URL}) + + set(FlatBuffersSource_DIR ${FLATBUFFERS_SOURCE_DIR} PARENT_SCOPE) + set(FlatBuffersSource_FOUND TRUE PARENT_SCOPE) +endfunction(_FlatBuffersSource_import) + +_FlatBuffersSource_import() diff --git a/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfigVersion.cmake b/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfigVersion.cmake new file mode 100644 index 000000000..ac5e9b2b9 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSource-1.8/FlatBuffersSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.8") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/FlatBuffersSourceConfig.cmake b/infra/nncc/cmake/packages/FlatBuffersSourceConfig.cmake new file mode 100644 index 000000000..63a9ccdd0 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSourceConfig.cmake @@ -0,0 +1,25 @@ +function(_FlatBuffersSource_import) + if(NOT DOWNLOAD_FLATBUFFERS) + set(FlatBuffersSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_FLATBUFFERS) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # Each TensorFlow needs a specific version of Flatbuffers + # - TensorFlow 1.7 downloads it from https://github.com/google/flatbuffers/archive/971a68110e4.tar.gz + # - TensorFlow 1.12 downloads it from https://github.com/google/flatbuffers/archive/1f5eae5d6a1.tar.gz + # + # Let's use 1.10 released in 2018.10 (compatible with 1f5eae5d6a1). + # + # TODO Manage multiple versions + envoption(FLATBUFFERS_URL https://github.com/google/flatbuffers/archive/v1.10.0.tar.gz) + + ExternalSource_Download(FLATBUFFERS ${FLATBUFFERS_URL}) + + set(FlatBuffersSource_DIR ${FLATBUFFERS_SOURCE_DIR} PARENT_SCOPE) + set(FlatBuffersSource_FOUND TRUE PARENT_SCOPE) +endfunction(_FlatBuffersSource_import) + +_FlatBuffersSource_import() diff --git a/infra/nncc/cmake/packages/FlatBuffersSourceConfigVersion.cmake b/infra/nncc/cmake/packages/FlatBuffersSourceConfigVersion.cmake new file mode 100644 index 000000000..ac9e22e51 --- /dev/null +++ b/infra/nncc/cmake/packages/FlatBuffersSourceConfigVersion.cmake @@ -0,0 +1,9 @@ +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(NOT PACKAGE_FIND_VERSION) + # This package works only when find_package(...) call has no EXACT option + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(NOT PACKAGE_FIND_VERSION) diff --git a/infra/nncc/cmake/packages/GEMMLowpConfig.cmake b/infra/nncc/cmake/packages/GEMMLowpConfig.cmake new file mode 100644 index 000000000..f469a0a08 --- /dev/null +++ b/infra/nncc/cmake/packages/GEMMLowpConfig.cmake @@ -0,0 +1,20 @@ +function(_GEMMLowp_import) + nncc_find_package(GEMMLowpSource QUIET) + + if(NOT GEMMLowpSource_FOUND) + set(GEMMLowp_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT GEMMLowpSource_FOUND) + + if(NOT TARGET gemmlowp) + find_package(Threads REQUIRED) + + add_library(gemmlowp INTERFACE) + target_include_directories(gemmlowp INTERFACE ${GEMMLowpSource_DIR}) + target_link_libraries(gemmlowp INTERFACE Threads::Threads) + endif(NOT TARGET gemmlowp) + + set(GEMMLowp_FOUND TRUE PARENT_SCOPE) +endfunction(_GEMMLowp_import) + +_GEMMLowp_import() diff --git a/infra/nncc/cmake/packages/GEMMLowpSourceConfig.cmake b/infra/nncc/cmake/packages/GEMMLowpSourceConfig.cmake new file mode 100644 index 000000000..a18a4cdc0 --- /dev/null +++ b/infra/nncc/cmake/packages/GEMMLowpSourceConfig.cmake @@ -0,0 +1,19 @@ +function(_GEMMLowpSource_import) + if(NOT DOWNLOAD_GEMMLOWP) + set(GEMMLowpSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_GEMMLOWP) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # NOTE TensorFlow 1.7 uses the following URL + envoption(GEMMLOWP_URL https://github.com/google/gemmlowp/archive/7c7c744640ddc3d0af18fb245b4d23228813a71b.zip) + + ExternalSource_Download(GEMMLOWP ${GEMMLOWP_URL}) + + set(GEMMLowpSource_DIR ${GEMMLOWP_SOURCE_DIR} PARENT_SCOPE) + set(GEMMLowpSource_FOUND TRUE PARENT_SCOPE) +endfunction(_GEMMLowpSource_import) + +_GEMMLowpSource_import() diff --git a/infra/nncc/cmake/packages/GFlagsConfig.cmake b/infra/nncc/cmake/packages/GFlagsConfig.cmake new file mode 100644 index 000000000..891320a95 --- /dev/null +++ b/infra/nncc/cmake/packages/GFlagsConfig.cmake @@ -0,0 +1,35 @@ +function(_GFlags_import) + if(TARGET gflags) + set(GFlags_FOUND True PARENT_SCOPE) + return() + endif() + + nncc_find_package(GFlagsSource QUIET) + + if(GFlagsSource_FOUND) + nncc_include(ExternalProjectTools) + # build shared multi-threading gflag library + set(BUILD_SHARED_LIBS On) + set(BUILD_STATIC_LIBS Off) + set(BUILD_gflags_LIB On) + set(BUILD_gflags_nothreads_LIB Off) + add_extdirectory(${GFLAGS_SOURCE_DIR} gflags) + else(GFlagsSource_FOUND) + set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains GFlags") + find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS ${GFLAGS_ROOT_DIR}) + find_library(GFLAGS_LIBRARY gflags) + + if(NOT GFLAGS_INCLUDE_DIR) + set(GFlags_FOUND False PARENT_SCOPE) + return() + endif(NOT GFLAGS_INCLUDE_DIR) + + add_library(gflags INTERFACE) + target_include_directories(gflags INTERFACE ${GFLAGS_INCLUDE_DIR}) + target_link_libraries(gflags INTERFACE ${GFLAGS_LIBRARY}) + endif(GFlagsSource_FOUND) + + set(GFlags_FOUND True PARENT_SCOPE) +endfunction(_GFlags_import) + +_GFlags_import() diff --git a/infra/nncc/cmake/packages/GFlagsSourceConfig.cmake b/infra/nncc/cmake/packages/GFlagsSourceConfig.cmake new file mode 100644 index 000000000..17970b0ec --- /dev/null +++ b/infra/nncc/cmake/packages/GFlagsSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_GFlagsSource_import) + if(NOT DOWNLOAD_GFLAGS) + set(GFlagsSource_FOUND False PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_GFLAGS) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(GFLAGS_URL https://github.com/gflags/gflags/archive/v2.2.1.tar.gz) + + ExternalSource_Download(GFLAGS ${GFLAGS_URL}) + + set(GFLAGS_SOURCE_DIR ${GFLAGS_SOURCE_DIR} PARENT_SCOPE) + set(GFlagsSource_FOUND True PARENT_SCOPE) +endfunction(_GFlagsSource_import) + +_GFlagsSource_import() diff --git a/infra/nncc/cmake/packages/GLogConfig.cmake b/infra/nncc/cmake/packages/GLogConfig.cmake new file mode 100644 index 000000000..e5ed02cd3 --- /dev/null +++ b/infra/nncc/cmake/packages/GLogConfig.cmake @@ -0,0 +1,24 @@ +function(_GLog_import) + if(TARGET glog) + set(GLog_FOUND True PARENT_SCOPE) + return() + endif() + + set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google Log") + find_path(GLOG_INCLUDE_DIR glog/logging.h PATHS ${GLOG_ROOT_DIR}) + find_library(GLOG_LIBRARY glog) + + if(NOT GLOG_INCLUDE_DIR) + set(GLog_FOUND False PARENT_SCOPE) + return() + endif(NOT GLOG_INCLUDE_DIR) + + add_library(glog INTERFACE) + target_include_directories(glog INTERFACE ${GLOG_INCLUDE_DIR} ${GFLAGS_INCLUDE_DIR}) + target_link_libraries(glog INTERFACE ${GLOG_LIBRARY} gflags) + + message(STATUS "Found GLog: TRUE") + set(GLog_FOUND True PARENT_SCOPE) +endfunction(_GLog_import) + +_GLog_import() diff --git a/infra/nncc/cmake/packages/GTestConfig.cmake b/infra/nncc/cmake/packages/GTestConfig.cmake new file mode 100644 index 000000000..27f96b27d --- /dev/null +++ b/infra/nncc/cmake/packages/GTestConfig.cmake @@ -0,0 +1,86 @@ +function(_GTest_build) + if(NOT BUILD_GTEST) + return() + endif(NOT BUILD_GTEST) + + nncc_find_package(GTestSource QUIET) + + if(NOT GTestSource_FOUND) + return() + endif(NOT GTestSource_FOUND) + + # TODO Introduce helper functions + set(GTEST_SOURCE_DIR "${GTestSource_DIR}") + set(GTEST_BUILD_DIR "${CMAKE_BINARY_DIR}/externals/GTEST/build") + set(GTEST_INSTALL_DIR "${NNCC_OVERLAY_DIR}") + + set(STAMP_PATH "${GTEST_INSTALL_DIR}/GTEST.stamp") + set(LOG_PATH "${GTEST_INSTALL_DIR}/GTEST.log") + + if(EXISTS ${STAMP_PATH}) + return() + endif(EXISTS ${STAMP_PATH}) + + message(STATUS "Google Test Package: Source found (path: ${GTEST_SOURCE_DIR})") + + file(MAKE_DIRECTORY ${GTEST_BUILD_DIR}) + file(MAKE_DIRECTORY ${GTEST_INSTALL_DIR}) + + # NOTE Do NOT retry build once it failed + file(WRITE "${STAMP_PATH}") + + execute_process(COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${GTEST_INSTALL_DIR} + -DCMAKE_BUILD_TYPE=Release + ${GTestSource_DIR} + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${GTEST_BUILD_DIR} + RESULT_VARIABLE BUILD_EXITCODE) + + if(NOT BUILD_EXITCODE EQUAL 0) + message(FATAL_ERROR "Google Test Package: Build failed (check '${LOG_PATH}' for details)") + endif(NOT BUILD_EXITCODE EQUAL 0) + + execute_process(COMMAND ${CMAKE_COMMAND} --build . -- install + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${GTEST_BUILD_DIR} + RESULT_VARIABLE INSTALL_EXITCODE) + + if(NOT INSTALL_EXITCODE EQUAL 0) + message(FATAL_ERROR "Google Test Package: Installation failed (check '${LOG_PATH}' for details)") + endif(NOT INSTALL_EXITCODE EQUAL 0) + + message(STATUS "Google Test Package: Done") +endfunction(_GTest_build) + +_GTest_build() + +### Find and use pre-installed Google Test +find_package(GTest) +find_package(Threads) + +if(${GTEST_FOUND} AND TARGET Threads::Threads) + if(NOT TARGET gtest) + add_library(gtest INTERFACE) + target_include_directories(gtest INTERFACE ${GTEST_INCLUDE_DIRS}) + target_link_libraries(gtest INTERFACE ${GTEST_LIBRARIES} Threads::Threads) + endif(NOT TARGET gtest) + + if(NOT TARGET gtest_main) + add_library(gtest_main INTERFACE) + target_include_directories(gtest_main INTERFACE ${GTEST_INCLUDE_DIRS}) + target_link_libraries(gtest_main INTERFACE gtest) + target_link_libraries(gtest_main INTERFACE ${GTEST_MAIN_LIBRARIES}) + + # GTest_AddTest(TGT ...) creates an executable target and registers that executable as a CMake test + function(GTest_AddTest TGT) + add_executable(${TGT} ${ARGN}) + target_link_libraries(${TGT} gtest_main) + add_test(${TGT} ${TGT}) + endfunction(GTest_AddTest) + endif(NOT TARGET gtest_main) + + set(GTest_FOUND TRUE) +endif(${GTEST_FOUND} AND TARGET Threads::Threads) diff --git a/infra/nncc/cmake/packages/GTestSourceConfig.cmake b/infra/nncc/cmake/packages/GTestSourceConfig.cmake new file mode 100644 index 000000000..d7c9d53c6 --- /dev/null +++ b/infra/nncc/cmake/packages/GTestSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_GTestSource_import) + if(NOT DOWNLOAD_GTEST) + set(GTestSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_GTEST) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(GTEST_URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz) + + ExternalSource_Download(GTEST ${GTEST_URL}) + + set(GTestSource_DIR ${GTEST_SOURCE_DIR} PARENT_SCOPE) + set(GTestSource_FOUND TRUE PARENT_SCOPE) +endfunction(_GTestSource_import) + +_GTestSource_import() diff --git a/infra/nncc/cmake/packages/GoogleDoubleConversionConfig.cmake b/infra/nncc/cmake/packages/GoogleDoubleConversionConfig.cmake new file mode 100644 index 000000000..3fdc86102 --- /dev/null +++ b/infra/nncc/cmake/packages/GoogleDoubleConversionConfig.cmake @@ -0,0 +1,52 @@ +# https://github.com/google/double-conversion +set(GOOGLE_DOUBLE_CONVERSION_PREFIX "/usr" CACHE PATH "Google DoubleConversion install prefix") + +function(_GoogleDoubleConversion_import) + # Find the header & lib + find_library(GoogleDoubleConversion_LIB + NAMES double-conversion + PATHS "${GOOGLE_DOUBLE_CONVERSION_PREFIX}/lib" + ) + + find_path(GoogleDoubleConversion_INCLUDE_DIR + NAMES double-conversion/double-conversion.h + PATHS "${GOOGLE_DOUBLE_CONVERSION_PREFIX}/include" + ) + + # TODO Version check + set(GoogleDoubleConversion_FOUND TRUE) + + if(NOT GoogleDoubleConversion_LIB) + set(GoogleDoubleConversion_FOUND FALSE) + endif(NOT GoogleDoubleConversion_LIB) + + if(NOT GoogleDoubleConversion_INCLUDE_DIR) + set(GoogleDoubleConversion_FOUND FALSE) + endif(NOT GoogleDoubleConversion_INCLUDE_DIR) + + set(GoogleDoubleConversion_FOUND ${GoogleDoubleConversion_FOUND} PARENT_SCOPE) + + unset(MESSAGE) + list(APPEND MESSAGE "Found Google Double Conversion") + + if(NOT GoogleDoubleConversion_FOUND) + list(APPEND MESSAGE ": FALSE") + else(NOT GoogleDoubleConversion_FOUND) + list(APPEND MESSAGE " (include: ${GoogleDoubleConversion_INCLUDE_DIR} library: ${GoogleDoubleConversion_LIB})") + + # Add target + if(NOT TARGET google_double_conversion) + # NOTE IMPORTED target may be more appropriate for this case + add_library(google_double_conversion INTERFACE) + target_link_libraries(google_double_conversion INTERFACE ${GoogleDoubleConversion_LIB}) + target_include_directories(google_double_conversion INTERFACE ${GoogleDoubleConversion_INCLUDE_DIR}) + + add_library(Google::DoubleConversion ALIAS google_double_conversion) + endif(NOT TARGET google_double_conversion) + endif(NOT GoogleDoubleConversion_FOUND) + + message(STATUS ${MESSAGE}) + set(GoogleDoubleConversion_FOUND ${GoogleDoubleConversion_FOUND} PARENT_SCOPE) +endfunction(_GoogleDoubleConversion_import) + +_GoogleDoubleConversion_import() diff --git a/infra/nncc/cmake/packages/GoogleNSyncConfig.cmake b/infra/nncc/cmake/packages/GoogleNSyncConfig.cmake new file mode 100644 index 000000000..1fdf8cc20 --- /dev/null +++ b/infra/nncc/cmake/packages/GoogleNSyncConfig.cmake @@ -0,0 +1,62 @@ +# https://github.com/google/nsync +set(GOOGLE_NSYNC_PREFIX "/usr" CACHE PATH "Where to find Google NSync library") + +function(_GoogleNSync_import) + # Find the header & lib + find_library(GoogleNSync_C_LIB + NAMES nsync + PATHS "${GOOGLE_NSYNC_PREFIX}/lib" + ) + + find_library(GoogleNSync_CPP_LIB + NAMES nsync_cpp + PATHS "${GOOGLE_NSYNC_PREFIX}/lib" + ) + + find_path(GoogleNSync_INCLUDE_DIR + NAMES nsync.h + PATHS "${GOOGLE_NSYNC_PREFIX}/include" + ) + + message(STATUS "GoogleNSync_C_LIB: ${GoogleNSync_C_LIB}") + message(STATUS "GoogleNSync_CPP_LIB: ${GoogleNSync_CPP_LIB}") + message(STATUS "GoogleNSync_INCLUDE_DIR: ${GoogleNSync_INCLUDE_DIR}") + + set(GoogleNSync_FOUND TRUE) + + if(NOT GoogleNSync_C_LIB) + set(GoogleNSync_FOUND FALSE) + endif(NOT GoogleNSync_C_LIB) + + if(NOT GoogleNSync_CPP_LIB) + set(GoogleNSync_FOUND FALSE) + endif(NOT GoogleNSync_CPP_LIB) + + if(NOT GoogleNSync_INCLUDE_DIR) + set(GoogleNSync_FOUND FALSE) + endif(NOT GoogleNSync_INCLUDE_DIR) + + unset(MESSAGE) + list(APPEND MESSAGE "Found Google NSync") + + if(NOT GoogleNSync_FOUND) + list(APPEND MESSAGE ": FALSE") + else(NOT GoogleNSync_FOUND) + list(APPEND MESSAGE " (include: ${GoogleNSync_INCLUDE_DIR} library: ${GoogleNSync_C_LIB} ${GoogleNSync_CPP_LIB})") + + # Add target + if(NOT TARGET google_nsync) + # NOTE IMPORTED target may be more appropriate for this case + add_library(google_nsync INTERFACE) + target_link_libraries(google_nsync INTERFACE ${GoogleNSync_C_LIB} ${GoogleNSync_CPP_LIB}) + target_include_directories(google_nsync INTERFACE ${GoogleNSync_INCLUDE_DIR}) + + add_library(Google::NSync ALIAS google_nsync) + endif(NOT TARGET google_nsync) + endif(NOT GoogleNSync_FOUND) + + message(STATUS ${MESSAGE}) + set(GoogleNSync_FOUND ${GoogleNSync_FOUND} PARENT_SCOPE) +endfunction(_GoogleNSync_import) + +_GoogleNSync_import() diff --git a/infra/nncc/cmake/packages/LLVMConfig.cmake b/infra/nncc/cmake/packages/LLVMConfig.cmake new file mode 100644 index 000000000..0f8faec7f --- /dev/null +++ b/infra/nncc/cmake/packages/LLVMConfig.cmake @@ -0,0 +1,45 @@ +function(_LLVM_import) + + if(NOT TARGET llvm) + find_program(llvm_config "llvm-config") + if (NOT llvm_config) + return() + endif(NOT llvm_config) + message(STATUS "Found llvm-config: ${llvm_config}") + + # get llvm compile options + execute_process(COMMAND ${llvm_config} --cppflags OUTPUT_VARIABLE + LLVM_CPPFLAGS_STR OUTPUT_STRIP_TRAILING_WHITESPACE) + # split one string to list of option items + string(REPLACE " " ";" LLVM_CPPFLAGS ${LLVM_CPPFLAGS_STR}) + execute_process(COMMAND ${llvm_config} --has-rtti OUTPUT_VARIABLE + LLVM_HAS_RTTI OUTPUT_STRIP_TRAILING_WHITESPACE) + if("${LLVM_HAS_RTTI}" STREQUAL "NO") + list(APPEND LLVM_CPPFLAGS "-fno-rtti") + endif() + # note: "llvm-config --cxxflags" returns whole string but also includes + # unwanted "-O3 -DNDEBUG" and several "-Wno-" options so this is not used + + # get llvm link options + execute_process(COMMAND ${llvm_config} --ldflags OUTPUT_VARIABLE + LLVM_LINKFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${llvm_config} --system-libs + OUTPUT_VARIABLE LLVM_LINKSYSLIBS OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${llvm_config} --libs core mcjit native + OUTPUT_VARIABLE LLVM_LINKLIBS OUTPUT_STRIP_TRAILING_WHITESPACE) + + add_library(llvm INTERFACE) + + foreach(ONE_CPPFLAG ${LLVM_CPPFLAGS}) + target_compile_options(llvm INTERFACE ${ONE_CPPFLAG}) + endforeach() + target_link_libraries(llvm INTERFACE ${LLVM_LINKFLAGS}) + target_link_libraries(llvm INTERFACE ${LLVM_LINKLIBS}) + target_link_libraries(llvm INTERFACE ${LLVM_LINKSYSLIBS}) + + endif(NOT TARGET llvm) + + set(LLVM_FOUND TRUE PARENT_SCOPE) +endfunction(_LLVM_import) + +_LLVM_import() diff --git a/infra/nncc/cmake/packages/NEON2SSEConfig.cmake b/infra/nncc/cmake/packages/NEON2SSEConfig.cmake new file mode 100644 index 000000000..c7f0c294e --- /dev/null +++ b/infra/nncc/cmake/packages/NEON2SSEConfig.cmake @@ -0,0 +1,17 @@ +function(_NEON2SSE_import) + nncc_find_package(NEON2SSESource QUIET) + + if(NOT NEON2SSESource_FOUND) + set(NEON2SSE_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT NEON2SSESource_FOUND) + + if(NOT TARGET neon2sse) + add_library(neon2sse INTERFACE) + target_include_directories(neon2sse INTERFACE "${NEON2SSESource_DIR}") + endif(NOT TARGET neon2sse) + + set(NEON2SSE_FOUND TRUE PARENT_SCOPE) +endfunction(_NEON2SSE_import) + +_NEON2SSE_import() diff --git a/infra/nncc/cmake/packages/NEON2SSESourceConfig.cmake b/infra/nncc/cmake/packages/NEON2SSESourceConfig.cmake new file mode 100644 index 000000000..f66c5cf41 --- /dev/null +++ b/infra/nncc/cmake/packages/NEON2SSESourceConfig.cmake @@ -0,0 +1,19 @@ +function(_NEON2SSESource_import) + if(NOT DOWNLOAD_NEON2SSE) + set(NEON2SSESource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_NEON2SSE) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + # NOTE TensorFlow 1.7 downloads NEON2SSE from the following URL + envoption(NEON2SSE_URL https://github.com/intel/ARM_NEON_2_x86_SSE/archive/0f77d9d182265259b135dad949230ecbf1a2633d.tar.gz) + + ExternalSource_Download(NEON2SSE ${NEON2SSE_URL}) + + set(NEON2SSESource_DIR ${NEON2SSE_SOURCE_DIR} PARENT_SCOPE) + set(NEON2SSESource_FOUND TRUE PARENT_SCOPE) +endfunction(_NEON2SSESource_import) + +_NEON2SSESource_import() diff --git a/infra/nncc/cmake/packages/ONNXProto/CMakeLists.txt b/infra/nncc/cmake/packages/ONNXProto/CMakeLists.txt new file mode 100644 index 000000000..8291958a4 --- /dev/null +++ b/infra/nncc/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 STATIC ${ONNX_PROTO_SOURCES}) +set_target_properties(onnxproto PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(onnxproto PUBLIC ${ONNX_PROTO_INCLUDE_DIRS}) +target_link_libraries(onnxproto libprotobuf) diff --git a/infra/nncc/cmake/packages/ONNXProtoConfig.cmake b/infra/nncc/cmake/packages/ONNXProtoConfig.cmake new file mode 100644 index 000000000..a6dc7a01d --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXProtoConfig.cmake @@ -0,0 +1,25 @@ +function(_ONNXProto_import) + nncc_find_package(ONNXSource EXACT 1.3.0 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/infra/nncc/cmake/packages/ONNXRuntimeConfig.cmake b/infra/nncc/cmake/packages/ONNXRuntimeConfig.cmake new file mode 100644 index 000000000..cfccfff88 --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXRuntimeConfig.cmake @@ -0,0 +1,29 @@ +set(ONNXRUNTIME_PREFIX "/usr" CACHE PATH "The location of pre-installed ONNX Runtime library") + +# TODO Download ONNXRuntime binaries + +function(_ONNXRuntime_import) + # Find the header & lib + find_library(ONNXRuntime_LIB NAMES onnxruntime PATHS "${ONNXRUNTIME_PREFIX}/lib") + find_path(ONNXRuntime_INCLUDE_DIR NAMES onnxruntime_c_api.h PATHS "${ONNXRUNTIME_PREFIX}/include") + + if(NOT ONNXRuntime_LIB OR NOT ONNXRuntime_INCLUDE_DIR) + message(STATUS "Found ONNXRuntime: FALSE") + + set(ONNXRuntime_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT ONNXRuntime_LIB OR NOT ONNXRuntime_INCLUDE_DIR) + + # Add onnxruntime target + if(NOT TARGET onnxruntime) + message(STATUS "Found ONNXRuntime (include: ${ONNXRuntime_INCLUDE_DIR}, library: ${ONNXRuntime_LIB})") + + add_library(onnxruntime INTERFACE) + target_link_libraries(onnxruntime INTERFACE ${ONNXRuntime_LIB}) + target_include_directories(onnxruntime INTERFACE ${ONNXRuntime_INCLUDE_DIR}) + endif(NOT TARGET onnxruntime) + + set(ONNXRuntime_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXRuntime_import) + +_ONNXRuntime_import() diff --git a/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfig.cmake b/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfig.cmake new file mode 100644 index 000000000..0ff33232d --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfig.cmake @@ -0,0 +1,20 @@ +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_1_3_0_URL https://github.com/onnx/onnx/archive/v1.3.0.zip) + + ExternalSource_Download(ONNX DIRNAME ONNX-1.3.0 + CHECKSUM MD5=5d588ffcf43bb18f99a67c015c97f92e + URL ${ONNX_1_3_0_URL}) + + set(ONNXSource_DIR ${ONNX_SOURCE_DIR} PARENT_SCOPE) + set(ONNXSource_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXSource_import) + +_ONNXSource_import() diff --git a/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfigVersion.cmake b/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfigVersion.cmake new file mode 100644 index 000000000..0ecf9d222 --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.3.0/ONNXSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.3.0") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfig.cmake b/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfig.cmake new file mode 100644 index 000000000..b60e9446e --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfig.cmake @@ -0,0 +1,20 @@ +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_1_4_1_URL https://github.com/onnx/onnx/archive/v1.4.1.zip) + + ExternalSource_Download(ONNX DIRNAME ONNX-1.4.1 + CHECKSUM MD5=604b43a22fbc758f32ae9f3a4fb9d397 + URL ${ONNX_1_4_1_URL}) + + set(ONNXSource_DIR ${ONNX_SOURCE_DIR} PARENT_SCOPE) + set(ONNXSource_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXSource_import) + +_ONNXSource_import() diff --git a/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfigVersion.cmake b/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfigVersion.cmake new file mode 100644 index 000000000..802b464da --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.4.1/ONNXSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.4.1") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfig.cmake b/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfig.cmake new file mode 100644 index 000000000..7f890e911 --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfig.cmake @@ -0,0 +1,20 @@ +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_1_5_0_URL https://github.com/onnx/onnx/archive/v1.5.0.zip) + + ExternalSource_Download(ONNX DIRNAME ONNX-1.5.0 + CHECKSUM MD5=1a5fe554569a3819705b26de33d8fe02 + URL ${ONNX_1_5_0_URL}) + + set(ONNXSource_DIR ${ONNX_SOURCE_DIR} PARENT_SCOPE) + set(ONNXSource_FOUND TRUE PARENT_SCOPE) +endfunction(_ONNXSource_import) + +_ONNXSource_import() diff --git a/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfigVersion.cmake b/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfigVersion.cmake new file mode 100644 index 000000000..70b2804b0 --- /dev/null +++ b/infra/nncc/cmake/packages/ONNXSource-1.5.0/ONNXSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.5.0") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/ProtobufConfig.cmake b/infra/nncc/cmake/packages/ProtobufConfig.cmake new file mode 100644 index 000000000..9064d1140 --- /dev/null +++ b/infra/nncc/cmake/packages/ProtobufConfig.cmake @@ -0,0 +1,139 @@ +# NOTE This function is unused, but remains for future reference +function(_Protobuf_module_import) + # Let's use find_package here not to export unnecessary definitions + find_package(Protobuf MODULE QUIET) + + if(NOT PROTOBUF_FOUND) + set(Protobuf_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT PROTOBUF_FOUND) + + if(NOT TARGET protoc) + add_executable(protoc IMPORTED) + set_target_properties(protoc PROPERTIES IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE}) + endif(NOT TARGET protoc) + + if(NOT TARGET libprotobuf) + add_library(libprotobuf INTERFACE) + target_include_directories(libprotobuf INTERFACE ${PROTOBUF_INCLUDE_DIRS}) + target_link_libraries(libprotobuf INTERFACE ${PROTOBUF_LIBRARIES}) + endif(NOT TARGET libprotobuf) + + set(Protobuf_FOUND TRUE PARENT_SCOPE) +endfunction(_Protobuf_module_import) + +function(_Protobuf_import) + # Let's use find_package here not to export unnecessary definitions + # NOTE Here we use "exact" match to avoid possible infinite loop + find_package(protobuf EXACT 3.5.2 QUIET) + + if(NOT protobuf_FOUND) + set(Protobuf_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT protobuf_FOUND) + + if(NOT TARGET libprotobuf) + add_library(libprotobuf INTERFACE) + target_link_libraries(libprotobuf INTERFACE protobuf::libprotobuf) + endif(NOT TARGET libprotobuf) + + set(Protobuf_FOUND TRUE PARENT_SCOPE) +endfunction(_Protobuf_import) + +function(_Protobuf_build) + if(NOT BUILD_PROTOBUF) + return() + endif(NOT BUILD_PROTOBUF) + + nncc_find_package(ProtobufSource QUIET) + + if(NOT ProtobufSource_FOUND) + # Source is not available + return() + endif(NOT ProtobufSource_FOUND) + + # TODO Introduce helper functions + set(PROTOBUF_BUILD_DIR "${CMAKE_BINARY_DIR}/externals/PROTOBUF/build") + set(PROTOBUF_INSTALL_DIR "${NNCC_OVERLAY_DIR}") + + set(STAMP_PATH "${PROTOBUF_INSTALL_DIR}/PROTOBUF.stamp") + set(LOG_PATH "${PROTOBUF_INSTALL_DIR}/PROTOBUF.log") + + if(EXISTS ${STAMP_PATH}) + return() + endif(EXISTS ${STAMP_PATH}) + + message(STATUS "Build Protocol Buffer from ${ProtobufSource_DIR}") + + file(MAKE_DIRECTORY ${PROTOBUF_BUILD_DIR}) + file(MAKE_DIRECTORY ${PROTOBUF_INSTALL_DIR}) + + # NOTE Do NOT retry Protocol Buffer build + file(WRITE "${STAMP_PATH}") + + execute_process(COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR} + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_CXX_FLAGS="-fPIC" + -Dprotobuf_BUILD_TESTS=OFF + -Dprotobuf_WITH_ZLIB=OFF + "${ProtobufSource_DIR}/cmake" + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${PROTOBUF_BUILD_DIR} + RESULT_VARIABLE CONFIGURE_EXITCODE) + + if(NOT CONFIGURE_EXITCODE EQUAL 0) + message(FATAL_ERROR "Fail to configure Protocol Buffer (check '${LOG_PATH}' for details)") + endif(NOT CONFIGURE_EXITCODE EQUAL 0) + + execute_process(COMMAND ${CMAKE_COMMAND} --build . -- install + OUTPUT_FILE ${LOG_PATH} + ERROR_FILE ${LOG_PATH} + WORKING_DIRECTORY ${PROTOBUF_BUILD_DIR} + RESULT_VARIABLE BUILD_AND_INSTALL_EXITCODE) + + if(NOT BUILD_AND_INSTALL_EXITCODE EQUAL 0) + message(FATAL_ERROR "Fail to build/install Protocol Buffer (check '${LOG_PATH}' for details)") + endif(NOT BUILD_AND_INSTALL_EXITCODE EQUAL 0) + + message(STATUS "Succeeded in building Protocol Buffer") +endfunction(_Protobuf_build) + +_Protobuf_build() +_Protobuf_import() + +if(Protobuf_FOUND) + function(Protobuf_Generate PREFIX OUTPUT_DIR PROTO_DIR) + get_filename_component(abs_output_dir ${OUTPUT_DIR} ABSOLUTE) + get_filename_component(abs_proto_dir ${PROTO_DIR} ABSOLUTE) + + # Let's reset variables before using them + # NOTE This DOES NOT AFFECT variables in the parent scope + unset(PROTO_FILES) + unset(OUTPUT_FILES) + + foreach(proto ${ARGN}) + get_filename_component(fil "${proto}" NAME) + get_filename_component(dir "${proto}" DIRECTORY) + + get_filename_component(fil_we "${fil}" NAME_WE) + + get_filename_component(abs_fil "${abs_proto_base}/${proto}" ABSOLUTE) + get_filename_component(abs_dir "${abs_fil}" DIRECTORY) + + list(APPEND PROTO_FILES "${abs_proto_dir}/${proto}") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb.h") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb.cc") + endforeach() + + add_custom_command(OUTPUT ${OUTPUT_FILES} + COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}" + COMMAND "$<TARGET_FILE:protobuf::protoc>" --cpp_out "${abs_output_dir}" -I "${abs_proto_dir}" ${PROTO_FILES} + DEPENDS ${PROTO_FILES}) + + set(${PREFIX}_SOURCES ${OUTPUT_FILES} PARENT_SCOPE) + set(${PREFIX}_INCLUDE_DIRS ${abs_output_dir} PARENT_SCOPE) + set(${PREFIX}_LIBRARIES protobuf::libprotobuf PARENT_SCOPE) + endfunction(Protobuf_Generate) +endif(Protobuf_FOUND) diff --git a/infra/nncc/cmake/packages/ProtobufSourceConfig.cmake b/infra/nncc/cmake/packages/ProtobufSourceConfig.cmake new file mode 100644 index 000000000..89176eb61 --- /dev/null +++ b/infra/nncc/cmake/packages/ProtobufSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_ProtobufSource_import) + if(NOT DOWNLOAD_PROTOBUF) + set(ProtobufSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_PROTOBUF) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(PROTOBUF_URL https://github.com/protocolbuffers/protobuf/archive/v3.5.2.tar.gz) + + ExternalSource_Download(PROTOBUF ${PROTOBUF_URL}) + + set(ProtobufSource_DIR ${PROTOBUF_SOURCE_DIR} PARENT_SCOPE) + set(ProtobufSource_FOUND TRUE PARENT_SCOPE) +endfunction(_ProtobufSource_import) + +_ProtobufSource_import() diff --git a/infra/nncc/cmake/packages/PytorchSourceConfig.cmake b/infra/nncc/cmake/packages/PytorchSourceConfig.cmake new file mode 100644 index 000000000..c28bc7c00 --- /dev/null +++ b/infra/nncc/cmake/packages/PytorchSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_PytorchSource_import) + if(NOT DOWNLOAD_PYTORCH) + set(PytorchSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_PYTORCH) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(PYTORCH_URL https://github.com/pytorch/pytorch/archive/v0.4.1.tar.gz) + + ExternalSource_Download(PYTORCH ${PYTORCH_URL}) + + set(PytorchSource_DIR ${PYTORCH_SOURCE_DIR} PARENT_SCOPE) + set(PytorchSource_FOUND ${DOWNLOAD_PYTORCH} PARENT_SCOPE) +endfunction(_PytorchSource_import) + +_PytorchSource_import() diff --git a/infra/nncc/cmake/packages/TensorFlowConfig.cmake b/infra/nncc/cmake/packages/TensorFlowConfig.cmake new file mode 100644 index 000000000..14d2fdf26 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowConfig.cmake @@ -0,0 +1,53 @@ +set(TENSORFLOW_PREFIX "/usr" CACHE PATH "The location of pre-installed TensorFlow library") +set(TENSORFLOW_VERSION_REQUIRED "1.12.0") + +# TODO Build TensorFlow from the (downloaded) source + +function(_TensorFlow_import) + # Find the header & lib + find_library(TensorFlow_LIB NAMES tensorflow PATHS "${TENSORFLOW_PREFIX}/lib") + find_path(TensorFlow_INCLUDE_DIR NAMES tensorflow/c/c_api.h PATHS "${TENSORFLOW_PREFIX}/include") + + if(NOT TensorFlow_LIB OR NOT TensorFlow_INCLUDE_DIR) + message(STATUS "Found TensorFlow: FALSE") + + set(TensorFlow_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT TensorFlow_LIB OR NOT TensorFlow_INCLUDE_DIR) + + # Check TensorFlow version + try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/TensorFlowVersionChecker.c + COMPILE_DEFINITIONS -I${TensorFlow_INCLUDE_DIR} + LINK_LIBRARIES ${TensorFlow_LIB} + ARGS ${TENSORFLOW_VERSION_REQUIRED}) + + if(NOT COMPILE_RESULT_VAR) + message(STATUS "Failed to build TensorFlowVersionChecker. Your libtensorflow may be built on different version of Ubuntu.") + message(STATUS "Found TensorFlow: FALSE") + set(TensorFlow_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT COMPILE_RESULT_VAR) + + if(NOT RUN_RESULT_VAR EQUAL 0) + message(STATUS "you need tensorflow version ${TENSORFLOW_VERSION_REQUIRED}") + message(STATUS "Found TensorFlow: FALSE") + set(TensorFlow_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT RUN_RESULT_VAR EQUAL 0) + + # Add tensorflow target (if necessary) + if(NOT TARGET tensorflow) + message(STATUS "Found TensorFlow (include: ${TensorFlow_INCLUDE_DIR}, library: ${TensorFlow_LIB})") + + # NOTE IMPORTED target may be more appropriate for this case + add_library(tensorflow INTERFACE) + target_link_libraries(tensorflow INTERFACE ${TensorFlow_LIB}) + target_include_directories(tensorflow INTERFACE ${TensorFlow_INCLUDE_DIR}) + endif(NOT TARGET tensorflow) + + set(TensorFlow_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlow_import) + +_TensorFlow_import() diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.12/Lite/CMakeLists.txt b/infra/nncc/cmake/packages/TensorFlowLite-1.12/Lite/CMakeLists.txt new file mode 100644 index 000000000..068022fcf --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.12/Lite/CMakeLists.txt @@ -0,0 +1,41 @@ +# NOTE The followings SHOULD be defined before using this CMakeLists.txt +# +# 'TensorFlowSource_DIR' variable +# 'FlatBuffersSource_DIR' variable +# 'eigen' target +# 'gemmlowp' target +# 'neon2sse' target +# 'farmhash' target +# 'abseil' target +# +message(STATUS "Build TensorFlow Lite from ${TensorFlowSource_DIR}") + +set(TensorFlowLiteSource_DIR ${TensorFlowSource_DIR}/tensorflow/contrib/lite) + +file(GLOB CORE_SRCS "${TensorFlowLiteSource_DIR}/*.c" "${TensorFlowLiteSource_DIR}/*.cc" "${TensorFlowLiteSource_DIR}/c/*.c" "${TensorFlowLiteSource_DIR}/core/api/*.cc") +file(GLOB_RECURSE CORE_TESTS "${TensorFlowLiteSource_DIR}/*test*.cc") +list(REMOVE_ITEM CORE_SRCS ${CORE_TESTS}) + +file(GLOB_RECURSE KERNEL_SRCS "${TensorFlowLiteSource_DIR}/kernels/*.cc") +file(GLOB_RECURSE KERNEL_TESTS "${TensorFlowLiteSource_DIR}/kernels/*test*.cc") +list(REMOVE_ITEM KERNEL_SRCS ${KERNEL_TESTS}) +# Exclude buggy kernel(s) from the build +#list(REMOVE_ITEM KERNEL_SRCS "${TensorFlowLiteSource_DIR}/kernels/internal/spectrogram.cc") + +list(APPEND SRCS ${CORE_SRCS}) +list(APPEND SRCS ${KERNEL_SRCS}) + +include(CheckCXXCompilerFlag) + +CHECK_CXX_COMPILER_FLAG(-Wno-extern-c-compat COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) + +add_library(tensorflowlite-1.12 ${SRCS}) +set_target_properties(tensorflowlite-1.12 PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(tensorflowlite-1.12 PUBLIC ${TensorFlowSource_DIR}) +target_include_directories(tensorflowlite-1.12 PUBLIC ${FlatBuffersSource_DIR}/include) +target_compile_options(tensorflowlite-1.12 PUBLIC -Wno-ignored-attributes) +if(COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) + target_compile_options(tensorflowlite-1.12 PUBLIC -Wno-extern-c-compat) +endif(COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) +target_compile_definitions(tensorflowlite-1.12 PUBLIC "GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK") +target_link_libraries(tensorflowlite-1.12 eigen gemmlowp neon2sse farmhash abseil dl) diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfig.cmake b/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfig.cmake new file mode 100644 index 000000000..2f4ff0a46 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfig.cmake @@ -0,0 +1,62 @@ +function(_TensorFlowLite_import) + nncc_find_package(TensorFlowSource EXACT 1.12 QUIET) + + if(NOT TensorFlowSource_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT TensorFlowSource_FOUND) + + # TensorFlow 1.12 downloads FlatBuffers from https://github.com/google/flatbuffers/archive/1f5eae5d6a1.tar.gz + # + # Let's use 1.10 released in 2018.10 (compatible with 1f5eae5d6a1). + nncc_find_package(FlatBuffersSource EXACT 1.10 QUIET) + + if(NOT FlatBuffersSource_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT FlatBuffersSource_FOUND) + + nncc_find_package(Farmhash QUIET) + + if(NOT Farmhash_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Farmhash_FOUND) + + nncc_find_package(Eigen QUIET) + + if(NOT Eigen_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Eigen_FOUND) + + nncc_find_package(GEMMLowp QUIET) + + if(NOT GEMMLowp_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT GEMMLowp_FOUND) + + nncc_find_package(NEON2SSE QUIET) + + if(NOT NEON2SSE_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT NEON2SSE_FOUND) + + nncc_find_package(Abseil QUIET) + + if(NOT Abseil_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Abseil_FOUND) + + if(NOT TARGET tensorflowlite-1.12) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/Lite" tflite-1.12) + endif(NOT TARGET tensorflowlite-1.12) + + set(TensorFlowLite_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowLite_import) + +_TensorFlowLite_import() diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfigVersion.cmake new file mode 100644 index 000000000..4a57b655b --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.12/TensorFlowLiteConfigVersion.cmake @@ -0,0 +1,9 @@ +set(PACKAGE_VERSION "1.12") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.7/Lite/CMakeLists.txt b/infra/nncc/cmake/packages/TensorFlowLite-1.7/Lite/CMakeLists.txt new file mode 100644 index 000000000..c5e89eebe --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.7/Lite/CMakeLists.txt @@ -0,0 +1,38 @@ +# NOTE The followings SHOULD be defined before using this CMakeLists.txt +# +# 'TensorFlowSource_DIR' variable +# 'FlatBuffersSource_DIR' variable +# 'eigen' target +# 'gemmlowp' target +# 'neon2sse' target +# 'farmhash' target +# +set(TensorFlowLiteSource_DIR ${TensorFlowSource_DIR}/tensorflow/contrib/lite) + +file(GLOB CORE_SRCS "${TensorFlowLiteSource_DIR}/*.c" "${TensorFlowLiteSource_DIR}/*.cc") +file(GLOB CORE_TESTS "${TensorFlowLiteSource_DIR}/*test*.cc") +list(REMOVE_ITEM CORE_SRCS ${CORE_TESTS}) + +file(GLOB_RECURSE KERNEL_SRCS "${TensorFlowLiteSource_DIR}/kernels/*.cc") +file(GLOB_RECURSE KERNEL_TESTS "${TensorFlowLiteSource_DIR}/kernels/*test*.cc") +list(REMOVE_ITEM KERNEL_SRCS ${KERNEL_TESTS}) +# Exclude buggy kernel(s) from the build +list(REMOVE_ITEM KERNEL_SRCS "${TensorFlowLiteSource_DIR}/kernels/internal/spectrogram.cc") + +list(APPEND SRCS ${CORE_SRCS}) +list(APPEND SRCS ${KERNEL_SRCS}) + +include(CheckCXXCompilerFlag) + +CHECK_CXX_COMPILER_FLAG(-Wno-extern-c-compat COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) + +add_library(tensorflowlite-1.7 ${SRCS}) +set_target_properties(tensorflowlite-1.7 PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(tensorflowlite-1.7 PUBLIC ${TensorFlowSource_DIR}) +target_include_directories(tensorflowlite-1.7 PUBLIC ${FlatBuffersSource_DIR}/include) +target_compile_options(tensorflowlite-1.7 PUBLIC -Wno-ignored-attributes) +if(COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) + target_compile_options(tensorflowlite-1.7 PUBLIC -Wno-extern-c-compat) +endif(COMPILER_SUPPORT_EXTERN_C_COMPAT_WARNING) +target_compile_definitions(tensorflowlite-1.7 PUBLIC "GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK") +target_link_libraries(tensorflowlite-1.7 eigen gemmlowp neon2sse farmhash dl) diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfig.cmake b/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfig.cmake new file mode 100644 index 000000000..44bc817e1 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfig.cmake @@ -0,0 +1,55 @@ +function(_TensorFlowLite_import) + nncc_find_package(TensorFlowSource EXACT 1.7 QUIET) + + if(NOT TensorFlowSource_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT TensorFlowSource_FOUND) + + # TensorFlow 1.7 downloads FlatBuffers from https://github.com/google/flatbuffers/archive/971a68110e4.tar.gz + # + # FlatBuffers 1.8 is compatible with 971a68110e4. + nncc_find_package(FlatBuffersSource EXACT 1.8 QUIET) + + if(NOT FlatBuffersSource_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT FlatBuffersSource_FOUND) + + nncc_find_package(Farmhash QUIET) + + if(NOT Farmhash_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Farmhash_FOUND) + + nncc_find_package(Eigen QUIET) + + if(NOT Eigen_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT Eigen_FOUND) + + nncc_find_package(GEMMLowp QUIET) + + if(NOT GEMMLowp_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT GEMMLowp_FOUND) + + nncc_find_package(NEON2SSE QUIET) + + if(NOT NEON2SSE_FOUND) + set(TensorFlowLite_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT NEON2SSE_FOUND) + + if(NOT TARGET tensorflowlite-1.7) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/Lite" tflite-1.7) + endif(NOT TARGET tensorflowlite-1.7) + + set(TensorFlowLite_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowLite_import) + +_TensorFlowLite_import() diff --git a/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfigVersion.cmake new file mode 100644 index 000000000..46609dc10 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowLite-1.7/TensorFlowLiteConfigVersion.cmake @@ -0,0 +1,9 @@ +set(PACKAGE_VERSION "1.7") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfig.cmake b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfig.cmake new file mode 100644 index 000000000..5963ce418 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfig.cmake @@ -0,0 +1,104 @@ +function(_TensorFlowProtoText_import) + macro(require_package PKGNAME) + nncc_find_package(${PKGNAME} ${ARGN} QUIET) + if(NOT ${PKGNAME}_FOUND) + message(STATUS "Found TensorFlowProtoText: FALSE (${PKGNAME} is missing)") + set(TensorFlowProtoText_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT ${PKGNAME}_FOUND) + endmacro(require_package) + + require_package(TensorFlowSource EXACT 1.12) + require_package(Abseil) + require_package(Eigen) + require_package(Protobuf) + require_package(GoogleDoubleConversion) + require_package(GoogleNSync) + + if(NOT TARGET tensorflow-prototext-1.12) + nncc_include(ExternalProjectTools) + add_extdirectory("${CMAKE_CURRENT_LIST_DIR}/build" TensorFlowProtoText-1.12) + endif(NOT TARGET tensorflow-prototext-1.12) + + set(TensorFlowProtoText_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowProtoText_import) + +_TensorFlowProtoText_import() + +if(TensorFlowProtoText_FOUND) + # CMAKE_CURRENT_LIST_DIR + # + # ... The value has dynamic scope. ... Therefore the value of the variable inside a macro + # or function is the directory of the file invoking the bottom-most entry on the call stack, + # not the directory of the file containing the macro or function definition. + # + # Reference: https://cmake.org/cmake/help/v3.1/variable/CMAKE_CURRENT_LIST_DIR.html + set(TENSORLFLOW_PROTO_TEXT_1_12_CMAKE_DIR + "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL + "Where to find make_directories" + ) + + # Comments from "gen_proto_text_functions.cc" + # > + # > Main program to take input protos and write output pb_text source files that + # > contain generated proto text input and output functions. + # > + # > Main expects: + # > - First argument is output path + # > - Second argument is the relative path of the protos to the root. E.g., + # > for protos built by a rule in tensorflow/core, this will be + # > tensorflow/core. + # > - Then any number of source proto file names, plus one source name must be + # > placeholder.txt from this gen tool's package. placeholder.txt is + # > ignored for proto resolution, but is used to determine the root at which + # > the build tool has placed the source proto files. + # > + function(ProtoText_Generate PREFIX OUTPUT_DIR) + # THIS SHOULD SUCCEED! + nncc_find_package(TensorFlowSource EXACT 1.12 REQUIRED) + + set(OUTPUT_REL "tensorflow") + set(PROTO_DIR "${TensorFlowSource_DIR}") + + set(PROTO_INPUTS ${ARGN}) + list(APPEND PROTO_INPUTS "tensorflow/tools/proto_text/placeholder.txt") + + get_filename_component(abs_output_dir ${OUTPUT_DIR} ABSOLUTE) + get_filename_component(abs_proto_dir ${TensorFlowSource_DIR} ABSOLUTE) + + # Let's reset variables before using them + # NOTE This DOES NOT AFFECT variables in the parent scope + unset(PROTO_FILES) + unset(OUTPUT_DIRS) + unset(OUTPUT_FILES) + + foreach(proto ${PROTO_INPUTS}) + get_filename_component(fil "${proto}" NAME) + get_filename_component(dir "${proto}" DIRECTORY) + + get_filename_component(fil_we "${fil}" NAME_WE) + + get_filename_component(abs_fil "${abs_proto_base}/${proto}" ABSOLUTE) + get_filename_component(abs_dir "${abs_fil}" DIRECTORY) + + list(APPEND PROTO_FILES "${abs_proto_dir}/${proto}") + + if(NOT ${fil} STREQUAL "placeholder.txt") + list(APPEND OUTPUT_DIRS "${abs_output_dir}/${dir}") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb_text.h") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb_text-impl.h") + list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb_text.cc") + endif(NOT ${fil} STREQUAL "placeholder.txt") + endforeach() + + add_custom_command(OUTPUT ${OUTPUT_FILES} + # "make_directory" in CMake 3.1 cannot create multiple directories at once. + # COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIRS} + COMMAND "${TENSORLFLOW_PROTO_TEXT_1_12_CMAKE_DIR}/make_directories.sh" ${OUTPUT_DIRS} + COMMAND "$<TARGET_FILE:tensorflow-prototext-1.12>" "${abs_output_dir}/${OUTPUT_REL}" "${OUTPUT_REL}" ${PROTO_FILES} + DEPENDS ${PROTO_FILES}) + + set(${PREFIX}_SOURCES ${OUTPUT_FILES} PARENT_SCOPE) + set(${PREFIX}_INCLUDE_DIRS ${abs_output_dir} PARENT_SCOPE) + endfunction(ProtoText_Generate) +endif(TensorFlowProtoText_FOUND) diff --git a/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfigVersion.cmake new file mode 100644 index 000000000..4a57b655b --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/TensorFlowProtoTextConfigVersion.cmake @@ -0,0 +1,9 @@ +set(PACKAGE_VERSION "1.12") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/build/CMakeLists.txt b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/build/CMakeLists.txt new file mode 100644 index 000000000..86d6e6fe5 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/build/CMakeLists.txt @@ -0,0 +1,78 @@ +message(STATUS "Build TensorFlowProtoText from '${TensorFlowSource_DIR}'") + +# +# Build "proto_text" tool +# +unset(SOURCE_FILES) + +macro(Source_Add RPATH) + list(APPEND SOURCE_FILES "${TensorFlowSource_DIR}/${RPATH}") +endmacro(Source_Add) + +# This list comes from "tensorflow/contrib/makefile/proto_text_cc_files.txt" +Source_Add(tensorflow/core/lib/core/status.cc) +Source_Add(tensorflow/core/lib/core/threadpool.cc) +Source_Add(tensorflow/core/lib/hash/hash.cc) +Source_Add(tensorflow/core/lib/io/inputstream_interface.cc) +Source_Add(tensorflow/core/lib/io/random_inputstream.cc) +Source_Add(tensorflow/core/lib/io/buffered_inputstream.cc) +Source_Add(tensorflow/core/lib/io/inputbuffer.cc) +Source_Add(tensorflow/core/lib/io/iterator.cc) +Source_Add(tensorflow/core/lib/io/path.cc) +Source_Add(tensorflow/core/lib/strings/numbers.cc) +Source_Add(tensorflow/core/lib/strings/scanner.cc) +Source_Add(tensorflow/core/lib/strings/str_util.cc) +Source_Add(tensorflow/core/lib/strings/strcat.cc) +Source_Add(tensorflow/core/lib/strings/stringprintf.cc) +Source_Add(tensorflow/core/lib/strings/proto_text_util.cc) +Source_Add(tensorflow/core/platform/cpu_info.cc) +Source_Add(tensorflow/core/platform/denormal.cc) +Source_Add(tensorflow/core/platform/env.cc) +Source_Add(tensorflow/core/platform/env_time.cc) +Source_Add(tensorflow/core/platform/file_system.cc) +Source_Add(tensorflow/core/platform/file_system_helper.cc) +Source_Add(tensorflow/core/platform/protobuf_util.cc) +Source_Add(tensorflow/core/platform/setround.cc) +Source_Add(tensorflow/core/platform/tracing.cc) +Source_Add(tensorflow/core/platform/posix/env.cc) +Source_Add(tensorflow/core/platform/posix/env_time.cc) +Source_Add(tensorflow/core/platform/posix/error.cc) +Source_Add(tensorflow/core/platform/posix/load_library.cc) +Source_Add(tensorflow/core/platform/posix/port.cc) +Source_Add(tensorflow/core/platform/posix/posix_file_system.cc) +Source_Add(tensorflow/core/platform/default/logging.cc) +Source_Add(tensorflow/core/platform/default/mutex.cc) +Source_Add(tensorflow/core/platform/default/protobuf.cc) + +Source_Add(tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc) +Source_Add(tensorflow/tools/proto_text/gen_proto_text_functions.cc) + +unset(PROTO_FILES) + +macro(Proto_Add RPATH) + list(APPEND PROTO_FILES "${RPATH}") +endmacro(Proto_Add) + +Proto_Add(tensorflow/core/lib/core/error_codes.proto) +Proto_Add(tensorflow/core/framework/types.proto) +Proto_Add(tensorflow/core/framework/tensor.proto) +Proto_Add(tensorflow/core/framework/tensor_shape.proto) +Proto_Add(tensorflow/core/framework/summary.proto) +Proto_Add(tensorflow/core/framework/resource_handle.proto) + +Protobuf_Generate(PROTO_TEXT_PROTO + "${CMAKE_CURRENT_BINARY_DIR}/generated/proto_text" + "${TensorFlowSource_DIR}" + ${PROTO_FILES} +) + +add_executable(tensorflow-prototext-1.12 ${SOURCE_FILES} ${PROTO_TEXT_PROTO_SOURCES}) +target_include_directories(tensorflow-prototext-1.12 PRIVATE ${TensorFlowSource_DIR}) +target_include_directories(tensorflow-prototext-1.12 PRIVATE ${PROTO_TEXT_PROTO_INCLUDE_DIRS}) + +target_link_libraries(tensorflow-prototext-1.12 PRIVATE abseil) +target_link_libraries(tensorflow-prototext-1.12 PRIVATE eigen) +target_link_libraries(tensorflow-prototext-1.12 PRIVATE ${PROTO_TEXT_PROTO_LIBRARIES}) +target_link_libraries(tensorflow-prototext-1.12 PRIVATE Google::DoubleConversion) +target_link_libraries(tensorflow-prototext-1.12 PRIVATE Google::NSync) +target_link_libraries(tensorflow-prototext-1.12 PRIVATE dl) diff --git a/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/make_directories.sh b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/make_directories.sh new file mode 100644 index 000000000..1fb2ab683 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowProtoText-1.12/make_directories.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +while [[ $# -ne 0 ]]; do + DIR=$1; shift + mkdir -p "${DIR}" +done diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfig.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfig.cmake new file mode 100644 index 000000000..b3adef052 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_TensorFlowSource_import) + if(NOT DOWNLOAD_TENSORFLOW) + set(TensorFlowSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_TENSORFLOW) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(TENSORFLOW_1_12_URL https://github.com/tensorflow/tensorflow/archive/v1.12.0.tar.gz) + + ExternalSource_Download(TENSORFLOW DIRNAME TENSORFLOW-1.12 ${TENSORFLOW_1_12_URL}) + + set(TensorFlowSource_DIR ${TENSORFLOW_SOURCE_DIR} PARENT_SCOPE) + set(TensorFlowSource_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowSource_import) + +_TensorFlowSource_import() diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfigVersion.cmake new file mode 100644 index 000000000..8cfdbf8e5 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.12/TensorFlowSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.12") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfig.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfig.cmake new file mode 100644 index 000000000..f9df7dc18 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_TensorFlowSource_import) + if(NOT DOWNLOAD_TENSORFLOW) + set(TensorFlowSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_TENSORFLOW) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(TENSORFLOW_1_14_URL https://github.com/tensorflow/tensorflow/archive/v1.14.0.tar.gz) + + ExternalSource_Download(TENSORFLOW DIRNAME TENSORFLOW-1.14 ${TENSORFLOW_1_14_URL}) + + set(TensorFlowSource_DIR ${TENSORFLOW_SOURCE_DIR} PARENT_SCOPE) + set(TensorFlowSource_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowSource_import) + +_TensorFlowSource_import() diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfigVersion.cmake new file mode 100644 index 000000000..e9d7db2be --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.14/TensorFlowSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.14") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfig.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfig.cmake new file mode 100644 index 000000000..11dbf01c5 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_TensorFlowSource_import) + if(NOT DOWNLOAD_TENSORFLOW) + set(TensorFlowSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_TENSORFLOW) + + nncc_include(ExternalSourceTools) + nncc_include(OptionTools) + + envoption(TENSORFLOW_URL https://github.com/tensorflow/tensorflow/archive/v1.7.0.tar.gz) + + ExternalSource_Download(TENSORFLOW ${TENSORFLOW_URL}) + + set(TensorFlowSource_DIR ${TENSORFLOW_SOURCE_DIR} PARENT_SCOPE) + set(TensorFlowSource_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowSource_import) + +_TensorFlowSource_import() diff --git a/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfigVersion.cmake b/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfigVersion.cmake new file mode 100644 index 000000000..b1d5282b2 --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowSource-1.7/TensorFlowSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "1.7") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/nncc/cmake/packages/TensorFlowVersionChecker.c b/infra/nncc/cmake/packages/TensorFlowVersionChecker.c new file mode 100644 index 000000000..6161ef74a --- /dev/null +++ b/infra/nncc/cmake/packages/TensorFlowVersionChecker.c @@ -0,0 +1,9 @@ +#include <string.h> +#include <tensorflow/c/c_api.h> + +int main(int argc, char **argv) +{ + if (argc >= 2 && !strcmp(argv[1], TF_Version())) + return 0; + return 255; +} diff --git a/infra/nncc/command/build b/infra/nncc/command/build new file mode 100644 index 000000000..86082c188 --- /dev/null +++ b/infra/nncc/command/build @@ -0,0 +1,11 @@ +#!/bin/bash + +import "build.configuration" + +BUILD_WORKSPACE_PATH="${NNCC_PROJECT_PATH}/${BUILD_WORKSPACE_RPATH}" + +if [[ ! -d "${BUILD_WORKSPACE_PATH}" ]]; then + echo "'${BUILD_WORKSPACE_RPATH}' does not exist. Please run 'configure' first" + exit 255 +fi +cd "${BUILD_WORKSPACE_PATH}" && cmake --build . -- "$@" diff --git a/infra/nncc/command/check-copyright b/infra/nncc/command/check-copyright new file mode 100644 index 000000000..b70785971 --- /dev/null +++ b/infra/nncc/command/check-copyright @@ -0,0 +1,62 @@ +#!/bin/bash + +# HOW TO USE +# +# Create .COPYRIGHT file at the root of your project (compiler/[PROJECT]/.COPYRIGHT) +# with the copyright pattern required for your project. +# +# echo "Copyright (c) [0-9]\+ Samsung Electronics Co., Ltd. All Rights Reserved" > compiler/[PROJECT]/.COPYRIGHT +# +# DISCLAIMER +# +# This check works only when your copyright notice is of the following form: +# +# /** +# * [Copyright notice] +# ... +# */ +# +# NOTE +# +# The current implementation does not validate YEAR in the copyright notice. +# +# TODO Validate YEAR without FALSE POSTIVIES +# +# It already turns out that checking the initial commit year introduces +# FALSE POSITIVES if there are relocated files. +INVALID_FILES=() + +for COPYRIGHT_PATH in $(ls ${NNCC_PROJECT_PATH}/compiler/*/.COPYRIGHT); do + PROJECT_PATH="$(dirname ${COPYRIGHT_PATH})" + PROJECT_NAME="$(basename ${PROJECT_PATH})" + + CANDIDATE_FILES=$(find "${PROJECT_PATH}" -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.c') + + # Skip copyright check if there is no candidate files + # + # NOTE "git ls-files" with no argument will enumerate all the files in the repo + if [[ -z ${CANDIDATE_FILES} ]]; then + continue + fi + + for TRACKED_FILE in $(git ls-files $CANDIDATE_FILES); do + MATCHED=$(cat "${NNCC_PROJECT_PATH}/${TRACKED_FILE}" | head -n2 | tail -n1 | sed 's/^ \* //g' | grep -f "${COPYRIGHT_PATH}" | wc -l) + + if [[ ${MATCHED} -ne 1 ]]; then + INVALID_FILES+=(${TRACKED_FILE}) + fi + done +done + +if [[ ${#INVALID_FILES[@]} -ne 0 ]]; then + echo ">> FAILED <<" + echo + echo "PLEASE CHECK THE FOLLOWING FILES" + for INVALID_FILE in "${INVALID_FILES[@]}"; do + echo "- ${INVALID_FILE}" + done + exit 255 +fi + +echo ">> PASSED <<" +exit 0 diff --git a/infra/nncc/command/configure b/infra/nncc/command/configure new file mode 100644 index 000000000..2648cb893 --- /dev/null +++ b/infra/nncc/command/configure @@ -0,0 +1,10 @@ +#!/bin/bash + +import "build.configuration" + +BUILD_WORKSPACE_PATH="${NNCC_PROJECT_PATH}/${BUILD_WORKSPACE_RPATH}" + +mkdir -p "${BUILD_WORKSPACE_PATH}" + +cd "${BUILD_WORKSPACE_PATH}" +cmake "${NNCC_PROJECT_PATH}/infra/nncc" "$@" diff --git a/infra/nncc/command/docker-nncc b/infra/nncc/command/docker-nncc new file mode 100644 index 000000000..0eea016c6 --- /dev/null +++ b/infra/nncc/command/docker-nncc @@ -0,0 +1,10 @@ +#!/bin/bash + +import "docker.configuration" + +docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME ./nncc "$@" +EXITCODE=$? + +docker_cleanup + +exit $EXITCODE diff --git a/infra/nncc/command/docker-run b/infra/nncc/command/docker-run new file mode 100644 index 000000000..863b2b8f1 --- /dev/null +++ b/infra/nncc/command/docker-run @@ -0,0 +1,10 @@ +#!/bin/bash + +import "docker.configuration" + +docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME "$@" +EXITCODE=$? + +docker_cleanup + +exit $EXITCODE diff --git a/infra/nncc/command/docker-shell b/infra/nncc/command/docker-shell new file mode 100644 index 000000000..7f8449855 --- /dev/null +++ b/infra/nncc/command/docker-shell @@ -0,0 +1,11 @@ +#!/bin/bash + +import "docker.configuration" + +DOCKER_RUN_OPTS+=" -it" +docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME /bin/bash +EXITCODE=$? + +docker_cleanup + +exit $EXITCODE diff --git a/infra/nncc/command/test b/infra/nncc/command/test new file mode 100644 index 000000000..96ddd7a17 --- /dev/null +++ b/infra/nncc/command/test @@ -0,0 +1,13 @@ +#!/bin/bash + +import "build.configuration" + +BUILD_WORKSPACE_PATH="${NNCC_PROJECT_PATH}/${BUILD_WORKSPACE_RPATH}" + +if [[ ! -d "${BUILD_WORKSPACE_PATH}" ]]; then + echo "'${BUILD_WORKSPACE_RPATH}' does not exist. Please run 'configure' first" + exit 255 +fi + +export CTEST_OUTPUT_ON_FAILURE=1 +cd "${BUILD_WORKSPACE_PATH}" && ctest "$@" diff --git a/infra/nncc/config/build.configuration b/infra/nncc/config/build.configuration new file mode 100644 index 000000000..25ffb6ee0 --- /dev/null +++ b/infra/nncc/config/build.configuration @@ -0,0 +1 @@ +BUILD_WORKSPACE_RPATH=${NNCC_WORKSPACE:-build} diff --git a/infra/nncc/config/docker.configuration b/infra/nncc/config/docker.configuration new file mode 100644 index 000000000..7078585a2 --- /dev/null +++ b/infra/nncc/config/docker.configuration @@ -0,0 +1,46 @@ +DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-nnas} +echo "Using docker image ${DOCKER_IMAGE_NAME}" + +if [ -z "`docker images ${DOCKER_IMAGE_NAME}`" ]; then + echo "Need docker image!" + exit 1 +fi + +HOST_PATH="$NNCC_PROJECT_PATH" +DOCKER_PATH="$NNCC_PROJECT_PATH" + +export GIT_SSL_NO_VERIFY=1 + +DOCKER_VOLUMES=" -v $HOST_PATH:$DOCKER_PATH" + +DOCKER_ENV_VARS+=" -e http_proxy" +DOCKER_ENV_VARS+=" -e no_proxy" +DOCKER_ENV_VARS+=" -e GIT_SSL_NO_VERIFY" +DOCKER_ENV_VARS+=" -e CAFFE_URL" +DOCKER_ENV_VARS+=" -e GTEST_URL" +DOCKER_ENV_VARS+=" -e EIGEN_URL" +DOCKER_ENV_VARS+=" -e GEMMLOWP_URL" +DOCKER_ENV_VARS+=" -e FLATBUFFERS_URL" +DOCKER_ENV_VARS+=" -e FARMHASH_URL" +DOCKER_ENV_VARS+=" -e NEON2SSE_URL" +DOCKER_ENV_VARS+=" -e TENSORFLOW_URL" + +DOCKER_ENV_VARS+=" -e NNCC_WORKSPACE" + +DOCKER_RUN_OPTS="${DOCKER_OPTS}" +DOCKER_RUN_OPTS+=" --rm" +DOCKER_RUN_OPTS+=" -w $DOCKER_PATH" + +function docker_cleanup() +{ + # Newly created files during during docker run can have different ownership. + # This may cause some problems, for example, some jenkins slaves or developers + # can't remove built files due to lack of permission. + # To address this issue, let's change owner of all files + # in nncc to owner of nncc. + NNCC_OWNER_UID=$(stat -c "%u" $HOST_PATH) + NNCC_OWNER_GID=$(stat -c "%g" $HOST_PATH) + + CMD="chown -R $NNCC_OWNER_UID:$NNCC_OWNER_GID $DOCKER_PATH" + docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD +} |