Commit a0e58901c398cf4db491af62fff8be77ee7af08a
1 parent
31a1e592
去掉CMultiSourceProcess的多GPU参数,多GPU由上一层来设置更为方便简单;去掉多余成员变量;优化代码
Showing
3 changed files
with
24 additions
and
75 deletions
FFNvDecoder/FFNvDecoderManager.cpp
tsl_aiplatform/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -93,6 +93,7 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam) { |
93 | 93 | |
94 | 94 | m_bfinish = false; |
95 | 95 | |
96 | + // 设置gpuid | |
96 | 97 | gpu_id_ = to_string(vptParam.gpuid); |
97 | 98 | |
98 | 99 | int ret = SUCCESS; |
... | ... | @@ -113,12 +114,6 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam) { |
113 | 114 | { |
114 | 115 | /*初始化全局参数*/ |
115 | 116 | |
116 | - mModeSnapshotVideo = "cpu"; | |
117 | - mModeSnapshotLittle = "cpu"; | |
118 | - | |
119 | - taskFinishCallbackFunc = nullptr; | |
120 | - taskObjInfoCallbackFunc = nullptr; | |
121 | - | |
122 | 117 | set_default_logger(LogLevel(vptParam.log_level), "multi_source_video_process", vptParam.log_path, vptParam.log_mem, |
123 | 118 | vptParam.log_mem); |
124 | 119 | |
... | ... | @@ -327,35 +322,19 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ |
327 | 322 | #endif |
328 | 323 | |
329 | 324 | // 启动算法处理线程 |
330 | - startProcessByGpuid(gpu_id_); | |
325 | + startProcessByGpuid(); | |
331 | 326 | } |
332 | 327 | |
333 | 328 | // 启动算法处理线程 |
334 | -void CMultiSourceProcess::startProcessByGpuid(const string gpuid){ | |
335 | - | |
336 | - struct ThreadArg{ | |
337 | - const string gpu_id; | |
338 | - void* opaque; | |
339 | - }; | |
340 | - | |
341 | - ThreadArg thread_arg = {gpuid, this}; | |
342 | - | |
343 | - pthread_t* processThread = gpuProcessthreadMap[gpuid]; | |
344 | - if(processThread == nullptr){ | |
345 | - pthread_t* pTread = new pthread_t; | |
346 | - pthread_create(pTread,0, | |
347 | - [](void* arg) | |
348 | - { | |
349 | - ThreadArg* ptr=(ThreadArg*)arg; | |
350 | - if(ptr != nullptr){ | |
351 | - CMultiSourceProcess* process = (CMultiSourceProcess*)ptr->opaque ; | |
352 | - process->algorthim_process_thread(ptr->gpu_id); | |
353 | - } | |
354 | - return (void*)0; | |
355 | - } | |
356 | - ,&thread_arg); | |
357 | - gpuProcessthreadMap[gpuid] = pTread; | |
358 | - } | |
329 | +void CMultiSourceProcess::startProcessByGpuid(){ | |
330 | + pthread_create(&m_gpuProcessthread,0, | |
331 | + [](void* arg) | |
332 | + { | |
333 | + CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; | |
334 | + process->algorthim_process_thread(); | |
335 | + return (void*)0; | |
336 | + } | |
337 | + ,this); | |
359 | 338 | } |
360 | 339 | |
361 | 340 | void CMultiSourceProcess::post_decode_thread(task_param _cur_task_param, AVFrame * gpuFrame){ |
... | ... | @@ -378,7 +357,7 @@ void CMultiSourceProcess::post_decode_thread(task_param _cur_task_param, AVFrame |
378 | 357 | } |
379 | 358 | // TODO 本循环需要一个可以手动终止的开关 |
380 | 359 | m_QueueMtx.lock(); |
381 | - if(m_RgbDataList.size() >= (20 * gpuProcessthreadMap.size() + 20)){ | |
360 | + if(m_RgbDataList.size() >= 40){ | |
382 | 361 | m_QueueMtx.unlock(); |
383 | 362 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); |
384 | 363 | continue; |
... | ... | @@ -390,6 +369,7 @@ void CMultiSourceProcess::post_decode_thread(task_param _cur_task_param, AVFrame |
390 | 369 | } |
391 | 370 | } |
392 | 371 | |
372 | +// 解码线程退出的最后回调的实际任务函数 | |
393 | 373 | void CMultiSourceProcess::decode_finished_thread(task_param t_param){ |
394 | 374 | // 任务结束,关闭跟踪 |
395 | 375 | if (!FinishTaskTracker(VPT_Handle_, t_param.task_id)) |
... | ... | @@ -436,7 +416,7 @@ void CMultiSourceProcess::cuda_free_wrap(sy_img &img) { |
436 | 416 | } |
437 | 417 | |
438 | 418 | // 算法处理函数,由算法线程调用 |
439 | -void CMultiSourceProcess::algorthim_process_thread(const string gpuid){ | |
419 | +void CMultiSourceProcess::algorthim_process_thread(){ | |
440 | 420 | |
441 | 421 | map<string, int> task_id_to_n_frame; |
442 | 422 | while(true){ |
... | ... | @@ -454,16 +434,12 @@ void CMultiSourceProcess::algorthim_process_thread(const string gpuid){ |
454 | 434 | m_QueueMtx.lock(); |
455 | 435 | |
456 | 436 | vector<GpuRgbMemory*> vec_gpuMem; |
457 | - for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ){ | |
437 | + for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){ | |
458 | 438 | GpuRgbMemory* gpuMem = *iter; |
459 | - if(gpuMem->getGpuId() == gpuid){ | |
460 | - vec_gpuMem.push_back(gpuMem); | |
461 | - iter = m_RgbDataList.erase(iter); | |
462 | - if(vec_gpuMem.size() >= 20){ | |
463 | - break; | |
464 | - } | |
465 | - } else { | |
466 | - ++ iter; | |
439 | + vec_gpuMem.push_back(gpuMem); | |
440 | + iter = m_RgbDataList.erase(iter); | |
441 | + if(vec_gpuMem.size() >= 20){ | |
442 | + break; | |
467 | 443 | } |
468 | 444 | } |
469 | 445 | |
... | ... | @@ -1171,7 +1147,6 @@ int CMultiSourceProcess::GetTaskStatus(const string taskID) { |
1171 | 1147 | |
1172 | 1148 | if (!taskids.empty()) { |
1173 | 1149 | auto json_str = helpers::gen_json::gen_task_status_json(taskids, statues); |
1174 | - // mq_manager_->publish(mq_type_t::GET_TASK_MQ, json_str.c_str()); | |
1175 | 1150 | mq_manager_->publish(mq_type_t::GET_TASK_MQ, json_str.c_str(),true); |
1176 | 1151 | } |
1177 | 1152 | |
... | ... | @@ -1226,13 +1201,7 @@ void CMultiSourceProcess::CloseAllTask(){ |
1226 | 1201 | FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); |
1227 | 1202 | pDecManager->closeAllDecoder(); |
1228 | 1203 | |
1229 | - for (auto it = gpuProcessthreadMap.begin(); it != gpuProcessthreadMap.end(); it++){ | |
1230 | - if(it->second != 0){ | |
1231 | - pthread_join(*(it->second),0); | |
1232 | - delete it->second; | |
1233 | - } | |
1234 | - } | |
1235 | - gpuProcessthreadMap.clear(); | |
1204 | + pthread_join(m_gpuProcessthread,0); | |
1236 | 1205 | |
1237 | 1206 | m_QueueMtx.lock(); |
1238 | 1207 | for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ){ | ... | ... |
tsl_aiplatform/ai_platform/MultiSourceProcess.h
... | ... | @@ -155,7 +155,7 @@ public: |
155 | 155 | |
156 | 156 | public: |
157 | 157 | // 生成线程的内部接口,外部勿调用 |
158 | - void algorthim_process_thread(const string gpuid); // 算法处理线程 | |
158 | + void algorthim_process_thread(); // 算法处理线程 | |
159 | 159 | void post_decode_thread(task_param _cur_task_param, AVFrame * gpuFrame); // 解码数据处理函数,在解码线程中执行 |
160 | 160 | void decode_finished_thread(task_param _cur_task_param); // 解码线程结束后处理函数,在解码线程中执行 |
161 | 161 | |
... | ... | @@ -164,7 +164,7 @@ public: |
164 | 164 | #endif |
165 | 165 | |
166 | 166 | private: |
167 | - void startProcessByGpuid(const string gpuid); | |
167 | + void startProcessByGpuid(); | |
168 | 168 | bool task_has_vpt_algor(const std::string &task_id); |
169 | 169 | bool task_has_face_algor(const std::string &task_id); |
170 | 170 | void cuda_free_wrap(sy_img &img); |
... | ... | @@ -202,7 +202,7 @@ private: |
202 | 202 | int everyframe_process(vector<string> &task_in_play_id, sy_img *images, vector<onelevel_det_result> &ol_det_result); |
203 | 203 | |
204 | 204 | private: |
205 | - map<string, pthread_t*> gpuProcessthreadMap; // 本想做个多GPU的,但是原版的多GPU设置由上层来做,而且似乎可以更好 | |
205 | + pthread_t m_gpuProcessthread; | |
206 | 206 | list<GpuRgbMemory*> m_RgbDataList; |
207 | 207 | std::mutex m_QueueMtx; |
208 | 208 | bool m_bfinish; |
... | ... | @@ -215,27 +215,6 @@ private: |
215 | 215 | int licence_status_; |
216 | 216 | string gpu_id_; |
217 | 217 | |
218 | - | |
219 | - // vector<onelevel_det_result> VPTResult; | |
220 | - std::atomic<bool> ProcessFlag; | |
221 | - bool SourceFlag; | |
222 | - unsigned char *imgDataDevice; | |
223 | - void *FrameTemp; | |
224 | - char *mModeSnapshotVideo; | |
225 | - char *mModeSnapshotLittle; | |
226 | - string viewTaskID; | |
227 | - | |
228 | - map<int, set<int>> objDelete; | |
229 | - | |
230 | - FINISH_CALLBACK taskFinishCallbackFunc; | |
231 | - OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc; | |
232 | - | |
233 | - bool beginSaveSnapshot; | |
234 | - boost::thread_group saveSnapshotsThreadGroup; | |
235 | - std::mutex taskMutex; | |
236 | - std::condition_variable taskCondVar; | |
237 | - bool AttributionAnalysis; // 用于控制,每帧分析只进行一个二次属性分析 | |
238 | - | |
239 | 218 | snapshot_reprocessing *m_snapshot_reprocessing{nullptr}; |
240 | 219 | task_param_manager *m_task_param_manager{nullptr}; |
241 | 220 | ... | ... |