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

Add support for offset load/store #2804

Merged
merged 11 commits into from
Dec 19, 2024

Conversation

YixingZhang007
Copy link
Contributor

@YixingZhang007 YixingZhang007 commented Oct 25, 2024

Add a new form of load/store operations for cooperative matrices that accepts two separate arguments: the row index and the column index. Unlike the original approach requiring a pointer to the matrix base, this new form of load/store operations is expected to yield better optimized code on 2dblock read/write instructions on PVC.

CapabilityCooperativeMatrixOffsetInstructionsINTEL = 6238
OpCooperativeMatrixLoadOffsetINTEL = 6239
OpCooperativeMatrixStoreOffsetINTEL = 6240

@CLAassistant
Copy link

CLAassistant commented Oct 25, 2024

CLA assistant check
All committers have signed the CLA.

@YixingZhang007 YixingZhang007 marked this pull request as draft October 25, 2024 02:15
!4 = !{}
!5 = !{i16 6, i16 14}
!6 = !{!"-ze-opt-level=O2"}
!7 = !{!"ModuleMD", !8, !9, !111, !112, !143, !144, !148, !151, !152, !153, !189, !215, !228, !229, !230, !246, !247, !248, !249, !250, !251, !252, !253, !254, !255, !259, !260, !267, !268, !269, !270, !271, !272, !273, !274, !275, !276, !277, !278, !280, !284, !285, !286, !287, !288, !289, !290, !291, !292, !293, !294, !295, !296, !297, !298, !299, !300, !301, !302, !303, !304, !305, !307, !310, !311, !312, !314, !315, !316, !321}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please shorten the tests - we won't need all of these metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions! I have updated the test.

@YixingZhang007 YixingZhang007 marked this pull request as ready for review November 18, 2024 20:33
Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

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

2 nits, other than that the patch is LGTM

@@ -3710,6 +3710,27 @@ _SPIRV_OP(CooperativeMatrixStoreChecked, false, 8, true, 8)
_SPIRV_OP(CooperativeMatrixConstructChecked, true, 8)
#undef _SPIRV_OP

class SPIRVJointMatrixOffsetInstructionsINTELInstBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class SPIRVJointMatrixOffsetInstructionsINTELInstBase
class SPIRVCooperativeMatrixOffsetInstructionsINTELInstBase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I have fixed this :)


#define _SPIRV_OP(x, ...) \
typedef SPIRVInstTemplate< \
SPIRVJointMatrixOffsetInstructionsINTELInstBase, \
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have also fixed this.

@@ -0,0 +1,152 @@
; This is an adapted copy of test/extensions/INTEL/SPV_INTEL_joint_matrix/joint_matrix.ll
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use KHR/SPV_KHR_cooperative_matrix test as the template...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions! I have updated the test :)

; CHECK-SPIRV: CooperativeMatrixLoadOffsetINTEL [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixLoadOffsetINTEL [[#MatTy2]]
; CHECK-SPIRV: CooperativeMatrixLoadOffsetINTEL [[#MatTy3]]
; CHECK-SPIRV: JointMatrixMadINTEL [[#MatTy1]]
Copy link
Contributor

Choose a reason for hiding this comment

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

...so here we would have CooperativeMatrixMulAddKHR instruction.

Reason: JointMatrixMadINTEL will be deprecated. And real-life SYCL joint_matrix workflows with switch to cooperative matrix KHR when intel/llvm#16045 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I have change this.

@YixingZhang007
Copy link
Contributor Author

@vmaksimo I just did some code clean up. Could you please help review this PR? Thanks for helping :)

@MrSidims
Copy link
Contributor

Spec is available as rev 17 of intel/llvm#12497
@vmaksimo may I ask you to take a look at CI issues?

@vmaksimo
Copy link
Contributor

CI issue was fixed in main by 4a85dd8, please rebase on top to get CI passing

Comment on lines 3749 to 3750
_SPIRV_OP(CooperativeMatrixLoadOffset, true, 8, true, 6)
_SPIRV_OP(CooperativeMatrixStoreOffset, false, 7, true, 7)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please verify that the last optional operand Memory Operand is really translated as Literal to SPIR-V (there are no checks for that in test, so the bug can be hidden). If no, please apply my suggestion, it should work this way if I'm not misunderstanding

Suggested change
_SPIRV_OP(CooperativeMatrixLoadOffset, true, 8, true, 6)
_SPIRV_OP(CooperativeMatrixStoreOffset, false, 7, true, 7)
_SPIRV_OP(CooperativeMatrixLoadOffset, true, 8, true, 5)
_SPIRV_OP(CooperativeMatrixStoreOffset, false, 7, true, 6)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello Viktoria! Thanks so much for the suggestion! I have checked that the last operand Memory Operand is not translated to Literal. I have applied the suggested change :)

Copy link
Contributor

@vmaksimo vmaksimo left a comment

Choose a reason for hiding this comment

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

LGTM.
Applying the suggestion is not required to get this merged.

@YixingZhang007
Copy link
Contributor Author

@vmaksimo Could you please help merge this PR or if I need to get approval from anyone else? Thanks!

@vmaksimo vmaksimo merged commit 193661c into KhronosGroup:main Dec 19, 2024
9 checks passed
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.

4 participants