Browse Source

!3998 remove unused third_party & strip so when Release

Merge pull request !3998 from hangq/master
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
cbd6e7633d
16 changed files with 178 additions and 213 deletions
  1. +0
    -1
      mindspore/core/utils/log_adapter.h
  2. +13
    -9
      mindspore/lite/CMakeLists.txt
  3. +4
    -2
      mindspore/lite/include/model.h
  4. +6
    -2
      mindspore/lite/src/CMakeLists.txt
  5. +109
    -142
      mindspore/lite/src/common/anf_importer/import_from_protobuf.cc
  6. +3
    -2
      mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc
  7. +2
    -1
      mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc
  8. +3
    -2
      mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc
  9. +3
    -2
      mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc
  10. +1
    -5
      mindspore/lite/src/ir/tensor.cc
  11. +4
    -5
      mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc
  12. +4
    -4
      mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc
  13. +18
    -25
      mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc
  14. +3
    -2
      mindspore/lite/test/CMakeLists.txt
  15. +2
    -7
      mindspore/lite/tools/benchmark/CMakeLists.txt
  16. +3
    -2
      mindspore/lite/tools/converter/quantizer/quantize_util.cc

+ 0
- 1
mindspore/core/utils/log_adapter.h View File

@@ -24,7 +24,6 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include "utils/overload.h" #include "utils/overload.h"
#include "./securec.h"
#ifndef USE_ANDROID_LOG #ifndef USE_ANDROID_LOG
#ifdef USE_GLOG #ifdef USE_GLOG
#include "glog/logging.h" #include "glog/logging.h"


+ 13
- 9
mindspore/lite/CMakeLists.txt View File

@@ -16,15 +16,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${TOP_DIR}/third_party) include_directories(${TOP_DIR}/third_party)
include_directories(${TOP_DIR}/third_party/flatbuffers/include) 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/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(CMAKE_BUILD_TYPE "build type" Release)
option(BUILD_DEVICE "if build device" on) option(BUILD_DEVICE "if build device" on)
option(SUPPORT_TRAIN "if build for on-device train" off) option(SUPPORT_TRAIN "if build for on-device train" off)
option(PLATFORM_ARM64 "if build device for arm64" off) option(PLATFORM_ARM64 "if build device for arm64" off)
@@ -35,6 +27,14 @@ option(SUPPORT_GPU "if support gpu" off)
option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off) option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
option(BUILD_MINDDATA "" off) option(BUILD_MINDDATA "" off)


set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_definitions(USE_ANDROID_LOG)
add_compile_definitions(NO_DLIB)
add_compile_options(-fPIC)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()

if (BUILD_DEVICE) if (BUILD_DEVICE)
add_compile_definitions(BUILD_DEVICE) add_compile_definitions(BUILD_DEVICE)
endif() endif()
@@ -91,6 +91,10 @@ if (BUILD_CONVERTER)
set(PYTHON_LIBRARIES "${py_lib}") set(PYTHON_LIBRARIES "${py_lib}")
endif() endif()
include_directories(${PYTHON_INCLUDE_DIRS}) include_directories(${PYTHON_INCLUDE_DIRS})
include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/dependency_utils.cmake)
include(${TOP_DIR}/cmake/external_libs/json.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
include(${TOP_DIR}/cmake/external_libs/pybind11.cmake) include(${TOP_DIR}/cmake/external_libs/pybind11.cmake)
include(${TOP_DIR}/cmake/external_libs/eigen.cmake) include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
include_directories(${TOP_DIR}/third_party/protobuf/build/include) include_directories(${TOP_DIR}/third_party/protobuf/build/include)


+ 4
- 2
mindspore/lite/include/model.h View File

@@ -23,6 +23,8 @@
#include "schema/model_generated.h" #include "schema/model_generated.h"


namespace mindspore { namespace mindspore {
#define MS_API __attribute__((visibility("default")))

/// \brief ModelImpl defined by MindSpore Lite. /// \brief ModelImpl defined by MindSpore Lite.
/// ///
/// \note List public class and interface for reference. /// \note List public class and interface for reference.
@@ -35,7 +37,7 @@ namespace lite {
class Primitive; class Primitive;


/// \brief Model defined by MindSpore Lite. /// \brief Model defined by MindSpore Lite.
class Model {
class MS_API Model {
public: public:
/// \brief Static method to create a Model pointer. /// \brief Static method to create a Model pointer.
/// ///
@@ -78,7 +80,7 @@ class Model {
}; };


/// \brief ModelBuilder defined by MindSpore Lite. /// \brief ModelBuilder defined by MindSpore Lite.
class ModelBuilder {
class MS_API ModelBuilder {
public: public:
/// \brief OutEdge defined by MindSpore Lite. /// \brief OutEdge defined by MindSpore Lite.
struct OutEdge { struct OutEdge {


+ 6
- 2
mindspore/lite/src/CMakeLists.txt View File

@@ -75,8 +75,6 @@ add_library(mindspore-lite SHARED ${LITE_SRC} ${ANF_SRC})
target_link_libraries(mindspore-lite target_link_libraries(mindspore-lite
cpu_kernel_mid_ cpu_kernel_mid_
ops_mid_ ops_mid_
${SECUREC_LIBRARY}
mindspore::json
) )


add_subdirectory(runtime/kernel/arm) add_subdirectory(runtime/kernel/arm)
@@ -89,3 +87,9 @@ endif ()


add_subdirectory(ops) add_subdirectory(ops)


if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND (PLATFORM_ARM64 OR PLATFORM_ARM32))
add_custom_command(TARGET mindspore-lite POST_BUILD
COMMAND ${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip
${TOP_DIR}/mindspore/lite/build/src/libmindspore-lite.so)
endif()


+ 109
- 142
mindspore/lite/src/common/anf_importer/import_from_protobuf.cc View File

@@ -37,6 +37,7 @@
#include "src/param_value_lite.h" #include "src/param_value_lite.h"
#include "tools/converter/parser/onnx/onnx.pb.h" #include "tools/converter/parser/onnx/onnx.pb.h"
#include "utils/log_adapter.h" #include "utils/log_adapter.h"
#include "securec/include/securec.h"


using string = std::string; using string = std::string;
using int32 = int32_t; using int32 = int32_t;
@@ -57,24 +58,16 @@ enum ParseForm : int {
}; };


static std::map<std::string, ParseForm> kParseTypeSwitchMap{ static std::map<std::string, ParseForm> kParseTypeSwitchMap{
{"type", FORM_PARSE_TYPE},
{"scalar", FORM_PARSE_SCALAR},
{"tensor", FORM_PARSE_TENSOR}};
{"type", FORM_PARSE_TYPE}, {"scalar", FORM_PARSE_SCALAR}, {"tensor", FORM_PARSE_TENSOR}};


static std::unordered_map<int, TypeId> kDefaultValueSwitchMap{ static std::unordered_map<int, TypeId> kDefaultValueSwitchMap{
{onnx::TensorProto_DataType_BOOL, kNumberTypeBool},
{onnx::TensorProto_DataType_INT8, kNumberTypeInt8},
{onnx::TensorProto_DataType_INT16, kNumberTypeInt16},
{onnx::TensorProto_DataType_INT32, kNumberTypeInt32},
{onnx::TensorProto_DataType_INT64, kNumberTypeInt64},
{onnx::TensorProto_DataType_UINT8, kNumberTypeUInt8},
{onnx::TensorProto_DataType_UINT16, kNumberTypeUInt16},
{onnx::TensorProto_DataType_UINT32, kNumberTypeUInt32},
{onnx::TensorProto_DataType_UINT64, kNumberTypeUInt64},
{onnx::TensorProto_DataType_FLOAT16, kNumberTypeFloat16},
{onnx::TensorProto_DataType_FLOAT, kNumberTypeFloat32},
{onnx::TensorProto_DataType_DOUBLE, kNumberTypeFloat64},
{onnx::TensorProto_DataType_STRING, kObjectTypeString},
{onnx::TensorProto_DataType_BOOL, kNumberTypeBool}, {onnx::TensorProto_DataType_INT8, kNumberTypeInt8},
{onnx::TensorProto_DataType_INT16, kNumberTypeInt16}, {onnx::TensorProto_DataType_INT32, kNumberTypeInt32},
{onnx::TensorProto_DataType_INT64, kNumberTypeInt64}, {onnx::TensorProto_DataType_UINT8, kNumberTypeUInt8},
{onnx::TensorProto_DataType_UINT16, kNumberTypeUInt16}, {onnx::TensorProto_DataType_UINT32, kNumberTypeUInt32},
{onnx::TensorProto_DataType_UINT64, kNumberTypeUInt64}, {onnx::TensorProto_DataType_FLOAT16, kNumberTypeFloat16},
{onnx::TensorProto_DataType_FLOAT, kNumberTypeFloat32}, {onnx::TensorProto_DataType_DOUBLE, kNumberTypeFloat64},
{onnx::TensorProto_DataType_STRING, kObjectTypeString},
}; };


#if 0 #if 0
@@ -194,16 +187,15 @@ ParserAttrShape(const std::string &attr_name, const std::unordered_map<string, a
return {}; return {};
} }


#define PARSE_ONNXATTR_IN_SCALAR_FORM(type, valuetype) \
ValuePtr ParseAttrInScalar_##type##_##valuetype( \
const onnx::TensorProto &attr_tensor) { \
if (attr_tensor.type##_data_size() == 1) { \
auto value = static_cast<valuetype>(attr_tensor.type##_data(0)); \
return MakeValue<valuetype>(value); \
} else { \
MS_LOG(ERROR) << "size of scalar tensor doesn't equal 1!"; \
} \
return {}; \
#define PARSE_ONNXATTR_IN_SCALAR_FORM(type, valuetype) \
ValuePtr ParseAttrInScalar_##type##_##valuetype(const onnx::TensorProto &attr_tensor) { \
if (attr_tensor.type##_data_size() == 1) { \
auto value = static_cast<valuetype>(attr_tensor.type##_data(0)); \
return MakeValue<valuetype>(value); \
} else { \
MS_LOG(ERROR) << "size of scalar tensor doesn't equal 1!"; \
} \
return {}; \
} }


PARSE_ONNXATTR_IN_SCALAR_FORM(double, double) PARSE_ONNXATTR_IN_SCALAR_FORM(double, double)
@@ -255,7 +247,11 @@ bool AnfImporterFromProtobuf::BuildParameterForFuncGraph(const ParameterPtr &nod
std::string initial_data = initialize_proto.raw_data(); std::string initial_data = initialize_proto.raw_data();
auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data()); auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data());
MS_EXCEPTION_IF_NULL(tensor_data_buf); MS_EXCEPTION_IF_NULL(tensor_data_buf);
memcpy_s(tensor_data_buf, tensor_info->Size(), initial_data.data(), initial_data.size());
auto ret = memcpy_s(tensor_data_buf, tensor_info->Size(), initial_data.data(), initial_data.size());
if (EOK != ret) {
MS_LOG(ERROR) << "memcpy_s error";
return false;
}


ParamValueLitePtr param_value = std::make_shared<ParamValueLite>(); ParamValueLitePtr param_value = std::make_shared<ParamValueLite>();
MS_EXCEPTION_IF_NULL(param_value); MS_EXCEPTION_IF_NULL(param_value);
@@ -402,7 +398,11 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(const std::string &val
tensor_info->MallocData(); tensor_info->MallocData();
const std::string &tensor_buf = attr_tensor.raw_data(); const std::string &tensor_buf = attr_tensor.raw_data();
auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data()); auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data());
memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(), tensor_buf.size());
auto ret = memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(), tensor_buf.size());
if (EOK != ret) {
MS_LOG(ERROR) << "memcpy_s error";
return false;
}
auto new_value_node = NewValueNode(MakeValue(tensor_info)); auto new_value_node = NewValueNode(MakeValue(tensor_info));
MS_EXCEPTION_IF_NULL(new_value_node); MS_EXCEPTION_IF_NULL(new_value_node);
auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]);
@@ -641,21 +641,20 @@ bool AnfImporterFromProtobuf::ImportNodesForGraph(const FuncGraphPtr &outputFunc
} }
#endif #endif


#define PARSE_ONNXATTR_IN_SCALAR_FORM(type, valuetype) \
void ParseAttrInScalar_##type##_##valuetype( \
const PrimitivePtr &prim, const std::string &attr_name, \
const onnx::TensorProto &attr_tensor) { \
MS_EXCEPTION_IF_NULL(prim); \
std::vector<ValuePtr> attr_value_vec; \
for (int i = 0; i < attr_tensor.type##_data_size(); ++i) { \
auto value = static_cast<valuetype>(attr_tensor.type##_data(i)); \
attr_value_vec.push_back(MakeValue<valuetype>(value)); \
} \
if (attr_value_vec.size() == 1) { \
prim->AddAttr(attr_name, attr_value_vec[0]); \
} else { \
prim->AddAttr(attr_name, std::make_shared<ValueList>(attr_value_vec)); \
} \
#define PARSE_ONNXATTR_IN_SCALAR_FORM(type, valuetype) \
void ParseAttrInScalar_##type##_##valuetype(const PrimitivePtr &prim, const std::string &attr_name, \
const onnx::TensorProto &attr_tensor) { \
MS_EXCEPTION_IF_NULL(prim); \
std::vector<ValuePtr> attr_value_vec; \
for (int i = 0; i < attr_tensor.type##_data_size(); ++i) { \
auto value = static_cast<valuetype>(attr_tensor.type##_data(i)); \
attr_value_vec.push_back(MakeValue<valuetype>(value)); \
} \
if (attr_value_vec.size() == 1) { \
prim->AddAttr(attr_name, attr_value_vec[0]); \
} else { \
prim->AddAttr(attr_name, std::make_shared<ValueList>(attr_value_vec)); \
} \
} }


PARSE_ONNXATTR_IN_SCALAR_FORM(double, double) PARSE_ONNXATTR_IN_SCALAR_FORM(double, double)
@@ -666,8 +665,8 @@ PARSE_ONNXATTR_IN_SCALAR_FORM(int32, bool)
PARSE_ONNXATTR_IN_SCALAR_FORM(int64, int64) PARSE_ONNXATTR_IN_SCALAR_FORM(int64, int64)
PARSE_ONNXATTR_IN_SCALAR_FORM(uint64, uint64) PARSE_ONNXATTR_IN_SCALAR_FORM(uint64, uint64)


bool AnfImporterFromProtobuf::BuildParameterForFuncGraph(
const ParameterPtr &node, const onnx::ValueInfoProto &value_proto) {
bool AnfImporterFromProtobuf::BuildParameterForFuncGraph(const ParameterPtr &node,
const onnx::ValueInfoProto &value_proto) {
MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(node);
if (!value_proto.has_type() || !value_proto.has_name()) { if (!value_proto.has_type() || !value_proto.has_name()) {
MS_LOG(ERROR) << "onnx ValueInfoProto has no type or name! "; MS_LOG(ERROR) << "onnx ValueInfoProto has no type or name! ";
@@ -690,30 +689,28 @@ bool AnfImporterFromProtobuf::BuildParameterForFuncGraph(
shape.push_back(tensor_shape.dim(i).dim_value()); shape.push_back(tensor_shape.dim(i).dim_value());
} }


if (kDefaultValueSwitchMap.find(tensor_typeproto.elem_type()) ==
kDefaultValueSwitchMap.end()) {
if (kDefaultValueSwitchMap.find(tensor_typeproto.elem_type()) == kDefaultValueSwitchMap.end()) {
MS_LOG(ERROR) << "onnx TypeProto_Tensor elem_type is not support yet!"; MS_LOG(ERROR) << "onnx TypeProto_Tensor elem_type is not support yet!";
return false; return false;
} }


auto type_ptr =
TypeIdToType(kDefaultValueSwitchMap[tensor_typeproto.elem_type()]);
auto abstract_tensor =
std::make_shared<abstract::AbstractTensor>(type_ptr, shape);
auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[tensor_typeproto.elem_type()]);
auto abstract_tensor = std::make_shared<abstract::AbstractTensor>(type_ptr, shape);
node->set_abstract(abstract_tensor); node->set_abstract(abstract_tensor);


if (default_para_map_.find(value_proto.name()) != default_para_map_.end()) { if (default_para_map_.find(value_proto.name()) != default_para_map_.end()) {
tensor::Tensor *tensor_info = new tensor::Tensor(
kDefaultValueSwitchMap[tensor_typeproto.elem_type()], shape);
tensor::Tensor *tensor_info = new tensor::Tensor(kDefaultValueSwitchMap[tensor_typeproto.elem_type()], shape);
MS_EXCEPTION_IF_NULL(tensor_info); MS_EXCEPTION_IF_NULL(tensor_info);
tensor_info->MallocData(); tensor_info->MallocData();
const onnx::TensorProto initialize_proto =
default_para_map_[value_proto.name()];
const onnx::TensorProto initialize_proto = default_para_map_[value_proto.name()];
std::string initial_data = initialize_proto.raw_data(); std::string initial_data = initialize_proto.raw_data();
auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data()); auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data());
MS_EXCEPTION_IF_NULL(tensor_data_buf); MS_EXCEPTION_IF_NULL(tensor_data_buf);
memcpy_s(tensor_data_buf, tensor_info->Size(), initial_data.data(),
initial_data.size());
auto ret = memcpy_s(tensor_data_buf, tensor_info->Size(), initial_data.data(), initial_data.size());
if (EOK != ret) {
MS_LOG(ERROR) << "memcpy_s error";
return false;
}


ParamValueLitePtr param_value = std::make_shared<ParamValueLite>(); ParamValueLitePtr param_value = std::make_shared<ParamValueLite>();
MS_EXCEPTION_IF_NULL(param_value); MS_EXCEPTION_IF_NULL(param_value);
@@ -725,18 +722,15 @@ bool AnfImporterFromProtobuf::BuildParameterForFuncGraph(
return true; return true;
} }


bool AnfImporterFromProtobuf::ImportParametersForGraph(
const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto) {
bool AnfImporterFromProtobuf::ImportParametersForGraph(const FuncGraphPtr &outputFuncGraph,
const onnx::GraphProto &importProto) {
MS_EXCEPTION_IF_NULL(outputFuncGraph); MS_EXCEPTION_IF_NULL(outputFuncGraph);
MS_LOG(INFO) << "Parameters had default paramerer size is: "
<< importProto.initializer_size();
MS_LOG(INFO) << "Parameters had default paramerer size is: " << importProto.initializer_size();


for (int i = 0; i < importProto.initializer_size(); ++i) { for (int i = 0; i < importProto.initializer_size(); ++i) {
const onnx::TensorProto &initializer_proto = importProto.initializer(i); const onnx::TensorProto &initializer_proto = importProto.initializer(i);
if (!initializer_proto.has_name()) { if (!initializer_proto.has_name()) {
MS_LOG(ERROR)
<< "initializer vector of onnx GraphProto has no name at index: "
<< i;
MS_LOG(ERROR) << "initializer vector of onnx GraphProto has no name at index: " << i;
return false; return false;
} }
default_para_map_[initializer_proto.name()] = initializer_proto; default_para_map_[initializer_proto.name()] = initializer_proto;
@@ -745,8 +739,7 @@ bool AnfImporterFromProtobuf::ImportParametersForGraph(
MS_LOG(INFO) << "all parameters size: " << importProto.input_size(); MS_LOG(INFO) << "all parameters size: " << importProto.input_size();
for (int i = 0; i < importProto.input_size(); ++i) { for (int i = 0; i < importProto.input_size(); ++i) {
const onnx::ValueInfoProto &input_proto = importProto.input(i); const onnx::ValueInfoProto &input_proto = importProto.input(i);
if (!BuildParameterForFuncGraph(outputFuncGraph->add_parameter(),
input_proto)) {
if (!BuildParameterForFuncGraph(outputFuncGraph->add_parameter(), input_proto)) {
MS_LOG(ERROR) << "Build parameter for funcgraph fail at index: " << i; MS_LOG(ERROR) << "Build parameter for funcgraph fail at index: " << i;
return false; return false;
} }
@@ -754,25 +747,20 @@ bool AnfImporterFromProtobuf::ImportParametersForGraph(
return true; return true;
} }


bool AnfImporterFromProtobuf::ObtainCNodeAttrInTypeForm(
const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainCNodeAttrInTypeForm(const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
MS_EXCEPTION_IF_NULL(prim); MS_EXCEPTION_IF_NULL(prim);
const int attr_tensor_type = attr_tensor.data_type(); const int attr_tensor_type = attr_tensor.data_type();
if (kDefaultValueSwitchMap.find(attr_tensor_type) ==
kDefaultValueSwitchMap.end()) {
MS_LOG(ERROR) << "Obtain attr in type-form has not support input type:"
<< attr_tensor_type;
if (kDefaultValueSwitchMap.find(attr_tensor_type) == kDefaultValueSwitchMap.end()) {
MS_LOG(ERROR) << "Obtain attr in type-form has not support input type:" << attr_tensor_type;
return false; return false;
} }
prim->AddAttr(attr_name,
TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]));
prim->AddAttr(attr_name, TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]));
return true; return true;
} }


bool AnfImporterFromProtobuf::ObtainCNodeAttrInScalarForm(
const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainCNodeAttrInScalarForm(const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
MS_EXCEPTION_IF_NULL(prim); MS_EXCEPTION_IF_NULL(prim);
const int attr_tensor_type = attr_tensor.data_type(); const int attr_tensor_type = attr_tensor.data_type();
switch (attr_tensor_type) { switch (attr_tensor_type) {
@@ -806,23 +794,20 @@ bool AnfImporterFromProtobuf::ObtainCNodeAttrInScalarForm(
break; break;
} }
default: default:
MS_LOG(ERROR) << "Obtain attr in scalar-form has not support input type: "
<< attr_tensor_type;
MS_LOG(ERROR) << "Obtain attr in scalar-form has not support input type: " << attr_tensor_type;
return false; return false;
} }
return true; return true;
} }


bool AnfImporterFromProtobuf::ObtainCNodeAttrInTensorForm(
const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainCNodeAttrInTensorForm(const PrimitivePtr &prim, const std::string &attr_name,
const onnx::TensorProto &attr_tensor) {
MS_EXCEPTION_IF_NULL(prim); MS_EXCEPTION_IF_NULL(prim);
MS_LOG(ERROR) << "parse attr type don't support attr type is tensor"; MS_LOG(ERROR) << "parse attr type don't support attr type is tensor";
return false; return false;
} }


bool AnfImporterFromProtobuf::GetAttrValueForCNode(
const PrimitivePtr &prim, const onnx::AttributeProto &attr_proto) {
bool AnfImporterFromProtobuf::GetAttrValueForCNode(const PrimitivePtr &prim, const onnx::AttributeProto &attr_proto) {
MS_EXCEPTION_IF_NULL(prim); MS_EXCEPTION_IF_NULL(prim);
const std::string &attr_name = attr_proto.name(); const std::string &attr_name = attr_proto.name();
if (!attr_proto.has_ref_attr_name()) { if (!attr_proto.has_ref_attr_name()) {
@@ -846,32 +831,33 @@ bool AnfImporterFromProtobuf::GetAttrValueForCNode(
return false; return false;
} }
} }
bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(
const std::string &value_node_name, const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
const int attr_tensor_type = attr_tensor.data_type(); const int attr_tensor_type = attr_tensor.data_type();
std::vector<int> shape; std::vector<int> shape;
for (int i = 0; i < attr_tensor.dims_size(); ++i) { for (int i = 0; i < attr_tensor.dims_size(); ++i) {
shape.push_back(attr_tensor.dims(i)); shape.push_back(attr_tensor.dims(i));
} }
tensor::TensorPtr tensor_info = std::make_shared<tensor::Tensor>(
kDefaultValueSwitchMap[attr_tensor_type], shape);
tensor::TensorPtr tensor_info = std::make_shared<tensor::Tensor>(kDefaultValueSwitchMap[attr_tensor_type], shape);
tensor_info->MallocData(); tensor_info->MallocData();
const std::string &tensor_buf = attr_tensor.raw_data(); const std::string &tensor_buf = attr_tensor.raw_data();
auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data()); auto *tensor_data_buf = reinterpret_cast<uint8_t *>(tensor_info->Data());
memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(),
tensor_buf.size());
auto ret = memcpy_s(tensor_data_buf, tensor_info->Size(), tensor_buf.data(), tensor_buf.size());
if (EOK != ret) {
MS_LOG(ERROR) << "memcpy_s error";
return false;
}
auto new_value_node = NewValueNode(MakeValue(tensor_info)); auto new_value_node = NewValueNode(MakeValue(tensor_info));
MS_EXCEPTION_IF_NULL(new_value_node); MS_EXCEPTION_IF_NULL(new_value_node);
auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]);
auto abstract_tensor =
std::make_shared<abstract::AbstractTensor>(type_ptr, shape);
auto abstract_tensor = std::make_shared<abstract::AbstractTensor>(type_ptr, shape);
new_value_node->set_abstract(abstract_tensor); new_value_node->set_abstract(abstract_tensor);
anfnode_build_map_[value_node_name] = new_value_node; anfnode_build_map_[value_node_name] = new_value_node;
return true; return true;
} }


bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm(
const std::string &value_node_name, const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm(const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
const int attr_tensor_type = attr_tensor.data_type(); const int attr_tensor_type = attr_tensor.data_type();
ValuePtr value_ptr = nullptr; ValuePtr value_ptr = nullptr;
switch (attr_tensor_type) { switch (attr_tensor_type) {
@@ -906,8 +892,7 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm(
break; break;
} }
default: default:
MS_LOG(ERROR) << "Obtain attr in scalar-form has not support input type: "
<< attr_tensor_type;
MS_LOG(ERROR) << "Obtain attr in scalar-form has not support input type: " << attr_tensor_type;
return false; return false;
} }
auto new_value_node = NewValueNode(value_ptr); auto new_value_node = NewValueNode(value_ptr);
@@ -918,28 +903,23 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm(
return true; return true;
} }


bool AnfImporterFromProtobuf::ObtainValueNodeInTypeForm(
const std::string &value_node_name, const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::ObtainValueNodeInTypeForm(const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
const int attr_tensor_type = attr_tensor.data_type(); const int attr_tensor_type = attr_tensor.data_type();
if (kDefaultValueSwitchMap.find(attr_tensor_type) ==
kDefaultValueSwitchMap.end()) {
MS_LOG(ERROR)
<< "Obtain ValueNode attr in type-form has not support input type: "
<< attr_tensor_type;
if (kDefaultValueSwitchMap.find(attr_tensor_type) == kDefaultValueSwitchMap.end()) {
MS_LOG(ERROR) << "Obtain ValueNode attr in type-form has not support input type: " << attr_tensor_type;
return false; return false;
} }
auto new_value_node =
NewValueNode(TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]));
abstract::AbstractTypePtr abs_type =
std::make_shared<abstract::AbstractType>(std::make_shared<TypeType>());
auto new_value_node = NewValueNode(TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]));
abstract::AbstractTypePtr abs_type = std::make_shared<abstract::AbstractType>(std::make_shared<TypeType>());
new_value_node->set_abstract(abs_type); new_value_node->set_abstract(abs_type);
anfnode_build_map_[value_node_name] = new_value_node; anfnode_build_map_[value_node_name] = new_value_node;
return true; return true;
} }


