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: Release CPU/GPU memory at the end of the Program #3534

Merged
merged 8 commits into from
Aug 17, 2017

Conversation

gangliao
Copy link
Contributor

@gangliao gangliao commented Aug 16, 2017

After unit test is passed, release memory!

[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (600 ms total)
[  PASSED  ] 4 tests.
I0816 19:44:47.157642 3000099776 buddy_allocator.cc:30] BuddyAllocator Disconstructor makes sure that all of these have actually been freed
I0816 19:44:47.157649 3000099776 buddy_allocator.cc:34] Free from block (0x700960000, 1818944052)
I0816 19:44:47.159529 3000099776 buddy_allocator.cc:30] BuddyAllocator Disconstructor makes sure that all of these have actually been freed
I0816 19:44:47.159555 3000099776 buddy_allocator.cc:34] Free from block (0x11419c000, 536870912)

fix #3536
fix #3537

@gangliao gangliao requested a review from QiJune August 16, 2017 11:49
@@ -45,4 +45,8 @@ TEST(Gather, GatherData) {

for (int i = 0; i < 4; ++i) EXPECT_EQ(p_output[i], i + 4);
for (int i = 4; i < 8; ++i) EXPECT_EQ(p_output[i], i - 4);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zchen0211 return tensor memory back to buddy allocator for free.

@gangliao gangliao changed the title FIX: Release CPU/GPU memory via deleter FIX: Release CPU/GPU memory at the end of the Program Aug 17, 2017

BuddyAllocator* GetCPUBuddyAllocator() {
static std::unique_ptr<BuddyAllocator, void (*)(BuddyAllocator*)> a{
nullptr, [](BuddyAllocator* p) { delete p; }};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here need to pass a lambda function, unique_ptr will delete the pointer automaticlly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Deleter could be default one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@QiJune QiJune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gangliao gangliao merged commit 812a64c into PaddlePaddle:develop Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tensor didn't free memory at the end of the program CPU free memory error
2 participants