Skip to content

Commit 9590fdd

Browse files
committed
[Runtime] Refactor EVAllocator and GPUEVAllocator.
1 parent db2b757 commit 9590fdd

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

tensorflow/core/framework/ev_allocator.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2021 The DeepRec Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@ limitations under the License.
1414
==============================================================================*/
1515

1616
#include "tensorflow/core/platform/mem.h"
17-
#include "ev_allocator.h"
17+
#include "tensorflow/core/framework/ev_allocator.h"
1818

1919
namespace tensorflow {
2020

@@ -61,8 +61,8 @@ void PageMap<CPUChunk>::Init() {
6161

6262
class CPUEVAllocator : public EVAllocator<CPUChunk> {
6363
public:
64-
CPUEVAllocator() {}
65-
~CPUEVAllocator() {}
64+
CPUEVAllocator() = default;
65+
~CPUEVAllocator() override = default;
6666

6767
string Name() override { return "ev_allocator"; }
6868

@@ -176,6 +176,7 @@ class EVAllocatorFactory : public AllocatorFactory {
176176
void Free(void* ptr, size_t num_bytes) override {
177177
ev_allocator_->DeallocateRaw(ptr);
178178
}
179+
179180
private:
180181
CPUEVAllocator* ev_allocator_;
181182
};

tensorflow/core/framework/ev_allocator.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2021 The DeepRec Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ template<typename ChunkType>
6767
class PageMap {
6868
public:
6969
PageMap() : root_{}, bytes_used_(0), page_shift_(0), npages_(0), bits_(0),
70-
root_bits_(0), root_length_(0){}
70+
root_bits_(0), root_length_(0){}
7171

7272
~PageMap() {
7373
delete root_;
@@ -201,7 +201,7 @@ class Chunk {
201201
GetMemBlock();
202202
if (start_ == nullptr) {
203203
LOG(FATAL) << "OOM, can't create new Chunk for EVAllocator, "
204-
<< "please check free memory.";
204+
<< "please check free memory.";
205205
}
206206
pm->SetBin(start_, bin);
207207
current_ = start_;
@@ -348,10 +348,10 @@ class Arena {
348348
mutex_lock l(mu_);
349349
auto it = bins_.find(bin_size);
350350
if (it == bins_.end()) {
351-
bin = new Bin<ChunkType>(bin_size, page_map_);
352-
bins_.emplace(bin_size, bin);
351+
bin = new Bin<ChunkType>(bin_size, page_map_);
352+
bins_.emplace(bin_size, bin);
353353
} else {
354-
bin = it->second;
354+
bin = it->second;
355355
}
356356
}
357357

@@ -364,10 +364,10 @@ class Arena {
364364
mutex_lock l(mu_);
365365
auto it = bins_.find(bin_size);
366366
if (it == bins_.end()) {
367-
bin = new Bin<ChunkType>(bin_size, page_map_);
368-
bins_.emplace(bin_size, bin);
367+
bin = new Bin<ChunkType>(bin_size, page_map_);
368+
bins_.emplace(bin_size, bin);
369369
} else {
370-
bin = it->second;
370+
bin = it->second;
371371
}
372372
}
373373

@@ -400,7 +400,7 @@ class ThreadLocalBin {
400400
int ptrs_num = arena_->BatchAllocate(kThreadLocalBinExchangeMaxPtrNum,
401401
t_bin_size_, ptrs.data());
402402
for (int i = 0; i < ptrs_num; i++) {
403-
list_.push_front(ptrs[i]);
403+
list_.push_front(ptrs[i]);
404404
}
405405
}
406406

@@ -415,8 +415,8 @@ class ThreadLocalBin {
415415
size_t BatchAllocate(size_t num, void **ret) {
416416
if (list_.size() >= num) {
417417
for (int i = 0; i < num; i++) {
418-
ret[i] = list_.back();
419-
list_.pop_back();
418+
ret[i] = list_.back();
419+
list_.pop_back();
420420
}
421421
return num;
422422
}
@@ -586,7 +586,7 @@ class EVAllocator : public Allocator {
586586
: single_allocation_warning_count_(0),
587587
total_allocation_warning_count_(0) {}
588588

589-
~EVAllocator() override {}
589+
~EVAllocator() override = default;
590590

591591
string Name() override { return ""; }
592592

tensorflow/core/framework/ev_allocator_gpu.cu.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2021 The DeepRec Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@ limitations under the License.
1515

1616
#ifdef GOOGLE_CUDA
1717
#include <cuda_runtime.h>
18-
#include "ev_allocator.h"
18+
#include "tensorflow/core/framework/ev_allocator.h"
1919

2020
namespace tensorflow {
2121

@@ -49,9 +49,8 @@ void PageMap<GPUChunk>::Init() {
4949

5050
class GPUEVAllocator : public EVAllocator<GPUChunk> {
5151
public:
52-
GPUEVAllocator() {}
53-
54-
~GPUEVAllocator() override {}
52+
GPUEVAllocator() = default;
53+
~GPUEVAllocator() override = default;
5554

5655
string Name() override { return "gpu_ev_allocator"; }
5756
};
@@ -81,6 +80,7 @@ class GPUEVAllocatorFactory : public AllocatorFactory {
8180
void Free(void *ptr, size_t num_bytes) override {
8281
gpu_ev_allocator_->DeallocateRaw(ptr);
8382
}
83+
8484
private:
8585
GPUEVAllocator* gpu_ev_allocator_;
8686
};

0 commit comments

Comments
 (0)