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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/triton/Dialect/TritonGPU/IR/TritonGPUAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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

kDimNum = 1 - kDimNum;
bool isKDimInner = (order[0] == kDimNum);
if (isKDimInner) {
const int numBanks = 32;
Expand Down