From 2941910cf075180994f6d4e0fda90d419e28d44c Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Thu, 28 Mar 2024 10:24:53 +0000 Subject: [PATCH 01/22] try fix tgs agitate --- .../runtime/core/allocator/DIPUAsyncResourcePool.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index 4533ac3fa..08292a6be 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -9,7 +9,7 @@ namespace dipu { -constexpr size_t kMaxAsyncResourcePoolLength = 3; +constexpr size_t kMaxAsyncResourcePoolLength = 32; template class AsyncResourcePool { @@ -31,7 +31,11 @@ class AsyncResourcePoolImpl : public AsyncResourcePool { public: void add(const T& t, std::deque& events) override { std::lock_guard lk(mutex_); - list_.emplace_back(t, std::move(events)); + if (events.size() > 0) { + list_.emplace_back(t, std::move(events)); + } else { + list_.emplace_front(t, std::move(events)); + } } T get() override { From d5f3696556f8bc6f39dbd6e79dba07fe4d165d82 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Thu, 28 Mar 2024 13:17:24 +0000 Subject: [PATCH 02/22] async_mempool.length-0 --- .../csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index 08292a6be..6685717f9 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -9,7 +9,7 @@ namespace dipu { -constexpr size_t kMaxAsyncResourcePoolLength = 32; +constexpr size_t kMaxAsyncResourcePoolLength = 0; template class AsyncResourcePool { From a18bfd04c51324a212684817aa67ce0c8da7729b Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Fri, 29 Mar 2024 02:40:15 +0000 Subject: [PATCH 03/22] use new param --- .../csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h | 2 +- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index 6685717f9..fa4c9aad4 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -9,7 +9,7 @@ namespace dipu { -constexpr size_t kMaxAsyncResourcePoolLength = 0; +constexpr size_t kMaxAsyncResourcePoolLength = 3; template class AsyncResourcePool { diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index cd7e191f1..8a1ea67a7 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -26,10 +26,10 @@ class BFCachingAllocatorImpl { static constexpr int kNumSubBins = 4; static constexpr int kLogNumSubBins = 2; // Allocation parameters - static constexpr size_t kMinAllocationSize = 512; + static constexpr size_t kMinAllocationSize = 1U << 20U; // 1MB static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 1U << 30U; // 1GB + static constexpr size_t kMaxExtendSize = 256U << 20U; // 1GB size_t cachedBytes = 0; size_t allocatedBytes = 0; From 9156868beb9a2aaff793d13d7e753aadc752707e Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 08:01:30 +0000 Subject: [PATCH 04/22] reduce max extend size --- .../csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 8a1ea67a7..e0bfb1ee0 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -29,7 +29,7 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 1U << 20U; // 1MB static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 256U << 20U; // 1GB + static constexpr size_t kMaxExtendSize = 64U << 20U; // 1GB size_t cachedBytes = 0; size_t allocatedBytes = 0; From 6139204534f3cdf81a01af0e765b710611d3a9c0 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 08:10:21 +0000 Subject: [PATCH 05/22] kMaxAsyncResourcePoolLength->8,kMaxExtendSize->256MB --- .../csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h | 2 +- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index fa4c9aad4..55cffee64 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -9,7 +9,7 @@ namespace dipu { -constexpr size_t kMaxAsyncResourcePoolLength = 3; +constexpr size_t kMaxAsyncResourcePoolLength = 8; template class AsyncResourcePool { diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index e0bfb1ee0..c2e335b42 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -26,10 +26,10 @@ class BFCachingAllocatorImpl { static constexpr int kNumSubBins = 4; static constexpr int kLogNumSubBins = 2; // Allocation parameters - static constexpr size_t kMinAllocationSize = 1U << 20U; // 1MB + static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 64U << 20U; // 1GB + static constexpr size_t kMaxExtendSize = 256U << 20U; // 256MB size_t cachedBytes = 0; size_t allocatedBytes = 0; From cf574662ac32cf9c0e0be1eaf313e473c1ca8664 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 09:31:31 +0000 Subject: [PATCH 06/22] supports using the value of environment variables to initialize kMaxAsyncResourcePoolLength --- .../runtime/core/allocator/DIPUAsyncResourcePool.h | 2 -- .../runtime/core/allocator/DIPUCachingAllocator.cpp | 9 +++++++++ .../runtime/core/allocator/DIPUCachingAllocator.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index 55cffee64..df9788542 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -9,8 +9,6 @@ namespace dipu { -constexpr size_t kMaxAsyncResourcePoolLength = 8; - template class AsyncResourcePool { public: diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index 29333f15e..60355b61e 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -18,6 +18,15 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) std::mutex DIPURawDeviceAllocator::mutex_; +size_t kMaxAsyncResourcePoolLength = [](){ + size_t maxAsyncResourcePoolLength = 8; + const char* env = std::getenv("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH"); + if (env != nullptr) { + maxAsyncResourcePoolLength = std::atoi(env); + } + return maxAsyncResourcePoolLength; +}(); + namespace { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h index 87d608375..00861264e 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h @@ -13,6 +13,8 @@ namespace dipu { constexpr size_t kDefaultMermoryAlignment = 512; +extern size_t kMaxAsyncResourcePoolLength; + class MemoryAlignmentStrategy { size_t kBytesAlign = kDefaultMermoryAlignment; size_t alpha = 1; // reserved From 949f83d1dc82141c1f989427b0507ae0a1f9a52b Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 12:05:26 +0000 Subject: [PATCH 07/22] kMaxExtendSize->32MB --- .../csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index c2e335b42..c408b7aea 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -29,7 +29,7 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 256U << 20U; // 256MB + static constexpr size_t kMaxExtendSize = 32 << 20U; // 32MB size_t cachedBytes = 0; size_t allocatedBytes = 0; From f87d57ec71e105079b6880236f32f96f34aa2203 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 12:10:52 +0000 Subject: [PATCH 08/22] kMaxExtendSize->128MB --- .../csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index c408b7aea..1717e8ac8 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -29,7 +29,7 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 32 << 20U; // 32MB + static constexpr size_t kMaxExtendSize = 128 << 20U; // 128MB size_t cachedBytes = 0; size_t allocatedBytes = 0; From ff5d314f29d2742932ff2fdd13ef132697de2f3c Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 12:22:40 +0000 Subject: [PATCH 09/22] enable init kMaxExtendSize using env var --- .../core/allocator/DIPUBFCachingAllocator.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 1717e8ac8..6ce9f06f5 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -12,6 +12,16 @@ namespace dipu { +const size_t DIPU_MAX_EXTEND_SIZE = [](){ + size_t maxExtendSize = 64; + const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); + if (env != nullptr) { + maxExtendSize = std::atoi(env); + } + maxExtendSize = maxExtendSize << 20U; // MB + return maxExtendSize; +}(); + class BFCachingAllocatorImpl { public: using allocate_fn_t = std::function; @@ -29,7 +39,7 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - static constexpr size_t kMaxExtendSize = 128 << 20U; // 128MB + const size_t kMaxExtendSize = DIPU_MAX_EXTEND_SIZE; size_t cachedBytes = 0; size_t allocatedBytes = 0; From 2f48b62af87e05b48051e7229c719669d9267de8 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Sun, 7 Apr 2024 12:52:20 +0000 Subject: [PATCH 10/22] enable init kMaxExtendSize using env var --- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 6ce9f06f5..5ab697a5c 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -12,7 +12,7 @@ namespace dipu { -const size_t DIPU_MAX_EXTEND_SIZE = [](){ +const size_t kMaxExtendSize = [](){ size_t maxExtendSize = 64; const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); if (env != nullptr) { @@ -39,7 +39,7 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - const size_t kMaxExtendSize = DIPU_MAX_EXTEND_SIZE; + //const size_t kMaxExtendSize = DIPU_MAX_EXTEND_SIZE; size_t cachedBytes = 0; size_t allocatedBytes = 0; From 549e274b2898be5c497e9b37b1fa88f5fbbba8f3 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Mon, 8 Apr 2024 07:11:59 +0000 Subject: [PATCH 11/22] fix lint --- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 6 +++--- .../runtime/core/allocator/DIPUCachingAllocator.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 5ab697a5c..8e4a0f68a 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -12,13 +12,14 @@ namespace dipu { -const size_t kMaxExtendSize = [](){ +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +const size_t kMaxExtendSize = []() { size_t maxExtendSize = 64; const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); if (env != nullptr) { maxExtendSize = std::atoi(env); } - maxExtendSize = maxExtendSize << 20U; // MB + maxExtendSize = maxExtendSize << 20U; return maxExtendSize; }(); @@ -39,7 +40,6 @@ class BFCachingAllocatorImpl { static constexpr size_t kMinAllocationSize = 512; static constexpr size_t kMaxInternalFragmentation = 8U << 20U; // 8MB static constexpr size_t kMinExtendSize = 8U << 20U; // 8MB - //const size_t kMaxExtendSize = DIPU_MAX_EXTEND_SIZE; size_t cachedBytes = 0; size_t allocatedBytes = 0; diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index 60355b61e..e37686c3a 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -18,7 +18,8 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) std::mutex DIPURawDeviceAllocator::mutex_; -size_t kMaxAsyncResourcePoolLength = [](){ +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +size_t kMaxAsyncResourcePoolLength = []() { size_t maxAsyncResourcePoolLength = 8; const char* env = std::getenv("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH"); if (env != nullptr) { From ea2db53d1f7322dec345089147ccec68896b18f9 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Mon, 8 Apr 2024 08:03:35 +0000 Subject: [PATCH 12/22] modify default value --- .../csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp | 2 +- .../csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 8e4a0f68a..c927e714d 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -14,7 +14,7 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) const size_t kMaxExtendSize = []() { - size_t maxExtendSize = 64; + size_t maxExtendSize = 512; const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); if (env != nullptr) { maxExtendSize = std::atoi(env); diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index e37686c3a..4e4189947 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -20,7 +20,7 @@ std::mutex DIPURawDeviceAllocator::mutex_; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) size_t kMaxAsyncResourcePoolLength = []() { - size_t maxAsyncResourcePoolLength = 8; + size_t maxAsyncResourcePoolLength = 32; const char* env = std::getenv("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH"); if (env != nullptr) { maxAsyncResourcePoolLength = std::atoi(env); From e49f4cf045a4ccbd7cdc08347b2aeba5103a318d Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Mon, 8 Apr 2024 15:08:13 +0000 Subject: [PATCH 13/22] back up --- .../core/allocator/DIPUBFCachingAllocator.cpp | 27 ++++++++++++++++++- .../core/allocator/DIPUCachingAllocator.cpp | 2 +- .../ascend/AscendCustomAllocatorStrategy.cpp | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index c927e714d..1ae9126cd 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -432,7 +432,7 @@ class BFCachingAllocator : public CacheAllocator { } set_memory_reserved(impl->memory_reserved()); } - + #if 0 void empty_resource_pool() const { std::lock_guard lk(resource_pool_mutex_); while (!async_mem_pool()->empty()) { @@ -450,6 +450,31 @@ class BFCachingAllocator : public CacheAllocator { impl->releaseRaw(ptr, id); } } + #endif + + void empty_resource_pool() const { + std::lock_guard lk(resource_pool_mutex_); + auto start = std::chrono::system_clock::now(); + while (!async_mem_pool()->empty()) { + if (!async_mem_pool()->ready()) { + auto elasped = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); + if (elasped < 32) { + std::this_thread::yield(); + continue; + } else { + return; + } + } + const auto block = async_mem_pool()->get(); + void* ptr = std::get<0>(block); + int id = static_cast(std::get<1>(block)); + DIPU_DEBUG_ALLOCATOR( + 8, "BFCachingAllocator: " << __FUNCTION__ << " ,ptr:" << ptr + << " ,id:" << id << " ,allocator:" << this + << ", device:" << device()); + impl->releaseRaw(ptr, id); + } + } void check_impl() const { if (impl) { diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index 4e4189947..0c557bacb 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -20,7 +20,7 @@ std::mutex DIPURawDeviceAllocator::mutex_; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) size_t kMaxAsyncResourcePoolLength = []() { - size_t maxAsyncResourcePoolLength = 32; + size_t maxAsyncResourcePoolLength = 64; const char* env = std::getenv("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH"); if (env != nullptr) { maxAsyncResourcePoolLength = std::atoi(env); diff --git a/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp b/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp index 79682dde9..de80e58ee 100644 --- a/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp +++ b/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp @@ -4,7 +4,7 @@ const static int ascend_init = []() { // – 内存大小向上对齐成32整数倍+32字节(m=ALIGN_UP[len,32]+32字节); // – 内存起始地址需满足64字节对齐(ALIGN_UP[m,64])。 // nbytes = align_64(1 * nbytes + 32); - static dipu::MemoryAlignmentStrategy memoryAlignStrategy(64, 1, 32); + static dipu::MemoryAlignmentStrategy memoryAlignStrategy(512, 1, 32); dipu::setMemoryAlignmentStrategy(&memoryAlignStrategy); return 0; }(); From c36dadbd6f4cd295979aa6f1d2183f001b658622 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 03:16:53 +0000 Subject: [PATCH 14/22] modify maxExtendSize 512->1024 --- .../csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 1ae9126cd..ad1b441e7 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -14,7 +14,7 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) const size_t kMaxExtendSize = []() { - size_t maxExtendSize = 512; + size_t maxExtendSize = 1024; const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); if (env != nullptr) { maxExtendSize = std::atoi(env); From 41284758cf4651d31ab1178d0be533c60d37c281 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 03:20:12 +0000 Subject: [PATCH 15/22] fix lint --- .../core/allocator/DIPUBFCachingAllocator.cpp | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index ad1b441e7..48b471f01 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -432,32 +432,15 @@ class BFCachingAllocator : public CacheAllocator { } set_memory_reserved(impl->memory_reserved()); } - #if 0 - void empty_resource_pool() const { - std::lock_guard lk(resource_pool_mutex_); - while (!async_mem_pool()->empty()) { - if (!async_mem_pool()->ready()) { - std::this_thread::yield(); - continue; - } - const auto block = async_mem_pool()->get(); - void* ptr = std::get<0>(block); - int id = static_cast(std::get<1>(block)); - DIPU_DEBUG_ALLOCATOR( - 8, "BFCachingAllocator: " << __FUNCTION__ << " ,ptr:" << ptr - << " ,id:" << id << " ,allocator:" << this - << ", device:" << device()); - impl->releaseRaw(ptr, id); - } - } - #endif void empty_resource_pool() const { std::lock_guard lk(resource_pool_mutex_); auto start = std::chrono::system_clock::now(); while (!async_mem_pool()->empty()) { if (!async_mem_pool()->ready()) { - auto elasped = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); + auto elasped = std::chrono::duration_cast( + std::chrono::system_clock::now() - start) + .count(); if (elasped < 32) { std::this_thread::yield(); continue; From a580fbf1cb4b69fc0bc606a396884efe27c15a77 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 06:54:15 +0000 Subject: [PATCH 16/22] add get_env_or_default func --- .../core/allocator/DIPUBFCachingAllocator.cpp | 23 ++++++++----------- .../core/allocator/DIPUCachingAllocator.cpp | 11 +++------ dipu/torch_dipu/csrc_dipu/utils/env.hpp | 18 +++++++++++++++ 3 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 dipu/torch_dipu/csrc_dipu/utils/env.hpp diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 48b471f01..b0993eaa8 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -7,21 +7,15 @@ #include #include +#include "csrc_dipu/utils/env.hpp" + #include "DIPUCachingAllocator.h" #include "DIPUSpinMutex.h" namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -const size_t kMaxExtendSize = []() { - size_t maxExtendSize = 1024; - const char* env = std::getenv("DIPU_MAX_EXTEND_SIZE"); - if (env != nullptr) { - maxExtendSize = std::atoi(env); - } - maxExtendSize = maxExtendSize << 20U; - return maxExtendSize; -}(); +const size_t kMaxExtendSize = get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024); class BFCachingAllocatorImpl { public: @@ -434,14 +428,15 @@ class BFCachingAllocator : public CacheAllocator { } void empty_resource_pool() const { + using namespace std::chrono_literals; std::lock_guard lk(resource_pool_mutex_); - auto start = std::chrono::system_clock::now(); + auto start = std::chrono::steady_clock::now(); + constexpr auto maxWaitTime = 32us; while (!async_mem_pool()->empty()) { if (!async_mem_pool()->ready()) { - auto elasped = std::chrono::duration_cast( - std::chrono::system_clock::now() - start) - .count(); - if (elasped < 32) { + auto now = std::chrono::steady_clock::now(); + auto elasped = now - start; + if (elasped < maxWaitTime) { std::this_thread::yield(); continue; } else { diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index 0c557bacb..54dc8b898 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -12,6 +12,7 @@ #include "csrc_dipu/base/basedef.h" #include "csrc_dipu/runtime/devproxy/deviceproxy.h" +#include "csrc_dipu/utils/env.hpp" namespace dipu { @@ -19,14 +20,8 @@ namespace dipu { std::mutex DIPURawDeviceAllocator::mutex_; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -size_t kMaxAsyncResourcePoolLength = []() { - size_t maxAsyncResourcePoolLength = 64; - const char* env = std::getenv("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH"); - if (env != nullptr) { - maxAsyncResourcePoolLength = std::atoi(env); - } - return maxAsyncResourcePoolLength; -}(); +size_t kMaxAsyncResourcePoolLength = + get_env_or_default("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH", 64); namespace { diff --git a/dipu/torch_dipu/csrc_dipu/utils/env.hpp b/dipu/torch_dipu/csrc_dipu/utils/env.hpp new file mode 100644 index 000000000..e561a429c --- /dev/null +++ b/dipu/torch_dipu/csrc_dipu/utils/env.hpp @@ -0,0 +1,18 @@ +// Copyright (c) 2024, DeepLink. +#pragma once +#include + +namespace dipu { + +template +T get_env_or_default(const char* env_name, const T& defalut_value) { + const char* env = std::getenv(env_name); + if (env == nullptr) { + return defalut_value; + } + T value; + std::istringstream(env) >> value; + return value; +} + +} // namespace dipu From 98dd0501ce06877927daa40caccafb6c70dc5542 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 07:02:19 +0000 Subject: [PATCH 17/22] fix no need change --- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 3 ++- .../csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index b0993eaa8..527ea7411 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -15,7 +15,8 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -const size_t kMaxExtendSize = get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024); +const size_t kMaxExtendSize = + get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024 << 20U); class BFCachingAllocatorImpl { public: diff --git a/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp b/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp index de80e58ee..79682dde9 100644 --- a/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp +++ b/dipu/torch_dipu/csrc_dipu/vendor/ascend/AscendCustomAllocatorStrategy.cpp @@ -4,7 +4,7 @@ const static int ascend_init = []() { // – 内存大小向上对齐成32整数倍+32字节(m=ALIGN_UP[len,32]+32字节); // – 内存起始地址需满足64字节对齐(ALIGN_UP[m,64])。 // nbytes = align_64(1 * nbytes + 32); - static dipu::MemoryAlignmentStrategy memoryAlignStrategy(512, 1, 32); + static dipu::MemoryAlignmentStrategy memoryAlignStrategy(64, 1, 32); dipu::setMemoryAlignmentStrategy(&memoryAlignStrategy); return 0; }(); From 31221002187a26839d93571dea2304283ee5a5e7 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 08:17:24 +0000 Subject: [PATCH 18/22] fix typo error --- dipu/torch_dipu/csrc_dipu/utils/env.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/utils/env.hpp b/dipu/torch_dipu/csrc_dipu/utils/env.hpp index e561a429c..c871d75fd 100644 --- a/dipu/torch_dipu/csrc_dipu/utils/env.hpp +++ b/dipu/torch_dipu/csrc_dipu/utils/env.hpp @@ -5,10 +5,10 @@ namespace dipu { template -T get_env_or_default(const char* env_name, const T& defalut_value) { +T get_env_or_default(const char* env_name, const T& default_value) { const char* env = std::getenv(env_name); if (env == nullptr) { - return defalut_value; + return default_value; } T value; std::istringstream(env) >> value; From f277255840d05254942ca2b523c8a7c4832a987f Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 10:06:31 +0000 Subject: [PATCH 19/22] fix lint --- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 3 +-- .../runtime/core/allocator/DIPUCachingAllocator.cpp | 5 +++-- .../csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 527ea7411..efe6a06ac 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -440,9 +440,8 @@ class BFCachingAllocator : public CacheAllocator { if (elasped < maxWaitTime) { std::this_thread::yield(); continue; - } else { - return; } + return; } const auto block = async_mem_pool()->get(); void* ptr = std::get<0>(block); diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp index 54dc8b898..fbf9c6704 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.cpp @@ -19,9 +19,10 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) std::mutex DIPURawDeviceAllocator::mutex_; +constexpr size_t kDefaultMaxAsyncResourcePoolLength = 64; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -size_t kMaxAsyncResourcePoolLength = - get_env_or_default("DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH", 64); +const size_t kMaxAsyncResourcePoolLength = get_env_or_default( + "DIPU_MAX_ASYNC_RESOURCE_POOL_LENGTH", kDefaultMaxAsyncResourcePoolLength); namespace { diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h index 00861264e..fe21919b7 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUCachingAllocator.h @@ -13,7 +13,7 @@ namespace dipu { constexpr size_t kDefaultMermoryAlignment = 512; -extern size_t kMaxAsyncResourcePoolLength; +extern const size_t kMaxAsyncResourcePoolLength; class MemoryAlignmentStrategy { size_t kBytesAlign = kDefaultMermoryAlignment; From 3a046789e8b482583d66710b4c33f615ab7c9acd Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Tue, 9 Apr 2024 10:14:56 +0000 Subject: [PATCH 20/22] minor change --- .../runtime/core/allocator/DIPUAsyncResourcePool.h | 6 +++--- .../runtime/core/allocator/DIPUBFCachingAllocator.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h index df9788542..fe99c5c49 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUAsyncResourcePool.h @@ -29,10 +29,10 @@ class AsyncResourcePoolImpl : public AsyncResourcePool { public: void add(const T& t, std::deque& events) override { std::lock_guard lk(mutex_); - if (events.size() > 0) { - list_.emplace_back(t, std::move(events)); - } else { + if (events.empty()) { list_.emplace_front(t, std::move(events)); + } else { + list_.emplace_back(t, std::move(events)); } } diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index efe6a06ac..13c902147 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -15,8 +15,8 @@ namespace dipu { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -const size_t kMaxExtendSize = - get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024 << 20U); +const size_t kMaxExtendSize = get_env_or_default("DIPU_MAX_EXTEND_SIZE", 1024) + << 20U; class BFCachingAllocatorImpl { public: @@ -436,8 +436,8 @@ class BFCachingAllocator : public CacheAllocator { while (!async_mem_pool()->empty()) { if (!async_mem_pool()->ready()) { auto now = std::chrono::steady_clock::now(); - auto elasped = now - start; - if (elasped < maxWaitTime) { + auto elapsed = now - start; + if (elapsed < maxWaitTime) { std::this_thread::yield(); continue; } From a5edb80f4bda34112d08fb9534148649cd73f7e8 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Wed, 10 Apr 2024 02:56:43 +0000 Subject: [PATCH 21/22] optimize BF cached-allocator logic --- .../core/allocator/DIPUBFCachingAllocator.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp index 13c902147..a13ce575d 100644 --- a/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp +++ b/dipu/torch_dipu/csrc_dipu/runtime/core/allocator/DIPUBFCachingAllocator.cpp @@ -429,6 +429,24 @@ class BFCachingAllocator : public CacheAllocator { } void empty_resource_pool() const { + std::lock_guard lk(resource_pool_mutex_); + while (!async_mem_pool()->empty()) { + if (!async_mem_pool()->ready()) { + std::this_thread::yield(); + continue; + } + const auto block = async_mem_pool()->get(); + void* ptr = std::get<0>(block); + int id = static_cast(std::get<1>(block)); + DIPU_DEBUG_ALLOCATOR( + 8, "BFCachingAllocator: " << __FUNCTION__ << " ,ptr:" << ptr + << " ,id:" << id << " ,allocator:" << this + << ", device:" << device()); + impl->releaseRaw(ptr, id); + } + } + + bool try_empty_resource_pool() const { using namespace std::chrono_literals; std::lock_guard lk(resource_pool_mutex_); auto start = std::chrono::steady_clock::now(); @@ -441,7 +459,7 @@ class BFCachingAllocator : public CacheAllocator { std::this_thread::yield(); continue; } - return; + return false; } const auto block = async_mem_pool()->get(); void* ptr = std::get<0>(block); @@ -452,6 +470,7 @@ class BFCachingAllocator : public CacheAllocator { << ", device:" << device()); impl->releaseRaw(ptr, id); } + return true; } void check_impl() const { @@ -520,7 +539,7 @@ class BFCachingAllocator : public CacheAllocator { c10::DataPtr allocate(size_t size) const override { restore(); if (async_mem_pool()->size() > kMaxAsyncResourcePoolLength) { - empty_resource_pool(); + try_empty_resource_pool(); } size = getMemoryAlignmentStrategy()->roundBytes(size); std::tuple block = impl->allocateRaw(size); From cd605ffc1280ea5f4fd607f59d0cfac2b5ca5fe1 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Wed, 10 Apr 2024 10:39:00 +0000 Subject: [PATCH 22/22] minor change --- dipu/torch_dipu/csrc_dipu/utils/env.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dipu/torch_dipu/csrc_dipu/utils/env.hpp b/dipu/torch_dipu/csrc_dipu/utils/env.hpp index c871d75fd..2ad796613 100644 --- a/dipu/torch_dipu/csrc_dipu/utils/env.hpp +++ b/dipu/torch_dipu/csrc_dipu/utils/env.hpp @@ -10,7 +10,7 @@ T get_env_or_default(const char* env_name, const T& default_value) { if (env == nullptr) { return default_value; } - T value; + T value = default_value; std::istringstream(env) >> value; return value; }