Merge pull request !4686 from liuwenhao/mastertags/v0.7.0-beta
| @@ -17,38 +17,111 @@ | |||
| SET BASEPATH=%CD% | |||
| IF NOT EXIST %BASEPATH%/build ( | |||
| md "build" | |||
| ) | |||
| md "build" | |||
| ) | |||
| cd %BASEPATH%/build | |||
| SET BUILD_PATH=%CD% | |||
| set BUILD_PATH=%CD% | |||
| IF NOT EXIST %BUILD_PATH%/mindspore ( | |||
| md "mindspore" | |||
| ) | |||
| md "mindspore" | |||
| ) | |||
| cd %CD%/mindspore | |||
| cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -G "CodeBlocks - MinGW Makefiles" ../.. | |||
| IF NOT %errorlevel% == 0 ( | |||
| echo "cmake fail." | |||
| goto run_fail | |||
| IF "%2%" == "lite" ( | |||
| call :gene_gtest | |||
| call :run_cmake | |||
| IF errorlevel 1 ( | |||
| echo "cmake fail one time." | |||
| call :gene_protobuf | |||
| call :gene_flatbuffer | |||
| call :run_cmake | |||
| IF errorlevel 1 ( | |||
| echo "cmake fail." | |||
| goto run_fail | |||
| ) | |||
| ) ELSE ( | |||
| call :gene_protobuf | |||
| call :gene_flatbuffer | |||
| ) | |||
| IF "%1%" == "" ( | |||
| cmake --build . --target package -- -j6 | |||
| cd %BUILD_PATH%/mindspore | |||
| IF "%1%" == "" ( | |||
| cmake --build . -- -j6 | |||
| ) ELSE ( | |||
| cmake --build . -- -j%1% | |||
| ) | |||
| IF errorlevel 1 ( | |||
| echo "build fail." | |||
| goto run_fail | |||
| ) | |||
| ) ELSE ( | |||
| cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON ^ | |||
| -G "CodeBlocks - MinGW Makefiles" ../.. | |||
| IF NOT %errorlevel% == 0 ( | |||
| echo "cmake fail." | |||
| goto run_fail | |||
| ) | |||
| IF "%1%" == "" ( | |||
| cmake --build . --target package -- -j6 | |||
| ) ELSE ( | |||
| cmake --build . --target package -- -j%1% | |||
| ) | |||
| IF NOT %errorlevel% == 0 ( | |||
| echo "build fail." | |||
| goto run_fail | |||
| IF NOT %errorlevel% == 0 ( | |||
| echo "build fail." | |||
| goto run_fail | |||
| ) | |||
| ) | |||
| cd %BASEPATH% | |||
| goto run_eof | |||
| :run_cmake | |||
| cd %BUILD_PATH%/mindspore | |||
| cmake -DBUILD_DEVICE=on -DBUILD_CONVERTER=on -DPLATFORM_ARM64=off -DSUPPORT_TRAIN=off ^ | |||
| -DCMAKE_BUILD_TYPE=Release -DSUPPORT_GPU=off -DBUILD_MINDDATA=off -DOFFLINE_COMPILE=off ^ | |||
| -G "CodeBlocks - MinGW Makefiles" %BASEPATH%/mindspore/lite | |||
| GOTO:EOF | |||
| :gene_gtest | |||
| cd %BASEPATH%/third_party | |||
| IF EXIST googletest rd /s /q googletest | |||
| git submodule update --init --recursive googletest | |||
| cd %BUILD_PATH%/mindspore | |||
| GOTO:EOF | |||
| :gene_protobuf | |||
| SET PROTOC=%BASEPATH%/build/mindspore/_deps/protobuf-src/_build/protoc | |||
| SET PROTO_SRC_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/caffe | |||
| cd %PROTO_SRC_DIR% | |||
| %PROTOC% *.proto --proto_path=%PROTO_SRC_DIR% --cpp_out=%PROTO_SRC_DIR% | |||
| SET PROTO_SRC_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/onnx | |||
| cd %PROTO_SRC_DIR% | |||
| %PROTOC% *.proto --proto_path=%PROTO_SRC_DIR% --cpp_out=%PROTO_SRC_DIR% | |||
| cd %BUILD_PATH%/mindspore | |||
| GOTO:EOF | |||
| :gene_flatbuffer | |||
| SET FLATC=%BASEPATH%/build/mindspore/_deps/flatbuffers-src/_build/flatc | |||
| SET FLAT_DIR=%BASEPATH%/mindspore/lite/schema | |||
| cd %FLAT_DIR% | |||
| IF EXIST inner rd /s /q inner | |||
| md inner | |||
| %FLATC% -c -b *.fbs | |||
| %FLATC% -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o %FLAT_DIR%/inner *.fbs | |||
| SET FLAT_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/tflite | |||
| cd %FLAT_DIR% | |||
| %FLATC% -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o %FLAT_DIR% *.fbs | |||
| cd %BUILD_PATH%/mindspore | |||
| GOTO:EOF | |||
| :run_fail | |||
| cd %BASEPATH% | |||
| set errorlevel=1 | |||
| @@ -44,6 +44,10 @@ include_directories(${TOP_DIR}/third_party/flatbuffers/include) | |||
| 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() | |||
| option(CMAKE_BUILD_TYPE "build type" Release) | |||
| option(BUILD_DEVICE "if build device" on) | |||
| @@ -89,6 +93,11 @@ if (SUPPORT_GPU) | |||
| include_directories(${TOP_DIR}/third_party/OpenCL-CLHPP/include) | |||
| endif() | |||
| if (WIN32) | |||
| add_compile_definitions(LITE_EXPORTS) | |||
| add_compile_definitions(BUILDING_DLL) | |||
| endif() | |||
| set(ANF_SRC | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../core/ir/meta_tensor.cc | |||
| ${CORE_DIR}/gvar/logging_level.cc | |||
| @@ -178,9 +187,11 @@ endif() | |||
| if (BUILD_DEVICE) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/time_profile) | |||
| if (NOT WIN32) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) | |||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/time_profile) | |||
| endif() | |||
| endif() | |||
| include(${TOP_DIR}/cmake/package_lite.cmake) | |||
| @@ -72,7 +72,11 @@ std::string RealPath(const char *path) { | |||
| MS_LOG(ERROR) << "new resolvedPath failed"; | |||
| return ""; | |||
| } | |||
| #ifdef _WIN32 | |||
| char *real_path = _fullpath(resolvedPath.get(), path, 1024); | |||
| #else | |||
| char *real_path = realpath(path, resolvedPath.get()); | |||
| #endif | |||
| if (real_path == nullptr || strlen(real_path) == 0) { | |||
| MS_LOG(ERROR) << "Proto file path is not valid"; | |||
| return ""; | |||
| @@ -120,7 +120,7 @@ if (IsPrint(log_level_)) { | |||
| __android_log_print(GetAndroidLogLevel(log_level_), ANDROID_LOG_TAG, "[%s:%d] %s] %s", location_.file_, | |||
| location_.line_, location_.func_, msg.str().c_str()); | |||
| #else | |||
| printf("%s [%s:%d] %s] %s\n:", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_, | |||
| printf("%s [%s:%d] %s] %s\n", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_, | |||
| msg.str().c_str()); | |||
| #endif | |||
| } | |||
| @@ -17,7 +17,9 @@ | |||
| #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_OPTIMIZED_KERNEL_H_ | |||
| #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_OPTIMIZED_KERNEL_H_ | |||
| #ifndef _WIN32 | |||
| #include <dlfcn.h> | |||
| #endif | |||
| #ifdef __ANDROID__ | |||
| #include <asm/hwcap.h> | |||
| #include "nnacl/nnacl_utils.h" | |||
| @@ -58,7 +60,9 @@ class OptimizeModule { | |||
| if ((!support_optimize_ops) && (!support_fp16)) { | |||
| return; | |||
| } | |||
| #ifndef _WIN32 | |||
| optimized_op_handler_ = dlopen(OPTIMIZE_SHARED_LIBRARY_PATH, RTLD_LAZY); | |||
| #endif | |||
| if (optimized_op_handler_ == nullptr) { | |||
| printf("Open optimize shared library failed.\n"); | |||
| } | |||
| @@ -212,11 +212,13 @@ bool LiteThreadBind::SetCPUBind(pthread_t threadId, cpu_set_t *cpuSet) { | |||
| MS_LOG(ERROR) << "not bind thread to apple's cpu."; | |||
| return false; | |||
| #else | |||
| #ifndef _WIN32 | |||
| int ret = pthread_setaffinity_np(threadId, sizeof(cpuSet), cpuSet); | |||
| if (ret != 0) { | |||
| MS_LOG(ERROR) << "bind thread " << threadId << " to cpu failed.ERROR " << ret; | |||
| return false; | |||
| } | |||
| #endif | |||
| #endif // __APPLE__ | |||
| #endif | |||
| return true; | |||
| @@ -47,8 +47,12 @@ void *WorkspacePool::AllocWorkSpaceMem(size_t size) { | |||
| MS_LOGE("posix_memalign failed, error code:%d", err); | |||
| return alloc.second; | |||
| } | |||
| #else | |||
| #ifdef _WIN32 | |||
| alloc.second = _aligned_malloc(nbytes, kTempAllocaAlignment); | |||
| #else | |||
| alloc.second = memalign(kTempAllocaAlignment, nbytes); | |||
| #endif | |||
| #endif | |||
| } else if (freeList.size() == 1) { // one element | |||
| alloc = *(freeList.begin()); | |||
| @@ -62,8 +66,12 @@ void *WorkspacePool::AllocWorkSpaceMem(size_t size) { | |||
| MS_LOGE("posix_memalign failed, error code:%d", err); | |||
| return alloc.second; | |||
| } | |||
| #else | |||
| #ifdef _WIN32 | |||
| alloc.second = _aligned_malloc(nbytes, kTempAllocaAlignment); | |||
| #else | |||
| alloc.second = memalign(kTempAllocaAlignment, nbytes); | |||
| #endif | |||
| #endif | |||
| } | |||
| } else { | |||
| @@ -91,8 +99,12 @@ void *WorkspacePool::AllocWorkSpaceMem(size_t size) { | |||
| MS_LOGE("posix_memalign failed, error code:%d", err); | |||
| return alloc.second; | |||
| } | |||
| #else | |||
| #ifdef _WIN32 | |||
| alloc.second = _aligned_malloc(nbytes, kTempAllocaAlignment); | |||
| #else | |||
| alloc.second = memalign(kTempAllocaAlignment, nbytes); | |||
| #endif | |||
| #endif | |||
| } | |||
| } | |||
| @@ -657,10 +657,17 @@ int AnfImporterFromProtobuf::Import(const schema::QuantType &quantType) { | |||
| onnx::ModelProto *AnfImporterFromProtobuf::ReadOnnxFromBinary(const std::string &model_path) { | |||
| std::unique_ptr<char> onnx_file(new (std::nothrow) char[PATH_MAX]{0}); | |||
| #ifdef _WIN32 | |||
| if (_fullpath(onnx_file.get(), model_path.c_str(), 1024) == nullptr) { | |||
| MS_LOG(ERROR) << "open file failed."; | |||
| return nullptr; | |||
| } | |||
| #else | |||
| if (realpath(model_path.c_str(), onnx_file.get()) == nullptr) { | |||
| MS_LOG(ERROR) << "open file failed."; | |||
| return nullptr; | |||
| } | |||
| #endif | |||
| int fd = open(onnx_file.get(), O_RDONLY); | |||
| google::protobuf::io::FileInputStream input(fd); | |||
| google::protobuf::io::CodedInputStream code_input(&input); | |||
| @@ -1,15 +1,15 @@ | |||
| set(ANF_SRC | |||
| ${ANF_SRC} | |||
| #core / abstract | |||
| #core / abstract | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/abstract_function.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/analysis_context.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/param_validator.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/abstract_value.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/dshape.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/abstract/utils.cc | |||
| #core / base | |||
| #core / base | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/base/base_ref.cc | |||
| #core / ir | |||
| #core / ir | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/ir/anf.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/ir/anf_extends.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/ir/meta_func_graph.cc | |||
| @@ -55,6 +55,28 @@ set(ANF_SRC | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/graph_utils_extends.cc | |||
| ) | |||
| if (WIN32) | |||
| set(LITE_SRC | |||
| #src | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ir/tensor.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/model.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/context.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/lite_session.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/kernel_registry.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/graph_util.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/runtime_api.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/thread_pool.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/workspace_pool.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/allocator.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/executor.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/scheduler.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/lite_kernel.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/ms_tensor_utils.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/kernel/arm/nnacl/pack.c | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/populate_parameter.cc | |||
| ) | |||
| endif() | |||
| file(GLOB_RECURSE OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc) | |||
| file(GLOB_RECURSE CONVERTER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | |||
| @@ -91,12 +113,20 @@ add_subdirectory(parser/onnx) | |||
| add_subdirectory(legacy_optimizer) | |||
| add_subdirectory(quantizer) | |||
| if (WIN32) | |||
| set(PROTO_LIBRARY mindspore::protobuf) | |||
| else() | |||
| set(PROTO_LIBRARY protobuf) | |||
| endif() | |||
| add_executable(converter_lite | |||
| main.cc | |||
| ${ANF_SRC} | |||
| ${CONVERTER_SRC} | |||
| ${OPS_SRC} | |||
| ${LITE_SRC} | |||
| ) | |||
| target_link_libraries(converter_lite PRIVATE | |||
| tflite_parser_mid | |||
| caffe_parser_mid | |||
| @@ -106,9 +136,9 @@ target_link_libraries(converter_lite PRIVATE | |||
| graph_pass_mid | |||
| fusion_mid | |||
| quantizer_mid | |||
| protobuf | |||
| quantizer_mid | |||
| pthread | |||
| ${PROTO_LIBRARY} | |||
| mindspore-lite | |||
| ${SECUREC_LIBRARY} | |||
| mindspore::json | |||
| @@ -56,10 +56,17 @@ std::vector<int32_t> OnnxModelParser::GetDimsFromOnnxValue(const onnx::ValueInfo | |||
| STATUS OnnxModelParser::ReadOnnxModelFromBinary(const std::string &modelFile, google::protobuf::Message *onnx_model) { | |||
| std::unique_ptr<char> onnx_file(new (std::nothrow) char[PATH_MAX]{0}); | |||
| #ifdef _WIN32 | |||
| if (_fullpath(onnx_file.get(), modelFile.c_str(), 1024) == nullptr) { | |||
| MS_LOG(ERROR) << "get realpath " << modelFile << " fail"; | |||
| return RET_ERROR; | |||
| } | |||
| #else | |||
| if (realpath(modelFile.c_str(), onnx_file.get()) == nullptr) { | |||
| MS_LOG(ERROR) << "get realpath " << modelFile << " fail"; | |||
| return RET_ERROR; | |||
| } | |||
| #endif | |||
| int fd = open(onnx_file.get(), O_RDONLY); | |||
| google::protobuf::io::FileInputStream input(fd); | |||
| google::protobuf::io::CodedInputStream code_input(&input); | |||
| @@ -426,9 +426,15 @@ STATUS Calibrator::ReadConfig() { | |||
| MS_LOG(ERROR) << "New an object failed."; | |||
| return RET_ERROR; | |||
| } | |||
| if (nullptr != realpath(config_path_.c_str(), resolved_path)) { | |||
| #ifdef _WIN32 | |||
| if (_fullpath(resolved_path, config_path_.c_str(), 1024) != nullptr) { | |||
| config_path_ = string(resolved_path); | |||
| } | |||
| #else | |||
| if (realpath(config_path_.c_str(), resolved_path) != nullptr) { | |||
| config_path_ = string(resolved_path); | |||
| } | |||
| #endif | |||
| std::ifstream fs(config_path_.c_str(), std::ifstream::in); | |||
| if (!fs.is_open()) { | |||
| MS_LOG(ERROR) << "config proto file %s open failed: " << config_path_; | |||