diff --git a/build_helper.py b/build_helper.py index 9a1950d35c3a8f78e025d2b54f271494e4cc437e..e040efd4ee187b429c30ee04c937eea28da3a0d7 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 0000000000000000000000000000000000000000..ae0853f2d110c1c594ce443a97b8030971779386 --- /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 0000000000000000000000000000000000000000..aabab0765092b7deb82454c95986676a5cc869f7 --- /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 0000000000000000000000000000000000000000..4fac7f070806462f27284633b509bf86215eb33e --- /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) {