KEMBAR78
Add torch.xpu.get_arch_list and torch.xpu.get_gencode_flags for XPU by guangyey · Pull Request #137773 · pytorch/pytorch · GitHub
Skip to content

Conversation

@guangyey
Copy link
Collaborator

@guangyey guangyey commented Oct 11, 2024

Stack from ghstack (oldest at bottom):

Motivation

Add torch.xpu.get_arch_list() and torch.xpu.get_gencode_flags() methods that return architecture list and AOT flags to preserve what flags PyTorch XPU was built with.

cc @albanD @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 11, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 7db91db with merge base 28a521e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@guangyey guangyey changed the title Preserve XPU arch flags [WIP] Preserve XPU arch flags Oct 11, 2024
@guangyey guangyey marked this pull request as draft October 11, 2024 10:36
@guangyey guangyey changed the title [WIP] Preserve XPU arch flags Preserve XPU arch flags Oct 11, 2024
@guangyey guangyey marked this pull request as ready for review October 11, 2024 11:49
@guangyey guangyey added ciflow/xpu Run XPU CI tasks ciflow/trunk Trigger trunk jobs on your pull request release notes: xpu release notes category module: python frontend For issues relating to PyTorch's Python frontend intel This tag is for PR from Intel labels Oct 11, 2024
guangyey added a commit that referenced this pull request Oct 11, 2024
ghstack-source-id: c4ac191
Pull Request resolved: #137773
Copy link
Collaborator

@EikanWang EikanWang left a comment

Choose a reason for hiding this comment

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

LGTM. Pls. add test cases.

@EikanWang
Copy link
Collaborator

By the way, Pls. help refine the PR title a little bit.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
github-merge-queue bot pushed a commit to intel/torch-xpu-ops that referenced this pull request Oct 12, 2024
# Motivation
To support `torch.xpu.get_arch_list` and `torch.xpu.get_gencode_flags`.

This PR is related to pytorch/pytorch#137773
@guangyey guangyey changed the title Preserve XPU arch flags Add torch.xpu.get_arch_list and torch.xpu.get_gencode_flags for XPU Oct 12, 2024
guangyey added a commit that referenced this pull request Oct 12, 2024
ghstack-source-id: 6322673
Pull Request resolved: #137773
guangyey added a commit that referenced this pull request Oct 12, 2024
ghstack-source-id: 3044a0b
Pull Request resolved: #137773
@guangyey
Copy link
Collaborator Author

LGTM. Pls. add test cases.

Done.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guangyey
Copy link
Collaborator Author

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

[ghstack-poisoned]
@pytorchmergebot
Copy link
Collaborator

Successfully rebased gh/guangyey/73/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/137773)

pytorchmergebot pushed a commit that referenced this pull request Oct 16, 2024
ghstack-source-id: 1c5e9ef
Pull Request resolved: #137773
@guangyey guangyey requested review from albanD, atalman and malfet October 17, 2024 06:55
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Small nits, but sounds good!

arch_flags = torch._C._xpu_getArchFlags()
if arch_flags is None:
return []
return arch_flags.split()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the default for split to split across "," ?

Copy link
Collaborator Author

@guangyey guangyey Oct 18, 2024

Choose a reason for hiding this comment

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

Thanks for your approval. By default any whitespace is a separator. This is expected.
We need to set env variable TORCH_XPU_ARCH_LIST via splitting arch name with commas here . And we have to replace commas with whitespace in TORCH_XPU_ARCH_LIST here. The reason is that C10_STRINGIZE, used in this line, is a macro which could process only an argument into a string (it will consider input separated by commas as multi-arguments, resulting a compilation error). So, _xpu_getArchFlags will return an arch string separated by whitespace instead of commas.

arch_list = get_arch_list()
if len(arch_list) == 0:
return ""
return f'-device {",".join(arch for arch in arch_list)}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this just f'-device {torch._C._xpu_getArchFlags()}' ? :p

Copy link
Collaborator Author

@guangyey guangyey Oct 18, 2024

Choose a reason for hiding this comment

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

As described above, torch._C._xpu_getArchFlags will return an arch list without commas. And here we expect to return the compilation flag, formatted by "-device ats-m150,lnl-m", that the compiler can recognize.

@guangyey
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions github-actions bot deleted the gh/guangyey/73/head branch November 18, 2024 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks intel This tag is for PR from Intel Merged module: python frontend For issues relating to PyTorch's Python frontend open source release notes: xpu release notes category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants