From a3c2fae41caf9cd322a878218749b14653394342 Mon Sep 17 00:00:00 2001 From: "q.yao" Date: Wed, 6 Sep 2023 17:52:48 +0800 Subject: [PATCH] Fix ONNX Runtime Op memory leak (#2406) --- .../modulated_deform_conv/modulated_deform_conv.cpp | 2 ++ .../backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.cpp b/csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.cpp index 3c4404de5f..73a0b8acef 100644 --- a/csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.cpp +++ b/csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.cpp @@ -190,6 +190,8 @@ void MMCVModulatedDeformConvKernel::Compute(OrtKernelContext *context) { group, deformable_group, channels, num_output, kernel_height, kernel_width, stride_height, stride_width, padding_height, padding_width, dilation_height, dilation_width, columns, out_ptr); + + allocator_.Free(columns); } REGISTER_ONNXRUNTIME_OPS(mmdeploy, MMCVModulatedDeformConvOp); REGISTER_ONNXRUNTIME_OPS(mmcv, MMCVModulatedDeformConvOp); diff --git a/csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp b/csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp index 9da0091049..9d8cc4597e 100644 --- a/csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp +++ b/csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp @@ -358,6 +358,10 @@ void NMSRotatedKernel::Compute(OrtKernelContext* context) { int64_t* res_data = ort_.GetTensorMutableData(res); memcpy(res_data, res_order.data(), sizeof(int64_t) * res_order.size()); + + allocator_.Free(tmp_boxes); + allocator_.Free(sc); + allocator_.Free(select); } REGISTER_ONNXRUNTIME_OPS(mmdeploy, NMSRotatedOp);