Skip to content

Add MPS support for getHostAllocator API #151913

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

Closed
wants to merge 12 commits into from

Conversation

guangyey
Copy link
Collaborator

@guangyey guangyey commented Apr 22, 2025

Stack from ghstack (oldest at bottom):

Motivation

In #151431, PyTorch provides a unified API at::getHostAllocator(...) that facilitates writing device-agnostic code. This PR aims to add MPS support for at::getHostAllocator API.

Additional Context

The following APIs are not support on at::getHostAllocator(at::kMPS) yet:

  • at::getHostAllocator()->record_event
  • at::getHostAllocator()->get_stats
  • at::getHostAllocator()->reset_accumulated_stats
  • at::getHostAllocator()->reset_peak_stats

Copy link

pytorch-bot bot commented Apr 22, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/151913

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 92eaeb9 with merge base f4ac9a1 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added ciflow/mps Run MPS tests (subset of trunk) release notes: mps Release notes category labels Apr 22, 2025
@guangyey guangyey changed the title Add MPS support for getHostAllocator API [WIP] Add MPS support for getHostAllocator API Apr 22, 2025
@guangyey guangyey requested review from gujinghui and EikanWang April 22, 2025 16:00
@guangyey guangyey requested review from eqy and syed-ahmed as code owners April 22, 2025 16:40
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
private:
bool m_has_unified_memory;
uint32_t m_usage;

static void Delete(void* ptr) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make Delete as public since it is used in MPSHostAllocator.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guangyey guangyey changed the title [WIP] Add MPS support for getHostAllocator API Add MPS support for getHostAllocator API Apr 23, 2025
@guangyey guangyey requested a review from albanD April 24, 2025 08:58
@guangyey
Copy link
Collaborator Author

@malfet @albanD May I know if this PR is reasonable for you?

Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

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

It does not move MPS allocator to this unified one, but rather adds a new interface which is not used.
Which makes me wonder what is the point? I.e. shouldn't existing MPSCachingAllocator start inheriting from HostAllocator rather than introducing a new API

And is there a design document somewhere that explains unified interface all accelerators should support


// A wrapper for MPSAllocator to be used in `getHostAllocator(at::kMPS)` API
struct MPSHostAllocator final : public at::HostAllocator {
public:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to add public for struct, as it's public by default, isn't it?

@guangyey
Copy link
Collaborator Author

I.e. shouldn't existing MPSCachingAllocator start inheriting from HostAllocator rather than introducing a new API

Different from other backend, MPSCachingAllocator is an allocator including both host and device, so it can't inherit from HostAllocator which is a host-specific allocator.

And is there a design document somewhere that explains unified interface all accelerators should support

No public document yet, only some comments inside this file.

@guangyey guangyey closed this May 22, 2025
@github-actions github-actions bot deleted the gh/guangyey/141/head branch June 23, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/mps Run MPS tests (subset of trunk) open source release notes: mps Release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants