[Openmp-commits] [PATCH] D85274: [OpenMP] Introduced a bump-like allocator into the target memory management

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Aug 4 21:32:50 PDT 2020

tianshilei1992 created this revision.
Herald added subscribers: openmp-commits, jfb, guansong, yaxunl, mgorny.
Herald added a project: OpenMP.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

In this patch, a bump-like allocator is introduced to improve the efficiency of
target memory allocation and deallocation. The reason it is called a bump-like
allocator is it supports deallocation. Everytime a memory allocation request is
from the memory manager, it first checks whether there is a fitted slab. If not,
create a new slab. Bump the pointer in the slab and return to the memory manager,
like a regular bump allocator. We set a reference count for each slab to track
the number of memory requests from the slab.

Of course it is possible that we may run out of target memory. Then the memory
manager will try to release all its buffered memory in its FreeLists. For each
deallocation, the allocator first finds the slab it is from. If it cannot find
a slab, then it must be allocated directly on device so it will be deallocated
directly from the device. Otherwise, just decrease the reference count of the
slab. If the reference count is zero, which means all memory allocated are
returned. So we will call the device routine to deallocate the slab.

It is worth noting that the deallocation might only be called in three cases:

1. Destructor of the memory manager;
2. We are out of memory. The memory manager wants to free all its hold free memory;
3. A large block of memory which is not allocated from a slab. For this case,

we might optimize it such that if the size is not too large, we may take it as
another slab when it is gonna be released by the memory manager.

  rG LLVM Github Monorepo



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85274.283123.patch
Type: text/x-patch
Size: 12870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200805/3ab3dd90/attachment.bin>

More information about the Openmp-commits mailing list