Commit 5baff1f33db9612282e2cc954491e86fb088475c

Authored by Hu Chunming
1 parent 4356373c

优化aclrtDestroyStream

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