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

Add GetBasePtr interface in paddle::memory #39145

Merged
merged 1 commit into from
Jan 25, 2022

Conversation

From00
Copy link
Contributor

@From00 From00 commented Jan 22, 2022

PR types

New features

PR changes

Others

Describe

After PR #38853 merged, the memory::allocation::Allocation is a derived class of pten::Allocation, and the Alloc interface in malloc.h return a pten::Allocation type. Since the base_ptr function introduced in #37978 is implenmemted in memoy::allocation::Allocation, now we have to get the base-pointer from an allocation like:

std::shared_ptr<pten::Allocation> allocation = memory::AllocShared(place_, size);
void* base_ptr = static_cast<memory::allocation::Allocation*>(allocation.get())->base_ptr();

It is so inconvenient compared with the previous method:

void* base_ptr = allocation->base_ptr();

This PR adds a GetBasePtr interface in paddle::memory that hides the inelegant static_cast in AllocatorFacadePrivate, therefore we can get the base-pointer by a simple way like:

void* base_ptr = memory::GetBasePtr(allocation);

@From00 From00 force-pushed the add-interface-GetBasePtr branch from 2499cf9 to 5521002 Compare January 23, 2022 15:39
@From00 From00 requested review from Shixiaowei02 and zhiqiu January 24, 2022 08:40
Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@From00 From00 merged commit b2a7261 into PaddlePaddle:develop Jan 25, 2022
@From00 From00 deleted the add-interface-GetBasePtr branch January 27, 2022 10:54
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.

3 participants