bool AnfImporterFromProtobuf::GetAttrValueForValueNode(
const std::string &ref_attr_name, const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
bool AnfImporterFromProtobuf::GetAttrValueForValueNode(const std::string &ref_attr_name,
const std::string &value_node_name,
const onnx::TensorProto &attr_tensor) {
switch (kParseTypeSwitchMap[ref_attr_name]) { switch (kParseTypeSwitchMap[ref_attr_name]) {
case FORM_PARSE_SCALAR: { case FORM_PARSE_SCALAR: {
return ObtainValueNodeInScalarForm(value_node_name, attr_tensor); return ObtainValueNodeInScalarForm(value_node_name, attr_tensor);
@@ -951,14 +931,12 @@ bool AnfImporterFromProtobuf::GetAttrValueForValueNode(
return ObtainValueNodeInTypeForm(value_node_name, attr_tensor); return ObtainValueNodeInTypeForm(value_node_name, attr_tensor);
} }
default: default:
MS_LOG(ERROR)
<< "parse ValueNode value don't support input of ref_attr_name";
MS_LOG(ERROR) << "parse ValueNode value don't support input of ref_attr_name";
return false; return false;
} }
} }


bool AnfImporterFromProtobuf::BuildValueNodeForFuncGraph(
const onnx::NodeProto &node_proto) {
bool AnfImporterFromProtobuf::BuildValueNodeForFuncGraph(const onnx::NodeProto &node_proto) {
const std::string &value_node_name = node_proto.output(0); const std::string &value_node_name = node_proto.output(0);
const onnx::AttributeProto &attr_proto = node_proto.attribute(0); const onnx::AttributeProto &attr_proto = node_proto.attribute(0);
if (!attr_proto.has_ref_attr_name()) { if (!attr_proto.has_ref_attr_name()) {
@@ -971,22 +949,20 @@ bool AnfImporterFromProtobuf::BuildValueNodeForFuncGraph(
return GetAttrValueForValueNode(ref_attr_name, value_node_name, attr_tensor); return GetAttrValueForValueNode(ref_attr_name, value_node_name, attr_tensor);
} }


abstract::AbstractTensorPtr AnfImporterFromProtobuf::GetAbstractForCNode(
const onnx::AttributeProto &attr_proto) {
abstract::AbstractTensorPtr AnfImporterFromProtobuf::GetAbstractForCNode(const onnx::AttributeProto &attr_proto) {
std::vector<int> shape_vec; std::vector<int> shape_vec;
const onnx::TensorProto &attr_tensor = attr_proto.t(); const onnx::TensorProto &attr_tensor = attr_proto.t();
for (int i = 0; i < attr_tensor.dims_size(); ++i) { for (int i = 0; i < attr_tensor.dims_size(); ++i) {
shape_vec.push_back(attr_tensor.dims(i)); shape_vec.push_back(attr_tensor.dims(i));
} }
auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor.data_type()]); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor.data_type()]);
auto abstract_tensor =
std::make_shared<abstract::AbstractTensor>(type_ptr, shape_vec);
auto abstract_tensor = std::make_shared<abstract::AbstractTensor>(type_ptr, shape_vec);
MS_EXCEPTION_IF_NULL(abstract_tensor); MS_EXCEPTION_IF_NULL(abstract_tensor);
return abstract_tensor; return abstract_tensor;
} }


