Browse Source

Fix error of single_op memory free.

tags/v1.3.0
zhaozhixuan 4 years ago
parent
commit
07b9a48f11
4 changed files with 20 additions and 0 deletions
  1. +8
    -0
      ge/graph/manager/graph_caching_allocator.cc
  2. +7
    -0
      ge/graph/manager/graph_caching_allocator.h
  3. +4
    -0
      ge/single_op/single_op_manager.cc
  4. +1
    -0
      tests/ut/ge/graph/manager/graph_caching_allocator_unittest.cc

+ 8
- 0
ge/graph/manager/graph_caching_allocator.cc View File

@@ -356,6 +356,14 @@ void CachingAllocator::FreeBlocks() {
(void) FreeCachedBlocks(); (void) FreeCachedBlocks();
} }


void CachingAllocator::TryFreeBlocks() {
GELOGI("Try free blocks.");
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (allocated_blocks_.empty()) {
(void) FreeCachedBlocks();
}
}

void CachingAllocator::FreeBlockBins() { void CachingAllocator::FreeBlockBins() {
GELOGI("Free block bins."); GELOGI("Free block bins.");
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);


+ 7
- 0
ge/graph/manager/graph_caching_allocator.h View File

@@ -94,6 +94,13 @@ class CachingAllocator {
/// ///
Status Free(uint8_t *memory_addr, uint32_t device_id = 0); Status Free(uint8_t *memory_addr, uint32_t device_id = 0);


///
/// @ingroup ge_graph
/// @brief try to free memory when no memory is referenced
/// @return void
///
void TryFreeBlocks();

private: private:


/// ///


+ 4
- 0
ge/single_op/single_op_manager.cc View File

@@ -19,6 +19,9 @@
#include <mutex> #include <mutex>
#include <string> #include <string>


#include "graph/manager/graph_mem_allocator.h"
#include "graph/manager/graph_caching_allocator.h"

namespace ge { namespace ge {
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOpManager::~SingleOpManager() { FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOpManager::~SingleOpManager() {
for (auto &it : stream_resources_) { for (auto &it : stream_resources_) {
@@ -69,6 +72,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status SingleOpManager::Release
delete it->second; delete it->second;
it->second = nullptr; it->second = nullptr;
(void)stream_resources_.erase(it); (void)stream_resources_.erase(it);
MemManager::Instance().CachingInstance(RT_MEMORY_HBM).TryFreeBlocks();
return SUCCESS; return SUCCESS;
} }




+ 1
- 0
tests/ut/ge/graph/manager/graph_caching_allocator_unittest.cc View File

@@ -58,6 +58,7 @@ TEST_F(UtestGraphCachingAllocatorTest, malloc_success) {
EXPECT_EQ(MemManager::Instance().Initialize(mem_type), SUCCESS); EXPECT_EQ(MemManager::Instance().Initialize(mem_type), SUCCESS);
uint8_t *ptr = MemManager::Instance().CachingInstance(RT_MEMORY_HBM).Malloc(kMByteSize); uint8_t *ptr = MemManager::Instance().CachingInstance(RT_MEMORY_HBM).Malloc(kMByteSize);
EXPECT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr);
MemManager::Instance().CachingInstance(RT_MEMORY_HBM).TryFreeBlocks();
MemManager::Instance().Finalize(); MemManager::Instance().Finalize();
} }


Loading…
Cancel
Save