-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[AMX] syscall to enable AMX instructions on real hardware #6909
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
Open
frengels
wants to merge
12
commits into
halide:main
Choose a base branch
from
frengels:amx-perm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d8dfc1
add runtime code for requesting amx permissions
frengels 3ecebf4
add amx module to cpp initmods
frengels 320912e
add error messages if support is not found
frengels fa14962
add class which will inject amx permission request
frengels fede360
print the error code on failure
frengels 4006516
add build of amx module to Makefile
frengels 7508092
Use AMXRequestPermission in ExtractTileOperations
frengels bc161c2
rename amx.cpp -> linux_amx.cpp
frengels d02e9bf
rename to `halide_enable_amx`
frengels a352217
add a symbol for `halide_enable_amx` in the runtime header
frengels 58dcd78
Revert changes to ExtractTileOperations
frengels 497536e
move the `halide_enable_amx` symbol to HalideRuntime.h
frengels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "HalideRuntime.h" | ||
| #include "printer.h" | ||
| #include "runtime_internal.h" | ||
|
|
||
| #define SYS_arch_prctl 158 | ||
|
|
||
| extern "C" int syscall(long sysno, ...) throw(); | ||
|
|
||
| extern "C" WEAK int halide_enable_amx() { | ||
| constexpr int XFEATURE_XTILECFG = 17; | ||
| constexpr int XFEATURE_XTILEDATA = 18; | ||
| constexpr int ARCH_REQ_XCOMP_PERM = 0x1023; | ||
|
|
||
| // xgetbv instruction should always be present on CPUs with AMX | ||
| long long res = __builtin_ia32_xgetbv(0); | ||
|
|
||
| // if AMX is not supported by the OS these bits are not set | ||
| if (!(res & (1 << XFEATURE_XTILECFG))) { | ||
| error(nullptr) << "XTILECFG not available for AMX instructions.\n"; | ||
| return -2; | ||
| } | ||
|
|
||
| if (!(res & (1 << XFEATURE_XTILEDATA))) { | ||
| error(nullptr) << "XTILEDATA not available for AMX instruction.\n"; | ||
| return -2; | ||
| } | ||
|
|
||
| // we must request permission to use AMX | ||
| auto ret = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA); | ||
|
|
||
| if (ret) { | ||
| error(nullptr) << "Failed to enable AMX instructions: " << ret << '\n'; | ||
| return -1; | ||
| } | ||
|
|
||
| debug(nullptr) << "AMX permissions acquired\n"; | ||
|
|
||
| return 0; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FYI, these changes/additions will also need to be made in src/runtime/CMakeLists.txt -- we support CMake on all our platforms, whereas Make only on a small percentage.