Skip to content

Fix memory leak in assume() - #1657

Open
siramok wants to merge 4 commits into
task/JustinPrivitera/05_01_24/device_supportfrom
task/siramok/07_24_26/fix_device_execution_memory_leaks
Open

Fix memory leak in assume()#1657
siramok wants to merge 4 commits into
task/JustinPrivitera/05_01_24/device_supportfrom
task/siramok/07_24_26/fix_device_execution_memory_leaks

Conversation

@siramok

@siramok siramok commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes a memory leak within the assume() implementation for both DataAccessor and DataArray.

After creating #1656, I was performing device-based test runs on my local PC to see how quick the new implementation was running relative to the old implementation. I noticed that I wasn't able to go above 256 dim test meshes on my GPU due to CUDA trying to allocate too much memory.

Maybe a 256 dim braid mesh is just too much for my 12GB of VRAM to handle, I thought. But by random chance, I simultaneously scaled the dim sizes down but increased the iteration count, and to my surprise, this also caused CUDA to ask for too much memory and crash. I did some digging to try to understand why device memory wasn't getting freed and believe I found the issue:

Previously, assume() was handing off a pointer to its execution location buffer without handing off ownership (i.e. letting the receiving node know that it was now holding allocated memory). This resulted in .reset() never actually freeing that memory. The fix is to set the necessary fields in the receiving node (in addition to the data_ptr itself) so that ownership of the buffer is effectively transferred.

I included a test that demonstrates the memory leak, which fails if the changes in this PR are reverted. I initially believed that sync() was leaking memory as well (which is why those tests are here), but splitting them into 4 separate tests proved that sync() was correctly cleaning up after itself.

I can now do hundreds of large mesh conversion tests without running out of device memory.

@siramok
siramok requested a review from JustinPrivitera July 25, 2026 01:31
@siramok siramok changed the title Fix memory leaks in sync/assume Fix memory leak in assume() Jul 27, 2026
Comment thread src/libs/conduit/conduit_node.cpp Outdated
Comment on lines +1430 to +1442
static size_t
umpire_bytes_allocated(const char *pool_name)
{
return umpire::ResourceManager::getInstance()
.getAllocator(pool_name)
.getCurrentSize();
}

//-----------------------------------------------------------------------------
static void
expect_no_leak(void (*run_fn)(Node &, ExecutionPolicy),
index_t node_alloc_id,
ExecutionPolicy policy)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these live in the execution test utils instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are very cool

Comment on lines +625 to +634

// Allow m_node_ptr to take ownership of m_data so that future
// release()/reset() calls will free it, lest we leak memory.
const index_t owning_allocator_id =
execution::DeviceMemory::is_device_ptr(m_data)
? execution::get_device_allocator_id()
: execution::get_host_allocator_id();
m_node_ptr->assume_data_ptr(m_data,
dtype().element_bytes() * number_of_elements(),
owning_allocator_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder if this is bulletproof to other kinds of allocators? Like if someone had their own device/host allocator I wonder if this would matter that we use the default ones? I imagine this will be fine in all or almost all cases.

@JustinPrivitera JustinPrivitera left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this and being so thorough in fixing/testing! Great work 🦾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants