Skip to content

Commit

Permalink
clang_tidy:dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCac…
Browse files Browse the repository at this point in the history
…hingAllocator.cpp -v2
  • Loading branch information
lyp-liuyipeng committed Dec 4, 2023
1 parent a750837 commit b63a228
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2023, DeepLink.

Check notice on line 1 in dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp

File dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp does not conform to Custom style guidelines. (lines 64, 81, 121, 161, 444, 447)

#include <functional>
#include <memory>
#include <stack>
#include <thread>
#include <utility>
#include <vector>

#include "DIPUCachingAllocator.h"
Expand Down Expand Up @@ -158,7 +160,7 @@ class BFCachingAllocatorImpl {
// If `nbytes` is so large, we just put it into the last
if (bigBinIdx > kNumBigBins - 1) { return kNumBigBins * kNumSubBins - 1;}
// Get the index of sub bin
int subBinIdx = nBlocks ^ (1ULL << bigBinIdx);
int subBinIdx = static_cast<int>(nBlocks ^ (1ULL << bigBinIdx));
subBinIdx >>= std::max(bigBinIdx - kLogNumSubBins, 0);
return bigBinIdx * kNumSubBins + subBinIdx;
}
Expand Down Expand Up @@ -384,11 +386,11 @@ class BFCachingAllocatorImpl {
void set_mem_allocate_fn(allocate_fn_t allocate_fn,
deallocate_fn_t deallocate_fn) {
DIPU_DEBUG_ALLOCATOR(4, "BFCachingAllocator: set_mem_allocate_fn ");
this->allocate_fn = allocate_fn;
this->deallocate_fn = deallocate_fn;
this->allocate_fn = std::move(allocate_fn);
this->deallocate_fn = std::move(deallocate_fn);
}

size_t memory_reserved() { return cachedBytes; }
size_t memory_reserved() const { return cachedBytes; }
};

static void deleteBFContext(void* ptr);
Expand All @@ -404,7 +406,7 @@ class BFCachingAllocator : public CacheAllocator {
while (async_mem_pool()->ready()) {
const auto block = async_mem_pool()->get();
void* ptr = std::get<0>(block);
int id = std::get<1>(block);
int id = static_cast<int>(std::get<1>(block));
DIPU_DEBUG_ALLOCATOR(
8, "BFCachingAllocator: " << __FUNCTION__ << " ,ptr:" << ptr
<< " ,id:" << id << " ,allocator:" << this
Expand All @@ -423,7 +425,7 @@ class BFCachingAllocator : public CacheAllocator {
}
const auto block = async_mem_pool()->get();
void* ptr = std::get<0>(block);
int id = std::get<1>(block);
int id = static_cast<int>(std::get<1>(block));
DIPU_DEBUG_ALLOCATOR(
8, "BFCachingAllocator: " << __FUNCTION__ << " ,ptr:" << ptr
<< " ,id:" << id << " ,allocator:" << this
Expand All @@ -436,13 +438,13 @@ class BFCachingAllocator : public CacheAllocator {
if (impl) {
return;
}
impl.reset(new BFCachingAllocatorImpl());
impl = std::make_unique<BFCachingAllocatorImpl>();

std::function<void*(size_t)> alloc_fn =
std::bind(&BFCachingAllocator::allocate_raw, (BFCachingAllocator*)this,
std::bind(&BFCachingAllocator::allocate_raw, const_cast<BFCachingAllocator*>(this),
std::placeholders::_1);
std::function<void(void*)> dealloc_fn =
std::bind(&BFCachingAllocator::free_raw, (BFCachingAllocator*)this,
std::bind(&BFCachingAllocator::free_raw, const_cast<BFCachingAllocator*>(this),
std::placeholders::_1);
impl->set_mem_allocate_fn(alloc_fn, dealloc_fn);
}
Expand Down Expand Up @@ -545,7 +547,7 @@ class BFCachingAllocator : public CacheAllocator {

BFCachingAllocator() { check_impl(); }

~BFCachingAllocator() {
~BFCachingAllocator() override {
DIPU_DEBUG_ALLOCATOR(8, "~BFCachingAllocator allocator:" << this);
release_all_memory();
}
Expand Down

0 comments on commit b63a228

Please sign in to comment.