[RVV] Enable SpaceMiT vendor IME#24706
[RVV] Enable SpaceMiT vendor IME#24706TMahlatini wants to merge 6 commits intoiree-org:mainiree-org/iree:mainfrom akuhlken:users/tmahlatini/xsmtvdot-ime-mmt4dakuhlken/iree-mcw:users/tmahlatini/xsmtvdot-ime-mmt4dCopy head branch name to clipboard
Conversation
|
Hello @TMahlatini 👋 Thank you for submitting a Pull Request to IREE! It looks like this is your first one. Below are some useful links and pointers. General guidanceOur general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system. A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin. Action required: acknowledge IREE project policiesIREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct. Please also note that all contributions to IREE must follow our IREE AI Tool Use Policy. In particular:
We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy. If you have any questions, feel free to leave a comment here, or ask away on IREE Discord. Thank you, |
Add xsmtvdot microkernel: 12x16x8. Updated contracts, build, tests and benchmarks to validate the kernel. Fixes: iree-org#24576 Co-authored-by: Coden <github.com/coden-s> Co-authored-by: Andrew <github.com/akuhlken> Signed-off-by: Terence <terrencemahlatini@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
eafb0c9 to
60332b4
Compare
|
I understand and accept the cited policies, including the AI Tool Use Policy. |
60332b4 to
4354747
Compare
- Added definitions for SpaceMiT vendor and architecture IDs to support the XSMTVDot matrix extension. - Modified the `iree_cpu_initialize_from_platform_riscv_64` function to detect the presence of the XSMTVDot extension based on the machine identity. Fixes: iree-org#24576 Signed-off-by: Terence <terrencemahlatini@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
4354747 to
e33a309
Compare
egebeysel
left a comment
There was a problem hiding this comment.
Initial comments from my side, haven't checked the plumbing nor the ukernel itself completely yet, though I have an intiial comment regarding support for the VLEN that SpaceMiT IME allows. I think it should work quite easily without changing your ukernel much, but let me know if that's not the case.
| // SpaceMiT IME (vmadot): fixed tile shape derived from the 4×4×8 atom. | ||
| // M0=12 (3×4 atom grid) matches the registered runtime ukernel tile. | ||
| if (hasFeature(config, "+xsmtvdot")) { | ||
| return {TileMxNxK{12, 16, 8}}; |
There was a problem hiding this comment.
could you remind me why we didn't have the 8, 4 fallback sizes for M0 here?
There was a problem hiding this comment.
we prototyped M0=8 and 4 earlier, but weren’t confident in the performance. Our early structure put the K loop in C around separate asm blocks, so vector accumulators weren’t held live across K and the results were hard to trust. For this PR we intentionally only register the M0=12 primary. Happy to follow up with M0=8/4 using the same single-asm structure (2×4 and 1×4 atom grids).
| // SpaceMiT IME (vmadot): fixed tile shape derived from the 4×4×8 atom. | ||
| // M0=12 (3×4 atom grid) matches the registered runtime ukernel tile. | ||
| if (hasFeature(config, "+xsmtvdot")) { | ||
| return {TileMxNxK{12, 16, 8}}; |
There was a problem hiding this comment.
Also, the SpaceMiT IME extension technically allows for vector lengths from 128 to 4096 as powers of two. I know the board you has VLEN=256bits, but we could easily support other powers of two as well.
Though there is a caveat: depending on the VLEN, the layout that the instruction operates on changes, i.e. there is a new variable called copy or Copies that can be 1 or 2:
=1forVLEN=256, 1024, 4096=2forVLEN=128, 512, 2048
Your microkernel and your layout should be able to cover the =1 case, so you can maybe take the vector length from the +zvl*b features and set the M and N dims of the layout accordingly, i.e. instead of 3*4 x 4*4 x 8 we can set 3*(n0/8) x 4*(n0/8) x 8 AND bail out (don't pick vmadot) if we have the =2 case. We can add support for that later 👍 The microkernel should not change regardless, only the input layout would be different and more complex, but that is currently not representable cleanly with what we have with mmt4d at the moment. Reach out to me if you want more details from the RISC-V Discord channel of IREE.
There was a problem hiding this comment.
The SpaceMiT IME documentation is here: https://github.com/spacemit-com/riscv-ime-extension-spec/releases/tag/v1.0, check section 3.1.1.
(I think the sentence that starts with "Input data is stored in VS1 and VS1+1 (the index of VS1 must be even)" for the non-sliding vmadot is wrong, you don't have VS1 + 1 involved here, the layout figure is correct though)
There was a problem hiding this comment.
Thanks. I will update this PR so that it covers Copies=1 and fall through when Copies=2. Agreed on the non-sliding vmadot comment.
There was a problem hiding this comment.
Also, the SpaceMiT IME extension technically allows for vector lengths from 128 to 4096 as powers of two. I know the board you has
VLEN=256bits, but we could easily support other powers of two as well.Though there is a caveat: depending on the VLEN, the layout that the instruction operates on changes, i.e. there is a new variable called copy or Copies that can be 1 or 2:
* `=1` for `VLEN=256, 1024, 4096` * `=2` for `VLEN=128, 512, 2048`Your microkernel and your layout should be able to cover the
=1case, so you can maybe take the vector length from the+zvl*bfeatures and set the M and N dims of the layout accordingly, i.e. instead of3*4 x 4*4 x 8we can set3*(n0/8) x 4*(n0/8) x 8AND bail out (don't pick vmadot) if we have the=2case. We can add support for that later 👍 The microkernel should not change regardless, only the input layout would be different and more complex, but that is currently not representable cleanly with what we have with mmt4d at the moment. Reach out to me if you want more details from the RISC-V Discord channel of IREE.
Latest commit extends support to 1024, 4096 however only 256 has been validated on hardware.
| // Auto-enable mmt4d for IME-capable RISC-V targets so callers do not need | ||
| // --iree-llvmcpu-enable-ukernels=mmt4d explicitly. Plain +v targets are | ||
| // unaffected; they still require the explicit flag. |
There was a problem hiding this comment.
jfyi, there's #24620 that wants to enable mmt4d ukernels for RVV regardless, and I think it's fine to do so. No action item needed from your side.
| IREE_UK_MMT4D_TILE(riscv_64, f16, f16, f16, 4, 1, _zvfh) | ||
| IREE_UK_MMT4D_TILE(riscv_64, f16, f16, f16, 7, 1, _zvfh) | ||
|
|
||
| IREE_UK_MMT4D_TILE(riscv_64, s8, s8, s32, 12, 8, _xsmtvdot) |
There was a problem hiding this comment.
todo for myself (and you can also check this 😄), what happens when M0 can also take multiple values? (i.e. dependent on VLEN)
…gurations that cover vlen=1024 and 4096. Signed-off-by: Terence <terrencemahlatini@gmail.com>
Re-add IME tile cases dropped when resolving the main merge conflict. Signed-off-by: Terence <terrencemahlatini@gmail.com>
|
Reflecting the offline feedback here: hey, I was going to try and give it another go tomorrow, but now that you're at it: I would actually try and contain the inline_asm to the instructions for which you do not have intrinsics for: if I'm not mistaken, that is just the vmadot's. If you do that, you can also use Can also wrap them around like this: As far as I can see, you are not doing much hand-scheduling that would require a full inline assembly kernel with pipelining and stuff (not saying you should). In that case, it's fine to keep the inline asm to the minimum and wrap it around. Finally: for the scatter/gather of the accumulator, AArch64 has these zip/unzip-like instructions. I think RVV also has similar instructions or shuffles, maybe it's worth checking that out :slight_smile: You can do that directly without storing and reading after the K loop: |
Will work on it and update the PR. |
Summary
This PR adds an s8s8s32 mmt4d ukernel for SpaceMiT IME (
+xsmtvdot/smt.vmadot)and wires the compiler to use it. The tile is fixed at 12x16x8 (3x4 grid of 4x4x8 atoms). Under
+xsmtvdotweselect that shape and auto-enable mmt4d; plain
+vtargets are unchanged.Also, runtime detection can't use the usual ISA hwprobe bits for this vendor extension, so we set the feature bit from SpaceMiT X60
mvendorid/marchid. And adds lit coverage, mmt4d unit/benchmark entries, and anriscv_64:ime:+v,+zvl256b,+xsmtvdote2e matmul variant. Validated on Banana Pi (BPI-F3 / X60): cpuinfo, mmt4d_test, and the ukernel e2e path.Fixes #24576
Co-authored-by: Coden <github.com/coden-s>
Co-authored-by: Andrew <github.com/akuhlken>
Co-authored-by: Cursor cursoragent@cursor.com
Signed-off-by: Terence terrencemahlatini@gmail.com