Commit 80793f7bc4d46a2b0022a5cdf4578969f21433cd

Authored by Hu Chunming
1 parent c5950ce3

acl执行错误直接abort

src/util/JpegUtil.cpp
... ... @@ -6,39 +6,48 @@
6 6  
7 7 using namespace std;
8 8  
  9 +#define ACL_CHECK_AND_ABORT(ret, message) \
  10 + if(ret != 0) {LOG_ERROR("{}", message); std::abort();}
9 11  
10 12 int JpegUtil::jpeg_init(int32_t devId){
11 13 deviceId_ = devId;
12 14  
13   - aclError ret;
14   - /* 2.Run the management resource application, including Device, Context, Stream */
15   - aclrtCreateContext(&context_, deviceId_);
  15 + ACL_CHECK_AND_ABORT(aclrtCreateContext(&context_, deviceId_), "aclrtCreateContext failed!");
16 16  
17 17 // channel 准备
18 18 dvppChannelDesc_ = acldvppCreateChannelDesc();
19   - ret = acldvppCreateChannel(dvppChannelDesc_);
  19 + if (dvppChannelDesc_ == nullptr)
  20 + {
  21 + LOG_ERROR("acldvppCreateChannelDesc failed!");
  22 + std::abort();
  23 + }
  24 +
  25 + ACL_CHECK_AND_ABORT(acldvppCreateChannel(dvppChannelDesc_), "acldvppCreateChannel failed!");
20 26  
21 27 // 创建图片编码配置数据,设置编码质量
22 28 // 编码质量范围[0, 100],其中level 0编码质量与level 100差不多,而在[1, 100]内数值越小输出图片质量越差。
23 29 jpegeConfig_ = acldvppCreateJpegeConfig();
24   - acldvppSetJpegeConfigLevel(jpegeConfig_, 100);
  30 + if (jpegeConfig_ == nullptr)
  31 + {
  32 + LOG_ERROR("acldvppCreateJpegeConfig failed!");
  33 + std::abort();
  34 + }
  35 + ACL_CHECK_AND_ABORT(acldvppSetJpegeConfigLevel(jpegeConfig_, 100), "acldvppSetJpegeConfigLevel failed!");
25 36 }
26 37  
27 38 void JpegUtil::jpeg_release(){
28   - aclError ret;
29   - aclrtSetCurrentContext(context_);
30 39  
31   - ret = acldvppDestroyChannel(dvppChannelDesc_);
32   - ret = acldvppDestroyChannelDesc(dvppChannelDesc_);
  40 + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed!");
  41 +
  42 + ACL_CHECK_AND_ABORT(acldvppDestroyChannel(dvppChannelDesc_), "acldvppDestroyChannel failed!");
  43 + ACL_CHECK_AND_ABORT(acldvppDestroyChannelDesc(dvppChannelDesc_), "acldvppDestroyChannelDesc failed!");
  44 +
33 45 dvppChannelDesc_ = nullptr;
34 46  
35 47 acldvppDestroyJpegeConfig(jpegeConfig_);
36 48  
37 49 if (context_ != nullptr) {
38   - ret = aclrtDestroyContext(context_);
39   - if (ret != ACL_SUCCESS) {
40   - LOG_ERROR("destroy context failed");
41   - }
  50 + ACL_CHECK_AND_ABORT(aclrtDestroyContext(context_), "aclrtDestroyContext failed!");
42 51 context_ = nullptr;
43 52 }
44 53 }
... ... @@ -61,38 +70,23 @@ int32_t JpegUtil::jpege_save(char* pcData , uint32_t dataLen, string out_file_na
61 70  
62 71 bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name) {
63 72  
64   - aclError aclRet ;
65   - aclrtSetCurrentContext(context_);
  73 + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed!");
66 74  
67 75 // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据
68 76 uint32_t outBufferSize= 0;
69   - int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize);
70   - if (ret != ACL_SUCCESS) {
71   - LOG_ERROR("acldvppJpegPredictEncSize failed!");
72   - return false;
73   - }
  77 + ACL_CHECK_AND_ABORT(acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize), "acldvppJpegPredictEncSize failed!");
  78 + int ret ;
  79 +
74 80 void *encodeOutBufferDev_ = nullptr;
75   - ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize);
76   - if (ret != ACL_SUCCESS) {
77   - LOG_ERROR("acldvppMalloc failed!");
78   - return false;
79   - }
  81 + ACL_CHECK_AND_ABORT(acldvppMalloc(&encodeOutBufferDev_, outBufferSize), "acldvppJpegPredictEncSize failed!");
80 82  
81 83 bool bRet = false;
82 84 aclrtStream stream_{nullptr};
83 85 aclrtCreateStream(&stream_);
84 86 do {
85 87 // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
86   - aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_);
87   - if (ret != ACL_SUCCESS) {
88   - LOG_ERROR("acldvppJpegEncodeAsync failed!");
89   - break;
90   - }
91   - aclRet = aclrtSynchronizeStream(stream_);
92   - if (ret != ACL_SUCCESS) {
93   - LOG_ERROR("aclrtSynchronizeStream failed!");
94   - break;
95   - }
  88 + ACL_CHECK_AND_ABORT(acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_), "acldvppJpegEncodeAsync failed!");
  89 + ACL_CHECK_AND_ABORT(aclrtSynchronizeStream(stream_), "aclrtSynchronizeStream failed!");
