-
Notifications
You must be signed in to change notification settings - Fork 22k
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
[Intel GPU] xpu-ops codegen via backend whitelist #127865
Conversation
ghstack-source-id: 47b77bf426021ce6aa3c64c13c7d24ca38b13703 Pull Request resolved: #127865
ghstack-source-id: d2f0b7ca5b8f2d386a12b605e5ad1d19ba24041a Pull Request resolved: #127865
ghstack-source-id: d9b26a516a9ba776b7639a21a6df10cfc71f74a9 Pull Request resolved: #127865
ghstack-source-id: 8c71248152e86debe227fcf2f964b90c3ff35bae Pull Request resolved: #127865
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add UT.
ghstack-source-id: 4fe1274ff777b79e4a9e0c164eb2bb1e3b19b89f Pull Request resolved: #127865
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the test cases should be part of test_codegen.py but not a dedicated test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have moved the ut into test_codegen.py
ghstack-source-id: 680b8b6b496a854d61f24327f7c5e35d86555433 Pull Request resolved: #127865
ghstack-source-id: 36beb6c4158282d776ab3246a969028618810405 Pull Request resolved: #127865
@ZhiweiYan-96 , please fix UT failures and we need to enable it ASAP. |
aten/src/ATen/xpu/xpu_functions.yaml
Outdated
@@ -0,0 +1,55 @@ | |||
# This yaml is used only for testing the XPU codegen functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to add this yaml to the source code? I think it should be the data file of test folder. Why is it not be a part of test/xpu
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, have moved into test/xpu, thanks for the comment
ghstack-source-id: 9b4b4ec286689733ab3da6d6b72e5f24b8203897 Pull Request resolved: #127865
ghstack-source-id: 8f93fe94e2b0964208b29a7734f91756b48c0823 Pull Request resolved: #127865
ghstack-source-id: f3d8f75998366b2efc771df01483c97718377a8a Pull Request resolved: pytorch/pytorch#127865
Motivation
This PR intends to enhance the
gen.py
to allow generate codes for a specific backend.XPU operators need be registered in an hand-written way currently. Developers have no chance to take the advantage of shared code to handle tensor meta setting (like strides, proxy output, structured kernels). Manually porting code is erro-prone and may lead to high maintaining efforts.
We intend to enhance the
bckend_whitelist
argument ingen.py
to generate independent backend specific files. Then backend developers could directly use such generated codeUsage
The specialty of XPU ops is that they lie in
third_pary/torch-xpu-ops
, so it codegen resides in a separate process.We use the following commands to trigger XPU codegen
python -m torchgen.gen --source-path path/to/yaml/of/xpu --install-dir build/aten/src/ATen/xpu --per-operator-headers --static-dispatch-backend --backend-whitelist=XPU
The diff lies at
backend-whitelist=XPU
. The backend-whitelist key is an existent argument in torchgen. But we observe that it can be hardly used for generating source files likeRegistexxx.cpp
. We enhance the backend-white list argument ingen.py
, where we could use it to generate backend only code. Likebuild/aten/src/ATen/xpu/RegisterXPU.cpp, build/aten/src/ATen/xpu/ops/as_strided_native.h
The input of
gen.py
are code templates and operators yaml. We share the same templates inaten
. A simplified yaml lies inthird_party/torch-xpu-ops
, which only includes the supported xpu operators. This yaml is a copy-and-modify ofnative_functions.yaml
. No extra entry is added, the format is same as the one inaten
Result
All operators headers are generated in
build/aten/src/ATen/xpu/ops
independently, which would not affect operators declared/defined by CPU/CUDA or any other backend. XPU operators only include headers in this folder.Verification
We add a ut for verifying xpu codgen in
test_codegen.py
and it could be triggered throughpython -m tools.test.test_codegen -k BackendWhitelist
In
third-party/torch-xpu-ops
, we migrate some operators to structured kernels style, where they are registered throughREGISTER_XPU_DISPATCH
orTORCH_IMPL_FUNC
. And it is tested withtest_xpu.py
Others
As for the longer term, we would unify code generation system with other backend also, like cuda, mps.
Stack from ghstack (oldest at bottom):
cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @chauhang @d4l3k @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @mcarilli @ptrblck @leslie-fang-intel @EikanWang @voznesenskym @penguinwu @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @LucasLLC @MeetVadakkanchery @mhorowitz