Skip to content

Zgc/dipu optimize bs #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ class BSCachingAllocator : public CacheAllocator {

static size_t getAllocateSize(size_t nbytes) {
nbytes = getMemoryAlignmentStrategy()->roundBytes(nbytes);
static bool less_fragmentation =
std::getenv("DIPU_BS_MORE_ADAPTABLE") == nullptr;
return less_fragmentation ? getAllocateSizeLessFragmentation(nbytes)
: getAllocateSizeMoreAdaptable(nbytes);
constexpr size_t kMinBlockSize = 1 << 20; // 1M
if (nbytes <= kMinBlockSize) {
return kMinBlockSize;
}
int clz = __builtin_clzll(nbytes - 1);
return (1 << (sizeof(int64_t) - clz));
}

c10::DataPtr allocate(size_t size) const override {
DIPU_DEBUG_ALLOCATOR(8, "BSCachingAllocator::allocate "
<< size << ",allocator:" << this
<< ", memory-usage" << memory_allocated() << "/"
<< memory_reserved());
std::lock_guard<mutex_t> lk(mutex_);
flush_mem_pool();
std::lock_guard<mutex_t> lk(mutex_);
size_t nbytes = getAllocateSize(size);
void* ptr = nullptr;
auto& idel_blocks = impl->idel_blocks_[nbytes];
Expand Down Expand Up @@ -138,6 +140,7 @@ class BSCachingAllocator : public CacheAllocator {
}

void empty_resource_pool() const {
std::lock_guard<mutex_t> lk(mutex_);
DIPU_DEBUG_ALLOCATOR(
8, "BSCachingAllocator::empty_resource_pool ,allocator:" << this);
while (!async_mem_pool()->empty()) {
Expand Down Expand Up @@ -180,6 +183,7 @@ class BSCachingAllocator : public CacheAllocator {
void release_all_memory() const override { release_all_memory_impl(); }

void flush_mem_pool() const {
std::lock_guard<mutex_t> lk(mutex_);
DIPU_DEBUG_ALLOCATOR(
8, "BSCachingAllocator::flush_mem_pool allocator:" << this);
while (async_mem_pool()->ready()) {
Expand Down
Loading