96 90  
97 91 // 申请Host内存outputHostBuffer
98 92 void* outputHostBuffer = malloc(outBufferSize);
... ... @@ -102,13 +96,7 @@ bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam
102 96 }
103 97  
104 98 // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host
105   - aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST);
106   - if (ret != ACL_SUCCESS) {
107   - free(outputHostBuffer);
108   - outputHostBuffer = nullptr;
109   - LOG_ERROR("aclrtMemcpy failed!");
110   - break;
111   - }
  99 + ACL_CHECK_AND_ABORT(aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST), "aclrtMemcpy failed!");
112 100  
113 101 // 数据使用完成后,释放内存
114 102 ret = jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name);
... ... @@ -123,10 +111,7 @@ bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam
123 111 } while (0);
124 112  
125 113 if (stream_ != nullptr) {
126   - ret = aclrtDestroyStream(stream_);
127   - if (ret != ACL_SUCCESS) {
128   - LOG_ERROR("destroy stream failed");
129   - }
  114 + ACL_CHECK_AND_ABORT(aclrtDestroyStream(stream_), "aclrtDestroyStream failed!");
130 115 stream_ = nullptr;
131 116 }
132 117  
... ...
src/util/vpc_util.cpp
... ... @@ -18,6 +18,9 @@
18 18 #include "../decoder/interface/DeviceMemory.hpp"
19 19 #include "../common/logger.hpp"
20 20  
  21 +#define ACL_CHECK_AND_ABORT(ret, message) \
  22 + if(ret != 0) {LOG_ERROR("{}", message); std::abort();}
  23 +
21 24 static uint32_t AlignSize(uint32_t origSize, uint32_t alignment){
22 25 if (alignment == 0) {
23 26 return 0;
... ... @@ -29,37 +32,39 @@ static uint32_t AlignSize(uint32_t origSize, uint32_t alignment){
29 32 void VPCUtil::release()
30 33 {
31 34 if (context_ != nullptr) {
32   - aclrtSetCurrentContext(context_);
  35 + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
33 36  
34   - aclError ret = acldvppDestroyChannel(dvppChannelDesc_);
35   - ret = acldvppDestroyChannelDesc(dvppChannelDesc_);
  37 + ACL_CHECK_AND_ABORT(acldvppDestroyChannel(dvppChannelDesc_), "acldvppDestroyChannel failed !");
  38 + ACL_CHECK_AND_ABORT(acldvppDestroyChannelDesc(dvppChannelDesc_), "acldvppDestroyChannelDesc failed !");
36 39  
37 40 if (stream_ != nullptr) {
38   - aclrtDestroyStream(stream_);
  41 + ACL_CHECK_AND_ABORT(aclrtDestroyStream(stream_), "acldvppDestroyChannelDesc failed !");
39 42 stream_ = nullptr;
40 43 }
41 44  
42   - ret = aclrtDestroyContext(context_);
43   - if (ret != ACL_SUCCESS) {
44   - LOG_ERROR("destroy context failed");
45   - }
  45 + ACL_CHECK_AND_ABORT(aclrtDestroyContext(context_), "aclrtDestroyContext failed !");
  46 +
46 47 context_ = nullptr;
47 48 }
48 49  
49   - LOG_INFO("end to reset device is %d", deviceId_);
  50 + LOG_INFO("end to reset device is {}", deviceId_);
50 51 }
51 52  
52 53 int VPCUtil::init(int32_t devId){
53 54 deviceId_ = devId;
54 55  
55   - aclError ret;
56   - aclrtCreateContext(&context_, deviceId_);
57   -
58   - aclrtCreateStream(&stream_);
  56 + ACL_CHECK_AND_ABORT(aclrtCreateContext(&context_, deviceId_), "aclrtCreateContext failed !");
  57 + ACL_CHECK_AND_ABORT(aclrtCreateStream(&stream_), "aclrtCreateStream failed !");
59 58  
60 59 // channel 准备
61 60 dvppChannelDesc_ = acldvppCreateChannelDesc();
62   - ret = acldvppCreateChannel(dvppChannelDesc_);
  61 + if (dvppChannelDesc_ == nullptr)
  62 + {
  63 + LOG_INFO("acldvppCreateChannelDesc failed!");
  64 + std::abort();
  65 + }
  66 +
  67 + ACL_CHECK_AND_ABORT(acldvppCreateChannel(dvppChannelDesc_), "acldvppCreateChannel failed !");
63 68 }
64 69  
65 70 static void adjustCoordinate(uint32_t& left, uint32_t& right, uint32_t& top, uint32_t& bottom, const uint32_t& width, const uint32_t& height) {
... ... @@ -119,11 +124,7 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) {
119 124 }
120 125  
121 126 aclError ret;
122   - ret = aclrtSetCurrentContext(context_);
123   - if (ret != ACL_SUCCESS) {
124   - LOG_ERROR("aclrtSetCurrentContext failed");
125   - return img_info;
126   - }
  127 + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
127 128  
128 129 // LOG_INFO("crop src {} ({}, {}, {}, {})", obj.object_id, obj.left, obj.right, obj.top, obj.bottom);
129 130 // LOG_INFO("crop {} ({}, {}, {}, {})", obj.object_id, cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
... ... @@ -204,7 +205,7 @@ vector<vpc_img_info> VPCUtil::crop_batch(DeviceMemory *devMem, vector<video_obje
204 205 }
205 206  
206 207 aclError ret;
207   - ret = aclrtSetCurrentContext(context_);
  208 + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
208 209  
209 210 // 输入
210 211 acldvppBatchPicDesc *vpcInputBatchDesc_ = acldvppCreateBatchPicDesc(1);
... ...