diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 3fbf3b89a14..27cb1a6fb89 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -13,7 +13,7 @@ set(MSLITE_GPU_BACKEND "" CACHE STRING "enable gpu backend, \ set(MSLITE_REGISTRY_DEVICE "off" CACHE STRING "Compile Mindspore Lite that supports specific devices, \ currently supported devices: Hi3516D/Hi3519A/Hi3559A/SD3403") set(MSLITE_MICRO_PLATFORM "auto" CACHE STRING "Platform of micro static library micro static, \ - currently supported : cortex-m7/auto") + currently supported : cortex-m7/cortex-m4/cortex-m33/auto") option(MSLITE_ENABLE_NPU "enable npu, only arm64 or arm32 support" off) option(MSLITE_ENABLE_TRAIN "enable train" on) option(MSLITE_ENABLE_SSE "enable SSE instruction set, only x86_64 support" off) @@ -532,9 +532,7 @@ elseif(WIN32) set(RUNTIME_COMPONENT_NAME "win-x64") endif() elseif(PLATFORM_MCU) - if(TOOLCHAIN_NAME STREQUAL "cortex-m7") - set(RUNTIME_COMPONENT_NAME "none-cortex-m7") - endif() + set(RUNTIME_COMPONENT_NAME "none-${TOOLCHAIN_NAME}") else() if((CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") AND MSLITE_ENABLE_ACL) set(RUNTIME_COMPONENT_NAME "linux-aarch64") diff --git a/mindspore/lite/build_lite.sh b/mindspore/lite/build_lite.sh index 06873835089..522b1a324fa 100755 --- a/mindspore/lite/build_lite.sh +++ b/mindspore/lite/build_lite.sh @@ -270,7 +270,7 @@ build_lite() { elif [[ ("${MSLITE_ENABLE_NNIE}" == "on" || "${MSLITE_REGISTRY_DEVICE}" == "Hi3516D") && "${local_lite_platform}" == "x86_64" ]]; then MSLITE_REGISTRY_DEVICE=Hi3516D elif [[ "${MSLITE_MICRO_PLATFORM}" == cortex-m* && "${local_lite_platform}" == "x86_64" ]]; then - TOOLCHAIN_NAME="cortex-m7" + TOOLCHAIN_NAME=${MSLITE_MICRO_PLATFORM} fi machine=`uname -m` @@ -353,9 +353,9 @@ build_lite() { echo "Use the '-I arm64' command when compiling MindSpore Lite on an aarch64 architecture system." exit 1 fi - if [[ "${TOOLCHAIN_NAME}" == "cortex-m7" ]]; then - CMAKE_TOOLCHAIN_FILE=${BASEPATH}/mindspore/lite/cmake/cortex-m7.toolchain.cmake - LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DTOOLCHAIN_NAME=cortex-m7" + if [[ "${TOOLCHAIN_NAME}" == cortex-m* ]]; then + CMAKE_TOOLCHAIN_FILE=${BASEPATH}/mindspore/lite/cmake/${TOOLCHAIN_NAME}.toolchain.cmake + LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DTOOLCHAIN_NAME=${TOOLCHAIN_NAME}" LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DPLATFORM_MCU=on" LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_MINDDATA_IMPLEMENT=off -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off -DMSLITE_ENABLE_TOOLS=off" else diff --git a/mindspore/lite/cmake/cortex-m33.toolchain.cmake b/mindspore/lite/cmake/cortex-m33.toolchain.cmake new file mode 100644 index 00000000000..7bd1840c14a --- /dev/null +++ b/mindspore/lite/cmake/cortex-m33.toolchain.cmake @@ -0,0 +1,39 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +find_program(arm-none-eabi-gcc_EXE arm-none-eabi-gcc) +if(NOT arm-none-eabi-gcc_EXE) + message(FATAL_ERROR "Required C COMPILER arm-none-eabi-gcc not found, " + "please install the package and try building MindSpore again.") +else() + message("Find C COMPILER PATH: ${arm-none-eabi-gcc_EXE}") +endif() + +find_program(arm-none-eabi-g++_EXE arm-none-eabi-g++) +if(NOT arm-none-eabi-g++_EXE) + message(FATAL_ERROR "Required CXX COMPILER arm-none-eabi-g++ not found, " + "please install the package and try building MindSpore again.") +else() + message("Find CXX COMPILER PATH: ${arm-none-eabi-g++_EXE}") +endif() + +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_CXX_COMPILER arm-none-eabi-g++) + +set(CMAKE_CXX_FLAGS "-mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -std=gnu11 \ +-specs=nosys.specs -specs=nano.specs") +set(CMAKE_C_FLAGS "-mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -std=gnu11 \ +-specs=nosys.specs -specs=nano.specs") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(CROSS_COMPILATION_ARM contex-m33) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") + +SET(CMAKE_C_COMPILER_WORKS TRUE) +SET(CMAKE_CXX_COMPILER_WORKS TRUE) +SET(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") diff --git a/mindspore/lite/cmake/cortex-m4.toolchain.cmake b/mindspore/lite/cmake/cortex-m4.toolchain.cmake new file mode 100644 index 00000000000..710ee00eaf2 --- /dev/null +++ b/mindspore/lite/cmake/cortex-m4.toolchain.cmake @@ -0,0 +1,37 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +find_program(arm-none-eabi-gcc_EXE arm-none-eabi-gcc) +if(NOT arm-none-eabi-gcc_EXE) + message(FATAL_ERROR "Required C COMPILER arm-none-eabi-gcc not found, " + "please install the package and try building MindSpore again.") +else() + message("Find C COMPILER PATH: ${arm-none-eabi-gcc_EXE}") +endif() + +find_program(arm-none-eabi-g++_EXE arm-none-eabi-g++) +if(NOT arm-none-eabi-g++_EXE) + message(FATAL_ERROR "Required CXX COMPILER arm-none-eabi-g++ not found, " + "please install the package and try building MindSpore again.") +else() + message("Find CXX COMPILER PATH: ${arm-none-eabi-g++_EXE}") +endif() + +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_CXX_COMPILER arm-none-eabi-g++) + +set(CMAKE_CXX_FLAGS "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nosys.specs -specs=nano.specs") +set(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -specs=nosys.specs -specs=nano.specs") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(CROSS_COMPILATION_ARM contex-m4) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") + +SET(CMAKE_C_COMPILER_WORKS TRUE) +SET(CMAKE_CXX_COMPILER_WORKS TRUE) +SET(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")