Skip to content

Commit

Permalink
bugfix: crash when competition (PaddlePaddle#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
m3ngyang committed Mar 24, 2022
1 parent f31494a commit cad1183
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Allocation* MixedMemBestFitAllocator::AllocateImpl(size_t size) {
platform::errors::InvalidArgument("Underlying host allocator of "
"MixedMemBestFitAllocator is nullptr"));

std::lock_guard<std::mutex> lock(mtx_);
if (!device_allocator_->ReachLimit()) {
try {
void* ptr = device_allocator_->Alloc(size);
Expand Down Expand Up @@ -83,9 +84,10 @@ Allocation* MixedMemBestFitAllocator::AllocateImpl(size_t size) {
}

void MixedMemBestFitAllocator::FreeImpl(Allocation* allocation) {
auto place = allocation->place();
const auto place = allocation->place();
bool succ = false;

std::lock_guard<std::mutex> lock(mtx_);
auto it = devptr2hostptr_.find(allocation->ptr());
if (it == devptr2hostptr_.end()) {
device_allocator_->Free(allocation->ptr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MixedMemBestFitAllocator : public Allocator {
std::shared_ptr<detail::BuddyAllocator> device_allocator_;
std::shared_ptr<detail::BuddyAllocator> host_allocator_;

std::mutex mtx_;
std::unordered_map<void*, MappedAddr> devptr2hostptr_;
};

Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/platform/gpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ class RecordedCudaMallocHelper {
private:
explicit RecordedCudaMallocHelper(int dev_id, uint64_t limit_size = 0)
: dev_id_(dev_id), limit_size_(limit_size) {
// if (NeedRecord()) {
mtx_.reset(new std::mutex());
// }
if (NeedRecord()) {
mtx_.reset(new std::mutex());
}
}

DISABLE_COPY_AND_ASSIGN(RecordedCudaMallocHelper);
Expand Down

0 comments on commit cad1183

Please sign in to comment.