From ea93087683f4882a55c3dfa209635248e03ddb1a Mon Sep 17 00:00:00 2001 From: sunsuodong Date: Sat, 31 Jul 2021 10:46:37 +0800 Subject: [PATCH] :support vs build --- build.bat | 12 +- cmake/external_libs/flatbuffers.cmake | 13 ++- cmake/external_libs/json.cmake | 10 +- cmake/package_lite.cmake | 31 +++-- .../kernel_compiler/cpu/nnacl/CMakeLists.txt | 19 +-- mindspore/lite/CMakeLists.txt | 110 ++++++++++-------- .../lite/cmake/ohos-lite.toolchain.cmake | 1 - mindspore/lite/java/native/CMakeLists.txt | 1 + mindspore/lite/micro/coder/CMakeLists.txt | 12 +- mindspore/lite/micro/coder/coder.cc | 1 - .../lite/micro/coder/generator/generator.h | 5 + .../nnacl_serializer/nnacl_fp32_serializer.h | 1 + mindspore/lite/micro/coder/utils/dir_utils.cc | 5 + mindspore/lite/src/CMakeLists.txt | 13 ++- mindspore/lite/src/common/utils.cc | 3 +- mindspore/lite/tools/benchmark/CMakeLists.txt | 2 + mindspore/lite/tools/common/tensor_util.h | 6 +- mindspore/lite/tools/converter/CMakeLists.txt | 5 +- third_party/securec/CMakeLists.txt | 22 ++-- 19 files changed, 173 insertions(+), 99 deletions(-) diff --git a/build.bat b/build.bat index 85226743559..03b43ed7830 100644 --- a/build.bat +++ b/build.bat @@ -55,9 +55,15 @@ IF "%1%" == "lite" ( echo "======Start building MindSpore Lite %VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_REVISION%======" rd /s /q "%BASE_PATH%\output" (git log -1 | findstr "^commit") > %BUILD_PATH%\.commit_id - cmake -DPLATFORM_X86_64=on -DBUILD_MINDDATA=off -DMSLITE_ENABLE_TRAIN=off ^ - -DMS_VERSION_MAJOR=%VERSION_MAJOR% -DMS_VERSION_MINOR=%VERSION_MINOR% -DMS_VERSION_REVISION=%VERSION_REVISION% ^ - -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - MinGW Makefiles" "%BASE_PATH%/mindspore/lite" + IF defined VisualStudioVersion ( + cmake -DBUILD_MINDDATA=off -DMSLITE_ENABLE_TRAIN=off ^ + -DMS_VERSION_MAJOR=%VERSION_MAJOR% -DMS_VERSION_MINOR=%VERSION_MINOR% -DMS_VERSION_REVISION=%VERSION_REVISION% ^ + -DCMAKE_BUILD_TYPE=Release -G "Ninja" "%BASE_PATH%/mindspore/lite" + ) ELSE ( + cmake -DBUILD_MINDDATA=off -DMSLITE_ENABLE_TRAIN=off ^ + -DMS_VERSION_MAJOR=%VERSION_MAJOR% -DMS_VERSION_MINOR=%VERSION_MINOR% -DMS_VERSION_REVISION=%VERSION_REVISION% ^ + -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - MinGW Makefiles" "%BASE_PATH%/mindspore/lite" + ) ) ELSE ( cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^ -G "CodeBlocks - MinGW Makefiles" ../.. diff --git a/cmake/external_libs/flatbuffers.cmake b/cmake/external_libs/flatbuffers.cmake index 53855203207..182632b09f1 100644 --- a/cmake/external_libs/flatbuffers.cmake +++ b/cmake/external_libs/flatbuffers.cmake @@ -1,5 +1,12 @@ -set(flatbuffers_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") -set(flatbuffers_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") +if(MSVC) + set(flatbuffers_CXXFLAGS "${CMAKE_CXX_FLAGS}") + set(flatbuffers_CFLAGS "${CMAKE_CXX_FLAGS}") + set(flatbuffers_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") +else() + set(flatbuffers_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") + set(flatbuffers_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") +endif() + if(WIN32) set(flatbuffers_USE_STATIC_LIBS ON) endif() @@ -30,7 +37,7 @@ else() URL ${REQ_URL} MD5 ${MD5} CMAKE_OPTION -DCMAKE_C_COMPILER=${FLATC_GCC_COMPILER} -DCMAKE_CXX_COMPILER=${FLATC_GXX_COMPILER} - -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_INSTALL_LIBDIR=lib) + -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release) endif() include_directories(${flatbuffers_INC}) diff --git a/cmake/external_libs/json.cmake b/cmake/external_libs/json.cmake index afed5c7d76d..ef9196d19fc 100644 --- a/cmake/external_libs/json.cmake +++ b/cmake/external_libs/json.cmake @@ -1,5 +1,11 @@ -set(nlohmann_json_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") -set(nlohmann_json_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") +if(MSVC) + set(flatbuffers_CXXFLAGS "${CMAKE_CXX_FLAGS}") + set(flatbuffers_CFLAGS "${CMAKE_CXX_FLAGS}") + set(flatbuffers_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") +else() + set(nlohmann_json_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") + set(nlohmann_json_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") +endif() if(ENABLE_GITEE) set(REQ_URL "https://gitee.com/mirrors/JSON-for-Modern-CPP/repository/archive/v3.6.1.zip") diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 0fbe2fcefc4..4b6d97cafd4 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -359,13 +359,18 @@ elseif(WIN32) __install_micro_codegen() endif() if(MSLITE_ENABLE_TOOLS) - install(TARGETS ${BENCHMARK_NAME} RUNTIME DESTINATION ${BENCHMARK_ROOT_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + if(MSVC) + install(FILES ${TOP_DIR}/build/mindspore/tools/benchmark/${BENCHMARK_NAME}.exe + DESTINATION ${BENCHMARK_ROOT_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + else() + install(TARGETS ${BENCHMARK_NAME} RUNTIME DESTINATION ${BENCHMARK_ROOT_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + endif() if(SUPPORT_TRAIN) install(TARGETS ${BENCHMARK_TRAIN_NAME} RUNTIME DESTINATION ${BENCHMARK_TRAIN_ROOT_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() endif() - install(FILES ${LIB_LIST} DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) if(SUPPORT_TRAIN) install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${RUNTIME_INC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "*registry.h" EXCLUDE) @@ -384,12 +389,22 @@ elseif(WIN32) COMPONENT ${RUNTIME_COMPONENT_NAME}) install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE) - install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR} - COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll.a DESTINATION ${RUNTIME_LIB_DIR} - COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll DESTINATION ${RUNTIME_LIB_DIR} - COMPONENT ${RUNTIME_COMPONENT_NAME}) + if(MSVC) + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.lib DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll.lib DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + else() + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll.a DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/build/mindspore/src/${MINDSPORE_LITE_LIB_NAME}.dll DESTINATION ${RUNTIME_LIB_DIR} + COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${LIB_LIST} DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + endif() else() if(SUPPORT_TRAIN) install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${RUNTIME_INC_DIR} diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt index 9ffeb66be10..c9986d8a7bb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt @@ -13,14 +13,17 @@ if(PLATFORM_ARM32 OR PLATFORM_ARM64) -ffunction-sections -fdata-sections -ffast-math") endif() endif() -if("${X86_64_SIMD}" STREQUAL "avx") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2 -mfma") -endif() -if("${X86_64_SIMD}" STREQUAL "avx512") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2 -mfma") -endif() -if("${X86_64_SIMD}" STREQUAL "sse") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") + +if(NOT MSVC) + if("${X86_64_SIMD}" STREQUAL "avx") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2 -mfma") + endif() + if("${X86_64_SIMD}" STREQUAL "avx512") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2 -mfma") + endif() + if("${X86_64_SIMD}" STREQUAL "sse") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") + endif() endif() ########################### files ########################### diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 336bddb0bad..38207a4edad 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -1,10 +1,9 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.12) project(Lite) set(BUILD_LITE "on") if(TOOLCHAIN_NAME STREQUAL "himix200") set(TARGET_HIMIX200 on) - set(ENABLE_MINDRT off) add_compile_definitions(SUPPORT_NNIE) elseif(TOOLCHAIN_NAME STREQUAL "ohos-lite") set(TARGET_OHOS_LITE on) @@ -39,6 +38,8 @@ option(ENABLE_VERBOSE "" off) option(ENABLE_MINDRT "if support mindrt" on) option(ENABLE_MODEL_OBF "if support model obfuscation" off) option(ENABLE_V0 "support v0 schema" on) +set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv, wrapper or full") + if(APPLE) find_package(Patch) if(NOT Patch_FOUND) @@ -134,6 +135,10 @@ if(MSLITE_ENABLE_NPU) endif() endif() +if(TARGET_HIMIX200 OR TARGET_OHOS_LITE) + set(ENABLE_MINDRT off) +endif() + message(STATUS "************MindSpore Lite Build Option:************") message(STATUS "\tMSLITE_GPU_BACKEND = \t${MSLITE_GPU_BACKEND}") message(STATUS "\tMSLITE_ENABLE_NPU = \t${MSLITE_ENABLE_NPU}") @@ -153,8 +158,42 @@ if(ENABLE_ASAN) endif() set(PKG_NAME_PREFIX mindspore-lite-${MS_VERSION_MAJOR}.${MS_VERSION_MINOR}.${MS_VERSION_REVISION}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") -set(BUILD_MINDDATA "lite_cv" CACHE STRING "off, lite, lite_cv, wrapper or full") +set(CMAKE_SKIP_RPATH TURE) + +if(MSVC) + add_compile_definitions(SUPPORT_MSVC) + add_compile_definitions(_ENABLE_ATOMIC_ALIGNMENT_FIX) + set(CMAKE_C_FLAGS "/O2 /EHsc /GS /Zi /utf-8") + set(CMAKE_CXX_FLAGS "/O2 /EHsc /GS /Zi /utf-8 /std:c++17") + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CMAKE_SHARED_LINKER_FLAGS "/SAFESEH ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "/SAFESEH ${CMAKE_EXE_LINKER_FLAGS}") + endif() + set(CMAKE_SHARED_LINKER_FLAGS "/NXCOMPAT /DYNAMICBASE /DEBUG ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "/NXCOMPAT /DYNAMICBASE /DEBUG ${CMAKE_EXE_LINKER_FLAGS}") +else() + string(REPLACE "-g" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "-g" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(LITE_COMPILE_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ + -Wno-deprecated-declarations -Wno-missing-braces") + set(CMAKE_C_FLAGS "${LITE_COMPILE_FLAGS} ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS_DEBUG "-DDebug -g -fvisibility=default") + + set(CMAKE_CXX_FLAGS "${LITE_COMPILE_FLAGS} -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS_DEBUG "-DDebug -g -fvisibility=default") + + if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-seh ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-seh ${CMAKE_EXE_LINKER_FLAGS}") + endif() + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase ${CMAKE_EXE_LINKER_FLAGS}") + else() + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack -s ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack -s -pie ${CMAKE_EXE_LINKER_FLAGS}") + endif() +endif() if(SUPPORT_NPU) set(DDK_PATH "$ENV{HWHIAI_DDK}/ddk/ai_ddk_lib") @@ -170,10 +209,6 @@ endif() add_compile_definitions(NO_DLIB) add_compile_options(-fPIC) -if(SUPPORT_TRAIN) - set(BUILD_MINDDATA "full") -endif() - if(PLATFORM_ARM64) set(RUNTIME_COMPONENT_NAME "android-aarch64") elseif(PLATFORM_ARM32) @@ -237,32 +272,6 @@ ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src 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(WIN32) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-seh ${CMAKE_SHARED_LINKER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-seh ${CMAKE_EXE_LINKER_FLAGS}") - endif() - set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase ${CMAKE_SHARED_LINKER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase ${CMAKE_EXE_LINKER_FLAGS}") - else() - 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() @@ -357,7 +366,7 @@ if(PLATFORM_ARM64) add_compile_definitions(ENABLE_ARM) endif() -if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64) +if(NOT PLATFORM_ARM) if(MSLITE_ENABLE_AVX) set(X86_64_SIMD "avx") add_compile_definitions(ENABLE_SSE) @@ -367,8 +376,10 @@ if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64) elseif(MSLITE_ENABLE_SSE) set(X86_64_SIMD "sse") add_compile_definitions(ENABLE_SSE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") + if(NOT MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") + endif() endif() endif() @@ -390,24 +401,21 @@ add_subdirectory(${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl build) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder) -if(NOT APPLE AND MSLITE_ENABLE_TOOLS) +if(MSLITE_ENABLE_TOOLS) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark) if(SUPPORT_TRAIN) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark_train) endif() - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark) + if(NOT PLATFORM_ARM AND NOT WIN32) + 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(NOT WIN32) - if(MSLITE_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(MSLITE_ENABLE_TESTCASES) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) - endif() + +if(NOT WIN32 AND MSLITE_ENABLE_TESTCASES) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) endif() if(NOT APPLE) diff --git a/mindspore/lite/cmake/ohos-lite.toolchain.cmake b/mindspore/lite/cmake/ohos-lite.toolchain.cmake index c8049becedb..3045268a511 100644 --- a/mindspore/lite/cmake/ohos-lite.toolchain.cmake +++ b/mindspore/lite/cmake/ohos-lite.toolchain.cmake @@ -20,7 +20,6 @@ set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINKER} ${MY_LINK_FLAGS} -o ") set(CMAKE_SYSROOT ${OHOS_SYSROOT_PATH}) -set(ENABLE_MINDRT "off") find_path(GCC_PATH gcc) find_path(GXX_PATH g++) if(NOT ${GCC_PATH} STREQUAL "GCC_PATH-NOTFOUND" AND NOT ${GXX_PATH} STREQUAL "GXX_PATH-NOTFOUND") diff --git a/mindspore/lite/java/native/CMakeLists.txt b/mindspore/lite/java/native/CMakeLists.txt index af1a706b24b..1b7a4e38e57 100644 --- a/mindspore/lite/java/native/CMakeLists.txt +++ b/mindspore/lite/java/native/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10) project(Lite-java) set(BUILD_LITE "on") +set(CMAKE_SKIP_RPATH TURE) if(PLATFORM_ARM64 OR PLATFORM_ARM32) set(PLATFORM_ARM "on") diff --git a/mindspore/lite/micro/coder/CMakeLists.txt b/mindspore/lite/micro/coder/CMakeLists.txt index 3b89b00f9ef..fc79cee63b1 100644 --- a/mindspore/lite/micro/coder/CMakeLists.txt +++ b/mindspore/lite/micro/coder/CMakeLists.txt @@ -15,17 +15,21 @@ endif() #include 3rd include_directories(${3RD_DIR}) include_directories(${3RD_DIR}/flatbuffers/include) + #include ms include_directories(${TOP_DIR}/) include_directories(${TOP_DIR}/mindspore/core/) include_directories(${NNACL_DIR}/../) include_directories(${LITE_DIR}) include_directories(${MICRO_DIR}) + #include coder -include(${TOP_DIR}/cmake/external_libs/cmsis.cmake) -include(${MICRO_DIR}/cmake/file_list.cmake) -include(${MICRO_DIR}/cmake/package_wrapper.cmake) -add_subdirectory(wrapper) +if(NOT MSVC) + include(${TOP_DIR}/cmake/external_libs/cmsis.cmake) + include(${MICRO_DIR}/cmake/file_list.cmake) + include(${MICRO_DIR}/cmake/package_wrapper.cmake) + add_subdirectory(wrapper) +endif() if(MSLITE_ENABLE_CONVERTER) add_executable(codegen main.cc ${FILE_SET}) diff --git a/mindspore/lite/micro/coder/coder.cc b/mindspore/lite/micro/coder/coder.cc index 93486f493f9..48696bac646 100644 --- a/mindspore/lite/micro/coder/coder.cc +++ b/mindspore/lite/micro/coder/coder.cc @@ -14,7 +14,6 @@ * limitations under the License. */ #include "coder/coder.h" -#include #include #include #include diff --git a/mindspore/lite/micro/coder/generator/generator.h b/mindspore/lite/micro/coder/generator/generator.h index 2e04140fa89..b16ba705a40 100644 --- a/mindspore/lite/micro/coder/generator/generator.h +++ b/mindspore/lite/micro/coder/generator/generator.h @@ -66,10 +66,15 @@ class Generator { int CodeSessionImplement(); std::string cmake_file_name_{"net.cmake"}; +#ifdef _MSC_VER + unsigned int user_umask_ = 18; + unsigned int origin_umask_ = 0; +#else // the user's generated file's permission mode_t user_umask_ = 0022; // the origin file's permission mode_t origin_umask_ = 0000; +#endif }; } // namespace mindspore::lite::micro diff --git a/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h b/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h index f4f5b692fcc..f7ce3bfdba2 100644 --- a/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h +++ b/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_fp32_serializer.h @@ -35,6 +35,7 @@ #include "nnacl/fp32/exp_fp32.h" #include "nnacl/fp32/strided_slice_fp32.h" #include "wrapper/fp32/arithmetic_fp32_wrapper.h" + namespace mindspore::lite::micro::nnacl { class NNaclFp32Serializer : public Serializer { diff --git a/mindspore/lite/micro/coder/utils/dir_utils.cc b/mindspore/lite/micro/coder/utils/dir_utils.cc index f90427c37be..f9fc65333a5 100644 --- a/mindspore/lite/micro/coder/utils/dir_utils.cc +++ b/mindspore/lite/micro/coder/utils/dir_utils.cc @@ -21,12 +21,17 @@ #endif #include #include +#include #include "include/errorcode.h" #include "src/common/log_adapter.h" namespace mindspore::lite::micro { #if defined(_WIN32) || defined(_WIN64) +#ifdef _MSC_VER +constexpr unsigned int kMicroDirMode = 511; +#else constexpr _mode_t kMicroDirMode = 0777; +#endif #else constexpr __mode_t kMicroDirMode = 0777; #endif diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 38f5a88c916..571714c701b 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -26,7 +26,7 @@ if(PLATFORM_ARM32 OR PLATFORM_ARM64) -fdata-sections -ffast-math -fno-rtti -fno-exceptions -Wno-shorten-64-to-32 \ -fno-aligned-allocation -DTARGET_OS_OSX") endif() -else() +elseif(NOT MSVC) if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \ -fdata-sections -ffast-math -fno-rtti") @@ -195,7 +195,16 @@ endif() set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite") set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") +if(NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") +endif() + +if(MSVC) + set_target_properties(mindspore-lite PROPERTIES PREFIX lib) + set_target_properties(mindspore-lite PROPERTIES IMPORT_PREFIX lib) + set_target_properties(mindspore-lite PROPERTIES IMPORT_SUFFIX .dll.lib) + set_target_properties(mindspore-lite_static PROPERTIES PREFIX lib) +endif() if(ENABLE_MINDRT) target_link_libraries(mindspore-lite mindrt_mid) diff --git a/mindspore/lite/src/common/utils.cc b/mindspore/lite/src/common/utils.cc index b7768309f64..c7baee91eb8 100644 --- a/mindspore/lite/src/common/utils.cc +++ b/mindspore/lite/src/common/utils.cc @@ -19,8 +19,9 @@ #include #endif #include "src/common/utils.h" -#ifdef SUPPORT_MSVC +#ifdef _MSC_VER #include +#undef ERROR #endif namespace mindspore { diff --git a/mindspore/lite/tools/benchmark/CMakeLists.txt b/mindspore/lite/tools/benchmark/CMakeLists.txt index a364ded6762..30479aa21b2 100644 --- a/mindspore/lite/tools/benchmark/CMakeLists.txt +++ b/mindspore/lite/tools/benchmark/CMakeLists.txt @@ -21,6 +21,8 @@ if((PLATFORM_ARM32 OR PLATFORM_ARM64) AND NOT TARGET_HIMIX200 AND NOT TARGET_OHO else() target_link_libraries(benchmark mindspore-lite mindspore::json) endif() +elseif(MSVC) + target_link_libraries(benchmark mindspore-lite mindspore::json) else() target_link_libraries(benchmark mindspore-lite mindspore::json pthread) endif() diff --git a/mindspore/lite/tools/common/tensor_util.h b/mindspore/lite/tools/common/tensor_util.h index d69568e2be9..2d7815c99d1 100644 --- a/mindspore/lite/tools/common/tensor_util.h +++ b/mindspore/lite/tools/common/tensor_util.h @@ -38,8 +38,6 @@ using schema::FusedBatchNormT; using schema::MetaGraphT; using schema::QuantParamT; using schema::TensorT; -using schema::Format::Format_NCHW; -using schema::Format::Format_NHWC; std::unique_ptr GetTensorQuantParam(const std::unique_ptr &tensor); @@ -77,7 +75,7 @@ std::unique_ptr CopyQuantParamT(const std::unique_ptr CopyQuantParamArrayT( const std::unique_ptr &srcQuantParamArray); -enum Category { CONST = 0, GRAPH_INPUT = 1, OP_OUTPUT = 2, TF_CONST = 3 }; +enum Category { CONSTANT = 0, GRAPH_INPUT = 1, OP_OUTPUT = 2, TF_CONST = 3 }; class TensorCache { public: @@ -87,7 +85,7 @@ class TensorCache { int AddTensor(const std::string &name, TensorT *tensor, int Category) { index++; - if (Category == CONST || Category == TF_CONST || Category == GRAPH_INPUT) { + if (Category == CONSTANT || Category == TF_CONST || Category == GRAPH_INPUT) { tensor->refCount = 1; tensor->nodeType = NodeType_ValueNode; } else { diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index a8c6b3618ed..47c48a0be6d 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -202,9 +202,12 @@ target_link_libraries(converter_lite PRIVATE mindspore::glog mindspore::protobuf mindspore::flatbuffers - pthread ) +if(NOT MSVC) + target_link_libraries(converter_lite PRIVATE pthread) +endif() + if(NOT WIN32) target_link_libraries(converter_lite PRIVATE dl) endif() diff --git a/third_party/securec/CMakeLists.txt b/third_party/securec/CMakeLists.txt index 075a415cd40..91fb33b720a 100644 --- a/third_party/securec/CMakeLists.txt +++ b/third_party/securec/CMakeLists.txt @@ -1,14 +1,16 @@ -SET(CMAKE_BUILD_TYPE "Debug") -if(CMAKE_SYSTEM_NAME MATCHES "Windows") - SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -fPIC -O0 -Wall -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -fstack-protector-all") -else () - SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -Wno-nullability-completeness -fPIC -O0 -Wall -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -fstack-protector-all -D_LIBCPP_INLINE_VISIBILITY='' -D'_LIBCPP_EXTERN_TEMPLATE(...)='") -endif() -SET(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -fPIC -O3 -Wall -Wno-deprecated-declarations -fstack-protector-all") -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if(NOT MSVC) + SET(CMAKE_BUILD_TYPE "Debug") + if(CMAKE_SYSTEM_NAME MATCHES "Windows") + SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -fPIC -O0 -Wall -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -fstack-protector-all") + else () + SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -Wno-nullability-completeness -fPIC -O0 -Wall -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -fstack-protector-all -D_LIBCPP_INLINE_VISIBILITY='' -D'_LIBCPP_EXTERN_TEMPLATE(...)='") + endif() + SET(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -fPIC -O3 -Wall -Wno-deprecated-declarations -fstack-protector-all") + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -#add flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror") + #add flags + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror") +endif() include_directories(./include) add_subdirectory(src)