Commit 03c072bf138490e46309e86f5ec22f36990e4fb3
1 parent
7c5cf8c9
修复显存泄露。特别注意VpcUtils::release()中 acldvppDestroyChannel 需要 aclrtSetCurrentContext 才会生效
Showing
5 changed files
with
50 additions
and
109 deletions
src/decoder/dvpp/DvppStreamDecoder.cpp
@@ -67,13 +67,7 @@ bool DvppStreamDecoder::Init(FFDecConfig cfg) { | @@ -67,13 +67,7 @@ bool DvppStreamDecoder::Init(FFDecConfig cfg) { | ||
67 | m_deviceId = atoi(cfg.gpuid.c_str()); | 67 | m_deviceId = atoi(cfg.gpuid.c_str()); |
68 | 68 | ||
69 | do{ | 69 | do{ |
70 | - aclError ret = aclrtSetDevice(m_deviceId); | ||
71 | - if(ret != ACL_ERROR_NONE){ | ||
72 | - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); | ||
73 | - return false; | ||
74 | - } | ||
75 | - | ||
76 | - ret = aclrtCreateContext(&m_context, m_deviceId); | 70 | + aclError ret = aclrtCreateContext(&m_context, m_deviceId); |
77 | if (ret != ACL_ERROR_NONE) { | 71 | if (ret != ACL_ERROR_NONE) { |
78 | LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); | 72 | LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); |
79 | return false; | 73 | return false; |
@@ -138,15 +132,8 @@ int DvppStreamDecoder::getVdecType(int videoType) | @@ -138,15 +132,8 @@ int DvppStreamDecoder::getVdecType(int videoType) | ||
138 | 132 | ||
139 | void DvppStreamDecoder::doProcessReport(){ | 133 | void DvppStreamDecoder::doProcessReport(){ |
140 | 134 | ||
141 | - aclError ret = aclrtSetDevice(m_deviceId); | ||
142 | - if(ret != ACL_ERROR_NONE){ | ||
143 | - // cout << "aclrtSetDevice failed" << endl; | ||
144 | - LOG_ERROR("aclrtSetDevice failed !"); | ||
145 | - return ; | ||
146 | - } | ||
147 | - | ||
148 | aclrtContext ctx; | 135 | aclrtContext ctx; |
149 | - ret = aclrtCreateContext(&ctx, m_deviceId); | 136 | + aclError ret = aclrtCreateContext(&ctx, m_deviceId); |
150 | if (ret != ACL_ERROR_NONE) { | 137 | if (ret != ACL_ERROR_NONE) { |
151 | // cout << "aclrtCreateContext failed " << endl; | 138 | // cout << "aclrtCreateContext failed " << endl; |
152 | LOG_ERROR("aclrtCreateContext failed !"); | 139 | LOG_ERROR("aclrtCreateContext failed !"); |
src/decoder/dvpp/VpcUtils.cpp
@@ -17,30 +17,23 @@ VpcUtils::VpcUtils(){ | @@ -17,30 +17,23 @@ VpcUtils::VpcUtils(){ | ||
17 | } | 17 | } |
18 | 18 | ||
19 | VpcUtils::~VpcUtils(){ | 19 | VpcUtils::~VpcUtils(){ |
20 | - if(context_){ | ||
21 | - aclrtDestroyContext(context_); | ||
22 | - } | ||
23 | - | ||
24 | - if (dvppChannelDesc_) { | ||
25 | - (void)acldvppDestroyChannel(dvppChannelDesc_); | ||
26 | - (void)acldvppDestroyChannelDesc(dvppChannelDesc_); | ||
27 | - dvppChannelDesc_ = nullptr; | ||
28 | - } | 20 | + release(); |
29 | } | 21 | } |
30 | 22 | ||
31 | int VpcUtils::init(int devId){ | 23 | int VpcUtils::init(int devId){ |
32 | 24 | ||
33 | m_devId = devId; | 25 | m_devId = devId; |
34 | 26 | ||
35 | - aclrtCreateContext(&context_, m_devId); | ||
36 | - | ||
37 | - CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed"); | ||
38 | - | ||
39 | - dvppChannelDesc_ = acldvppCreateChannelDesc(); | 27 | + aclError ret = aclrtCreateContext(&context_, m_devId); |
28 | + if (ret != ACL_ERROR_NONE) { | ||
29 | + LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); | ||
30 | + return false; | ||
31 | + } | ||
40 | 32 | ||
41 | - int ret = ACL_ERROR_NONE; | ||
42 | do | 33 | do |
43 | { | 34 | { |
35 | + dvppChannelDesc_ = acldvppCreateChannelDesc(); | ||
36 | + | ||
44 | ret = acldvppCreateChannel(dvppChannelDesc_); | 37 | ret = acldvppCreateChannel(dvppChannelDesc_); |
45 | CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !"); | 38 | CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !"); |
46 | 39 | ||
@@ -51,6 +44,21 @@ int VpcUtils::init(int devId){ | @@ -51,6 +44,21 @@ int VpcUtils::init(int devId){ | ||
51 | return ret; | 44 | return ret; |
52 | } | 45 | } |
53 | 46 | ||
47 | +void VpcUtils::release() { | ||
48 | + | ||
49 | + if(context_){ | ||
50 | + aclrtSetCurrentContext(context_); | ||
51 | + | ||
52 | + if (dvppChannelDesc_) { | ||
53 | + (void)acldvppDestroyChannel(dvppChannelDesc_); | ||
54 | + (void)acldvppDestroyChannelDesc(dvppChannelDesc_); | ||
55 | + dvppChannelDesc_ = nullptr; | ||
56 | + } | ||
57 | + | ||
58 | + aclrtDestroyContext(context_); | ||
59 | + } | ||
60 | +} | ||
61 | + | ||
54 | DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ | 62 | DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ |
55 | 63 | ||
56 | aclrtSetCurrentContext(context_); | 64 | aclrtSetCurrentContext(context_); |
src/decoder/dvpp/VpcUtils.h
@@ -13,7 +13,8 @@ public: | @@ -13,7 +13,8 @@ public: | ||
13 | DvppDataMemory* convert2bgr(DvppDataMemory* inMem); | 13 | DvppDataMemory* convert2bgr(DvppDataMemory* inMem); |
14 | 14 | ||
15 | DvppDataMemory* resize(acldvppPicDesc *inputDesc_, int out_width, int out_height); | 15 | DvppDataMemory* resize(acldvppPicDesc *inputDesc_, int out_width, int out_height); |
16 | - | 16 | +private: |
17 | + void release(); | ||
17 | private: | 18 | private: |
18 | aclrtContext context_{nullptr}; | 19 | aclrtContext context_{nullptr}; |
19 | int m_devId; | 20 | int m_devId; |
src/decoder/interface/Makefile deleted
1 | -# 各项目录 | ||
2 | -LIB_DIR:=$(BUILD_DIR)/$(MODULE)/lib | ||
3 | -DEP_DIR:=$(BUILD_DIR)/$(MODULE)/.dep | ||
4 | -OBJ_DIR:=$(BUILD_DIR)/$(MODULE)/obj | ||
5 | -SRC_DIR:=$(TOP_DIR)/$(MODULE) | ||
6 | - | ||
7 | -# 源文件以及中间目标文件和依赖文件 | ||
8 | -SRCS:=$(notdir $(wildcard $(SRC_DIR)/*.cpp)) | ||
9 | -OBJS:=$(addprefix $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SRCS))) | ||
10 | -DEPS:=$(addprefix $(DEP_DIR)/, $(patsubst %.cpp, %.d,a $(SRCS))) | ||
11 | - | ||
12 | -# 自动生成头文件依赖选项 | ||
13 | -DEPFLAGS=-MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d | ||
14 | - | ||
15 | -JRTP_ROOT = $(THIRDPARTY_ROOT)/jrtp_export | ||
16 | - | ||
17 | -INCLUDE= -I $(TOP_DIR)/common/inc \ | ||
18 | - -I $(TOP_DIR)/common/UtilNPP \ | ||
19 | - -I $(TOP_DIR)/ \ | ||
20 | - -I $(JRTP_ROOT)/jrtplib/include/jrtplib3 \ | ||
21 | - -I $(JRTP_ROOT)/jthread/include/jthread \ | ||
22 | - -I $(TOP_DIR)/src/gb28181 \ | ||
23 | - -I $(TOP_DIR)/src/nvdec \ | ||
24 | - -I $(CUDA_ROOT)/include \ | ||
25 | - | ||
26 | -LIBSPATH= -L $(JRTP_ROOT)/jthread/lib -l:libjthread.a \ | ||
27 | - -L $(JRTP_ROOT)/jrtplib/lib -l:libjrtp.a \ | ||
28 | - -L $(CUDA_ROOT)/lib64 -lcuda -lcudart -lnvcuvid -lcurand -lcublas -lnvjpeg \ | ||
29 | - | ||
30 | - | ||
31 | -CXXFLAGS= -g -O0 -fPIC $(INCLUDE) $(LIBSPATH) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl -Wwrite-strings | ||
32 | - | ||
33 | - | ||
34 | -# 最终目标文件 | ||
35 | -TARGET:=$(LIB_DIR)/$(MODULE).a | ||
36 | - | ||
37 | - | ||
38 | -# 默认最终目标 | ||
39 | -.PHONY:all | ||
40 | -all:$(TARGET) | ||
41 | - | ||
42 | -# 生成最终目标 | ||
43 | -$(TARGET):$(OBJS) | $(LIB_DIR) | ||
44 | - @echo -e "\e[32m""Linking static library $(TARGET)""\e[0m" | ||
45 | - @echo -e "ar -rc $@ $^" | ||
46 | - @ar -rc $@ $^ | ||
47 | - | ||
48 | -# 若没有lib目录则自动生成 | ||
49 | -$(LIB_DIR): | ||
50 | - @mkdir -p $@ | ||
51 | - | ||
52 | -# 生成中间目标文件 | ||
53 | -$(OBJ_DIR)/%.o:$(SRC_DIR)/%.cpp $(DEP_DIR)/%.d | $(OBJ_DIR) $(DEP_DIR) | ||
54 | - @echo -e "\e[33m""Building object $@""\e[0m" | ||
55 | - @echo -e "$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBS) $(MACROS) -o $@ $<" | ||
56 | -# @$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBSPATH) $(MACROS) -o $@ $(MODULE_LIBS) $< | ||
57 | - @$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) $(INCS) $(LIBS) $(MACROS) -o $@ $< | ||
58 | - | ||
59 | -# 若没有obj目录则自动生成 | ||
60 | -$(OBJ_DIR): | ||
61 | - @mkdir -p $@ | ||
62 | - | ||
63 | -# 若没有.dep目录则自动生成 | ||
64 | -$(DEP_DIR): | ||
65 | - @mkdir -p $@ | ||
66 | - | ||
67 | -# 依赖文件会在生成中间文件的时候自动生成,这里只是为了防止报错 | ||
68 | -$(DEPS): | ||
69 | - | ||
70 | -# 引入中间目标文件头文件依赖关系 | ||
71 | -include $(wildcard $(DEPS)) | ||
72 | - | ||
73 | -# 直接删除组件build目录 | ||
74 | -.PHONY:clean | ||
75 | -clean: | ||
76 | - @rm -rf $(BUILD_DIR)/$(MODULE) |
src/demo/demo.cpp
1 | #include "../ai_platform/stl_aiplatform.h" | 1 | #include "../ai_platform/stl_aiplatform.h" |
2 | #include <chrono> | 2 | #include <chrono> |
3 | +#include <thread> | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -1330,6 +1331,26 @@ init_mq_conn(handle); | @@ -1330,6 +1331,26 @@ init_mq_conn(handle); | ||
1330 | 1331 | ||
1331 | 1332 | ||
1332 | 1333 | ||
1334 | + int status = -1; | ||
1335 | + while (true) | ||
1336 | + { | ||
1337 | + status = get_task_status(handle,"34020000001320000207"); | ||
1338 | + if (status == 0) | ||
1339 | + { | ||
1340 | + createTask_dvpp28181(handle, algor_vec, 4, false); | ||
1341 | + } | ||
1342 | + | ||
1343 | + status = get_task_status(handle,"34020000001310000176"); | ||
1344 | + if (status == 0) | ||
1345 | + { | ||
1346 | + createTask_dvpp28181(handle, algor_vec, 5, false); | ||
1347 | + } | ||
1348 | + | ||
1349 | + std::this_thread::sleep_for(std::chrono::seconds(5)); | ||
1350 | + } | ||
1351 | + | ||
1352 | + | ||
1353 | + | ||
1333 | char ch = 'a'; | 1354 | char ch = 'a'; |
1334 | while (ch != 'q') { | 1355 | while (ch != 'q') { |
1335 | ch = getchar(); | 1356 | ch = getchar(); |
@@ -1389,12 +1410,12 @@ int main(int argc, char *argv[]) { | @@ -1389,12 +1410,12 @@ int main(int argc, char *argv[]) { | ||
1389 | // int repeat_num = atoi(argv[3]); | 1410 | // int repeat_num = atoi(argv[3]); |
1390 | // int gpuID = atoi(argv[4]); | 1411 | // int gpuID = atoi(argv[4]); |
1391 | 1412 | ||
1392 | - test_gpu(0); | 1413 | + // test_gpu(0); |
1393 | // test_gpu(1); | 1414 | // test_gpu(1); |
1394 | // test_gpu(2); | 1415 | // test_gpu(2); |
1395 | // test_gpu(3); | 1416 | // test_gpu(3); |
1396 | 1417 | ||
1397 | - // test_dvpp28181(0); | 1418 | + test_dvpp28181(0); |
1398 | 1419 | ||
1399 | printf("Done.\n"); | 1420 | printf("Done.\n"); |
1400 | 1421 |