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

Get base pointer from Allocation #37978

Merged
merged 8 commits into from
Dec 17, 2021

Conversation

From00
Copy link
Contributor

@From00 From00 commented Dec 8, 2021

PR types

New features

PR changes

Others

Describe

For performance considering, Paddle caches and manages the memory malloced from devices. The memory pointer given to user is not the base-pointer that directly returned from the device interface, as it may have undergone many transformations such as split and align by Allocator.
However, sometimes the base-pointer is required. For example, cudaIpcGetMemHandle needs a base-pointer of the device allocation created with cudaMalloc, so it can achieve memory sharing between different processes.
This PR maintains the base-pointer information in all allocators existing in Paddle, and implement a base_ptr interface in Allocation class. Thereby we can get the base-pointer from an allocation like:

paddle::platform::CUDAPlace& place = paddle::platform::CUDAPlace(); 
size_t size = 1024; // bytes    
std::shared_ptr<Allocation> allocation = paddle::memory::AllocShared(place, size);
void* base_ptr = allocation->base_ptr();

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 8, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@From00 From00 changed the title Get GPU BasePtr from CUDA allocation Get BasePtr from CUDA allocation Dec 8, 2021
@From00 From00 changed the title Get BasePtr from CUDA allocation Get base point from CUDA allocation Dec 8, 2021
@From00 From00 changed the title Get base point from CUDA allocation Get base pointer from Allocation Dec 13, 2021
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

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.

2 participants