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

Enable swizzling SMEM for transposed dot operand #474

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

htyu
Copy link

@htyu htyu commented Jan 18, 2024

Transposed operand will be accessed in an opposite order from the original operand. Enabling swizzling seems to help performance. I'm seeing 10% performance improvement for our internal model.

@htyu htyu changed the title Enable swizzling SMEM for transposed operand Enable swizzling SMEM for transposed dot operand Jan 18, 2024
@@ -131,6 +131,8 @@ compared to 1*64 when the hasLeadingOffset is false.

if (mfmaEnc) {
int kDimNum = dotOpEnc.getOpIdx() == 0 ? 1 : 0;
if (needTrans)

Choose a reason for hiding this comment

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

@htyu Is this for tt.trans?
In other cases, we don't set the needTrans field when creating a sharedLayout.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's for tt.trans like below. When creating a shared encoding, it looks ahead to see if there's a transpose prior to the dot.

qk = tl.dot(q, tl.trans(k), allow_tf32=ALLOW_TF32) * alpha

Choose a reason for hiding this comment

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

I learned that tl.trans is a very tricky op.
Let me clarify. The 10% improvement is due to the enablement of swizzling?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this change speeds up our model that has above trans and dot operation by 10%.

Copy link
Author

@htyu htyu Jan 23, 2024

Choose a reason for hiding this comment

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

BTW, tl.trans is used quite often in attention kernel of a transformer model, iiuc.

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

With this change, do we need a change related to lines at: https://github.com/htyu/triton/blob/ab3aafb4a9158a60a4c3085a13b605f70488d6ff/include/triton/Dialect/TritonGPU/IR/TritonGPUAttrDefs.td#L166-L167
We have scenario of non-square tile now.

Choose a reason for hiding this comment

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

no they should be good.
The changes here is only used to enable swizzling for operands of dot.
getMDim and getNDim are shapes of the result of dot.

Copy link

Choose a reason for hiding this comment

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

Never mind, this is related to mfma layout

@zhanglx13 zhanglx13 self-requested a review January 23, 2024 18:03
@zhanglx13 zhanglx13 merged commit 6141b10 into ROCm:triton-mlir Jan 23, 2024
2 checks passed
htyu added a commit to triton-lang/triton that referenced this pull request Apr 15, 2024
Transposed operand will be accessed in an opposite order from the
original operand. Enabling swizzling seems to help performance. I'm
seeing 10% performance improvement for our internal model.

This is a backport of ROCm#474.
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