aicpu使用的代码备份,最后可以用单例模式来做,一个thread的单例子
diff --git a/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.cc b/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.cc
index b10c4d0f26..28494e82d7 100644
--- a/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.cc
+++ b/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.cc
@@ -56,6 +56,18 @@ Result CustomCPUKernel::GetModelAttr() {
return SUCCESS;
}
+void CustomCPUKernel::AicpuThread()
+{
+ while (g_threadExitFlag == true) {
+ svp_acl_error ret = svp_acl_ext_process_aicpu_task(1000); // 1000 ms
+ if (ret != SVP_ACL_SUCCESS && ret != SVP_ACL_ERROR_RT_REPORT_TIMEOUT) {
+ ERROR_LOG("creat aicpu thread failed!");
+ break;
+ }
+ }
+ return;
+}
+
int CustomCPUKernel::Prepare() {
if (prepared_) {
return SUCCESS;
@@ -83,6 +95,11 @@ int CustomCPUKernel::Prepare() {
ERROR_LOG("execute CreateDesc failed");
return FAILED;
}
+
+ svp_acl_ext_get_mdl_aicpu_task_num(modelId_, &aicpu_task_num_);
+ if (aicpu_task_num_ > 0) {
+ std::thread aicpu_thread_(AicpuThread);
+ }
}
if (!is_lstm_) {
@@ -174,12 +191,20 @@ int CustomCPUKernel::Execute() {
CustomCPUKernel::~CustomCPUKernel() {
Unload();
+ DestroyThread();
DestroyDesc();
DestroyInput();
DestroyOutput();
DestroyResource();
}
+void DestroyThread() {
+ if (aicpu_task_num_ > 0) {
+ g_threadExitFlag = false;
+ aicpu_thread_.join();
+ }
+}
+
diff --git a/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.h b/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.h
index 27d262d463..c41c73a3a1 100644
--- a/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.h
+++ b/mindspore/lite/tools/benchmark/nnie/src/custom_fp32.h
@@ -25,10 +25,12 @@
#include <sstream>
#include <vector>
#include <string>
+#include <thread>
#include "include/context.h"
#include "include/api/kernel.h"
#include "include/svp_acl.h"
#include "include/svp_acl_mdl.h"
+#include "include/svp_acl_ext.h"
using mindspore::kernel::Kernel;
using mindspore::tensor::MSTensor;
@@ -100,6 +102,8 @@ class CustomCPUKernel : public Kernel {
void WriteResult(const std::vector<std::vector<float>> &boxValue, uint32_t oriImgWidth, uint32_t oriImgHeight);
void OutputModelResult();
+ void AicpuThread();
+
private:
uint32_t modelId_ = 0;
size_t modelMemSize_ = 0;
@@ -124,6 +128,10 @@ class CustomCPUKernel : public Kernel {
size_t batch_size_ = 1;
int input_num_without_model_ = 1;
bool prepared_ = false;
+
+ bool g_threadExitFlag = true;
+ uint32_t aicpu_task_num_ = 0;
+ std::thread aicpu_thread_;
};
} // namespace lite
} // namespace mindspore