Skip to content
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

[LAYOUTS] Generalise HoistLayoutConversion to work with arbitrary layouts and chains of ops #5673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lezcano
Copy link
Contributor

@lezcano lezcano commented Jan 22, 2025

We generalise HoistLayoutConversion to lift a given convert_layout dot_operand
above any chain of operations that do not require data movement. We
could totally generalise this in the future to lift it over other ops. We do
this as a first step to keep the code somewhat similar to the previous
one.

Regarding the previous limitations of canHoistDotOpEncV2 I did a bit of archeology:

We also add proper support for isPure for elementwise_inline_asm ops

On the location of the code, we just leave it in RemoveLayoutConversion.cpp to
take advantage of the rather generic implementation of rewriteSlice. We could totally
move this pass outside of remove-layout-conversion, as it's probably enough to run
it once. This code will go through further changes in the near future, so we'll assess this
then.

@lezcano lezcano requested a review from ptillet as a code owner January 22, 2025 17:52
@lezcano lezcano marked this pull request as draft January 22, 2025 23:30
@lezcano lezcano force-pushed the remat_dot branch 2 times, most recently from 1eed10c to a77a54a Compare January 24, 2025 15:00
@lezcano lezcano changed the title [WIP][LAYOUTS] Remove HoistLayoutConversion in favour of backwardsRemat [LAYOUTS] Generalise HoistLayoutConversion to work with arbitrary layouts and chains of ops Jan 27, 2025
Comment on lines +3278 to +3187
#blocked = #ttg.blocked<{sizePerThread = [1, 2], threadsPerWarp = [4, 8], warpsPerCTA = [4, 1], order = [1, 0]}>
#mma = #ttg.nvidia_mma<{versionMajor = 2, versionMinor = 0, warpsPerCTA = [1, 4]}>
module attributes {"ttg.num-warps" = 4 : i32, "ttg.target" = "cuda:80"} {
tt.func @dot_op_hoisted_to_load_with_unsupported_op_and_initializer_above_slice(
Copy link
Contributor Author

@lezcano lezcano Jan 27, 2025

Choose a reason for hiding this comment

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

This is all codemovement + adding this test that was proposed but not merged in #5349 (comment)
as we now hoist everything as expected

test/TritonGPU/combine.mlir Outdated Show resolved Hide resolved
@lezcano lezcano marked this pull request as ready for review January 27, 2025 10:23
@lezcano lezcano requested a review from ThomasRaoux January 27, 2025 10:32
Copy link
Collaborator

@ThomasRaoux ThomasRaoux left a comment

Choose a reason for hiding this comment

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

LGTM. One comment is I'm not sure if we need the speculatively part but that's kind of a detail

// This could be generalised if necessary
if (!loadOp) {
auto op = v.getDefiningOp();
if (isa<arith::ConstantOp>(op) || noDataMovement(op)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should ConstantOp just be put inside noDataMovement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably yeah, but leaving it as-is for now because it currently works and we are probably going to refactor this pass in the near future so whatever.

We now support all layouts as LL, and reductions support any layout as
input. As such, at least in theory, we should be able to propagate
layouts freely, even DotOperands, similar to what we do with other
layouts.

This PR is a bit tentative. Let's see if anything interesting breaks
@lezcano lezcano enabled auto-merge (squash) January 29, 2025 10:07
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