!7045 Revert arena code back to use malloc

Merge pull request !7045 from JesseKLee/revert_arena_r1
This commit is contained in:
mindspore-ci-bot 2020-09-29 22:37:22 +08:00 committed by Gitee
commit bd48cee8c5
2 changed files with 14 additions and 7 deletions

View File

@ -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<uint8_t[]>(sz);
impl_ = std::make_unique<ArenaImpl>(mem_.get(), sz);
int64_t sz = size_in_MB_ * 1048576L;
RETURN_IF_NOT_OK(DeMalloc(sz, &ptr_, false));
impl_ = std::make_unique<ArenaImpl>(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<Arena> *p_ba, size_t val_in_MB) {
RETURN_UNEXPECTED_IF_NULL(p_ba);

View File

@ -19,6 +19,7 @@
#include <memory>
#include <mutex>
#include <utility>
#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<ArenaImpl> impl_;
std::unique_ptr<uint8_t[]> mem_;
void *ptr_;
size_t size_in_MB_;
explicit Arena(size_t val_in_MB = 4096);