Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix_Linux_[-Wterminate]warning #52186

Merged
merged 6 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions paddle/fluid/memory/allocation/cuda_device_context_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ class GPUContextAllocation : public Allocation {
underlying_allocation_(std::move(allocation)) {}

~GPUContextAllocation() {
PADDLE_ENFORCE_NOT_NULL(
dev_ctx_,
platform::errors::PreconditionNotMet(
"Device context is not set for GPUContextAllocation"));
try {
PADDLE_ENFORCE_NOT_NULL(
dev_ctx_,
platform::errors::PreconditionNotMet(
"Device context is not set for GPUContextAllocation"));
} catch (std::exception &e) {
}
auto *p_allocation = underlying_allocation_.release();
VLOG(4) << "Adding callback to delete GPUContextAllocation at "
<< p_allocation;
Expand Down Expand Up @@ -86,13 +89,17 @@ class GPUContextAllocator : public Allocator {
}

~GPUContextAllocator() {
if (event_) {
platform::CUDADeviceGuard guard(place_.device);
try {
if (event_) {
platform::CUDADeviceGuard guard(place_.device);
#ifdef PADDLE_WITH_HIP
PADDLE_ENFORCE_GPU_SUCCESS(hipEventDestroy(event_));

PADDLE_ENFORCE_GPU_SUCCESS(hipEventDestroy(event_));
#else
PADDLE_ENFORCE_GPU_SUCCESS(cudaEventDestroy(event_));
PADDLE_ENFORCE_GPU_SUCCESS(cudaEventDestroy(event_));
#endif
}
} catch (std::exception &e) {
}
}

Expand Down
27 changes: 17 additions & 10 deletions paddle/fluid/memory/allocation/mmap_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,26 @@ void RefcountedMemoryMapAllocation::close() {
}

MemoryMapWriterAllocation::~MemoryMapWriterAllocation() {
PADDLE_ENFORCE_NE(
munmap(this->ptr(), this->size()),
-1,
platform::errors::Unavailable("could not unmap the shared memory file %s",
this->ipc_name()));
try {
PADDLE_ENFORCE_NE(
munmap(this->ptr(), this->size()),
-1,
platform::errors::Unavailable(
"could not unmap the shared memory file %s", this->ipc_name()));
} catch (std::exception &e) {
}
}

MemoryMapReaderAllocation::~MemoryMapReaderAllocation() {
PADDLE_ENFORCE_NE(
munmap(this->ptr(), this->size()),
-1,
platform::errors::Unavailable("could not unmap the shared memory file %s",
this->ipc_name()));
try {
PADDLE_ENFORCE_NE(

munmap(this->ptr(), this->size()),
-1,
platform::errors::Unavailable(
"could not unmap the shared memory file %s", this->ipc_name()));
} catch (std::exception &e) {
}
/* Here we do not pay attention to the result of shm_unlink,
because the memory mapped file may have been cleared due to the
MemoryMapFdSet::Clear() */
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/memory/allocation/mmap_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace allocation {

TEST(MemoryMapAllocation, test_allocation_base) {
size_t data_size = 4UL * 1024;

// 1. allocate writer holader
auto mmap_writer_holder = AllocateMemoryMapWriterAllocation(data_size);
std::string ipc_name = mmap_writer_holder->ipc_name();
Expand Down