|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- cmake_minimum_required(VERSION 3.14)
- project(Lite)
-
- if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
- message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
- 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(COMPILE_LITE "compile for lite" 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_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(GPU_OPENCL "if support gpu opencl" off)
- option(GPU_VULKAN "if support gpu vulkan" off)
- option(GPU_CUDA "if support gpu cuda" off)
- option(SUPPORT_NPU "if support npu" off)
- option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
- option(BUILD_MINDDATA_EXAMPLE "" on)
- option(ENABLE_VERBOSE "" off)
- option(ENABLE_SSE "if x86_64 support SSE instruction set" off)
- option(ENABLE_AVX "if x86_64 support SSE instruction set" off)
- option(ENABLE_MINDRT "if support mindrt" on)
-
- set(DIR_PREFIX mindspore-lite)
- set(MS_VERSION ${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION})
- 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, wrapper or full")
- set(BUILD_LITE "on")
- set(PLATFORM_ARM "off")
- if(PLATFORM_ARM64 OR PLATFORM_ARM32)
- set(PLATFORM_ARM "on")
- #set for cross-compiling toolchain
- set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
- set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
- set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
- endif()
-
- #if(BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper")
- if(SUPPORT_GPU)
- set(PROCESS_UNIT gpu)
- elseif(SUPPORT_NPU)
- set(PROCESS_UNIT npu)
- else()
- set(PROCESS_UNIT cpu)
- endif()
-
-
- if(SUPPORT_NPU)
- set(DDK_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib")
- if(PLATFORM_ARM64)
- set(DDK_LIB_PATH ${DDK_PATH}/lib64)
- elseif(PLATFORM_ARM32)
- set(DDK_LIB_PATH ${DDK_PATH}/lib)
- endif()
- add_compile_definitions(SUPPORT_NPU)
- endif()
-
- add_compile_definitions(NO_DLIB)
- add_compile_options(-fPIC)
-
- if(SUPPORT_TRAIN)
- set(BUILD_MINDDATA "full")
- if(PLATFORM_ARM64)
- set(RUNTIME_COMPONENT_NAME train-android-aarch64)
- elseif(PLATFORM_ARM32)
- set(RUNTIME_COMPONENT_NAME train-android-aarch32)
- elseif(WIN32)
- set(RUNTIME_COMPONENT_NAME train-win-x64)
- else()
- set(RUNTIME_COMPONENT_NAME train-linux-x64)
- endif()
- else()
- if(PLATFORM_ARM64)
- set(RUNTIME_COMPONENT_NAME inference-android-aarch64)
- elseif(PLATFORM_ARM32)
- set(RUNTIME_COMPONENT_NAME inference-android-aarch32)
- elseif(WIN32)
- if("${X86_64_SIMD}" STREQUAL "off")
- set(RUNTIME_COMPONENT_NAME inference-win-x64)
- else()
- set(RUNTIME_COMPONENT_NAME inference-win-x64-${X86_64_SIMD})
- endif()
- else()
- if("${X86_64_SIMD}" STREQUAL "off")
- set(RUNTIME_COMPONENT_NAME inference-linux-x64)
- else()
- set(RUNTIME_COMPONENT_NAME inference-linux-x64-${X86_64_SIMD})
- endif()
- endif()
- endif()
-
- string(REPLACE "/mindspore/lite" "" TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
- set(CORE_DIR ${TOP_DIR}/mindspore/core)
- set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
- include_directories(${TOP_DIR})
- include_directories(${CORE_DIR})
- include_directories(${CORE_DIR}/ir)
- include_directories(${CCSRC_DIR})
- include_directories(${CMAKE_CURRENT_SOURCE_DIR})
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm)
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
- include_directories(${TOP_DIR}/third_party)
- include_directories(${CMAKE_BINARY_DIR})
- include_directories(${CCSRC_DIR}/minddata/dataset/liteapi)
-
- include(${TOP_DIR}/cmake/utils.cmake)
- include(${TOP_DIR}/cmake/dependency_utils.cmake)
- include(${TOP_DIR}/cmake/dependency_securec.cmake)
- include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
- if(SUPPORT_GPU STREQUAL opencl)
- include(${TOP_DIR}/cmake/external_libs/opencl.cmake)
- endif()
- if(SUPPORT_GPU STREQUAL vulkan)
- include(${TOP_DIR}/cmake/external_libs/vulkan.cmake)
- endif()
-
- if(ENABLE_CONVERTER OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper")
- include(${TOP_DIR}/cmake/external_libs/json.cmake)
- endif()
-
- if(SUPPORT_TRAIN OR WIN32)
- set(ENABLE_MINDRT "off")
- endif()
-
- if(DEFINED ARCHS)
- add_definitions(-DMS_COMPILE_IOS)
- endif()
-
- file(GLOB FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.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")
-
- string(REPLACE "-g" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
- string(REPLACE "-g" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDebug -g")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDebug -g")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
- else()
- ## enable for binscope for release
- set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \
- -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}")
- set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \
- -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}")
- if(NOT WIN32)
- set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_SHARED_LINKER_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_EXE_LINKER_FLAGS}")
- endif()
- endif()
- if(ENABLE_VERBOSE)
- set(CMAKE_VERBOSE_MAKEFILE on)
- endif()
- if(SUPPORT_TRAIN)
- add_compile_definitions(SUPPORT_TRAIN)
- endif()
- if(ENABLE_NEON)
- add_compile_definitions(ENABLE_NEON)
- endif()
- if(ENABLE_FP16)
- add_compile_definitions(ENABLE_FP16)
- endif()
- if(SUPPORT_GPU STREQUAL opencl)
- add_definitions(-DGPU_OPENCL)
- gene_opencl(${CMAKE_CURRENT_SOURCE_DIR})
- add_definitions(-DUSE_OPENCL_WRAPPER)
- add_definitions(-DMS_OPENCL_PROFILE=false)
- add_definitions(-DCL_TARGET_OPENCL_VERSION=200)
- add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=120)
- add_definitions(-DCL_HPP_MINIMUM_OPENCL_VERSION=120)
- add_compile_definitions(SUPPORT_GPU)
- if(OFFLINE_COMPILE)
- add_compile_definitions(PROGRAM_WITH_IL)
- endif()
- include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-headers-src/)
- include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-clhpp-src/include)
- endif()
- if(SUPPORT_GPU STREQUAL vulkan)
- add_definitions(-DGPU_VULKAN)
- add_definitions(-DVK_NO_PROTOTYPES)
- add_compile_definitions(SUPPORT_GPU)
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/_deps/vulkan-headers-src/include)
- endif()
- if(SUPPORT_GPU STREQUAL cuda)
- add_definitions(-DGPU_CUDA)
- add_compile_definitions(SUPPORT_GPU)
- endif()
-
- if(WIN32)
- add_compile_definitions(LITE_EXPORTS)
- add_compile_definitions(BUILDING_DLL)
- endif()
-
- if(ENABLE_MINDRT)
- include_directories(${CORE_DIR}/mindrt/include)
- endif()
-
- if(ENABLE_CONVERTER)
- if(PLATFORM_ARM)
- MESSAGE(FATAL_ERROR "Cannot build converter in arm platform")
- endif()
- include_directories(${PYTHON_INCLUDE_DIRS})
- include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
- include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
- endif()
-
- if(ENABLE_MINDRT)
- add_compile_definitions(ENABLE_MINDRT)
- endif()
-
-
- if(PLATFORM_ARM32 OR PLATFORM_ARM64)
- if(NOT APPLE AND NOT DEFINED ENV{ANDROID_NDK})
- message(FATAL_ERROR "env ANDROID_NDK should be set for ARM compile")
- 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)
- endif()
-
- if(PLATFORM_ARM32 OR PLATFORM_ARM64)
- if(ENABLE_CONVERTER)
- set(BUILD_MINDDATA "off")
- endif()
- endif()
-
- if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
- if("${X86_64_SIMD}" STREQUAL "sse")
- add_compile_definitions(ENABLE_SSE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
- endif()
- if("${X86_64_SIMD}" STREQUAL "avx")
- add_compile_definitions(ENABLE_SSE)
- add_compile_definitions(ENABLE_AVX)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx -mfma")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx -mfma")
- endif()
- endif()
-
- if(BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full" OR BUILD_MINDDATA STREQUAL "wrapper")
- add_compile_definitions(ENABLE_ANDROID)
- if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
- add_compile_definitions(ENABLE_MD_LITE_X86_64)
- endif()
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
- endif()
-
- if(BUILD_MINDDATA STREQUAL "lite_cv")
- add_compile_definitions(ENABLE_ANDROID)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
- endif()
-
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)
- if(NOT APPLE AND ENABLE_TOOLS)
- if(SUPPORT_TRAIN)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark_train)
- else()
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
- endif()
- endif()
- if(NOT WIN32)
- if(ENABLE_TOOLS)
- if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/cropper)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen)
- add_dependencies(fbs_src gen_ops)
- add_dependencies(fbs_inner_src gen_ops)
- endif()
- endif()
- if(BUILD_TESTCASES)
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
- endif()
- endif()
-
- if(NOT APPLE)
- include(${TOP_DIR}/cmake/package_lite.cmake)
- endif()
|