Skip to content

[SPIRV] Enable scf.forall-based workgroup distribution#23684

Merged
hanhanW merged 3 commits intomainfrom
users/hanhanW/spirv-forall-distribution
Mar 12, 2026
Merged

[SPIRV] Enable scf.forall-based workgroup distribution#23684
hanhanW merged 3 commits intomainfrom
users/hanhanW/spirv-forall-distribution

Conversation

@hanhanW
Copy link
Copy Markdown
Contributor

@hanhanW hanhanW commented Mar 6, 2026

The forall path also requires ConvertAccGEMMToGEMM before distribution to avoid accumulating matmul's shared_outs being bufferized to workgroup memory with a copy-out outside the forall, which violates the workgroup
distribution verifier.

@hanhanW hanhanW force-pushed the users/hanhanW/spirv-forall-distribution branch from 56d65a7 to b3ed406 Compare March 6, 2026 21:06
@hanhanW hanhanW changed the base branch from main to users/hanhanW/diff-spirv-forall-distribution March 6, 2026 21:07
@hanhanW hanhanW requested a review from qedawkins March 6, 2026 21:07
@hanhanW
Copy link
Copy Markdown
Contributor Author

hanhanW commented Mar 6, 2026

@hanhanW hanhanW marked this pull request as ready for review March 6, 2026 21:09
@hanhanW hanhanW requested a review from kuhar as a code owner March 6, 2026 21:09
static llvm::cl::opt<bool> clSPIRVTileDispatchUsingForall(
"iree-spirv-tile-dispatch-using-forall",
llvm::cl::desc("Enable tile and distribute to workgroups using scf.forall"),
llvm::cl::init(true));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this be hidden? I don't realistically expect anyone to flip this flag

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I forgot to mention that I'll remove the option if CI is happy. And yes, it should be hidden if we preserve the flag.

// CHECK-COUNT-8: %{{.+}} = spirv.KHR.CooperativeMatrixMulAdd %{{.+}}, %{{.+}}, %{{.+}}

// Matmul results are stored to workgroup memory for the epilogue.
// CHECK-COUNT-4: spirv.KHR.CooperativeMatrixStore %{{.+}}, %{{.+}}, %[[C9]], <RowMajor>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we restore checks for the order loaded values?

@hanhanW hanhanW force-pushed the users/hanhanW/spirv-forall-distribution branch from b3ed406 to e299cfc Compare March 7, 2026 01:00
@hanhanW hanhanW force-pushed the users/hanhanW/spirv-forall-distribution branch from e299cfc to 52c80d2 Compare March 11, 2026 01:14
@hanhanW hanhanW changed the base branch from users/hanhanW/diff-spirv-forall-distribution to main March 11, 2026 01:15
Copy link
Copy Markdown
Contributor

@krzysz00 krzysz00 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me

@hanhanW hanhanW force-pushed the users/hanhanW/spirv-forall-distribution branch from 52c80d2 to 8af48c7 Compare March 12, 2026 16:17
hanhanW added 3 commits March 12, 2026 09:32
Switch the SPIRV backend from the legacy `TileAndDistributeToWorkgroups`
pass to `TileAndDistributeToWorkgroupsUsingForallOp`. This aligns SPIRV
with the LLVMGPU backend's distribution approach.

The forall path also requires `ConvertAccGEMMToGEMM` before distribution
to avoid accumulating matmul's shared_outs being bufferized to workgroup
memory with a copy-out outside the forall, which violates the workgroup
distribution verifier.

Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
@hanhanW hanhanW force-pushed the users/hanhanW/spirv-forall-distribution branch from 8af48c7 to 1a68b3b Compare March 12, 2026 16:32
@hanhanW hanhanW enabled auto-merge (squash) March 12, 2026 17:20
@hanhanW hanhanW merged commit ccebc03 into main Mar 12, 2026
59 of 60 checks passed
@hanhanW hanhanW deleted the users/hanhanW/spirv-forall-distribution branch March 12, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants