add mindspore lite

pull/3620/head
hangq 5 years ago
parent 1f4222edfb
commit 174d308cfa

16
.gitignore vendored

@ -4,6 +4,20 @@ mindspore/lib
output
*.ir
# flatbuffer
mindspore/lite/tools/converter/parser/tflite/schema_generated.h
mindspore/lite/tools/converter/parser/caffe/caffe.pb.cc
mindspore/lite/tools/converter/parser/caffe/caffe.pb.h
mindspore/lite/tools/converter/parser/onnx/onnx.pb.h
mindspore/lite/tools/converter/parser/onnx/onnx.pb.h
mindspore/lite/tools/converter/schema/*.h
mindspore/lite/tools/converter/schema/inner
mindspore/lite/schema/*.h
mindspore/lite/schema/inner
mindspore/lite/src/runtime/kernel/opencl/cl/fp16/*.inc
mindspore/lite/src/runtime/kernel/opencl/cl/fp32/*.inc
# Cmake files
CMakeFiles/
cmake_install.cmake
@ -71,5 +85,3 @@ test_temp_summary_event_file/
mindspore/version.py
mindspore/default_config.py
mindspore/.commit_id
onnx.proto
mindspore/ccsrc/onnx.proto

8
.gitmodules vendored

@ -1,6 +1,7 @@
[submodule "third_party/flatbuffers"]
path = third_party/flatbuffers
url = https://github.com/google/flatbuffers.git
ignore = all
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
@ -10,9 +11,16 @@
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf.git
ignore = all
[submodule "akg"]
path = akg
url = https://gitee.com/mindspore/akg.git
[submodule "graphengine"]
path = graphengine
url = https://gitee.com/mindspore/graphengine.git
[submodule "third_party/OpenCL-CLHPP"]
path = third_party/OpenCL-CLHPP
url = https://github.com/KhronosGroup/OpenCL-CLHPP.git
[submodule "third_party/OpenCL-Headers"]
path = third_party/OpenCL-Headers
url = https://github.com/KhronosGroup/OpenCL-Headers.git

File diff suppressed because it is too large Load Diff

@ -1,7 +1,3 @@
file(GLOB_RECURSE _IR_SRC_LIST ./*.cc dtype/*.cc)
file(GLOB_RECURSE _IR_LITE_SRC_FILES
./lite/tensor.cc
)
list(REMOVE_ITEM _IR_SRC_LIST ${_IR_LITE_SRC_FILES})
set_property(SOURCE ${_IR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_IR)
add_library(_mindspore_ir_obj OBJECT ${_IR_SRC_LIST})

@ -1,88 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vector>
#include <utility>
#include "ir/lite/tensor.h"
#include "securec/include/securec.h"
namespace mindspore {
namespace tensor {
#define kMaxMallocSize 1024 * 1024 * 100
Tensor::Tensor(const TypeId data_type, const std::vector<int> &shape) : MetaTensor(data_type, shape) {}
Tensor::Tensor(const TypePtr &type_ptr, const std::vector<int> &shape) : MetaTensor(type_ptr, shape) {}
Tensor::Tensor(const Tensor &tensor) : MetaTensor(tensor) {
this->data_type_ = tensor.data_type_;
this->shape_ = tensor.shape_;
auto ret = CopyTensorData(tensor);
if (0 != ret) {
MS_LOG(EXCEPTION) << "CopyTensorData error";
}
}
int Tensor::CopyTensorData(const Tensor &srcTensor) {
if (srcTensor.data_ == nullptr) {
MS_LOG(ERROR) << "data of srcTensor is nullptr";
return -1;
}
size_t data_size = this->Size();
MS_ASSERT(data_size == tensor.Size());
if (this->data_ == nullptr) {
if (data_size > kMaxMallocSize) {
MS_LOG(ERROR) << "Malloc size is too big while coping data, " << data_size << " bytes";
return -1;
}
this->data_ = malloc(data_size);
}
memcpy_s(this->data_, data_size, tensor.data_, tensor.Size());
return 0;
}
Tensor::~Tensor() {
if (nullptr != this->data_) {
free(this->data_);
}
}
Tensor &Tensor::operator=(const Tensor &tensor) {
if (&tensor == this) {
return *this;
}
this->shape_ = tensor.shape_;
this->data_type_ = tensor.data_type_;
auto ret = CopyTensorData(tensor);
if (0 != ret) {
MS_LOG(EXCEPTION) << "CopyTensorData error";
}
return *this;
}
bool Tensor::operator==(const Tensor &tensor) {
return data_ == tensor.data_ && shape_ == tensor.shape_ && data_type_ == tensor.data_type_;
}
bool Tensor::operator==(const Value &other) const {
if (other.isa<Tensor>()) {
auto other_ = static_cast<const Tensor &>(other);
return *this == other_;
} else {
return false;
}
}
} // namespace tensor
} // namespace mindspore

@ -1,61 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CORE_IR_LITE_TENSOR_H_
#define MINDSPORE_CORE_IR_LITE_TENSOR_H_
#include <memory>
#include <vector>
#include "ir/meta_tensor.h"
#include "ir/dtype/type.h"
namespace mindspore {
namespace tensor {
class Tensor : public MetaTensor {
public:
Tensor() : MetaTensor() {}
Tensor(const TypeId data_type, const std::vector<int> &shape);
Tensor(const TypePtr &type_ptr, const std::vector<int> &shape);
Tensor(const Tensor &tensor);
~Tensor();
int CopyTensorData(const Tensor &srcTensor);
MS_DECLARE_PARENT(Tensor, MetaTensor)
virtual Tensor &operator=(const Tensor &tensor);
virtual bool operator==(const Tensor &tensor);
bool operator==(const Value &other) const override;
size_t Size() const { return MetaTensor::ElementsNum() * GetTypeByte(TypeIdToType(this->data_type_)); }
void *Data() const { return data_; }
protected:
void *data_;
};
using TensorPtr = std::shared_ptr<Tensor>;
} // namespace tensor
} // namespace mindspore
#endif // MINDSPORE_CORE_IR_LITE_TENSOR_H_

@ -75,8 +75,6 @@ int MetaTensor::ElementsNum() const {
return std::accumulate(shape_.begin(), shape_.end(), 1LL, std::multiplies<int>());
}
TypePtr MetaTensor::Dtype() const { return TypeIdToType(data_type_); }
TypePtr MetaTensor::SetDtype(const TypePtr type_ptr) {
if (type_ptr == nullptr) {
MS_LOG(ERROR) << "Dtype to be set is nullptr.";

@ -37,5 +37,7 @@ abstract::AbstractBasePtr MetaTensor::ToAbstract() {
abs_tensor->set_value(shared_from_base<MetaTensor>());
return abs_tensor;
}
TypePtr MetaTensor::Dtype() const { return TypeIdToType(data_type_); }
} // namespace tensor
} // namespace mindspore

@ -31,7 +31,7 @@ class ParamValue {
ParamValue(const ParamValue &other) = default;
~ParamValue() = default;
virtual ~ParamValue() = default;
tensor::MetaTensorPtr value() const { return value_; }
void set_value(const tensor::MetaTensorPtr &value) { value_ = value; }

@ -17,11 +17,15 @@
#include "utils/log_adapter.h"
#include <unistd.h>
#include <sys/time.h>
#include <map>
#ifndef USE_ANDROID_LOG
#include "debug/trace.h"
#endif
// namespace to support utils module definition
namespace mindspore {
#ifndef USE_ANDROID_LOG
#ifdef USE_GLOG
static std::string GetTime() {
#define BUFLEN 80
@ -125,6 +129,7 @@ static int GetSlogLevel(MsLogLevel level) {
}
}
#endif
#endif
static std::string ExceptionTypeToString(ExceptionType type) {
#define _TO_STRING(x) #x
@ -184,7 +189,24 @@ static const char *GetSubModuleName(SubModuleId module_id) {
return sub_module_names[module_id % NUM_SUBMODUES];
}
const char *EnumStrForMsLogLevel(MsLogLevel level) {
if (level == DEBUG) {
return "DEBUG";
} else if (level == INFO) {
return "INFO";
} else if (level == WARNING) {
return "WARNING";
} else if (level == ERROR) {
return "ERROR";
} else if (level == EXCEPTION) {
return "EXCEPTION";
} else {
return "NO_LEVEL";
}
}
void LogWriter::OutputLog(const std::ostringstream &msg) const {
#ifndef USE_ANDROID_LOG
#ifdef USE_GLOG
auto submodule_name = GetSubModuleName(submodule_);
google::LogMessage("", 0, GetGlogLevel(log_level_)).stream()
@ -197,6 +219,10 @@ void LogWriter::OutputLog(const std::ostringstream &msg) const {
Dlog(static_cast<int>(slog_module_id), GetSlogLevel(log_level_), "[%s:%d] %s] %s", location_.file_, location_.line_,
location_.func_, str_msg.c_str());
#endif
#else
printf("%s [%s:%d] %s] %s\n:", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_,
msg.str().c_str());
#endif
}
void LogWriter::operator<(const LogStream &stream) const noexcept {
@ -218,8 +244,10 @@ void LogWriter::operator^(const LogStream &stream) const {
}
oss << msg.str();
#ifndef USE_ANDROID_LOG
trace::TraceGraphEval();
trace::GetEvalStackInfo(oss);
#endif
if (exception_handler_ != nullptr) {
exception_handler_(exception_type_, oss.str());

@ -25,11 +25,13 @@
#include <functional>
#include "utils/overload.h"
#include "./securec.h"
#ifndef USE_ANDROID_LOG
#ifdef USE_GLOG
#include "glog/logging.h"
#else
#include "toolchain/slog.h"
#endif
#endif
// NOTICE: when relative path of 'log_adapter.h' changed, macro 'LOG_HDR_FILE_REL_PATH' must be changed
#define LOG_HDR_FILE_REL_PATH "mindspore/core/utils/log_adapter.h"
@ -129,6 +131,8 @@ enum SubModuleId : int {
#define SUBMODULE_ID mindspore::SubModuleId::SM_ME
#endif
const char *EnumStrForMsLogLevel(MsLogLevel level);
#if defined(_WIN32) || defined(_WIN64)
extern int g_ms_submodule_log_levels[] __attribute__((dllexport));
#else

@ -0,0 +1,119 @@
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 vesion ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(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(${CCSRC_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${TOP_DIR}/third_party)
include_directories(${TOP_DIR}/third_party/flatbuffers/include)
include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/external_libs/json.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_definitions(USE_ANDROID_LOG)
add_compile_definitions(NO_DLIB)
add_compile_options(-fPIC)
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(BUILD_CONVERTER "if build converter" 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)
if (BUILD_DEVICE)
add_compile_definitions(BUILD_DEVICE)
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)
add_definitions(-DUSE_OPENCL_WRAPPER)
add_definitions(-DMS_OPENCL_PROFILE=false)
add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=200)
add_compile_definitions(SUPPORT_GPU)
if(OFFLINE_COMPILE)
add_compile_definitions(PROGRAM_WITH_IL)
endif()
include_directories(${TOP_DIR}/third_party/OpenCL-Headers)
include_directories(${TOP_DIR}/third_party/OpenCL-CLHPP/include)
endif()
set(ANF_SRC
${CMAKE_CURRENT_SOURCE_DIR}/../core/ir/meta_tensor.cc
${CCSRC_DIR}/gvar/logging_level.cc
${CCSRC_DIR}/gvar/typeid_manager.cc
${CMAKE_CURRENT_SOURCE_DIR}/../core/base/base.cc
${CMAKE_CURRENT_SOURCE_DIR}/../core/utils/log_adapter.cc
)
if (BUILD_CONVERTER)
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
MESSAGE(FATAL_ERROR "Cannot build converter in arm platform")
endif()
find_package(Python3 3.7 COMPONENTS Interpreter Development)
if(Python3_FOUND)
set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
if (WIN32)
if (Python3_DIR)
message("Python3_DIR set already: " ${Python3_DIR})
else()
string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
math(EXPR Python3_DIR_LEN ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
message("Python3_DIR: " ${Python3_DIR})
endif()
link_directories(${Python3_DIR})
endif()
else()
find_python_package(py_inc py_lib)
set(PYTHON_INCLUDE_DIRS "${py_inc}")
set(PYTHON_LIBRARIES "${py_lib}")
endif()
include_directories(${PYTHON_INCLUDE_DIRS})
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)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
add_subdirectory(src/common/anf_exporter)
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)
endif()
if (PLATFORM_ARM32)
add_definitions(-mfloat-abi=softfp -mfpu=neon)
add_compile_definitions(ENABLE_ARM32)
endif()
if (PLATFORM_ARM64)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod+fp16")
add_compile_definitions(ENABLE_ARM64)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
endif()

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -0,0 +1,7 @@
# CMake generated Testfile for
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.
subdirs("googlemock")

@ -0,0 +1,7 @@
# CMake generated Testfile for
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest/googlemock
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest/googlemock
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.
subdirs("gtest")

File diff suppressed because one or more lines are too long

@ -0,0 +1,6 @@
# CMake generated Testfile for
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest/googletest
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest/googlemock/gtest
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.

@ -0,0 +1,33 @@
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was Config.cmake.in ########
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()
macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()
####################################################################################
include(CMakeFindDependencyMacro)
if (ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_dependency(Threads)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/GTestTargets.cmake")
check_required_components("")

@ -0,0 +1,37 @@
# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
# The variable CVF_VERSION must be set before calling configure_file().
set(PACKAGE_VERSION "1.9.0")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
# if the installed project requested no architecture check, don't perform the check
if("FALSE")
return()
endif()
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()

@ -0,0 +1,9 @@
libdir=/usr/local/lib
includedir=/usr/local/include
Name: gmock
Description: GoogleMock (without main() function)
Version: 1.9.0
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgmock -pthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread

@ -0,0 +1,9 @@
libdir=/usr/local/lib
includedir=/usr/local/include
Name: gmock_main
Description: GoogleMock (with main() function)
Version: 1.9.0
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgmock_main -pthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread

@ -0,0 +1,9 @@
libdir=/usr/local/lib
includedir=/usr/local/include
Name: gtest
Description: GoogleTest (without main() function)
Version: 1.9.0
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgtest -pthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread

@ -0,0 +1,10 @@
libdir=/usr/local/lib
includedir=/usr/local/include
Name: gtest_main
Description: GoogleTest (with main() function)
Version: 1.9.0
URL: https://github.com/google/googletest
Requires: gtest
Libs: -L${libdir} -lgtest_main -pthread
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save