Skip to content

Commit 7b29f08

Browse files
committed
[Bckport to 14] Add JointMatrixGetElementCoordINTEL instruction
The instruction returns (Row, Column) coordinate of dynamically selected element of a matrix Updated version of the spec is here intel/llvm#8175 Instruction correctness checks will be added later among non-backward compatible changes. Signed-off-by: Sidorov, Dmitry [email protected] Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 3b16190 commit 7b29f08

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ template <> inline void SPIRVMap<SPIRVCapabilityKind, SPIRVCapVec>::init() {
205205
{CapabilitySubgroupAvcMotionEstimationINTEL});
206206
ADD_VEC_INIT(CapabilitySubgroupAvcMotionEstimationChromaINTEL,
207207
{CapabilitySubgroupAvcMotionEstimationIntraINTEL});
208+
ADD_VEC_INIT(internal::CapabilityJointMatrixWIInstructionsINTEL,
209+
{internal::CapabilityJointMatrixINTEL});
208210
}
209211

210212
template <> inline void SPIRVMap<SPIRVExecutionModelKind, SPIRVCapVec>::init() {

lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,7 @@ _SPIRV_OP(JointMatrixMad, true, 7)
33753375
_SPIRV_OP(JointMatrixSUMad, true, 7)
33763376
_SPIRV_OP(JointMatrixUSMad, true, 7)
33773377
_SPIRV_OP(JointMatrixUUMad, true, 7)
3378+
// TODO: move to SPIRVJointMatrixINTELWorkItemInst
33783379
_SPIRV_OP(JointMatrixWorkItemLength, true, 4)
33793380
#undef _SPIRV_OP
33803381

@@ -3398,6 +3399,20 @@ _SPIRV_OP(CooperativeMatrixLengthKHR, true, 4, false)
33983399
_SPIRV_OP(CooperativeMatrixMulAddKHR, true, 6, true, 3)
33993400
#undef _SPIRV_OP
34003401

3402+
class SPIRVJointMatrixINTELWorkItemInst : public SPIRVJointMatrixINTELInstBase {
3403+
protected:
3404+
SPIRVCapVec getRequiredCapability() const override {
3405+
return getVec(internal::CapabilityJointMatrixWIInstructionsINTEL);
3406+
}
3407+
};
3408+
3409+
#define _SPIRV_OP(x, ...) \
3410+
typedef SPIRVInstTemplate<SPIRVJointMatrixINTELWorkItemInst, \
3411+
internal::Op##x##INTEL, __VA_ARGS__> \
3412+
SPIRV##x##INTEL;
3413+
_SPIRV_OP(JointMatrixGetElementCoord, true, 5)
3414+
#undef _SPIRV_OP
3415+
34013416
class SPIRVSplitBarrierINTELBase : public SPIRVInstTemplateBase {
34023417
protected:
34033418
SPIRVCapVec getRequiredCapability() const override {

lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
622622
add(internal::CapabilityTensorFloat32RoundingINTEL,
623623
"TensorFloat32RoundingINTEL");
624624
add(internal::CapabilityCacheControlsINTEL, "CacheControlsINTEL");
625+
add(internal::CapabilityJointMatrixWIInstructionsINTEL,
626+
"JointMatrixWIInstructionsINTEL");
625627
}
626628
SPIRV_DEF_NAMEMAP(Capability, SPIRVCapabilityNameMap)
627629

lib/SPIRV/libSPIRV/SPIRVOpCodeEnumInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ _SPIRV_OP_INTERNAL(JointMatrixUSMadINTEL, internal::OpJointMatrixUSMadINTEL)
1414
_SPIRV_OP_INTERNAL(JointMatrixUUMadINTEL, internal::OpJointMatrixUUMadINTEL)
1515
_SPIRV_OP_INTERNAL(JointMatrixWorkItemLengthINTEL,
1616
internal::OpJointMatrixWorkItemLengthINTEL)
17+
_SPIRV_OP_INTERNAL(JointMatrixGetElementCoordINTEL,
18+
internal::OpJointMatrixGetElementCoordINTEL)
1719
_SPIRV_OP_INTERNAL(ComplexFMulINTEL, internal::ComplexFMulINTEL)
1820
_SPIRV_OP_INTERNAL(ComplexFDivINTEL, internal::ComplexFDivINTEL)
1921
_SPIRV_OP_INTERNAL(MaskedGatherINTEL, internal::OpMaskedGatherINTEL)

lib/SPIRV/libSPIRV/spirv_internal.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum InternalOp {
7575
IOpRoundFToTF32INTEL = 6426,
7676
IOpMaskedGatherINTEL = 6428,
7777
IOpMaskedScatterINTEL = 6429,
78+
IOpJointMatrixGetElementCoordINTEL = 6440,
7879
IOpPrev = OpMax - 2,
7980
IOpForward
8081
};
@@ -109,6 +110,7 @@ enum InternalCapability {
109110
ICapabilityComplexFloatMulDivINTEL = 6414,
110111
ICapabilityTensorFloat32RoundingINTEL = 6425,
111112
ICapabilityMaskedGatherScatterINTEL = 6427,
113+
ICapabilityJointMatrixWIInstructionsINTEL = 6435,
112114
ICapabilityCacheControlsINTEL = 6441
113115
};
114116

@@ -155,6 +157,7 @@ enum class StoreCacheControlINTEL {
155157

156158
#define _SPIRV_OP(x, y) constexpr x x##y = static_cast<x>(I##x##y);
157159
_SPIRV_OP(Capability, JointMatrixINTEL)
160+
_SPIRV_OP(Capability, JointMatrixWIInstructionsINTEL)
158161
_SPIRV_OP(Op, TypeJointMatrixINTEL)
159162
_SPIRV_OP(Op, JointMatrixLoadINTEL)
160163
_SPIRV_OP(Op, JointMatrixStoreINTEL)
@@ -163,6 +166,8 @@ _SPIRV_OP(Op, JointMatrixSUMadINTEL)
163166
_SPIRV_OP(Op, JointMatrixUSMadINTEL)
164167
_SPIRV_OP(Op, JointMatrixUUMadINTEL)
165168
_SPIRV_OP(Op, JointMatrixWorkItemLengthINTEL)
169+
_SPIRV_OP(Op, JointMatrixGetElementCoordINTEL)
170+
166171
_SPIRV_OP(Capability, HWThreadQueryINTEL)
167172
_SPIRV_OP(BuiltIn, SubDeviceIDINTEL)
168173
_SPIRV_OP(BuiltIn, GlobalHWThreadIDINTEL)

test/transcoding/SPV_INTEL_joint_matrix/joint_matrix_element.ll

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
66
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM
77

8-
; CHECK-SPIRV: Capability JointMatrixINTEL
9-
; CHECK-SPIRV: Extension "SPV_INTEL_joint_matrix"
10-
; CHECK-SPIRV: TypeInt [[#TypeInt:]] 64
11-
; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32
12-
; CHECK-SPIRV: TypeJointMatrixINTEL [[#TypeMatrix:]] [[#TypeFloat]] [[#]] [[#]] [[#]] [[#]]
8+
; CHECK-SPIRV-DAG: Capability JointMatrixINTEL
9+
; CHECK-SPIRV-DAG: Capability JointMatrixWIInstructionsINTEL
10+
; CHECK-SPIRV-DAG: Extension "SPV_INTEL_joint_matrix"
11+
; CHECK-SPIRV-DAG: TypeInt [[#TypeInt32:]] 32
12+
; CHECK-SPIRV-DAG: TypeInt [[#TypeInt64:]] 64
13+
; CHECK-SPIRV-DAG: TypeFloat [[#TypeFloat:]] 32
14+
; CHECK-SPIRV-DAG: TypeJointMatrixINTEL [[#TypeMatrix:]] [[#TypeFloat]] [[#]] [[#]] [[#]] [[#]]
15+
; CHECK-SPIRV-DAG: TypeVector [[#TypeVec:]] [[#TypeInt32]] 2
1316
; CHECK-SPIRV: Phi [[#TypeMatrix]] [[#Matrix:]]
14-
; CHECK-SPIRV: JointMatrixWorkItemLengthINTEL [[#TypeInt]] [[#]] [[#Matrix]]
17+
; CHECK-SPIRV: JointMatrixWorkItemLengthINTEL [[#TypeInt64]] [[#]] [[#Matrix]]
1518
; CHECK-SPIRV: VectorExtractDynamic [[#TypeFloat]] [[#]] [[#Matrix]] [[#Index:]]
1619
; CHECK-SPIRV: FMul [[#TypeFloat]] [[#NewVal:]] [[#]] [[#]]
1720
; CHECK-SPIRV: VectorInsertDynamic [[#TypeMatrix]] [[#]] [[#Matrix]] [[#NewVal]] [[#Index]]
21+
; CHECK-SPIRV: JointMatrixGetElementCoordINTEL [[#TypeVec]] [[#]] [[#Matrix]] [[#Index]]
1822

1923
; CHECK-LLVM: [[Length:%.*]] = call spir_func i64 @_Z38__spirv_JointMatrixWorkItemLengthINTELPU3AS141__spirv_JointMatrixINTEL__float_16_16_0_3(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(1)* [[Matrix:%.*]])
2024
; CHECK-LLVM: [[Elem:%.*]] = call spir_func float @_Z28__spirv_VectorExtractDynamicPU3AS141__spirv_JointMatrixINTEL__float_16_16_0_3l(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(1)* [[Matrix]], i64 [[Index:%.*]])
2125
; CHECK-LLVM: [[NewVal:%.*]] = fmul float [[Elem]], 5.000000e+00
2226
; CHECK-LLVM: {{%.*}} = call spir_func %spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(1)* @_Z27__spirv_VectorInsertDynamicPU3AS141__spirv_JointMatrixINTEL__float_16_16_0_3fl(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(1)* [[Matrix]], float [[NewVal]], i64 [[Index]])
27+
; CHECK-LLVM: {{%.*}} = call spir_func <2 x i32> @_Z39__spirv_JointMatrixGetElementCoordINTELPU3AS141__spirv_JointMatrixINTEL__float_16_16_0_3l(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(1)* [[Matrix]], i64 [[Index]])
2328

2429
source_filename = "/work/tmp/matrix-slice.cpp"
2530
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
@@ -69,6 +74,7 @@ for.body.i: ; preds = %for.cond.i
6974
%call.i.i = tail call spir_func float @_Z28__spirv_VectorExtractDynamicIfLm16ELm16ELN5__spv12MatrixLayoutE0ELNS0_5Scope4FlagE3EmET_PNS0_24__spirv_JointMatrixINTELIS4_XT0_EXT1_EXT2_EXT3_EEET4_(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)* %A.sroa.0.0.i, i64 %conv.i) #2
7075
%mul.i.i = fmul float %call.i.i, 5.000000e+00
7176
%call5.i.i = tail call spir_func %spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)* @_Z27__spirv_VectorInsertDynamicIfLm16ELm16ELN5__spv12MatrixLayoutE0ELNS0_5Scope4FlagE3EmEPNS0_24__spirv_JointMatrixINTELIT_XT0_EXT1_EXT2_EXT3_EEES7_T4_S5_(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)* %A.sroa.0.0.i, float %mul.i.i, i64 %conv.i) #2
77+
%call6 = tail call spir_func <2 x i32> @_Z39__spirv_JointMatrixGetElementCoordINTELIaLm8ELm32ELN5__spv9MatrixUseE0ELNS0_12MatrixLayoutE0ELNS0_5Scope4FlagE3EEDv2_jPNS0_24__spirv_JointMatrixINTELIT_XT0_EXT1_EXT3_EXT4_EXT2_EEEm(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)* %A.sroa.0.0.i, i64 %conv.i) #2
7278
%inc.i = add nuw nsw i32 %i.0.i, 1
7379
br label %for.cond.i, !llvm.loop !7
7480

@@ -92,6 +98,9 @@ declare dso_local spir_func %spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4
9298
; Function Attrs: convergent
9399
declare dso_local spir_func void @_Z29__spirv_JointMatrixStoreINTELIfLm16ELm16ELN5__spv12MatrixLayoutE0ELNS0_5Scope4FlagE3EEvPT_PNS0_24__spirv_JointMatrixINTELIS4_XT0_EXT1_EXT2_EXT3_EEEmS1_S3_i(float addrspace(4)*, %spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)*, i64, i32, i32, i32) local_unnamed_addr #1
94100

101+
; Function Attrs: convergent
102+
declare dso_local spir_func <2 x i32> @_Z39__spirv_JointMatrixGetElementCoordINTELIaLm8ELm32ELN5__spv9MatrixUseE0ELNS0_12MatrixLayoutE0ELNS0_5Scope4FlagE3EEDv2_jPNS0_24__spirv_JointMatrixINTELIT_XT0_EXT1_EXT3_EXT4_EXT2_EEEm(%spirv.JointMatrixINTEL._float_16_16_0_3 addrspace(4)*, i64) #2
103+
95104
attributes #0 = { convergent norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="/work/tmp/matrix-slice.cpp" "uniform-work-group-size"="true" }
96105
attributes #1 = { convergent "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
97106
attributes #2 = { convergent }

0 commit comments

Comments
 (0)