-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLVMGPU] Add Virtual MFMA layout that maximizes load through adjuste…
…d K-width (#18930) The main use case for the virtual intrinsics are to change the layout of intrinsics in K-dimension, such that we can coalesce reads from shared memory to register. Currently, the "native" intrinsics need to enforce the "native" layout (i.e read 4 element per thread for MFMA_F32_16x16x16), however since we know that K-dim is a reduction dimension which is associative, we can read the data in non "native"/"correct" but "faster"/"more elements per read" way but as long as we match the K-dim on both lhs and rhs we will still get correct results (i.e read 8 contiguous element per thread from shared memory along dimension K for and then slice them into two MFMA_F32_16x16x16)). an IR example for this is if we want to do a 16x16x32(MxNxK) matmul with MFMA_F32_16x16x16_F16 intrinsics, on lane 0 we used to have something like: ``` lhs_0 = read(lhs_shared_mem[0:4]) rhs_0 = read(rhs_shared_mem[0:4]) mma_0 = vector.contract(lhs_0, rhs_0) (16 offset since MFMA_F32_16x16x16xF16 has intrinsic K size of 16) lhs_1 = read(lhs_shared_mem[16 + 0: 16 + 4]) rhs_1 = read(rhs_shared_mem[16 + 0 : 16 + 4]) mma_1 = vector.contract(lhs_1, rhs_1, mma_0) ``` With this optimization, we will turn into something like: ``` lhs_reg = read(lhs_shared_mem[0:8]) rhs_reg = read(rhs_shared_mem[0:8]) lhs_0 = slice(lhs_reg, [0 : 4]) rhs_0 = slice(rhs_reg, [0 : 4]) mma_0 = vector.contract(lhs_0, rhs_0) lhs_1 = slice(lhs_reg, [4 : 8]) rhs_1 = slice(rhs_reg, [4 : 8]) mma_1 = vector.contract(lhs_0, rhs_0, mma_0) ``` Currently, we are plumbing it in as MMA intrinsic enums for two variants of unrolled k == 2 on the F16s(per discussion with @qedawkins and @Groverkss ), as they are the easiest and non tangly way to integrate/plumb through. all though in the future we can expose this attribute as k-width for maximizing generability. --------- Signed-off-by: Stanley Winata <[email protected]>
- Loading branch information
1 parent
20c8347
commit bb542ee
Showing
7 changed files
with
305 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Oops, something went wrong.