You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ru...@apache.org on 2023/04/18 21:37:41 UTC
[tvm] branch unity updated: [Unity] Improve and reduces possible memory leak RPC debug (#14662)
This is an automated email from the ASF dual-hosted git repository.
ruihangl pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new ee53619661 [Unity] Improve and reduces possible memory leak RPC debug (#14662)
ee53619661 is described below
commit ee536196619015b17287de7d86e57da605596ab7
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Tue Apr 18 17:37:34 2023 -0400
[Unity] Improve and reduces possible memory leak RPC debug (#14662)
This PR improves and reduces possible memory leak
during lib comparator and rpc debug.
---
python/tvm/relax/testing/lib_comparator.py | 8 ++++++--
src/support/ring_buffer.h | 3 +++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/python/tvm/relax/testing/lib_comparator.py b/python/tvm/relax/testing/lib_comparator.py
index af21ef7a7c..b15698c8db 100644
--- a/python/tvm/relax/testing/lib_comparator.py
+++ b/python/tvm/relax/testing/lib_comparator.py
@@ -118,11 +118,15 @@ class LibCompareVMInstrument:
new_args = []
# not always true, true for most ops.
ret_indices = (len(args) - 1,)
+ temp_args = []
for i, arg in enumerate(args):
arr = tvm.nd.empty(arg.shape, arg.dtype, device=self.device)
# copy from cpu since we look at different device
if i not in ret_indices:
- arr.copyfrom(arg.copyto(tvm.cpu()))
+ temp_cpu = arg.copyto(tvm.cpu())
+ temp_args.append(temp_cpu)
+ arr.copyfrom(temp_cpu)
new_args.append(arr)
-
+ # wait until all copy complete before we release temp_cpu
+ self.device.sync()
self.compare(name, args, new_args, ret_indices)
diff --git a/src/support/ring_buffer.h b/src/support/ring_buffer.h
index 1c6a6f8b43..6b4812e169 100644
--- a/src/support/ring_buffer.h
+++ b/src/support/ring_buffer.h
@@ -61,6 +61,9 @@ class RingBuffer {
if (head_ptr_ + bytes_available_ > old_size) {
// copy the ring overflow part into the tail.
size_t ncopy = head_ptr_ + bytes_available_ - old_size;
+ if (old_size + ncopy > ring_.size()) {
+ ring_.resize(old_size + ncopy);
+ }
memcpy(&ring_[0] + old_size, &ring_[0], ncopy);
}
} else if (ring_.size() > n * 8 && ring_.size() > kInitCapacity) {