use .cmake to compile protobuf and flatbuffers

This commit is contained in:
hangq 2020-10-09 17:28:33 +08:00 committed by xuanyue
parent fd0c03c493
commit 16e1653c14
31 changed files with 176 additions and 145 deletions

View File

@ -463,37 +463,6 @@ build_flatbuffer() {
fi
}
gene_protobuf() {
PROTO_SRC_DIR="${BASEPATH}/mindspore/lite/tools/converter/parser/caffe"
find ${PROTO_SRC_DIR} -name "*.proto" -print0 | xargs -0 "${PROTOC}" -I"${PROTO_SRC_DIR}" --cpp_out="${PROTO_SRC_DIR}"
PROTO_SRC_DIR="${BASEPATH}/mindspore/lite/tools/converter/parser/onnx"
find ${PROTO_SRC_DIR} -name "*.proto" -print0 | xargs -0 "${PROTOC}" -I"${PROTO_SRC_DIR}" --cpp_out="${PROTO_SRC_DIR}"
}
build_protobuf() {
cd ${BASEPATH}
PROTOC="${BASEPATH}"/third_party/protobuf/build/bin/protoc
if [[ ! -f "${PROTOC}" ]]; then
if [[ "${MSLIBS_SERVER}" ]]; then
cd "${BASEPATH}"/third_party/
rm -rf ./v3.8.0.tar.gz ./protobuf
wget http://${MSLIBS_SERVER}:8081/libs/protobuf/v3.8.0.tar.gz
tar -zxvf ./v3.8.0.tar.gz
mv ./protobuf-3.8.0 ./protobuf
else
git submodule update --init --recursive third_party/protobuf
fi
cd ${BASEPATH}/third_party/protobuf
rm -rf build && mkdir -pv build && ./autogen.sh
./configure --prefix=${BASEPATH}/third_party/protobuf/build
make clean && make -j$THREAD_NUM && make install
gene_protobuf
fi
if [[ "${INC_BUILD}" == "off" ]]; then
gene_protobuf
fi
}
build_gtest() {
cd ${BASEPATH}
git submodule update --init --recursive third_party/googletest
@ -663,10 +632,6 @@ build_lite()
echo "start build opencl"
build_opencl
fi
if [[ "${LITE_PLATFORM}" == "x86_64" ]]; then
build_protobuf
fi
build_flatbuffer
build_gtest
if [ "${COMPILE_MINDDATA_LITE}" == "lite" ] || [ "${COMPILE_MINDDATA_LITE}" == "full" ]; then
@ -689,7 +654,7 @@ build_lite()
cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \
-DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \
-DANDROID_STL="c++_static" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
-DBUILD_DEVICE=on -DPLATFORM_ARM64=on -DENABLE_NEON=on -DENABLE_FP16="off" \
-DPLATFORM_ARM64=on -DENABLE_NEON=on -DENABLE_FP16="off" \
-DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \
-DSUPPORT_GPU=${ENABLE_GPU} -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DMS_VERSION_MAJOR=${VERSION_MAJOR} \
@ -700,14 +665,14 @@ build_lite()
cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \
-DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="armeabi-v7a" -DANDROID_TOOLCHAIN_NAME="clang" \
-DANDROID_STL="c++_static" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBUILD_DEVICE=on -DPLATFORM_ARM32=on -DENABLE_NEON=on -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
-DPLATFORM_ARM32=on -DENABLE_NEON=on -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
-DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \
-DSUPPORT_GPU=${ENABLE_GPU} -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DMS_VERSION_MAJOR=${VERSION_MAJOR} \
-DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} -DENABLE_VERBOSE=${ENABLE_VERBOSE} \
"${BASEPATH}/mindspore/lite"
else
cmake -DBUILD_DEVICE=on -DPLATFORM_ARM64=off -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
cmake -DPLATFORM_ARM64=off -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
-DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_GPU=${ENABLE_GPU} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
-DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp \

View File

