From ea1c0e7743a915e3c65f8701fb77dd581fc7b74e Mon Sep 17 00:00:00 2001 From: liujiaxin25 Date: Fri, 12 Apr 2024 17:11:18 +0800 Subject: [PATCH] =?UTF-8?q?AI=E5=9F=BA=E7=A1=80=E8=83=BD=E5=8A=9B=EF=BC=9A?= =?UTF-8?q?mindspore=E6=94=AF=E6=8C=81nnrt=E8=AE=BE=E5=A4=87=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=94=AF=E6=8C=81int8/uint8=20NCHW=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E7=9A=84tensor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_helper.py | 3 ++ patches/0040-js-add-nnrt-device.patch | 41 +++++++++++++++++++++++++++ patches/0041-fix-int8-bug.patch | 11 +++++++ patches/0042_nnrt_support_nchw.patch | 24 ++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 patches/0040-js-add-nnrt-device.patch create mode 100644 patches/0041-fix-int8-bug.patch create mode 100644 patches/0042_nnrt_support_nchw.patch diff --git a/build_helper.py b/build_helper.py index 9a1950d35c..e040efd4ee 100755 --- a/build_helper.py +++ b/build_helper.py @@ -56,6 +56,9 @@ def do_patch(patch_dir, target_dir): '0037-npu-support-custom-model.patch', '0038-adapt-nnrt-ext-deps.patch', '0039-fix-double-destry-nnrt-mode.patch', + '0040-js-add-nnrt-device.patch', + '0041-fix-int8-bug.patch', + '0042_nnrt_support_nchw.patch', ] cwd = os.getcwd() diff --git a/patches/0040-js-add-nnrt-device.patch b/patches/0040-js-add-nnrt-device.patch new file mode 100644 index 0000000000..ae0853f2d1 --- /dev/null +++ b/patches/0040-js-add-nnrt-device.patch @@ -0,0 +1,41 @@ +diff --git a/mindspore/lite/src/runtime/js_api/BUILD.gn b/mindspore/lite/src/runtime/js_api/BUILD.gn +index b105bb77..d52044fc 100644 +--- a/mindspore/lite/src/runtime/js_api/BUILD.gn ++++ b/mindspore/lite/src/runtime/js_api/BUILD.gn +@@ -38,6 +38,7 @@ ohos_shared_library("mindsporelite_napi") { + + deps = [ + "../../../:mindspore_lib", ++ "../../../:mindspore_ndk", + ] + external_deps = [ + "ability_runtime:abilitykit_native", +diff --git a/mindspore/lite/src/runtime/js_api/mslite_model_napi.cc b/mindspore/lite/src/runtime/js_api/mslite_model_napi.cc +index e477f253..7f3d2a34 100644 +--- a/mindspore/lite/src/runtime/js_api/mslite_model_napi.cc ++++ b/mindspore/lite/src/runtime/js_api/mslite_model_napi.cc +@@ -30,6 +30,8 @@ + #include "include/js_api/ms_parameters_napi.h" + #include "include/js_api/ms_errors.h" + #include "include/js_api/mslite_model_callback_napi.h" ++#include "include/c_api/context_c.h" ++#include "include/c_api/types_c.h" + #include "src/common/log.h" + + namespace mindspore { +@@ -355,6 +357,15 @@ int32_t MSLiteModelNapi::GetDeviceInfoContext(ContextInfo *context_ptr, + MS_LOG(ERROR) << "Failed to new NNRT deviceInfo."; + return ERR_INVALID_OPERATION; + } ++ size_t num = 0; ++ auto desc = OH_AI_GetAllNNRTDeviceDescs(&num); ++ if ((desc == nullptr) && (num == 0)) { ++ MS_LOG(WARNING) << "Failed to get nnrt device id, skip adding nnrt device info"; ++ break; ++ } ++ auto id = OH_AI_GetDeviceIdFromNNRTDeviceDesc(desc); ++ OH_AI_DestroyAllNNRTDeviceDescs(&desc); ++ nnrt_device->SetDeviceID(id); + device_infos.push_back(nnrt_device); + break; + } diff --git a/patches/0041-fix-int8-bug.patch b/patches/0041-fix-int8-bug.patch new file mode 100644 index 0000000000..aabab07650 --- /dev/null +++ b/patches/0041-fix-int8-bug.patch @@ -0,0 +1,11 @@ +diff --git a/mindspore/lite/src/runtime/kernel/cpu/base/custom_base.cc b/mindspore/lite/src/runtime/kernel/cpu/base/custom_base.cc +index 03477072..ea82e1d8 100644 +--- a/mindspore/lite/src/runtime/kernel/cpu/base/custom_base.cc ++++ b/mindspore/lite/src/runtime/kernel/cpu/base/custom_base.cc +@@ -43,4 +43,6 @@ int CustomBaseCPUKernel::Run() { + REG_KERNEL(kCPU, kNumberTypeInt32, PrimType_Inner_ThirdPartyModel, LiteKernelCreator) + REG_KERNEL(kCPU, kNumberTypeFloat32, PrimType_Inner_ThirdPartyModel, LiteKernelCreator) + REG_KERNEL(kCPU, kNumberTypeBool, PrimType_Inner_ThirdPartyModel, LiteKernelCreator) ++REG_KERNEL(kCPU, kNumberTypeInt8, PrimType_Inner_ThirdPartyModel, LiteKernelCreator) ++REG_KERNEL(kCPU, kNumberTypeUInt8, PrimType_Inner_ThirdPartyModel, LiteKernelCreator) + } // namespace mindspore::kernel diff --git a/patches/0042_nnrt_support_nchw.patch b/patches/0042_nnrt_support_nchw.patch new file mode 100644 index 0000000000..4fac7f0708 --- /dev/null +++ b/patches/0042_nnrt_support_nchw.patch @@ -0,0 +1,24 @@ +diff --git a/mindspore/lite/src/runtime/delegate/nnrt/nnrt_delegate.cc b/mindspore/lite/src/runtime/delegate/nnrt/nnrt_delegate.cc +index fa7b55ff..2a3e4e55 100644 +--- a/mindspore/lite/src/runtime/delegate/nnrt/nnrt_delegate.cc ++++ b/mindspore/lite/src/runtime/delegate/nnrt/nnrt_delegate.cc +@@ -578,8 +578,7 @@ Status NNRTDelegate::CreateNNRTSubgraphKernels(DelegateModel + KernelIter kernel_iter = nnrt_subgraph_ranges[i].begin_iter_ + location.node_index; + in_tensors.push_back((*kernel_iter)->inputs()[location.tensor_index]); + if (in_tensors.back().format() != Format::NHWC) { +- format_not_support = true; +- break ; ++ MS_LOG(INFO) << "subgraph " << i << " input tensor " << in_tensors.back().Name() << " format isn't NHWC "; + } + } + +@@ -600,8 +599,7 @@ Status NNRTDelegate::CreateNNRTSubgraphKernels(DelegateModel + KernelIter kernel_iter = nnrt_subgraph_ranges[i].begin_iter_ + location.node_index; + out_tensors.push_back((*kernel_iter)->outputs()[location.tensor_index]); + if (out_tensors.back().format() != Format::NHWC) { +- format_not_support = true; +- break ; ++ MS_LOG(INFO) << "subgraph " << i << " output tensor " << out_tensors.back().Name() << " format isn't NHWC "; + } + } + if (format_not_support) { -- Gitee