aicpu代码备份

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

andeyeluguo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值