已关闭
【缺陷报告】内存泄漏 - 文件test_aclnn_swin_transformer_ln_qkv_quant.cpp - 函数main - 行号192 #4803
zhangjunkai9创建于 8月31日关闭于 24 天前
游震
9月3日 评论:
9月3日 评论:
/assign @chaotang233


9月3日 将 chaotang233 设为负责人
25 天前 关联了pull request:fix(swin_transformer_ln_qkv_quant): free all tensors in example
24 天前 关闭了 issue
24 天前 添加了label:resolved
缺陷信息
缺陷描述
main 函数通过 CreateAclTensor 模板函数分配了 11 个 device 内存(aclrtMalloc)并创建了 11 个 aclTensor(aclCreateTensor),包括 x/gamma/beta/weight/bias/quantScale/quantOffset/dequantScale/queryOutput/keyOutput/valueOutput。但在第189-196行的清理代码中,仅 aclDestroyTensor(x) 和 aclDestroyTensor(queryOutput) 销毁了 2 个 Tensor,仅 aclrtFree(xDeviceAddr) 和 aclrtFree(outqDeviceAddr) 释放了 2 个 device 内存。gamma、beta、weight、bias、quantScale、quantOffset、dequantScale、keyOutput、valueOutput 共 9 个 aclTensor 未销毁,gammaDeviceAddr、betaDeviceAddr、weightDeviceAddr、biasDeviceAddr、scaleDeviceAddr、offsetDeviceAddr、dequantDeviceAddr、outkDeviceAddr、outvDeviceAddr 共 9 个 device 内存未释放。main 是程序入口,调用链可达。
事实核查
数据流证据
传播路径:
调用链
可达调用链1 起点:
(entry functions)→ 终点:main深度:0修复建议
// 在第189行处替换为完整的清理代码: aclDestroyTensor(x); aclDestroyTensor(gamma); aclDestroyTensor(beta); aclDestroyTensor(weight); aclDestroyTensor(bias); aclDestroyTensor(quantScale); aclDestroyTensor(quantOffset); aclDestroyTensor(dequantScale); aclDestroyTensor(queryOutput); aclDestroyTensor(keyOutput); aclDestroyTensor(valueOutput); aclrtFree(xDeviceAddr); aclrtFree(gammaDeviceAddr); aclrtFree(betaDeviceAddr); aclrtFree(weightDeviceAddr); aclrtFree(biasDeviceAddr); aclrtFree(scaleDeviceAddr); aclrtFree(offsetDeviceAddr); aclrtFree(dequantDeviceAddr); aclrtFree(outqDeviceAddr); aclrtFree(outkDeviceAddr); aclrtFree(outvDeviceAddr); if (workspaceSize > 0) { aclrtFree(workspaceAddr); } aclrtDestroyStream(stream); aclrtResetDevice(deviceId); aclFinalize();