Skip to content

Commit

Permalink
Add support for offset load/store (#2804)
Browse files Browse the repository at this point in the history
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

Spec: intel/llvm#12497
  • Loading branch information
YixingZhang007 authored Dec 19, 2024
1 parent 112caf9 commit 193661c
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3705,6 +3705,7 @@ Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst(SPIRVInstruction *BI,
case internal::OpJointMatrixLoadINTEL:
case OpCooperativeMatrixLoadKHR:
case internal::OpCooperativeMatrixLoadCheckedINTEL:
case internal::OpCooperativeMatrixLoadOffsetINTEL:
case internal::OpTaskSequenceCreateINTEL:
case internal::OpConvertHandleToImageINTEL:
case internal::OpConvertHandleToSampledImageINTEL:
Expand Down
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ template <> inline void SPIRVMap<SPIRVCapabilityKind, SPIRVCapVec>::init() {
{CapabilityCooperativeMatrixKHR});
ADD_VEC_INIT(internal::CapabilityCooperativeMatrixCheckedInstructionsINTEL,
{CapabilityCooperativeMatrixKHR});
ADD_VEC_INIT(internal::CapabilityCooperativeMatrixOffsetInstructionsINTEL,
{CapabilityCooperativeMatrixKHR});
}

template <> inline void SPIRVMap<SPIRVExecutionModelKind, SPIRVCapVec>::init() {
Expand Down
20 changes: 20 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,26 @@ _SPIRV_OP(CooperativeMatrixStoreChecked, false, 8, true, 8)
_SPIRV_OP(CooperativeMatrixConstructChecked, true, 8)
#undef _SPIRV_OP

class SPIRVCooperativeMatrixOffsetInstructionsINTELInstBase
: public SPIRVInstTemplateBase {
protected:
std::optional<ExtensionID> getRequiredExtension() const override {
return ExtensionID::SPV_INTEL_joint_matrix;
}
SPIRVCapVec getRequiredCapability() const override {
return getVec(internal::CapabilityCooperativeMatrixOffsetInstructionsINTEL);
}
};

#define _SPIRV_OP(x, ...) \
typedef SPIRVInstTemplate< \
SPIRVCooperativeMatrixOffsetInstructionsINTELInstBase, \
internal::Op##x##INTEL, __VA_ARGS__> \
SPIRV##x##INTEL;
_SPIRV_OP(CooperativeMatrixLoadOffset, true, 8, true, 5)
_SPIRV_OP(CooperativeMatrixStoreOffset, false, 7, true, 6)
#undef _SPIRV_OP

class SPIRVCooperativeMatrixInvocationInstructionsINTELInstBase
: public SPIRVInstTemplateBase {
protected:
Expand Down
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
"CooperativeMatrixInvocationInstructionsINTEL");
add(internal::CapabilityCooperativeMatrixCheckedInstructionsINTEL,
"CooperativeMatrixCheckedInstructionsINTEL");
add(internal::CapabilityCooperativeMatrixOffsetInstructionsINTEL,
"CooperativeMatrixOffsetInstructionsINTEL");
add(internal::CapabilitySubgroupRequirementsINTEL,
"SubgroupRequirementsINTEL");
add(internal::CapabilityTaskSequenceINTEL, "TaskSequenceINTEL");
Expand Down
4 changes: 4 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVOpCodeEnumInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ _SPIRV_OP_INTERNAL(CooperativeMatrixStoreCheckedINTEL,
internal::OpCooperativeMatrixStoreCheckedINTEL)
_SPIRV_OP_INTERNAL(CooperativeMatrixConstructCheckedINTEL,
internal::OpCooperativeMatrixConstructCheckedINTEL)
_SPIRV_OP_INTERNAL(CooperativeMatrixLoadOffsetINTEL,
internal::OpCooperativeMatrixLoadOffsetINTEL)
_SPIRV_OP_INTERNAL(CooperativeMatrixStoreOffsetINTEL,
internal::OpCooperativeMatrixStoreOffsetINTEL)
_SPIRV_OP_INTERNAL(CooperativeMatrixApplyFunctionINTEL,
internal::OpCooperativeMatrixApplyFunctionINTEL)
_SPIRV_OP_INTERNAL(ComplexFMulINTEL, internal::ComplexFMulINTEL)
Expand Down
7 changes: 7 additions & 0 deletions lib/SPIRV/libSPIRV/spirv_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ enum InternalOp {
IOpCooperativeMatrixLoadCheckedINTEL = 6193,
IOpCooperativeMatrixStoreCheckedINTEL = 6194,
IOpCooperativeMatrixConstructCheckedINTEL = 6195,
IOpCooperativeMatrixLoadOffsetINTEL = 6239,
IOpCooperativeMatrixStoreOffsetINTEL = 6240,
IOpJointMatrixWorkItemLengthINTEL = 6410,
IOpTypeTaskSequenceINTEL = 6199,
IOpComplexFMulINTEL = 6415,
Expand Down Expand Up @@ -114,6 +116,7 @@ enum InternalCapability {
ICapGlobalVariableDecorationsINTEL = 6146,
ICapabilityTaskSequenceINTEL = 6162,
ICapabilityCooperativeMatrixCheckedInstructionsINTEL = 6192,
ICapabilityCooperativeMatrixOffsetInstructionsINTEL = 6238,
ICapabilityCooperativeMatrixPrefetchINTEL = 6411,
ICapabilityComplexFloatMulDivINTEL = 6414,
ICapabilityTensorFloat32RoundingINTEL = 6425,
Expand Down Expand Up @@ -187,6 +190,10 @@ _SPIRV_OP(Op, CooperativeMatrixLoadCheckedINTEL)
_SPIRV_OP(Op, CooperativeMatrixStoreCheckedINTEL)
_SPIRV_OP(Op, CooperativeMatrixConstructCheckedINTEL)

_SPIRV_OP(Capability, CooperativeMatrixOffsetInstructionsINTEL)
_SPIRV_OP(Op, CooperativeMatrixLoadOffsetINTEL)
_SPIRV_OP(Op, CooperativeMatrixStoreOffsetINTEL)

_SPIRV_OP(Capability, CooperativeMatrixInvocationInstructionsINTEL)
_SPIRV_OP(Op, CooperativeMatrixApplyFunctionINTEL)

Expand Down
Loading

0 comments on commit 193661c

Please sign in to comment.