@ -3,6 +3,7 @@ set(flatbuffers_CFLAGS "-D_FORTIFY_SOURCE=2 -O2")
if (WIN32)
set(flatbuffers_USE_STATIC_LIBS ON)
endif()
mindspore_add_pkg(flatbuffers
VER 1.11.0
LIBS flatbuffers
@ -14,7 +15,6 @@ mindspore_add_pkg(flatbuffers
include_directories(${flatbuffers_INC})
add_library(mindspore::flatbuffers ALIAS flatbuffers::flatbuffers)
add_executable(mindspore::flatc ALIAS flatbuffers::flatc)
include_directories(${flatbuffers_INC})
function(ms_build_flatbuffers source_schema_files
source_schema_dirs
custom_target_name
@ -54,3 +54,55 @@ function(ms_build_flatbuffers source_schema_files
${generated_output_dir})
endif()
endfunction()
function(ms_build_flatbuffers_lite source_schema_files
source_schema_dirs
custom_target_name
generated_output_dir
if_inner)
set(total_schema_dirs "")
set(total_generated_files "")
set(FLATC mindspore::flatc)
foreach (schema_dir ${source_schema_dirs})
set(total_schema_dirs -I ${schema_dir} ${total_schema_dirs})
endforeach()
foreach(schema IN LISTS ${source_schema_files})
get_filename_component(filename ${schema} NAME_WE)
if (NOT ${generated_output_dir} STREQUAL "")
set(generated_file ${generated_output_dir}/${filename}_generated.h)
if (if_inner MATCHES "inner")
add_custom_command(
OUTPUT ${generated_file}
COMMAND ${FLATC} --gen-mutable
--reflect-names --gen-object-api -o ${generated_output_dir}
${total_schema_dirs}
-c -b --reflect-types ${schema}
DEPENDS ${FLATC} ${schema}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Running C++ flatbuffers compiler on ${schema}" VERBATIM)
else()
add_custom_command(
OUTPUT ${generated_file}
COMMAND ${FLATC} -o ${generated_output_dir}
${total_schema_dirs}
-c -b ${schema}
DEPENDS ${FLATC} ${schema}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Running C++ flatbuffers compiler on ${schema}" VERBATIM)
endif()
list(APPEND total_generated_files ${generated_file})
endif()
endforeach()
add_custom_target(${custom_target_name} ALL
DEPENDS ${total_generated_files})
if (NOT ${generated_output_dir} STREQUAL "")
include_directories(${generated_output_dir})
set_property(TARGET ${custom_target_name}
PROPERTY GENERATED_OUTPUT_DIR
${generated_output_dir})
endif()
endfunction()

View File

@ -1,11 +1,15 @@
set(protobuf_USE_STATIC_LIBS ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (BUILD_LITE)
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
else()
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=0 -O2")
endif()
else(BUILD_LITE)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
else()
set(protobuf_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=0 -O2")
endif()
endif(BUILD_LITE)
set(protobuf_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
set(_ms_tmp_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

View File

@ -67,14 +67,14 @@ if (PLATFORM_ARM64)
install(DIRECTORY ${TOP_DIR}/mindspore/lite/schema/ DESTINATION ${INC_DIR}/schema COMPONENT ${COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "inner" EXCLUDE)
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite-optimize.so DESTINATION ${LIB_DIR} COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite-fp16.so DESTINATION ${LIB_DIR} COMPONENT ${COMPONENT_NAME})
install(DIRECTORY ${TOP_DIR}/third_party/flatbuffers/include DESTINATION ${FLATBF_DIR} COMPONENT ${COMPONENT_NAME})
install(DIRECTORY ${flatbuffers_INC} DESTINATION ${FLATBF_DIR} COMPONENT ${COMPONENT_NAME})
elseif (PLATFORM_ARM32)
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.so DESTINATION ${LIB_DIR} COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.a DESTINATION ${LIB_DIR} COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${INC_DIR}/ir/dtype COMPONENT ${COMPONENT_NAME})
install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${INC_DIR} COMPONENT ${COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${TOP_DIR}/mindspore/lite/schema/ DESTINATION ${INC_DIR}/schema COMPONENT ${COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "inner" EXCLUDE)
install(DIRECTORY ${TOP_DIR}/third_party/flatbuffers/include DESTINATION ${FLATBF_DIR} COMPONENT ${COMPONENT_NAME})
install(DIRECTORY ${flatbuffers_INC} DESTINATION ${FLATBF_DIR} COMPONENT ${COMPONENT_NAME})
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
get_filename_component(CXX_DIR ${CMAKE_CXX_COMPILER} PATH)
file(GLOB LIB_LIST ${CXX_DIR}/libstdc++-6.dll ${CXX_DIR}/libwinpthread-1.dll ${CXX_DIR}/libssp-0.dll ${CXX_DIR}/libgcc_s_seh-1.dll)
@ -85,11 +85,9 @@ else ()
install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${INC_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${TOP_DIR}/mindspore/lite/schema/ DESTINATION ${INC_DIR_RUN_X86}/schema COMPONENT ${RUN_X86_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "inner" EXCLUDE)
install(FILES ${TOP_DIR}/mindspore/core/ir/dtype/type_id.h DESTINATION ${INC_DIR_RUN_X86}/ir/dtype COMPONENT ${RUN_X86_COMPONENT_NAME})
install(DIRECTORY ${TOP_DIR}/third_party/flatbuffers/include DESTINATION ${FLATBF_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME})
install(DIRECTORY ${flatbuffers_INC} DESTINATION ${FLATBF_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.so DESTINATION ${LIB_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.a DESTINATION ${LIB_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME})
install(FILES ${TOP_DIR}/third_party/protobuf/build/lib/libprotobuf.so.19.0.0 DESTINATION ${PROTOBF_DIR}/lib RENAME libprotobuf.so.19 COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/third_party/flatbuffers/build/libflatbuffers.so.1.11.0 DESTINATION ${FLATBF_DIR}/lib RENAME libflatbuffers.so.1 COMPONENT ${COMPONENT_NAME})
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Windows")

View File

@ -134,7 +134,9 @@ function(__find_pkg_then_add_target pkg_name pkg_exe lib_path)
endif ()
set(${_LIB_NAME}_LIB ${_LIB_NAME}_LIB-NOTFOUND)
find_library(${_LIB_NAME}_LIB ${_LIB_SEARCH_NAME} PATHS ${${pkg_name}_BASE_DIR}/${lib_path} NO_DEFAULT_PATH)
if (NOT ${_LIB_NAME}_LIB AND BUILD_LITE AND PLATFORM_ARM)
set(${_LIB_NAME}_LIB "${${pkg_name}_BASE_DIR}/${lib_path}/lib${_LIB_SEARCH_NAME}.so")
endif(NOT ${_LIB_NAME}_LIB AND BUILD_LITE AND PLATFORM_ARM)
if(NOT ${_LIB_NAME}_LIB)
return()
endif()

View File

@ -8,6 +8,18 @@ endif ()
option(MS_VERSION_MAJOR "major version" 0)
option(MS_VERSION_MINOR "minor version" 7)
option(MS_VERSION_REVISION "revision version" 0)
option(CMAKE_BUILD_TYPE "build type" Release)
option(SUPPORT_TRAIN "if build for on-device train" off)
option(PLATFORM_ARM64 "if build device for arm64" off)
option(PLATFORM_ARM32 "if build device for arm32" off)
option(ENABLE_CONVERTER "if build converter" on)
option(ENABLE_FP16 "if build fp16 ops" off)
option(ENABLE_TOOLS "if build tools" on)
option(BUILD_TESTCASES "if build testcase" on)
option(SUPPORT_GPU "if support gpu" off)
option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
option(BUILD_MINDDATA_EXAMPLE "" on)
option(ENABLE_VERBOSE "" off)
set(DIR_PREFIX mindspore-lite)
set(MS_VERSION ${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION})
@ -15,6 +27,12 @@ set(MAIN_DIR ${DIR_PREFIX}-${MS_VERSION})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}")
set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv or full")
set(BUILD_LITE "on")
set(PLATFORM_ARM "off")
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
set(PLATFORM_ARM "on")
endif()
if (SUPPORT_GPU)
set(PROCESS_UNIT gpu)
@ -22,6 +40,9 @@ else ()
set(PROCESS_UNIT cpu)
endif ()
add_compile_definitions(NO_DLIB)
add_compile_options(-fPIC)
if (SUPPORT_TRAIN)
if (PLATFORM_ARM64)
set(COMPONENT_NAME runtime-arm64-${PROCESS_UNIT}-train)
@ -59,31 +80,20 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm)
include_directories(${TOP_DIR}/third_party)
include_directories(${TOP_DIR}/third_party/flatbuffers/include)
include_directories(${CMAKE_BINARY_DIR})
include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/dependency_utils.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
if (WIN32)
include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
endif()
include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
set(FBS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/schema/model.fbs
${CMAKE_CURRENT_SOURCE_DIR}/schema/ops.fbs
)
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src ${CMAKE_BINARY_DIR}/schema "")
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_inner_src ${CMAKE_BINARY_DIR}/schema/inner "inner")
option(CMAKE_BUILD_TYPE "build type" Release)
option(BUILD_DEVICE "if build device" on)
option(SUPPORT_TRAIN "if build for on-device train" off)
option(PLATFORM_ARM64 "if build device for arm64" off)
option(PLATFORM_ARM32 "if build device for arm32" off)
option(ENABLE_CONVERTER "if build converter" on)
option(ENABLE_TOOLS "if build tools" on)
option(BUILD_TESTCASES "if build testcase" on)
option(ENABLE_FP16 "if build fp16 ops" off)
option(SUPPORT_GPU "if support gpu" off)
option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv or full")
option(BUILD_MINDDATA_EXAMPLE "" on)
option(ENABLE_VERBOSE "" off)
add_compile_definitions(NO_DLIB)
add_compile_options(-fPIC)
string(REPLACE "-g" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE "-g" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
@ -103,9 +113,6 @@ endif ()
if (ENABLE_VERBOSE)
set(CMAKE_VERBOSE_MAKEFILE on)
endif ()
if (BUILD_DEVICE)
add_compile_definitions(BUILD_DEVICE)
endif ()
if (SUPPORT_TRAIN)
add_compile_definitions(SUPPORT_TRAIN)
endif()
@ -133,7 +140,7 @@ if (WIN32)
endif ()
if (ENABLE_CONVERTER)
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
if (PLATFORM_ARM)
MESSAGE(FATAL_ERROR "Cannot build converter in arm platform")
endif()
find_package(Python3 3.7 COMPONENTS Interpreter Development)
@ -161,27 +168,24 @@ if (ENABLE_CONVERTER)
include(${TOP_DIR}/cmake/external_libs/json.cmake)
include(${TOP_DIR}/cmake/external_libs/pybind11.cmake)
include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
include_directories(${TOP_DIR}/third_party/protobuf/build/include)
link_directories(${TOP_DIR}/third_party/protobuf/build/lib)
include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
endif ()
if (BUILD_DEVICE)
if (PLATFORM_ARM32 OR PLATFORM_ARM64)
if (NOT DEFINED ENV{ANDROID_NDK})
message(FATAL_ERROR "env ANDROID_NDK should be setted for ARM compile")
endif ()
add_compile_definitions(ENABLE_ARM)
if (PLATFORM_ARM32 OR PLATFORM_ARM64)
if (NOT DEFINED ENV{ANDROID_NDK})
message(FATAL_ERROR "env ANDROID_NDK should be setted for ARM compile")
endif ()
if (PLATFORM_ARM32)
add_definitions(-mfloat-abi=softfp -mfpu=neon)
add_compile_definitions(ENABLE_ARM32)
endif ()
if (PLATFORM_ARM64)
add_compile_definitions(ENABLE_ARM64)
if (ENABLE_FP16)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+dotprod+fp16")
endif ()
add_compile_definitions(ENABLE_ARM)
endif ()
if (PLATFORM_ARM32)
add_definitions(-mfloat-abi=softfp -mfpu=neon)
add_compile_definitions(ENABLE_ARM32)
endif ()
if (PLATFORM_ARM64)
add_compile_definitions(ENABLE_ARM64)
if (ENABLE_FP16)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+dotprod+fp16")
endif ()
endif ()
@ -218,20 +222,17 @@ if (BUILD_MINDDATA STREQUAL "lite_cv")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
endif ()
if (BUILD_DEVICE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/internal)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl)
if (NOT WIN32)
if (ENABLE_TOOLS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/time_profiler)
endif()
if (BUILD_TESTCASES)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
endif ()
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/internal)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl)
if (NOT WIN32)
if (ENABLE_TOOLS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/time_profiler)
endif()
if (BUILD_TESTCASES)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()
endif ()
include(${TOP_DIR}/cmake/package_lite.cmake)

View File

@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -I/usr/local/include -std=c++17 -Wall -fPIC"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTION_CXX_FLAGS}")
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
if (PLATFORM_ARM)
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Werror -Wno-return-std-move -Wno-unused-private-field -Wno-unused-lambda-capture -Wno-sign-compare -Wno-overloaded-virtual -Wno-unneeded-internal-declaration -Wno-unused-variable -Wno-pessimizing-move -Wno-inconsistent-missing-override -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
else()
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wl,--allow-shlib-undefined -DHALF_ENABLE_CPP11_USER_LITERALS=0 -D_FORTIFY_SOURCE=2")
@ -20,7 +20,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sequence-point")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
if (PLATFORM_ARM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
else()

View File

@ -67,9 +67,11 @@ file(GLOB_RECURSE C_OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc)
add_subdirectory(runtime/kernel/arm)
add_library(mindspore-lite SHARED ${LITE_SRC} ${C_OPS_SRC})
add_dependencies(mindspore-lite fbs_src)
set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1)
add_library(mindspore-lite_static STATIC ${LITE_SRC} ${C_OPS_SRC})
add_dependencies(mindspore-lite_static fbs_src)
set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite")
set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
@ -90,14 +92,14 @@ if (BUILD_MINDDATA STREQUAL "lite")
target_link_libraries(mindspore-lite_static minddata_eager_mid)
endif ()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND (PLATFORM_ARM64 OR PLATFORM_ARM32))
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND PLATFORM_ARM)
add_custom_command(TARGET mindspore-lite POST_BUILD
COMMAND ${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip
${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.so)
endif ()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
if (PLATFORM_ARM)
add_custom_command(TARGET mindspore-lite POST_BUILD
COMMAND ${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip
${CMAKE_BINARY_DIR}/src/libmindspore-lite.so)

View File

@ -287,7 +287,7 @@ if (BUILD_CONVERTER)
fusion_mid
quantizer_mid
pthread
protobuf
mindspore::protobuf
mindspore::eigen
mindspore::json
mindspore_core

View File

@ -5,3 +5,4 @@ set_property(SOURCE ${ANF_IMPORTER_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMOD
add_library(anf_importer_mid OBJECT
${ANF_IMPORTER_SRC_LIST}
)
add_dependencies(anf_importer_mid proto_mid)

View File

@ -34,7 +34,7 @@
#include "securec/include/securec.h"
#include "src/tensor.h"
#include "src/param_value_lite.h"
#include "tools/converter/parser/onnx/onnx.pb.h"
#include "proto/onnx.pb.h"
#include "src/common/log_adapter.h"
#include "tools/common/protobuf_utils.h"

View File

@ -23,7 +23,7 @@
#include <utility>
#include "include/errorcode.h"
#include "tools/converter/parser/onnx/onnx.pb.h"
#include "proto/onnx.pb.h"
#include "tools/converter/converter_context.h"
#include "tools/anf_importer/anf_importer.h"
#include "abstract/abstract_value.h"

View File

@ -9,6 +9,7 @@ add_executable(benchmark
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cc
${COMMON_SRC})
add_dependencies(benchmark fbs_src)
if (PLATFORM_ARM32 OR PLATFORM_ARM64)
target_link_libraries(benchmark mindspore-lite)

View File

@ -20,9 +20,9 @@
#include <string>
#include <vector>
#include "google/protobuf/message.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "proto/caffe.pb.h"
#include "include/errorcode.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
namespace mindspore {
namespace lite {

View File

@ -117,11 +117,15 @@ if (PLATFORM_ARM64)
set(KERNEL_SRC ${KERNEL_SRC} ${ASSEMBLY_SRC})
endif ()
if (WIN32)
set(PROTO_LIBRARY mindspore::protobuf)
else()
set(PROTO_LIBRARY protobuf)
endif()
file(GLOB PROTO_FILE ""
${CMAKE_CURRENT_SOURCE_DIR}/parser/caffe/caffe.proto
${CMAKE_CURRENT_SOURCE_DIR}/parser/onnx/onnx.proto)
ms_protobuf_generate(PROTO_SRCS PROTO_HDRS ${PROTO_FILE})
add_library(proto_mid OBJECT ${PROTO_SRCS})
set(TFLITE_FBS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/parser/tflite/schema.fbs
)
ms_build_flatbuffers_lite(TFLITE_FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/parser/tflite/ tflite_fbs_src ${CMAKE_BINARY_DIR}/schema "inner")
set_property(SOURCE ${CONVERTER_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
set_property(SOURCE ${CCSRC_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
@ -136,6 +140,9 @@ add_executable(converter_lite
${KERNEL_SRC}
${LITE_SRC}
)
add_dependencies(converter_lite tflite_fbs_src)
add_dependencies(converter_lite fbs_inner_src)
if (WIN32)
add_library(converter_mid OBJECT
${CCSRC_SRC}
@ -143,6 +150,7 @@ if (WIN32)
${OPS_SRC}
${KERNEL_SRC}
${LITE_SRC}
${PROTO_SRCS}
)
add_library(converter_parser STATIC
$<TARGET_OBJECTS:tflite_parser_mid>
@ -166,13 +174,15 @@ target_link_libraries(converter_lite PRIVATE
graph_pass_mid
fusion_mid
quantizer_mid
pthread
${PROTO_LIBRARY}
proto_mid
${SECUREC_LIBRARY}
mindspore::json
mindspore::eigen
mindspore_core
mindspore::glog
mindspore::protobuf
mindspore::flatbuffers
pthread
)
if (NOT PLATFORM_ARM64 AND NOT PLATFORM_ARM32)

View File

@ -30,7 +30,7 @@
#include "parser/onnx/onnx_converter.h"
#include "tools/anf_exporter/anf_exporter.h"
#include "tools/anf_importer/import_from_protobuf.h"
#include "tools/converter/parser/onnx/onnx.pb.h"
#include "proto/onnx.pb.h"
#include "tools/converter/quantizer/post_training_quantizer.h"
#include "tools/converter/quantizer/quant_cast.h"
#include "include/version.h"

View File

@ -21,7 +21,7 @@
#include "src/common/log_adapter.h"
#include "tools/common/graph_util.h"
#include "include/errorcode.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
namespace mindspore {
namespace lite {

View File

@ -23,7 +23,7 @@
#include "securec/include/securec.h"
#include "tools/common/graph_util.h"
#include "include/errorcode.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
namespace mindspore {
namespace lite {

View File

@ -24,7 +24,7 @@
#include "src/common/utils.h"
#include "tools/common/graph_util.h"
#include "include/errorcode.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
#include "mindspore/core/ir/dtype/type_id.h"
namespace mindspore {

View File

@ -3,3 +3,5 @@ file(GLOB_RECURSE CAFFE_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
set_property(SOURCE ${CAFFE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
add_library(caffe_parser_mid OBJECT ${CAFFE_SRC_LIST})
add_dependencies(caffe_parser_mid proto_mid)

View File

@ -21,7 +21,7 @@
#include <string>
#include <unordered_map>
#include <memory>
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "proto/caffe.pb.h"
#include "include/errorcode.h"
namespace mindspore {

View File

@ -23,7 +23,7 @@
#include <set>
#include <unordered_map>
#include "tools/converter/model_parser.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "proto/caffe.pb.h"
#include "tools/common/tensor_util.h"
namespace mindspore {

View File

@ -21,7 +21,7 @@
#include <vector>
#include "google/protobuf/message.h"
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "proto/caffe.pb.h"
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "include/errorcode.h"
#include "src/common/log_adapter.h"

View File

@ -20,7 +20,7 @@
#include <string>
#include <unordered_map>
#include "tools/converter/parser/caffe/caffe_node_parser.h"
#include "tools/converter/parser/caffe/caffe.pb.h"
#include "proto/caffe.pb.h"
namespace mindspore::lite {
class CaffeNodeParserRegistry {

View File

@ -3,3 +3,4 @@ set_property(SOURCE ${ONNX_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=m
add_library(onnx_parser_mid OBJECT
${ONNX_SRC_LIST}
)
add_dependencies(onnx_parser_mid proto_mid)

View File

@ -30,7 +30,7 @@
#include "tools/converter/model_parser.h"
#include "tools/converter/parser/onnx/onnx_node_parser_registry.h"
#include "tools/common/tensor_util.h"
#include "tools/converter/parser/onnx/onnx.pb.h"
#include "proto/onnx.pb.h"
namespace mindspore {
namespace lite {

View File

@ -20,7 +20,7 @@
#include <string>
#include <vector>
#include "google/protobuf/message.h"
#include "tools/converter/parser/onnx/onnx.pb.h"
#include "proto/onnx.pb.h"
#include "include/errorcode.h"
#include "src/common/log_adapter.h"
#include "schema/inner/model_generated.h"

View File

@ -2,15 +2,7 @@ file(GLOB_RECURSE TFLITE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.cc
)
set_property(SOURCE ${TFLITE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
if (NOT WIN32)
ADD_DEFINITIONS(-DFLATBUFFERS_LOCALE_INDEPENDENT=1)
find_library(FLATBUFFERS_LIBRARY flatbuffers HINTS ${TOP_DIR}/third_party/flatbuffers/build)
endif ()
add_library(tflite_parser_mid OBJECT
${TFLITE_SRC_LIST}
)
if (WIN32)
target_link_libraries(tflite_parser_mid mindspore::flatbuffers)
else ()
target_link_libraries(tflite_parser_mid ${FLATBUFFERS_LIBRARY})
endif ()
target_link_libraries(tflite_parser_mid mindspore::flatbuffers)

View File

@ -31,7 +31,7 @@
#include "tools/converter/model_parser.h"
#include "tools/converter/parser/tflite/tflite_node_parser_registry.h"
#include "tools/common/tensor_util.h"
#include "mindspore/lite/schema/inner/model_generated.h"
#include "schema/inner/model_generated.h"
namespace mindspore {
namespace lite {

View File

@ -24,7 +24,7 @@
#include <utility>
#include "src/common/log_adapter.h"
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/tflite/schema_generated.h"
#include "schema/schema_generated.h"
#include "tools/common/tensor_util.h"
#include "ir/dtype/type_id.h"
#include "include/errorcode.h"

View File

@ -23,7 +23,7 @@
#include <memory>
#include "src/common/log_adapter.h"
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/tflite/schema_generated.h"
#include "schema/schema_generated.h"
#include "schema/inner/ops_generated.h"
#include "ir/dtype/type_id.h"
#include "include/errorcode.h"