From 1e25fb76a30980474fb95d459749c66ff837bc46 Mon Sep 17 00:00:00 2001 From: Jesse Lee Date: Tue, 29 Sep 2020 08:40:17 -0400 Subject: [PATCH] revert arena changes back to use malloc --- mindspore/ccsrc/minddata/dataset/util/arena.cc | 11 ++++++----- mindspore/ccsrc/minddata/dataset/util/arena.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/util/arena.cc b/mindspore/ccsrc/minddata/dataset/util/arena.cc index 85ce35e661..6bd6d295ff 100644 --- a/mindspore/ccsrc/minddata/dataset/util/arena.cc +++ b/mindspore/ccsrc/minddata/dataset/util/arena.cc @@ -37,7 +37,8 @@ struct MemHdr { ArenaImpl::ArenaImpl(void *ptr, size_t sz) : size_in_bytes_(sz), ptr_(ptr) { // Divide the memory into blocks. Ignore the last partial block. uint64_t num_blks = size_in_bytes_ / ARENA_BLK_SZ; - MS_LOG(DEBUG) << "Size of memory pool is " << num_blks << ", number of blocks of size is " << ARENA_BLK_SZ << "."; + MS_LOG(DEBUG) << "Arena memory pool is created. Number of blocks : " << num_blks << ". Block size : " << ARENA_BLK_SZ + << "."; tr_.Insert(0, num_blks); } @@ -233,16 +234,16 @@ std::ostream &operator<<(std::ostream &os, const ArenaImpl &s) { Status Arena::Init() { try { - auto sz = size_in_MB_ * 1048576L; - mem_ = std::make_unique(sz); - impl_ = std::make_unique(mem_.get(), sz); + int64_t sz = size_in_MB_ * 1048576L; + RETURN_IF_NOT_OK(DeMalloc(sz, &ptr_, false)); + impl_ = std::make_unique(ptr_, sz); } catch (std::bad_alloc &e) { return Status(StatusCode::kOutOfMemory); } return Status::OK(); } -Arena::Arena(size_t val_in_MB) : size_in_MB_(val_in_MB) {} +Arena::Arena(size_t val_in_MB) : ptr_(nullptr), size_in_MB_(val_in_MB) {} Status Arena::CreateArena(std::shared_ptr *p_ba, size_t val_in_MB) { RETURN_UNEXPECTED_IF_NULL(p_ba); diff --git a/mindspore/ccsrc/minddata/dataset/util/arena.h b/mindspore/ccsrc/minddata/dataset/util/arena.h index 132ff0e7eb..8cf686a4c0 100644 --- a/mindspore/ccsrc/minddata/dataset/util/arena.h +++ b/mindspore/ccsrc/minddata/dataset/util/arena.h @@ -19,6 +19,7 @@ #include #include #include +#include "minddata/dataset/util/allocator.h" #include "minddata/dataset/util/memory_pool.h" #include "minddata/dataset/util/treap.h" @@ -103,7 +104,12 @@ class Arena : public MemoryPool { // Disable copy and assignment constructor Arena(const Arena &) = delete; Arena &operator=(const Arena &) = delete; - ~Arena() override = default; + ~Arena() override { + if (ptr_ != nullptr) { + free(ptr_); + } + ptr_ = nullptr; + } /// As a derived class of MemoryPool, we have to implement the following. /// But we simply transfer the call to the implementation class @@ -140,7 +146,7 @@ class Arena : public MemoryPool { protected: mutable std::mutex mux_; std::unique_ptr impl_; - std::unique_ptr mem_; + void *ptr_; size_t size_in_MB_; explicit Arena(size_t val_in_MB = 4096);