Blame view

src/utils/DeviceUtil.hpp 602 Bytes
01b357d4   Hu Chunming   添加获取显存占用的代码
1
2
3
4
5
6
7
8
9
10
  
  #ifndef __DEVICE_UTIL__
  #define __DEVICE_UTIL__
  
  #include "acl/acl.h"
  #include "acl/ops/acl_dvpp.h"
  
  #include "logger.hpp"
  
  
d708ccb3   Hu Chunming   增加日志
11
  size_t GetDeviceMem(int dev_id) {
01b357d4   Hu Chunming   添加获取显存占用的代码
12
13
14
15
16
17
18
19
20
      aclrtSetDevice(dev_id);
      size_t free = 0;
      size_t total = 0;
      aclError  err = aclrtGetMemInfo(ACL_DDR_MEM, &free, &total);
      aclrtResetDevice(dev_id);
      if (err != 0){
          LOG_ERROR("aclrtGetMemInfo error!");
          return -1;
      }
01b357d4   Hu Chunming   添加获取显存占用的代码
21
  
d708ccb3   Hu Chunming   增加日志
22
23
24
25
      size_t usage = (total - free)/(1024*1024);
      LOG_INFO("device {} memory usage/total:{}/{}", dev_id, usage, total/(1024*1024));
  
      return usage;
01b357d4   Hu Chunming   添加获取显存占用的代码
26
27
28
29
  }
  
  
  #endif      // __DEVICE_UTIL__