From e12edf15913746b5531c32ac9097df3c4c62705f Mon Sep 17 00:00:00 2001 From: hangq Date: Wed, 5 Aug 2020 14:41:41 +0800 Subject: [PATCH] remove unused third_party & strip so when Release --- mindspore/core/utils/log_adapter.h | 1 - mindspore/lite/CMakeLists.txt | 22 +- mindspore/lite/include/model.h | 6 +- mindspore/lite/src/CMakeLists.txt | 8 +- .../anf_importer/import_from_protobuf.cc | 251 ++++++++---------- .../src/gllo/fusion/conv_biasadd_fusion.cc | 5 +- .../lite/src/gllo/fusion/conv_bn_fusion.cc | 3 +- .../lite/src/gllo/fusion/conv_scale_fusion.cc | 5 +- .../src/gllo/fusion/conv_transform_fusion.cc | 5 +- mindspore/lite/src/ir/tensor.cc | 6 +- .../runtime/kernel/opencl/kernel/concat.cc | 9 +- .../kernel/opencl/kernel/convolution.cc | 8 +- .../kernel/opencl/kernel/depthwise_conv2d.cc | 43 ++- mindspore/lite/test/CMakeLists.txt | 5 +- mindspore/lite/tools/benchmark/CMakeLists.txt | 9 +- .../converter/quantizer/quantize_util.cc | 5 +- 16 files changed, 178 insertions(+), 213 deletions(-) diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index ce31ce9ab..703cf7494 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -24,7 +24,6 @@ #include #include #include "utils/overload.h" -#include "./securec.h" #ifndef USE_ANDROID_LOG #ifdef USE_GLOG #include "glog/logging.h" diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 0aad94d2f..b3e8e31c0 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -16,15 +16,7 @@ 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/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(SUPPORT_TRAIN "if build for on-device train" 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(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) add_compile_definitions(BUILD_DEVICE) endif() @@ -91,6 +91,10 @@ if (BUILD_CONVERTER) set(PYTHON_LIBRARIES "${py_lib}") endif() 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/eigen.cmake) include_directories(${TOP_DIR}/third_party/protobuf/build/include) diff --git a/mindspore/lite/include/model.h b/mindspore/lite/include/model.h index c08cbf76a..5000d8a1d 100644 --- a/mindspore/lite/include/model.h +++ b/mindspore/lite/include/model.h @@ -23,6 +23,8 @@ #include "schema/model_generated.h" namespace mindspore { +#define MS_API __attribute__((visibility("default"))) + /// \brief ModelImpl defined by MindSpore Lite. /// /// \note List public class and interface for reference. @@ -35,7 +37,7 @@ namespace lite { class Primitive; /// \brief Model defined by MindSpore Lite. -class Model { +class MS_API Model { public: /// \brief Static method to create a Model pointer. /// @@ -78,7 +80,7 @@ class Model { }; /// \brief ModelBuilder defined by MindSpore Lite. -class ModelBuilder { +class MS_API ModelBuilder { public: /// \brief OutEdge defined by MindSpore Lite. struct OutEdge { diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index c41ad846e..8b96e731a 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -75,8 +75,6 @@ add_library(mindspore-lite SHARED ${LITE_SRC} ${ANF_SRC}) target_link_libraries(mindspore-lite cpu_kernel_mid_ ops_mid_ - ${SECUREC_LIBRARY} - mindspore::json ) add_subdirectory(runtime/kernel/arm) @@ -89,3 +87,9 @@ endif () 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() + diff --git a/mindspore/lite/src/common/anf_importer/import_from_protobuf.cc b/mindspore/lite/src/common/anf_importer/import_from_protobuf.cc index 5daaeb12d..904e0bd0a 100644 --- a/mindspore/lite/src/common/anf_importer/import_from_protobuf.cc +++ b/mindspore/lite/src/common/anf_importer/import_from_protobuf.cc @@ -37,6 +37,7 @@ #include "src/param_value_lite.h" #include "tools/converter/parser/onnx/onnx.pb.h" #include "utils/log_adapter.h" +#include "securec/include/securec.h" using string = std::string; using int32 = int32_t; @@ -57,24 +58,16 @@ enum ParseForm : int { }; static std::map 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 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 @@ -194,16 +187,15 @@ ParserAttrShape(const std::string &attr_name, const std::unordered_map(attr_tensor.type##_data(0)); \ - return MakeValue(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(attr_tensor.type##_data(0)); \ + return MakeValue(value); \ + } else { \ + MS_LOG(ERROR) << "size of scalar tensor doesn't equal 1!"; \ + } \ + return {}; \ } 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(); auto *tensor_data_buf = reinterpret_cast(tensor_info->Data()); 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(); MS_EXCEPTION_IF_NULL(param_value); @@ -402,7 +398,11 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInTensorForm(const std::string &val tensor_info->MallocData(); const std::string &tensor_buf = attr_tensor.raw_data(); auto *tensor_data_buf = reinterpret_cast(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)); MS_EXCEPTION_IF_NULL(new_value_node); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]); @@ -641,21 +641,20 @@ bool AnfImporterFromProtobuf::ImportNodesForGraph(const FuncGraphPtr &outputFunc } #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 attr_value_vec; \ - for (int i = 0; i < attr_tensor.type##_data_size(); ++i) { \ - auto value = static_cast(attr_tensor.type##_data(i)); \ - attr_value_vec.push_back(MakeValue(value)); \ - } \ - if (attr_value_vec.size() == 1) { \ - prim->AddAttr(attr_name, attr_value_vec[0]); \ - } else { \ - prim->AddAttr(attr_name, std::make_shared(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 attr_value_vec; \ + for (int i = 0; i < attr_tensor.type##_data_size(); ++i) { \ + auto value = static_cast(attr_tensor.type##_data(i)); \ + attr_value_vec.push_back(MakeValue(value)); \ + } \ + if (attr_value_vec.size() == 1) { \ + prim->AddAttr(attr_name, attr_value_vec[0]); \ + } else { \ + prim->AddAttr(attr_name, std::make_shared(attr_value_vec)); \ + } \ } 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(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); if (!value_proto.has_type() || !value_proto.has_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()); } - 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!"; return false; } - auto type_ptr = - TypeIdToType(kDefaultValueSwitchMap[tensor_typeproto.elem_type()]); - auto abstract_tensor = - std::make_shared(type_ptr, shape); + auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[tensor_typeproto.elem_type()]); + auto abstract_tensor = std::make_shared(type_ptr, shape); node->set_abstract(abstract_tensor); 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); 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(); auto *tensor_data_buf = reinterpret_cast(tensor_info->Data()); 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(); MS_EXCEPTION_IF_NULL(param_value); @@ -725,18 +722,15 @@ bool AnfImporterFromProtobuf::BuildParameterForFuncGraph( 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_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) { const onnx::TensorProto &initializer_proto = importProto.initializer(i); 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; } default_para_map_[initializer_proto.name()] = initializer_proto; @@ -745,8 +739,7 @@ bool AnfImporterFromProtobuf::ImportParametersForGraph( MS_LOG(INFO) << "all parameters size: " << importProto.input_size(); for (int i = 0; i < importProto.input_size(); ++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; return false; } @@ -754,25 +747,20 @@ bool AnfImporterFromProtobuf::ImportParametersForGraph( 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); 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; } - prim->AddAttr(attr_name, - TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type])); + prim->AddAttr(attr_name, TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type])); 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); const int attr_tensor_type = attr_tensor.data_type(); switch (attr_tensor_type) { @@ -806,23 +794,20 @@ bool AnfImporterFromProtobuf::ObtainCNodeAttrInScalarForm( break; } 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 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_LOG(ERROR) << "parse attr type don't support attr type is tensor"; 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); const std::string &attr_name = attr_proto.name(); if (!attr_proto.has_ref_attr_name()) { @@ -846,32 +831,33 @@ bool AnfImporterFromProtobuf::GetAttrValueForCNode( 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(); std::vector shape; for (int i = 0; i < attr_tensor.dims_size(); ++i) { shape.push_back(attr_tensor.dims(i)); } - tensor::TensorPtr tensor_info = std::make_shared( - kDefaultValueSwitchMap[attr_tensor_type], shape); + tensor::TensorPtr tensor_info = std::make_shared(kDefaultValueSwitchMap[attr_tensor_type], shape); tensor_info->MallocData(); const std::string &tensor_buf = attr_tensor.raw_data(); auto *tensor_data_buf = reinterpret_cast(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)); MS_EXCEPTION_IF_NULL(new_value_node); auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type]); - auto abstract_tensor = - std::make_shared(type_ptr, shape); + auto abstract_tensor = std::make_shared(type_ptr, shape); new_value_node->set_abstract(abstract_tensor); anfnode_build_map_[value_node_name] = new_value_node; 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(); ValuePtr value_ptr = nullptr; switch (attr_tensor_type) { @@ -906,8 +892,7 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm( break; } 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; } auto new_value_node = NewValueNode(value_ptr); @@ -918,28 +903,23 @@ bool AnfImporterFromProtobuf::ObtainValueNodeInScalarForm( 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(); - 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; } - auto new_value_node = - NewValueNode(TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type])); - abstract::AbstractTypePtr abs_type = - std::make_shared(std::make_shared()); + auto new_value_node = NewValueNode(TypeIdToType(kDefaultValueSwitchMap[attr_tensor_type])); + abstract::AbstractTypePtr abs_type = std::make_shared(std::make_shared()); new_value_node->set_abstract(abs_type); anfnode_build_map_[value_node_name] = new_value_node; 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]) { case FORM_PARSE_SCALAR: { return ObtainValueNodeInScalarForm(value_node_name, attr_tensor); @@ -951,14 +931,12 @@ bool AnfImporterFromProtobuf::GetAttrValueForValueNode( return ObtainValueNodeInTypeForm(value_node_name, attr_tensor); } 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; } } -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 onnx::AttributeProto &attr_proto = node_proto.attribute(0); if (!attr_proto.has_ref_attr_name()) { @@ -971,22 +949,20 @@ bool AnfImporterFromProtobuf::BuildValueNodeForFuncGraph( 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 shape_vec; const onnx::TensorProto &attr_tensor = attr_proto.t(); for (int i = 0; i < attr_tensor.dims_size(); ++i) { shape_vec.push_back(attr_tensor.dims(i)); } auto type_ptr = TypeIdToType(kDefaultValueSwitchMap[attr_tensor.data_type()]); - auto abstract_tensor = - std::make_shared(type_ptr, shape_vec); + auto abstract_tensor = std::make_shared(type_ptr, shape_vec); MS_EXCEPTION_IF_NULL(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); if (!node_proto.has_op_type()) { 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) { const std::string &input_name = node_proto.input(i); 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; } inputs.push_back(anfnode_build_map_[input_name]); @@ -1061,9 +1036,8 @@ CNodePtr AnfImporterFromProtobuf::BuildCNodeForFuncGraph( 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(cnode_ptr); std::vector inputs; @@ -1078,8 +1052,7 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph( elem.push_back(anfnode_build_map_[out_tuple]->abstract()); } auto maketuple_ptr = outputFuncGraph->NewCNode(inputs); - maketuple_ptr->set_abstract( - std::make_shared(elem)); + maketuple_ptr->set_abstract(std::make_shared(elem)); inputs.clear(); inputs.push_back(NewValueNode(prim::kPrimReturn)); inputs.push_back(maketuple_ptr); @@ -1092,14 +1065,11 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph( const onnx::TypeProto &output_typeproto = output_node.type(); int output_type = output_typeproto.tensor_type().elem_type(); std::vector 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 abstract_tensor = - std::make_shared(type_ptr, output_shape); + auto abstract_tensor = std::make_shared(type_ptr, output_shape); inputs.clear(); inputs.push_back(NewValueNode(prim::kPrimReturn)); @@ -1113,8 +1083,8 @@ bool AnfImporterFromProtobuf::BuildReturnForFuncGraph( 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_LOG(INFO) << "The CNdoe size : " << importProto.node_size(); CNodePtr cnode_ptr = nullptr; @@ -1139,8 +1109,7 @@ bool AnfImporterFromProtobuf::ImportNodesForGraph( 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); GraphDebugInfoPtr debug_info_ptr = outputFuncGraph->debug_info(); MS_EXCEPTION_IF_NULL(debug_info_ptr); @@ -1156,8 +1125,7 @@ bool AnfImporterFromProtobuf::BuildFuncGraph( 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()) { MS_LOG(ERROR) << "Parse model producer name from pb file failed!"; return false; @@ -1194,8 +1162,7 @@ int AnfImporterFromProtobuf::Import() { return RET_OK; } -onnx::ModelProto *AnfImporterFromProtobuf::ReadOnnxFromBinary( - const std::string &model_path) { +onnx::ModelProto *AnfImporterFromProtobuf::ReadOnnxFromBinary(const std::string &model_path) { std::unique_ptr onnx_file(new (std::nothrow) char[PATH_MAX]{0}); if (realpath(model_path.c_str(), onnx_file.get()) == nullptr) { MS_LOG(ERROR) << "open file failed."; diff --git a/mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc b/mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc index 234c23b34..dabcf95f7 100644 --- a/mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc +++ b/mindspore/lite/src/gllo/fusion/conv_biasadd_fusion.cc @@ -20,6 +20,7 @@ #include "mindspore/lite/src/ir/primitive_t_value.h" #include "mindspore/ccsrc/utils/utils.h" #include "mindspore/lite/src/gllo/common/utils.h" +#include "securec/include/securec.h" namespace mindspore::opt { namespace { @@ -90,11 +91,11 @@ void GenConvNewBias(const FuncGraphPtr &func_graph, const CNodePtr &conv_node, c auto add_weight_data = reinterpret_cast(add_weight_tensor->tensor_addr()); 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"; } } 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"; } } diff --git a/mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc b/mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc index fced388e0..340cfc73b 100644 --- a/mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc +++ b/mindspore/lite/src/gllo/fusion/conv_bn_fusion.cc @@ -21,6 +21,7 @@ #include "mindspore/lite/src/ir/primitive_t_value.h" #include "mindspore/ccsrc/utils/utils.h" #include "mindspore/lite/src/gllo/common/utils.h" +#include "securec/include/securec.h" namespace mindspore::opt { 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(bn_var_param); auto bn_var_data = reinterpret_cast(bn_var_tensor->tensor_addr()); // 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"; return; } diff --git a/mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc b/mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc index 76a1693ed..accc310c2 100644 --- a/mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc +++ b/mindspore/lite/src/gllo/fusion/conv_scale_fusion.cc @@ -22,6 +22,7 @@ #include "mindspore/ccsrc/utils/utils.h" #include "mindspore/lite/src/gllo/common/utils.h" #include "include/errorcode.h" +#include "securec/include/securec.h" namespace mindspore::opt { namespace { @@ -69,7 +70,7 @@ const void ConvScaleFusion::InitTransParam(const CNodePtr &scale_node, int kerne auto weight_value = std::dynamic_pointer_cast(scale_weight_param); auto weight_data = reinterpret_cast(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"; } @@ -77,7 +78,7 @@ const void ConvScaleFusion::InitTransParam(const CNodePtr &scale_node, int kerne auto scale_bias_param = scale_bias_node->cast()->default_param(); auto bias_value = std::dynamic_pointer_cast(scale_bias_param); auto bias_data = reinterpret_cast(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"; } } diff --git a/mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc b/mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc index ef40cf2d7..82971c947 100644 --- a/mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc +++ b/mindspore/lite/src/gllo/fusion/conv_transform_fusion.cc @@ -22,6 +22,7 @@ #include "mindspore/ccsrc/utils/utils.h" #include "mindspore/lite/src/gllo/common/utils.h" #include "include/errorcode.h" +#include "securec/include/securec.h" namespace mindspore::opt { namespace { @@ -176,7 +177,7 @@ const void ConvTransformFusion::CalNewBiasTensor(float *bias_data, int kernel_nu MS_ASSERT(bias_data != nullptr); if (bias_flag) { 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"; } 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; } 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"; } auto ret = memcpy_s(bias_data, kernel_num * sizeof(float), trans_bias, kernel_num * sizeof(float)); diff --git a/mindspore/lite/src/ir/tensor.cc b/mindspore/lite/src/ir/tensor.cc index 55a9f80fa..cd9fb766d 100644 --- a/mindspore/lite/src/ir/tensor.cc +++ b/mindspore/lite/src/ir/tensor.cc @@ -50,11 +50,7 @@ int Tensor::CopyTensorData(const Tensor &srcTensor) { } 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; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc index d73110281..4823f1eca 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc @@ -80,9 +80,8 @@ int ConcatOpenCLKernel::Run_axis0() { 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(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(outputs_[0]->Data()) + inputs_[0]->Size(), inputs_[1]->Data(), inputs_[1]->Size()); for (auto tensors : {&inputs_, &outputs_}) { for (auto &tensor : *tensors) { @@ -202,8 +201,8 @@ int ConcatOpenCLKernel::Run() { kernel::LiteKernel *OpenCLConcatKernelCreator(const std::vector &inputs, const std::vector &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 ret = kernel->Init(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc index 7ecc1870e..c2e5e9a44 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc @@ -66,12 +66,12 @@ int ConvolutionOpenCLKernel::InitBuffer() { if (io_dataformat_ == schema::Format_NHWC) { packed_weight_ = reinterpret_cast(allocator->Malloc(weight_tensor->Size())); packed_weight_ = reinterpret_cast(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_); packed_bias_ = reinterpret_cast(allocator->Malloc(bias_tensor->Size())); packed_bias_ = reinterpret_cast(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_); } else if (io_dataformat_ == schema::Format_NHWC4) { // OHWI -> OHWIIO @@ -88,7 +88,7 @@ int ConvolutionOpenCLKernel::InitBuffer() { packed_weight_ = reinterpret_cast(allocator->Malloc(packed_weight_size)); packed_weight_ = reinterpret_cast(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(weight_tensor->Data()); for (int co = 0; co < CO; ++co) { 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); packed_bias_ = reinterpret_cast(allocator->Malloc(packed_bias_size)); packed_bias_ = reinterpret_cast(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(bias_tensor->Data()); for (int co = 0; co < CO; ++co) { packed_bias_[co] = bias_data[co]; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc index 7c44f9c82..02cbc61ae 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -33,7 +33,6 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_DepthwiseConv2D; - namespace mindspore::kernel { int DepthwiseConv2dOpenCLKernel::Init() { @@ -42,7 +41,8 @@ int DepthwiseConv2dOpenCLKernel::Init() { auto in_format = inputs_[0]->GetFormat(); outputs_[0]->SetFormat(in_format); 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) { kernel_name += "_BUF"; @@ -62,7 +62,7 @@ int DepthwiseConv2dOpenCLKernel::Init() { ocl_runtime->CreateKernelFromIL(kernel_(), kernel_name); #else std::string program_name = "DepthwiseConv2d"; - std::set build_options; + std::set build_options; #ifdef ENABLE_FP16 std::string source = depthwise_conv2d_source_fp16; #else @@ -102,10 +102,9 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() { bias_data_ = reinterpret_cast(allocator->Malloc(C4NUM * CO4 * sizeof(FLOAT_t))); bias_data_ = reinterpret_cast(allocator->MapBuffer(bias_data_, CL_MAP_WRITE, nullptr, true)); 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(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_); } else { MS_ASSERT(inputs_.size() == kInputSize1); @@ -113,9 +112,7 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() { return 0; } -int DepthwiseConv2dOpenCLKernel::ReSize() { - return 0; -} +int DepthwiseConv2dOpenCLKernel::ReSize() { return 0; } int DepthwiseConv2dOpenCLKernel::Run() { MS_LOG(DEBUG) << this->Name() << " Running!"; @@ -123,17 +120,17 @@ int DepthwiseConv2dOpenCLKernel::Run() { auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM); size_t CI4 = UP_DIV(inputs_[0]->Channel(), C4NUM); - std::vector global = {(size_t) outputs_[0]->Width(), (size_t) outputs_[0]->Height(), CO4}; - std::vector local = {1, 1, CO4}; + std::vector global = {(size_t)outputs_[0]->Width(), (size_t)outputs_[0]->Height(), CO4}; + std::vector local = {1, 1, CO4}; float relu_clip1 = 6.0; cl_int2 kernel_size = {parameter->kernel_h_, parameter->kernel_w_}; cl_int2 stride = {parameter->stride_h_, parameter->stride_w_}; cl_int2 padding = {-parameter->pad_h_, -parameter->pad_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_, 2, bias_data_); @@ -168,11 +165,11 @@ int DepthwiseConv2dOpenCLKernel::Run() { im_dst_y = outputs_[0]->Height() * CO4; 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::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) { MS_LOG(DEBUG) << "in Image2D Failed, error=" << in_error_code; return 1; @@ -181,10 +178,8 @@ int DepthwiseConv2dOpenCLKernel::Run() { MS_LOG(DEBUG) << "out Image2D Failed, error= " << out_error_code; 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{0, 0, 0}; + auto region = cl::array{im_dst_x, im_dst_y, 1}; ocl_runtime->SetKernelArg(kernel_, 0, in_mem); ocl_runtime->SetKernelArg(kernel_, 4, out_mem); @@ -209,7 +204,5 @@ kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vector 1) { BitPack weight_bitpack(bitNum); 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"; return RET_ERROR; } } 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"; return RET_ERROR; } -- GitLab