CNodePtr AnfImporterFromProtobuf::BuildCNodeForFuncGraph(
const FuncGraphPtr &outputFuncGraph, const onnx::NodeProto &node_proto) {
CNodePtr AnfImporterFromProtobuf::BuildCNodeForFuncGraph(const FuncGraphPtr &outputFuncGraph,
const onnx::NodeProto &node_proto) {
MS_EXCEPTION_IF_NULL(outputFuncGraph); MS_EXCEPTION_IF_NULL(outputFuncGraph);
if (!node_proto.has_op_type()) { if (!node_proto.has_op_type()) {
MS_LOG(ERROR) << "Get CNode op_type failed!"; MS_LOG(ERROR) << "Get CNode op_type failed!";
@@ -1028,8 +1004,7 @@ CNodePtr AnfImporterFromProtobuf::BuildCNodeForFuncGraph(
for (int i = 0; i < node_proto.input_size(); ++i) { for (int i = 0; i < node_proto.input_size(); ++i) {
const std::string &input_name = node_proto.input(i); const std::string &input_name = node_proto.input(i);
if (anfnode_build_map_.find(input_name) == anfnode_build_map_.end()) { if (anfnode_build_map_.find(input_name) == anfnode_build_map_.end()) {
MS_LOG(ERROR) << node_name << " input " << i << input_name
<< "can't find in nodes have parsed";
MS_LOG(ERROR) << node_name << " input " << i << input_name << "can't find in nodes have parsed";
return nullptr; return nullptr;
} }
inputs.push_back(anfnode_build_map_[input_name]); inputs.push_back(anfnode_build_map_[input_name]);
@@ -1061,9 +1036,8 @@ CNodePtr AnfImporterFromProtobuf::BuildCNodeForFuncGraph(
return cnode_ptr; return cnode_ptr;
} }


bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(
const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto,
const CNodePtr &cnode_ptr) {
bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGraph,
const onnx::GraphProto &importProto, const CNodePtr &cnode_ptr) {
MS_EXCEPTION_IF_NULL(outputFuncGraph); MS_EXCEPTION_IF_NULL(outputFuncGraph);
MS_EXCEPTION_IF_NULL(cnode_ptr); MS_EXCEPTION_IF_NULL(cnode_ptr);
std::vector<AnfNodePtr> inputs; std::vector<AnfNodePtr> inputs;
@@ -1078,8 +1052,7 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(
elem.push_back(anfnode_build_map_[out_tuple]->abstract()); elem.push_back(anfnode_build_map_[out_tuple]->abstract());
} }
auto maketuple_ptr = outputFuncGraph->NewCNode(inputs); auto maketuple_ptr = outputFuncGraph->NewCNode(inputs);
maketuple_ptr->set_abstract(
std::make_shared<abstract::AbstractTuple>(elem));
maketuple_ptr->set_abstract(std::make_shared<abstract::AbstractTuple>(elem));
inputs.clear(); inputs.clear();
inputs.push_back(NewValueNode(prim::kPrimReturn)); inputs.push_back(NewValueNode(prim::kPrimReturn));
inputs.push_back(maketuple_ptr); inputs.push_back(maketuple_ptr);
@@ -1092,14 +1065,11 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(
const onnx::TypeProto &output_typeproto = output_node.type(); const onnx::TypeProto &output_typeproto = output_node.type();
int output_type = output_typeproto.tensor_type().elem_type(); int output_type = output_typeproto.tensor_type().elem_type();
std::vector<int> output_shape; std::vector<int> output_shape;
for (int i = 0; i < output_typeproto.tensor_type().shape().dim_size();
++i) {
output_shape.push_back(
output_typeproto.tensor_type().shape().dim(i).dim_value());
for (int i = 0; i < output_typeproto.tensor_type().shape().dim_size(); ++i) {
output_shape.push_back(output_typeproto.tensor_type().shape().dim(i).dim_value());
} }
auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[output_type]); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[output_type]);
auto abstract_tensor =
std::make_shared<abstract::AbstractTensor>(type_ptr, output_shape);
auto abstract_tensor = std::make_shared<abstract::AbstractTensor>(type_ptr, output_shape);


inputs.clear(); inputs.clear();
inputs.push_back(NewValueNode(prim::kPrimReturn)); inputs.push_back(NewValueNode(prim::kPrimReturn));
@@ -1113,8 +1083,8 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph(
return true; return true;
} }


bool AnfImporterFromProtobuf::ImportNodesForGraph(
const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto) {
bool AnfImporterFromProtobuf::ImportNodesForGraph(const FuncGraphPtr &outputFuncGraph,
const onnx::GraphProto &importProto) {
MS_EXCEPTION_IF_NULL(outputFuncGraph); MS_EXCEPTION_IF_NULL(outputFuncGraph);
MS_LOG(INFO) << "The CNdoe size : " << importProto.node_size(); MS_LOG(INFO) << "The CNdoe size : " << importProto.node_size();
CNodePtr cnode_ptr = nullptr; CNodePtr cnode_ptr = nullptr;
@@ -1139,8 +1109,7 @@ bool AnfImporterFromProtobuf::ImportNodesForGraph(
return true; return true;
} }


bool AnfImporterFromProtobuf::BuildFuncGraph(
const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto) {
bool AnfImporterFromProtobuf::BuildFuncGraph(const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto) {
MS_EXCEPTION_IF_NULL(outputFuncGraph); MS_EXCEPTION_IF_NULL(outputFuncGraph);
GraphDebugInfoPtr debug_info_ptr = outputFuncGraph->debug_info(); GraphDebugInfoPtr debug_info_ptr = outputFuncGraph->debug_info();
MS_EXCEPTION_IF_NULL(debug_info_ptr); MS_EXCEPTION_IF_NULL(debug_info_ptr);
@@ -1156,8 +1125,7 @@ bool AnfImporterFromProtobuf::BuildFuncGraph(
return ImportNodesForGraph(outputFuncGraph, importProto); return ImportNodesForGraph(outputFuncGraph, importProto);
} }


bool AnfImporterFromProtobuf::ParseModelConfigureInfo(
const onnx::ModelProto &model_proto) {
bool AnfImporterFromProtobuf::ParseModelConfigureInfo(const onnx::ModelProto &model_proto) {
if (!model_proto.has_producer_name()) { if (!model_proto.has_producer_name()) {
MS_LOG(ERROR) << "Parse model producer name from pb file failed!"; MS_LOG(ERROR) << "Parse model producer name from pb file failed!";
return false; return false;
@@ -1194,8 +1162,7 @@ int AnfImporterFromProtobuf::Import() {
return RET_OK; return RET_OK;
} }


onnx::ModelProto *AnfImporterFromProtobuf::ReadOnnxFromBinary(
const std::string &model_path) {
onnx::ModelProto *AnfImporterFromProtobuf::ReadOnnxFromBinary(const std::string &model_path) {
std::unique_ptr<char> onnx_file(new (std::nothrow) char[PATH_MAX]{0}); std::unique_ptr<char> onnx_file(new (std::nothrow) char[PATH_MAX]{0});
if (realpath(model_path.c_str(), onnx_file.get()) == nullptr) { if (realpath(model_path.c_str(), onnx_file.get()) == nullptr) {
MS_LOG(ERROR) << "open file failed."; MS_LOG(ERROR) << "open file failed.";


+ 3
- 2
mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc View File

@@ -20,6 +20,7 @@
#include "mindspore/lite/src/ir/primitive_t_value.h" #include "mindspore/lite/src/ir/primitive_t_value.h"
#include "mindspore/ccsrc/utils/utils.h" #include "mindspore/ccsrc/utils/utils.h"
#include "mindspore/lite/src/gllo/common/utils.h" #include "mindspore/lite/src/gllo/common/utils.h"
#include "securec/include/securec.h"


namespace mindspore::opt { namespace mindspore::opt {
namespace { namespace {
@@ -90,11 +91,11 @@ void GenConvNewBias(const FuncGraphPtr &func_graph, const CNodePtr &conv_node, c
auto add_weight_data = reinterpret_cast<float *>(add_weight_tensor->tensor_addr()); auto add_weight_data = reinterpret_cast<float *>(add_weight_tensor->tensor_addr());


if (add_weight_tensor->tensor_shape().empty()) { if (add_weight_tensor->tensor_shape().empty()) {
if (0 != memset_s(add_bias_data, kernel_nums * sizeof(float), *add_weight_data, kernel_nums * sizeof(float))) {
if (EOK != memset_s(add_bias_data, kernel_nums * sizeof(float), *add_weight_data, kernel_nums * sizeof(float))) {
MS_LOG(EXCEPTION) << "memset_s conv_bias_data failed"; MS_LOG(EXCEPTION) << "memset_s conv_bias_data failed";
} }
} else { } else {
if (0 != memcpy_s(add_bias_data, kernel_nums * sizeof(float), add_weight_data, kernel_nums * sizeof(float))) {
if (EOK != memcpy_s(add_bias_data, kernel_nums * sizeof(float), add_weight_data, kernel_nums * sizeof(float))) {
MS_LOG(EXCEPTION) << "memset_s conv_bias_data failed"; MS_LOG(EXCEPTION) << "memset_s conv_bias_data failed";
} }
} }


+ 2
- 1
mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc View File

@@ -21,6 +21,7 @@
#include "mindspore/lite/src/ir/primitive_t_value.h" #include "mindspore/lite/src/ir/primitive_t_value.h"
#include "mindspore/ccsrc/utils/utils.h" #include "mindspore/ccsrc/utils/utils.h"
#include "mindspore/lite/src/gllo/common/utils.h" #include "mindspore/lite/src/gllo/common/utils.h"
#include "securec/include/securec.h"


namespace mindspore::opt { namespace mindspore::opt {
namespace { namespace {
@@ -46,7 +47,7 @@ void CalTransale(const AnfNodePtr &bn_scale_node, const AnfNodePtr &bn_var_node,
auto bn_var_tensor = std::dynamic_pointer_cast<ParamValueLite>(bn_var_param); auto bn_var_tensor = std::dynamic_pointer_cast<ParamValueLite>(bn_var_param);
auto bn_var_data = reinterpret_cast<float *>(bn_var_tensor->tensor_addr()); auto bn_var_data = reinterpret_cast<float *>(bn_var_tensor->tensor_addr());
// cal transScale, tf : scale/sqrt(variance + eps); caffe : 1/sqrt(variance + eps) // cal transScale, tf : scale/sqrt(variance + eps); caffe : 1/sqrt(variance + eps)
if (memcpy_s(trans_scale, kernel_num * sizeof(float), bn_var_data, kernel_num * sizeof(float)) != 0) {
if (memcpy_s(trans_scale, kernel_num * sizeof(float), bn_var_data, kernel_num * sizeof(float)) != EOK) {
MS_LOG(EXCEPTION) << "memcpy_s transScale error"; MS_LOG(EXCEPTION) << "memcpy_s transScale error";
return; return;
} }


+ 3
- 2
mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc View File

@@ -22,6 +22,7 @@
#include "mindspore/ccsrc/utils/utils.h" #include "mindspore/ccsrc/utils/utils.h"
#include "mindspore/lite/src/gllo/common/utils.h" #include "mindspore/lite/src/gllo/common/utils.h"
#include "include/errorcode.h" #include "include/errorcode.h"
#include "securec/include/securec.h"


namespace mindspore::opt { namespace mindspore::opt {
namespace { namespace {
@@ -69,7 +70,7 @@ const void ConvScaleFusion::InitTransParam(const CNodePtr &scale_node, int kerne
auto weight_value = std::dynamic_pointer_cast<ParamValueLite>(scale_weight_param); auto weight_value = std::dynamic_pointer_cast<ParamValueLite>(scale_weight_param);
auto weight_data = reinterpret_cast<const float *>(weight_value->tensor_addr()); auto weight_data = reinterpret_cast<const float *>(weight_value->tensor_addr());


if (0 != memcpy_s(trans_scale, kernel_num * sizeof(float), weight_data, kernel_num * sizeof(float))) {
if (EOK != memcpy_s(trans_scale, kernel_num * sizeof(float), weight_data, kernel_num * sizeof(float))) {
MS_LOG(EXCEPTION) << "memcpy_s transScale failed"; MS_LOG(EXCEPTION) << "memcpy_s transScale failed";
} }


@@ -77,7 +78,7 @@ const void ConvScaleFusion::InitTransParam(const CNodePtr &scale_node, int kerne
auto scale_bias_param = scale_bias_node->cast<ParameterPtr>()->default_param(); auto scale_bias_param = scale_bias_node->cast<ParameterPtr>()->default_param();
auto bias_value = std::dynamic_pointer_cast<ParamValueLite>(scale_bias_param); auto bias_value = std::dynamic_pointer_cast<ParamValueLite>(scale_bias_param);
auto bias_data = reinterpret_cast<const float *>(bias_value->tensor_addr()); auto bias_data = reinterpret_cast<const float *>(bias_value->tensor_addr());
if (0 != memcpy_s(trans_bias, kernel_num * sizeof(float), bias_data, kernel_num * sizeof(float))) {
if (EOK != memcpy_s(trans_bias, kernel_num * sizeof(float), bias_data, kernel_num * sizeof(float))) {
MS_LOG(EXCEPTION) << "memcpy_s transScale failed"; MS_LOG(EXCEPTION) << "memcpy_s transScale failed";
} }
} }


+ 3
- 2
mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc View File

@@ -22,6 +22,7 @@
#include "mindspore/ccsrc/utils/utils.h" #include "mindspore/ccsrc/utils/utils.h"
#include "mindspore/lite/src/gllo/common/utils.h" #include "mindspore/lite/src/gllo/common/utils.h"
#include "include/errorcode.h" #include "include/errorcode.h"
#include "securec/include/securec.h"


namespace mindspore::opt { namespace mindspore::opt {
namespace { namespace {
@@ -176,7 +177,7 @@ const void ConvTransformFusion::CalNewBiasTensor(float *bias_data, int kernel_nu
MS_ASSERT(bias_data != nullptr); MS_ASSERT(bias_data != nullptr);
if (bias_flag) { if (bias_flag) {
auto tmp_bias_data = new(std::nothrow) float[kernel_num]; auto tmp_bias_data = new(std::nothrow) float[kernel_num];
if (0 != memset_s(bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) {
if (EOK != memset_s(bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) {
MS_LOG(EXCEPTION) << "memset bias data failed"; MS_LOG(EXCEPTION) << "memset bias data failed";
} }
for (size_t i = 0; i < kernel_num; i++) { for (size_t i = 0; i < kernel_num; i++) {
@@ -189,7 +190,7 @@ const void ConvTransformFusion::CalNewBiasTensor(float *bias_data, int kernel_nu
} }
delete[] tmp_bias_data; delete[] tmp_bias_data;
} else { } else {
if (0 != memset_s(bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) {
if (EOK != memset_s(bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) {
MS_LOG(EXCEPTION) << "memset bias data failed"; MS_LOG(EXCEPTION) << "memset bias data failed";
} }
auto ret = memcpy_s(bias_data, kernel_num * sizeof(float), trans_bias, kernel_num * sizeof(float)); auto ret = memcpy_s(bias_data, kernel_num * sizeof(float), trans_bias, kernel_num * sizeof(float));


+ 1
- 5
mindspore/lite/src/ir/tensor.cc View File

@@ -50,11 +50,7 @@ int Tensor::CopyTensorData(const Tensor &srcTensor) {
} }
this->data_ = malloc(data_size); this->data_ = malloc(data_size);
} }
auto ret = memcpy_s(this->data_, data_size, srcTensor.data_, srcTensor.Size());
if (EOK != ret) {
MS_LOG(ERROR) << "memcpy_s failed : " << ret;
return mindspore::lite::RET_ERROR;
}
memcpy(this->data_, srcTensor.data_, data_size);
return 0; return 0;
} }




+ 4
- 5
mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc View File

@@ -80,9 +80,8 @@ int ConcatOpenCLKernel::Run_axis0() {
ocl_runtime->MapBuffer(*buffer, CL_MAP_WRITE, tensor->Size(), command_queue, true); ocl_runtime->MapBuffer(*buffer, CL_MAP_WRITE, tensor->Size(), command_queue, true);
} }


memcpy_s(outputs_[0]->Data(), inputs_[0]->Size(), inputs_[0]->Data(), inputs_[0]->Size());
memcpy_s(reinterpret_cast<char *>(outputs_[0]->Data()) + inputs_[0]->Size(), inputs_[1]->Size(), inputs_[1]->Data(),
inputs_[1]->Size());
memcpy(outputs_[0]->Data(), inputs_[0]->Data(), inputs_[0]->Size());
memcpy(reinterpret_cast<char *>(outputs_[0]->Data()) + inputs_[0]->Size(), inputs_[1]->Data(), inputs_[1]->Size());


for (auto tensors : {&inputs_, &outputs_}) { for (auto tensors : {&inputs_, &outputs_}) {
for (auto &tensor : *tensors) { for (auto &tensor : *tensors) {
@@ -202,8 +201,8 @@ int ConcatOpenCLKernel::Run() {


kernel::LiteKernel *OpenCLConcatKernelCreator(const std::vector<lite::tensor::Tensor *> &inputs, kernel::LiteKernel *OpenCLConcatKernelCreator(const std::vector<lite::tensor::Tensor *> &inputs,
const std::vector<lite::tensor::Tensor *> &outputs, const std::vector<lite::tensor::Tensor *> &outputs,
OpParameter *opParameter,
const lite::Context *ctx, const kernel::KernelKey &desc) {
OpParameter *opParameter, const lite::Context *ctx,
const kernel::KernelKey &desc) {
auto *kernel = new ConcatOpenCLKernel(opParameter, inputs, outputs); auto *kernel = new ConcatOpenCLKernel(opParameter, inputs, outputs);
auto ret = kernel->Init(); auto ret = kernel->Init();
if (0 != ret) { if (0 != ret) {


+ 4
- 4
mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc View File

@@ -66,12 +66,12 @@ int ConvolutionOpenCLKernel::InitBuffer() {
if (io_dataformat_ == schema::Format_NHWC) { if (io_dataformat_ == schema::Format_NHWC) {
packed_weight_ = reinterpret_cast<float *>(allocator->Malloc(weight_tensor->Size())); packed_weight_ = reinterpret_cast<float *>(allocator->Malloc(weight_tensor->Size()));
packed_weight_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true)); packed_weight_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true));
memcpy_s(packed_weight_, weight_tensor->Size(), weight_tensor->Data(), weight_tensor->Size());
memcpy(packed_weight_, weight_tensor->Data(), weight_tensor->Size());
allocator->UnmapBuffer(packed_weight_); allocator->UnmapBuffer(packed_weight_);


packed_bias_ = reinterpret_cast<float *>(allocator->Malloc(bias_tensor->Size())); packed_bias_ = reinterpret_cast<float *>(allocator->Malloc(bias_tensor->Size()));
packed_bias_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true)); packed_bias_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true));
memcpy_s(packed_bias_, bias_tensor->Size(), bias_tensor->Data(), bias_tensor->Size());
memcpy(packed_bias_, bias_tensor->Data(), bias_tensor->Size());
allocator->UnmapBuffer(packed_bias_); allocator->UnmapBuffer(packed_bias_);
} else if (io_dataformat_ == schema::Format_NHWC4) { } else if (io_dataformat_ == schema::Format_NHWC4) {
// OHWI -> OHWIIO // OHWI -> OHWIIO
@@ -88,7 +88,7 @@ int ConvolutionOpenCLKernel::InitBuffer() {


packed_weight_ = reinterpret_cast<float *>(allocator->Malloc(packed_weight_size)); packed_weight_ = reinterpret_cast<float *>(allocator->Malloc(packed_weight_size));
packed_weight_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true)); packed_weight_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true));
memset_s(packed_weight_, packed_weight_size, 0x00, packed_weight_size);
memset(packed_weight_, 0x00, packed_weight_size);
auto weight_data = reinterpret_cast<float *>(weight_tensor->Data()); auto weight_data = reinterpret_cast<float *>(weight_tensor->Data());
for (int co = 0; co < CO; ++co) { for (int co = 0; co < CO; ++co) {
for (int kh = 0; kh < KH; ++kh) { for (int kh = 0; kh < KH; ++kh) {
@@ -108,7 +108,7 @@ int ConvolutionOpenCLKernel::InitBuffer() {
size_t packed_bias_size = CO_SLICES * CO_TILE * sizeof(float); size_t packed_bias_size = CO_SLICES * CO_TILE * sizeof(float);
packed_bias_ = reinterpret_cast<float *>(allocator->Malloc(packed_bias_size)); packed_bias_ = reinterpret_cast<float *>(allocator->Malloc(packed_bias_size));
packed_bias_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true)); packed_bias_ = reinterpret_cast<float *>(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true));
memset_s(packed_bias_, packed_bias_size, 0x00, packed_bias_size);
memset(packed_bias_, 0x00, packed_bias_size);
auto bias_data = reinterpret_cast<float *>(bias_tensor->Data()); auto bias_data = reinterpret_cast<float *>(bias_tensor->Data());
for (int co = 0; co < CO; ++co) { for (int co = 0; co < CO; ++co) {
packed_bias_[co] = bias_data[co]; packed_bias_[co] = bias_data[co];


+ 18
- 25
mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc View File

@@ -33,7 +33,6 @@ using mindspore::kernel::KERNEL_ARCH::kGPU;
using mindspore::lite::KernelRegistrar; using mindspore::lite::KernelRegistrar;
using mindspore::schema::PrimitiveType_DepthwiseConv2D; using mindspore::schema::PrimitiveType_DepthwiseConv2D;



namespace mindspore::kernel { namespace mindspore::kernel {


int DepthwiseConv2dOpenCLKernel::Init() { int DepthwiseConv2dOpenCLKernel::Init() {
@@ -42,7 +41,8 @@ int DepthwiseConv2dOpenCLKernel::Init() {
auto in_format = inputs_[0]->GetFormat(); auto in_format = inputs_[0]->GetFormat();
outputs_[0]->SetFormat(in_format); outputs_[0]->SetFormat(in_format);
if (in_format != schema::Format_NHWC4 && in_format != schema::Format_NC4HW4) { if (in_format != schema::Format_NHWC4 && in_format != schema::Format_NC4HW4) {
MS_LOG(ERROR) << "input format(" << in_format << ") " << "format not support!";
MS_LOG(ERROR) << "input format(" << in_format << ") "
<< "format not support!";
} }
if (mem_type_ == MEM_TYPE::BUF) { if (mem_type_ == MEM_TYPE::BUF) {
kernel_name += "_BUF"; kernel_name += "_BUF";
@@ -62,7 +62,7 @@ int DepthwiseConv2dOpenCLKernel::Init() {
ocl_runtime->CreateKernelFromIL(kernel_(), kernel_name); ocl_runtime->CreateKernelFromIL(kernel_(), kernel_name);
#else #else
std::string program_name = "DepthwiseConv2d"; std::string program_name = "DepthwiseConv2d";
std::set <std::string> build_options;
std::set<std::string> build_options;
#ifdef ENABLE_FP16 #ifdef ENABLE_FP16
std::string source = depthwise_conv2d_source_fp16; std::string source = depthwise_conv2d_source_fp16;
#else #else
@@ -102,10 +102,9 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() {
bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->Malloc(C4NUM * CO4 * sizeof(FLOAT_t))); bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->Malloc(C4NUM * CO4 * sizeof(FLOAT_t)));
bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->MapBuffer(bias_data_, CL_MAP_WRITE, nullptr, true)); bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->MapBuffer(bias_data_, CL_MAP_WRITE, nullptr, true));
size_t up_co_size = C4NUM * CO4 * sizeof(FLOAT_t); size_t up_co_size = C4NUM * CO4 * sizeof(FLOAT_t);
memset_s(bias_data_, up_co_size, 0, up_co_size);
memset(bias_data_, 0, up_co_size);
auto ori_bias = reinterpret_cast<FLOAT_t *>(inputs_.at(kBiasIndex)->Data()); auto ori_bias = reinterpret_cast<FLOAT_t *>(inputs_.at(kBiasIndex)->Data());
memcpy_s(bias_data_, outputs_[0]->Channel() * sizeof(FLOAT_t), ori_bias,
outputs_[0]->Channel() * sizeof(FLOAT_t));
memcpy(bias_data_, ori_bias, outputs_[0]->Channel() * sizeof(FLOAT_t));
allocator->UnmapBuffer(bias_data_); allocator->UnmapBuffer(bias_data_);
} else { } else {
MS_ASSERT(inputs_.size() == kInputSize1); MS_ASSERT(inputs_.size() == kInputSize1);
@@ -113,9 +112,7 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() {
return 0; return 0;
} }


int DepthwiseConv2dOpenCLKernel::ReSize() {
return 0;
}
int DepthwiseConv2dOpenCLKernel::ReSize() { return 0; }


int DepthwiseConv2dOpenCLKernel::Run() { int DepthwiseConv2dOpenCLKernel::Run() {
MS_LOG(DEBUG) << this->Name() << " Running!"; MS_LOG(DEBUG) << this->Name() << " Running!";
@@ -123,17 +120,17 @@ int DepthwiseConv2dOpenCLKernel::Run() {
auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance();
size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM); size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM);
size_t CI4 = UP_DIV(inputs_[0]->Channel(), C4NUM); size_t CI4 = UP_DIV(inputs_[0]->Channel(), C4NUM);
std::vector <size_t> global = {(size_t) outputs_[0]->Width(), (size_t) outputs_[0]->Height(), CO4};
std::vector <size_t> local = {1, 1, CO4};
std::vector<size_t> global = {(size_t)outputs_[0]->Width(), (size_t)outputs_[0]->Height(), CO4};
std::vector<size_t> local = {1, 1, CO4};


float relu_clip1 = 6.0; float relu_clip1 = 6.0;
cl_int2 kernel_size = {parameter->kernel_h_, parameter->kernel_w_}; cl_int2 kernel_size = {parameter->kernel_h_, parameter->kernel_w_};
cl_int2 stride = {parameter->stride_h_, parameter->stride_w_}; cl_int2 stride = {parameter->stride_h_, parameter->stride_w_};
cl_int2 padding = {-parameter->pad_h_, -parameter->pad_w_}; cl_int2 padding = {-parameter->pad_h_, -parameter->pad_w_};
cl_int2 dilation = {parameter->dilation_h_, parameter->dilation_w_}; cl_int2 dilation = {parameter->dilation_h_, parameter->dilation_w_};
cl_int4 src_size = {inputs_[0]->Width(), inputs_[0]->Height(), (cl_int) CI4, inputs_[0]->Batch()};
cl_int4 dst_size = {(cl_int) outputs_[0]->Width(), (cl_int) outputs_[0]->Height(), (cl_int) CO4,
(cl_int) outputs_[0]->Batch()};
cl_int4 src_size = {inputs_[0]->Width(), inputs_[0]->Height(), (cl_int)CI4, inputs_[0]->Batch()};
cl_int4 dst_size = {(cl_int)outputs_[0]->Width(), (cl_int)outputs_[0]->Height(), (cl_int)CO4,
(cl_int)outputs_[0]->Batch()};


ocl_runtime->SetKernelArg(kernel_, 1, packed_weight_); ocl_runtime->SetKernelArg(kernel_, 1, packed_weight_);
ocl_runtime->SetKernelArg(kernel_, 2, bias_data_); ocl_runtime->SetKernelArg(kernel_, 2, bias_data_);
@@ -168,11 +165,11 @@ int DepthwiseConv2dOpenCLKernel::Run() {
im_dst_y = outputs_[0]->Height() * CO4; im_dst_y = outputs_[0]->Height() * CO4;
im_dst_x = outputs_[0]->Width(); im_dst_x = outputs_[0]->Width();
} }
cl::Image2D in_mem(*ocl_runtime->Context(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, image_format,
im_src_x, im_src_y, 0, inputs_[0]->Data(), &in_error_code);
cl::Image2D in_mem(*ocl_runtime->Context(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, image_format, im_src_x,
im_src_y, 0, inputs_[0]->Data(), &in_error_code);
cl_int out_error_code; cl_int out_error_code;
cl::Image2D out_mem(*ocl_runtime->Context(), CL_MEM_WRITE_ONLY, image_format,
im_dst_x, im_dst_y, 0, nullptr, &out_error_code);
cl::Image2D out_mem(*ocl_runtime->Context(), CL_MEM_WRITE_ONLY, image_format, im_dst_x, im_dst_y, 0, nullptr,
&out_error_code);
if (in_error_code != CL_SUCCESS) { if (in_error_code != CL_SUCCESS) {
MS_LOG(DEBUG) << "in Image2D Failed, error=" << in_error_code; MS_LOG(DEBUG) << "in Image2D Failed, error=" << in_error_code;
return 1; return 1;
@@ -181,10 +178,8 @@ int DepthwiseConv2dOpenCLKernel::Run() {
MS_LOG(DEBUG) << "out Image2D Failed, error= " << out_error_code; MS_LOG(DEBUG) << "out Image2D Failed, error= " << out_error_code;
return 1; return 1;
} }
auto origin = cl::array < cl::size_type,
3U > {0, 0, 0};
auto region = cl::array < cl::size_type,
3U > {im_dst_x, im_dst_y, 1};
auto origin = cl::array<cl::size_type, 3U>{0, 0, 0};
auto region = cl::array<cl::size_type, 3U>{im_dst_x, im_dst_y, 1};
ocl_runtime->SetKernelArg(kernel_, 0, in_mem); ocl_runtime->SetKernelArg(kernel_, 0, in_mem);
ocl_runtime->SetKernelArg(kernel_, 4, out_mem); ocl_runtime->SetKernelArg(kernel_, 4, out_mem);


@@ -209,7 +204,5 @@ kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vector<lite::t
return kernel; return kernel;
} }


REG_KERNEL(kGPU, kNumberTypeFloat32, PrimitiveType_DepthwiseConv2D, OpenCLDepthwiseConv2dKernelCreator
)
REG_KERNEL(kGPU, kNumberTypeFloat32, PrimitiveType_DepthwiseConv2D, OpenCLDepthwiseConv2dKernelCreator)
} // namespace mindspore::kernel } // namespace mindspore::kernel


+ 3
- 2
mindspore/lite/test/CMakeLists.txt View File

@@ -3,7 +3,6 @@ set(LITE_DIR ${TOP_DIR}/mindspore/lite)
include_directories(${TOP_DIR}) include_directories(${TOP_DIR})
include_directories(${TEST_DIR}) include_directories(${TEST_DIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/external_libs/gtest.cmake)


### anf src ### anf src
set(ANF_SRC set(ANF_SRC
@@ -294,7 +293,7 @@ endif ()


add_executable(lite-test ${TEST_SRC}) add_executable(lite-test ${TEST_SRC})


target_link_libraries(lite-test dl ${SECUREC_LIBRARY} ${GTEST_LIBRARY} mindspore::json)
target_link_libraries(lite-test dl ${GTEST_LIBRARY})
if (BUILD_MINDDATA) if (BUILD_MINDDATA)
target_link_libraries(lite-test target_link_libraries(lite-test
minddata-lite minddata-lite
@@ -316,5 +315,7 @@ if (BUILD_CONVERTER)
pthread pthread
protobuf protobuf
mindspore::eigen mindspore::eigen
mindspore::json
${SECUREC_LIBRARY}
) )
endif() endif()

+ 2
- 7
mindspore/lite/tools/benchmark/CMakeLists.txt View File

@@ -11,12 +11,7 @@ add_executable(benchmark
${COMMON_SRC}) ${COMMON_SRC})


if (PLATFORM_ARM32 OR PLATFORM_ARM64) if (PLATFORM_ARM32 OR PLATFORM_ARM64)
target_link_libraries(benchmark mindspore-lite ${SECUREC_LIBRARY})
target_link_libraries(benchmark mindspore-lite)
else() else()
target_link_libraries(benchmark mindspore-lite ${SECUREC_LIBRARY} pthread)
target_link_libraries(benchmark mindspore-lite pthread)
endif() endif()

target_link_libraries(benchmark
mindspore::json
# mindspore::eigen
)

+ 3
- 2
mindspore/lite/tools/converter/quantizer/quantize_util.cc View File

@@ -23,6 +23,7 @@
#include "mindspore/lite/tools/converter/quantizer/general_bitpacking.h" #include "mindspore/lite/tools/converter/quantizer/general_bitpacking.h"
#include "src/common/utils.h" #include "src/common/utils.h"
#include "abstract/abstract_value.h" #include "abstract/abstract_value.h"
#include "securec/include/securec.h"


using std::string; using std::string;
using std::vector; using std::vector;
@@ -310,12 +311,12 @@ STATUS PostBitPack(float *weight, size_t shapeSize, size_t bitNum) {
if (bitNum < 8 && bitNum > 1) { if (bitNum < 8 && bitNum > 1) {
BitPack weight_bitpack(bitNum); BitPack weight_bitpack(bitNum);
weight_bitpack.BitPacking(qDatas, qDatas_packed); weight_bitpack.BitPacking(qDatas, qDatas_packed);
if (0 != memcpy_s(rawDatas, shapeSize, &qDatas_packed[0], shapeSize)) {
if (EOK != memcpy_s(rawDatas, shapeSize, &qDatas_packed[0], shapeSize)) {
MS_LOG(ERROR) << "PostBitPack memcpy_s qDatas_packed failed"; MS_LOG(ERROR) << "PostBitPack memcpy_s qDatas_packed failed";
return RET_ERROR; return RET_ERROR;
} }
} else if (bitNum == 8) { } else if (bitNum == 8) {
if (0 != memcpy_s(rawDatas, shapeSize, &qDatas[0], shapeSize)) {
if (EOK != memcpy_s(rawDatas, shapeSize, &qDatas[0], shapeSize)) {
MS_LOG(ERROR) << "PostBitPack memcpy_s qDatas failed"; MS_LOG(ERROR) << "PostBitPack memcpy_s qDatas failed";
return RET_ERROR; return RET_ERROR;
} }


Loading…
Cancel
Save