Commit 5baff1f33db9612282e2cc954491e86fb088475c

Authored by Hu Chunming
1 parent 4356373c

优化aclrtDestroyStream

.vscode/launch.json
... ... @@ -104,8 +104,8 @@
104 104 "args": [],
105 105 "stopAtEntry": false,
106 106 "externalConsole": false,
107   - "cwd": "/home/cmhu/vpt_ascend_arm/src/demo",
108   - "program": "/home/cmhu/vpt_ascend_arm/src/demo/build/Debug/outDebug",
  107 + "cwd": "/home/cmhu/vpt_ascend_arm/src/decoder/dvpp",
  108 + "program": "/home/cmhu/vpt_ascend_arm/src/decoder/dvpp/build/Debug/outDebug",
109 109 "MIMode": "gdb",
110 110 "miDebuggerPath": "gdb",
111 111 "setupCommands": [
... ...
src/ai_engine_module/VPTProcess.cpp
... ... @@ -70,6 +70,10 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist,
70 70 }
71 71  
72 72 do{
  73 +
  74 + aclrtSetDevice(m_devId);
  75 + int ret = aclrtSetCurrentContext(m_algorthim_ctx);
  76 +
73 77 /* 路数太多时 按照最大batchsize数 拆批次运行 */
74 78 int cur_batch_size = m_max_batchsize;
75 79 int cycleTimes = batchsize / cur_batch_size + (batchsize % cur_batch_size == 0 ? 0 : 1);
... ... @@ -80,9 +84,6 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist,
80 84 int startbatch = c*cur_batch_size;
81 85  
82 86 vpt_result *real_res = vpt_det_result + startbatch;
83   -
84   - // aclrtSetDevice(m_devId);
85   - int ret = aclrtSetCurrentContext(m_algorthim_ctx);
86 87 if(ACL_SUCCESS != ret){
87 88 break;
88 89 }
... ...
src/decoder/dvpp/VpcUtils.cpp
... ... @@ -17,10 +17,6 @@ VpcUtils::VpcUtils(){
17 17 }
18 18  
19 19 VpcUtils::~VpcUtils(){
20   - if(nullptr != stream_){
21   - aclrtDestroyStream(stream_);
22   - }
23   -
24 20 if(context_){
25 21 aclrtDestroyContext(context_);
26 22 }
... ... @@ -40,7 +36,6 @@ int VpcUtils::init(int devId){
40 36 aclrtCreateContext(&context_, m_devId);
41 37  
42 38 CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed");
43   - CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! ");
44 39  
45 40 dvppChannelDesc_ = acldvppCreateChannelDesc();
46 41  
... ... @@ -79,6 +74,8 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
79 74 acldvppSetPicDescSize(outputDesc_, out_buf_size);
80 75  
81 76 aclError ret = ACL_ERROR_NONE;
  77 + aclrtStream stream_{nullptr};
  78 + aclrtCreateStream(&stream_);
82 79 do{
83 80 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
84 81 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -93,6 +90,11 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width,
93 90 }
94 91 }while(0);
95 92  
  93 + if(nullptr != stream_){
  94 + aclrtDestroyStream(stream_);
  95 + stream_ = nullptr;
  96 + }
  97 +
96 98 acldvppDestroyPicDesc(outputDesc_);
97 99  
98 100 if(ret != ACL_ERROR_NONE){
... ... @@ -138,6 +140,8 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
138 140 acldvppSetPicDescSize(outputDesc_, out_buf_size);
139 141  
140 142 aclError ret = ACL_ERROR_NONE;
  143 + aclrtStream stream_{nullptr};
  144 + aclrtCreateStream(&stream_);
141 145 do{
142 146 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
143 147 ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
... ... @@ -152,6 +156,11 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){
152 156 }
153 157 }while(0);
154 158  
  159 + if(nullptr != stream_){
  160 + aclrtDestroyStream(stream_);
  161 + stream_ = nullptr;
  162 + }
  163 +
155 164 acldvppDestroyPicDesc(outputDesc_);
156 165 acldvppDestroyPicDesc(inputDesc_);
157 166  
... ... @@ -187,6 +196,8 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
187 196 acldvppResizeConfig *resizeConfig_ = acldvppCreateResizeConfig();
188 197  
189 198 aclError ret = ACL_ERROR_NONE;
  199 + aclrtStream stream_{nullptr};
  200 + aclrtCreateStream(&stream_);
190 201 do{
191 202 // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
192 203 ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_);
... ... @@ -201,6 +212,11 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int
201 212 }
202 213 }while(0);
203 214  
  215 + if(nullptr != stream_){
  216 + aclrtDestroyStream(stream_);
  217 + stream_ = nullptr;
  218 + }
  219 +
204 220 acldvppDestroyResizeConfig(resizeConfig_);
205 221 acldvppDestroyPicDesc(outputDesc_);
206 222  
... ...
src/decoder/dvpp/VpcUtils.h
... ... @@ -16,7 +16,6 @@ public:
16 16  
17 17 private:
18 18 aclrtContext context_{nullptr};
19   - aclrtStream stream_{nullptr};
20 19 int m_devId;
21 20 acldvppChannelDesc *dvppChannelDesc_ {nullptr};
22 21 string m_dec_name;
... ...
src/util/JpegUtil.cpp
... ... @@ -14,7 +14,6 @@ int JpegUtil::jpeg_init(int32_t devId){
14 14 /* 2.Run the management resource application, including Device, Context, Stream */
15 15 aclrtSetDevice(deviceId_);
16 16 aclrtCreateContext(&context_, deviceId_);
17   - aclrtCreateStream(&stream_);
18 17  
19 18 // channel 准备
20 19 dvppChannelDesc_ = acldvppCreateChannelDesc();
... ... @@ -35,14 +34,6 @@ void JpegUtil::jpeg_release(){
35 34 ret = acldvppDestroyChannelDesc(dvppChannelDesc_);
36 35 dvppChannelDesc_ = nullptr;
37 36  
38   - if (stream_ != nullptr) {
39   - ret = aclrtDestroyStream(stream_);
40   - if (ret != ACL_SUCCESS) {
41   - LOG_ERROR("destroy stream failed");
42   - }
43   - stream_ = nullptr;
44   - }
45   -
46 37 acldvppDestroyJpegeConfig(jpegeConfig_);
47 38  
48 39 if (context_ != nullptr) {
... ... @@ -96,6 +87,8 @@ bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam
96 87 }
97 88  
98 89 bool bRet = false;
  90 + aclrtStream stream_{nullptr};
  91 + aclrtCreateStream(&stream_);
99 92 do {
100 93 // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
101 94 aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_);
... ... @@ -136,6 +129,14 @@ bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam
136 129  
137 130 bRet = true;
138 131 } while (0);
  132 +
  133 + if (stream_ != nullptr) {
  134 + ret = aclrtDestroyStream(stream_);
  135 + if (ret != ACL_SUCCESS) {
  136 + LOG_ERROR("destroy stream failed");
  137 + }
  138 + stream_ = nullptr;
  139 + }
139 140  
140 141 // 释放掉输入输出的device内存
141 142 (void)acldvppFree(encodeOutBufferDev_);
... ...
src/util/JpegUtil.h
... ... @@ -23,7 +23,6 @@ private:
23 23 private:
24 24 int32_t deviceId_;
25 25 aclrtContext context_;
26   - aclrtStream stream_;
27 26 acldvppChannelDesc *dvppChannelDesc_;
28 27 acldvppJpegeConfig *jpegeConfig_ ;
29 28 };
... ...