From ad82f36200c8f27015a1a0282ec42c75b914754f Mon Sep 17 00:00:00 2001 From: "Maksimova, Viktoria" Date: Mon, 1 Dec 2025 02:42:15 -0800 Subject: [PATCH 1/6] add missing capabilities --- lib/SPIRV/libSPIRV/spirv_internal.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/SPIRV/libSPIRV/spirv_internal.hpp b/lib/SPIRV/libSPIRV/spirv_internal.hpp index 4b605925b0..aa189bb955 100644 --- a/lib/SPIRV/libSPIRV/spirv_internal.hpp +++ b/lib/SPIRV/libSPIRV/spirv_internal.hpp @@ -128,10 +128,13 @@ enum InternalCapability { ICapabilityAtomicBFloat16LoadStoreINTEL = 6262, ICapabilityCooperativeMatrixPrefetchINTEL = 6411, ICapabilityMaskedGatherScatterINTEL = 6427, + ICapabilityPackedCooperativeMatrixINTEL = 6434, ICapabilityJointMatrixWIInstructionsINTEL = 6435, ICapabilityCooperativeMatrixInvocationInstructionsINTEL = 6435, ICapabilityJointMatrixTF32ComponentTypeINTEL = 6436, + ICapabilityCooperativeMatrixTF32ComponentTypeINTEL = 6436, ICapabilityJointMatrixBF16ComponentTypeINTEL = 6437, + ICapabilityCooperativeMatrixBFloat16ComponentTypeINTEL = 6437, ICapabilityJointMatrixPackedInt2ComponentTypeINTEL = 6438, ICapabilityJointMatrixPackedInt4ComponentTypeINTEL = 6439, ICapabilitySubgroupRequirementsINTEL = 6445, From 717107b8d4ea9ae5c4cac48405c2820ed6870066 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:20:06 +0000 Subject: [PATCH 2/6] Initial plan From d9a6a53a6b0946276323e8e907c17fafeecca7b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Dec 2025 14:08:02 +0000 Subject: [PATCH 3/6] Implement packed matrix layout capability for SPV_INTEL_joint_matrix Co-authored-by: vmaksimo <31696245+vmaksimo@users.noreply.github.com> --- lib/SPIRV/libSPIRV/SPIRVEnum.h | 2 + lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h | 2 + lib/SPIRV/libSPIRV/SPIRVType.cpp | 11 ++++ lib/SPIRV/libSPIRV/SPIRVType.h | 4 +- lib/SPIRV/libSPIRV/spirv_internal.hpp | 1 + .../joint_matrix_packed.ll | 56 +++++++++++++++++++ 6 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 test/extensions/INTEL/SPV_INTEL_joint_matrix/joint_matrix_packed.ll diff --git a/lib/SPIRV/libSPIRV/SPIRVEnum.h b/lib/SPIRV/libSPIRV/SPIRVEnum.h index 92c8da3834..4793b2f8b4 100644 --- a/lib/SPIRV/libSPIRV/SPIRVEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVEnum.h @@ -215,6 +215,8 @@ template <> inline void SPIRVMap::init() { {internal::CapabilityJointMatrixINTEL}); ADD_VEC_INIT(internal::CapabilityJointMatrixPackedInt4ComponentTypeINTEL, {internal::CapabilityJointMatrixINTEL}); + ADD_VEC_INIT(internal::CapabilityPackedCooperativeMatrixINTEL, + {internal::CapabilityJointMatrixINTEL}); ADD_VEC_INIT(internal::CapabilityCooperativeMatrixPrefetchINTEL, {CapabilityCooperativeMatrixKHR}); ADD_VEC_INIT(internal::CapabilityCooperativeMatrixInvocationInstructionsINTEL, diff --git a/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h b/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h index 8db5d568b5..1c8da747f2 100644 --- a/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h +++ b/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h @@ -674,6 +674,8 @@ template <> inline void SPIRVMap::init() { "JointMatrixPackedInt2ComponentTypeINTEL"); add(internal::CapabilityJointMatrixPackedInt4ComponentTypeINTEL, "JointMatrixPackedInt4ComponentTypeINTEL"); + add(internal::CapabilityPackedCooperativeMatrixINTEL, + "PackedCooperativeMatrixINTEL"); add(internal::CapabilityCooperativeMatrixPrefetchINTEL, "CooperativeMatrixPrefetchINTEL"); add(internal::CapabilityCooperativeMatrixInvocationInstructionsINTEL, diff --git a/lib/SPIRV/libSPIRV/SPIRVType.cpp b/lib/SPIRV/libSPIRV/SPIRVType.cpp index 9c0f612b55..46bcdfc861 100644 --- a/lib/SPIRV/libSPIRV/SPIRVType.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVType.cpp @@ -345,6 +345,17 @@ void SPIRVTypeJointMatrixINTEL::decode(std::istream &I) { Decoder >> Id >> CompType >> Args; } +SPIRVCapVec SPIRVTypeJointMatrixINTEL::getRequiredCapability() const { + auto CV = getVec(internal::CapabilityJointMatrixINTEL); + if (SPIRVValue *LayoutVal = getLayout()) { + uint64_t Layout = + static_cast(LayoutVal)->getZExtIntValue(); + if (Layout == internal::PackedA || Layout == internal::PackedB) + CV.push_back(internal::CapabilityPackedCooperativeMatrixINTEL); + } + return CV; +} + SPIRVTypeCooperativeMatrixKHR::SPIRVTypeCooperativeMatrixKHR( SPIRVModule *M, SPIRVId TheId, SPIRVType *CompType, std::vector Args) diff --git a/lib/SPIRV/libSPIRV/SPIRVType.h b/lib/SPIRV/libSPIRV/SPIRVType.h index bd6f91615f..717ff94a5f 100644 --- a/lib/SPIRV/libSPIRV/SPIRVType.h +++ b/lib/SPIRV/libSPIRV/SPIRVType.h @@ -1196,9 +1196,7 @@ class SPIRVTypeJointMatrixINTEL : public SPIRVType { std::optional getRequiredExtension() const override { return ExtensionID::SPV_INTEL_joint_matrix; } - SPIRVCapVec getRequiredCapability() const override { - return {internal::CapabilityJointMatrixINTEL}; - } + SPIRVCapVec getRequiredCapability() const override; void setWordCount(SPIRVWord WordCount) override { SPIRVType::setWordCount(WordCount); Args.resize(WordCount - FixedWC); diff --git a/lib/SPIRV/libSPIRV/spirv_internal.hpp b/lib/SPIRV/libSPIRV/spirv_internal.hpp index aa189bb955..d809e8126a 100644 --- a/lib/SPIRV/libSPIRV/spirv_internal.hpp +++ b/lib/SPIRV/libSPIRV/spirv_internal.hpp @@ -192,6 +192,7 @@ _SPIRV_OP(Op, JointMatrixUSMadINTEL) _SPIRV_OP(Op, JointMatrixUUMadINTEL) _SPIRV_OP(Op, JointMatrixWorkItemLengthINTEL) _SPIRV_OP(Op, JointMatrixGetElementCoordINTEL) +_SPIRV_OP(Capability, PackedCooperativeMatrixINTEL) _SPIRV_OP(Capability, CooperativeMatrixPrefetchINTEL) _SPIRV_OP(Op, CooperativeMatrixPrefetchINTEL) diff --git a/test/extensions/INTEL/SPV_INTEL_joint_matrix/joint_matrix_packed.ll b/test/extensions/INTEL/SPV_INTEL_joint_matrix/joint_matrix_packed.ll new file mode 100644 index 0000000000..66767bc4f1 --- /dev/null +++ b/test/extensions/INTEL/SPV_INTEL_joint_matrix/joint_matrix_packed.ll @@ -0,0 +1,56 @@ +; RUN: llvm-as < %s -o %t.bc +; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_joint_matrix -o %t.spv +; RUN: llvm-spirv %t.spv -to-text -o %t.spt +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV + +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM + +; Test that PackedCooperativeMatrixINTEL capability is emitted when using +; PackedA (layout=2) or PackedB (layout=3) matrix layouts. + +; CHECK-SPIRV-DAG: Capability JointMatrixINTEL +; CHECK-SPIRV-DAG: Capability PackedCooperativeMatrixINTEL +; CHECK-SPIRV-DAG: Extension "SPV_INTEL_joint_matrix" +; CHECK-SPIRV-DAG: TypeInt [[#Int8Ty:]] 8 0 +; CHECK-SPIRV-DAG: TypeInt [[#Int32Ty:]] 32 0 +; CHECK-SPIRV-DAG: Constant [[#Int32Ty]] [[#Const12:]] 12 +; CHECK-SPIRV-DAG: Constant [[#Int32Ty]] [[#Const48:]] 48 +; CHECK-SPIRV-DAG: Constant [[#Int32Ty]] [[#Const3:]] 3 +; CHECK-SPIRV-DAG: Constant [[#Int32Ty]] [[#Const2:]] 2 +; CHECK-SPIRV-DAG: Constant [[#Int32Ty]] [[#Const0:]] 0 +; Layout 2 = PackedA, Layout 3 = PackedB +; TypeJointMatrixINTEL: Result Type Rows Cols Layout Scope Use +; CHECK-SPIRV-DAG: TypeJointMatrixINTEL [[#MatTyA:]] [[#Int8Ty]] [[#Const12]] [[#Const48]] [[#Const2]] [[#Const3]] [[#Const0]] +; CHECK-SPIRV-DAG: TypeJointMatrixINTEL [[#MatTyB:]] [[#Int8Ty]] [[#Const48]] [[#Const12]] [[#Const3]] [[#Const3]] {{[0-9]+}} + +; CHECK-SPIRV: JointMatrixLoadINTEL [[#MatTyA]] +; CHECK-SPIRV: JointMatrixLoadINTEL [[#MatTyB]] + +; CHECK-LLVM: call spir_func target("spirv.JointMatrixINTEL", i8, 12, 48, 2, 3, 0) +; CHECK-LLVM: call spir_func target("spirv.JointMatrixINTEL", i8, 48, 12, 3, 3, 1) + +; ModuleID = 'joint_matrix_packed.bc' +source_filename = "joint_matrix_packed.cpp" +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" +target triple = "spir64-unknown-unknown" + +define weak_odr dso_local spir_kernel void @test_packed_matrix(ptr addrspace(1) noundef align 1 %_arg_accA, ptr addrspace(1) noundef align 1 %_arg_accB, i64 noundef %_arg_K) { +entry: + %call.ascast.i.a = addrspacecast ptr addrspace(1) %_arg_accA to ptr addrspace(4) + %call.ascast.i.b = addrspacecast ptr addrspace(1) %_arg_accB to ptr addrspace(4) + ; Load matrix A with PackedA layout (layout=2) + %matrixA = tail call spir_func noundef target("spirv.JointMatrixINTEL", i8, 12, 48, 2, 3, 0) @_Z28__spirv_JointMatrixLoadINTEL_PackedA(ptr addrspace(4) noundef %call.ascast.i.a, i64 noundef %_arg_K, i32 noundef 2, i32 noundef 3, i32 noundef 0) #1 + ; Load matrix B with PackedB layout (layout=3) + %matrixB = tail call spir_func noundef target("spirv.JointMatrixINTEL", i8, 48, 12, 3, 3, 1) @_Z28__spirv_JointMatrixLoadINTEL_PackedB(ptr addrspace(4) noundef %call.ascast.i.b, i64 noundef %_arg_K, i32 noundef 3, i32 noundef 3, i32 noundef 0) #1 + ret void +} + +; Function declaration for loading matrix with PackedA layout +declare dso_local spir_func noundef target("spirv.JointMatrixINTEL", i8, 12, 48, 2, 3, 0) @_Z28__spirv_JointMatrixLoadINTEL_PackedA(ptr addrspace(4) noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef) #0 + +; Function declaration for loading matrix with PackedB layout +declare dso_local spir_func noundef target("spirv.JointMatrixINTEL", i8, 48, 12, 3, 3, 1) @_Z28__spirv_JointMatrixLoadINTEL_PackedB(ptr addrspace(4) noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef) #0 + +attributes #0 = { convergent "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +attributes #1 = { convergent } From 61a833e1725d5de3874e0d8b6df0ab41fe0c87ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Dec 2025 14:10:40 +0000 Subject: [PATCH 4/6] Add safety check for constant opcode before casting to SPIRVConstant Co-authored-by: vmaksimo <31696245+vmaksimo@users.noreply.github.com> --- lib/SPIRV/libSPIRV/SPIRVType.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/SPIRV/libSPIRV/SPIRVType.cpp b/lib/SPIRV/libSPIRV/SPIRVType.cpp index 46bcdfc861..262d4b566a 100644 --- a/lib/SPIRV/libSPIRV/SPIRVType.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVType.cpp @@ -348,10 +348,12 @@ void SPIRVTypeJointMatrixINTEL::decode(std::istream &I) { SPIRVCapVec SPIRVTypeJointMatrixINTEL::getRequiredCapability() const { auto CV = getVec(internal::CapabilityJointMatrixINTEL); if (SPIRVValue *LayoutVal = getLayout()) { - uint64_t Layout = - static_cast(LayoutVal)->getZExtIntValue(); - if (Layout == internal::PackedA || Layout == internal::PackedB) - CV.push_back(internal::CapabilityPackedCooperativeMatrixINTEL); + if (isConstantOpCode(LayoutVal->getOpCode())) { + uint64_t Layout = + static_cast(LayoutVal)->getZExtIntValue(); + if (Layout == internal::PackedA || Layout == internal::PackedB) + CV.push_back(internal::CapabilityPackedCooperativeMatrixINTEL); + } } return CV; } From 1b1cca48c62085fa4108b7fc5decdce7a27f4b39 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Dec 2025 14:12:37 +0000 Subject: [PATCH 5/6] Final implementation Co-authored-by: vmaksimo <31696245+vmaksimo@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000000..945c9b46d6 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file From 2fe9779b170b7254e0eaf8d87288dfae7beeba11 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Dec 2025 14:13:24 +0000 Subject: [PATCH 6/6] Remove codeql artifact and add to gitignore Co-authored-by: vmaksimo <31696245+vmaksimo@users.noreply.github.com> --- .gitignore | 1 + _codeql_detected_source_root | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/.gitignore b/.gitignore index b34e02b49f..6cd8f37884 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ cscope.out autoconf/aclocal.m4 autoconf/autom4te.cache compile_commands.json +_codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46d6..0000000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file