Bug#1145357: spirv-tools: spirv-val does not fully handle OpCooperativeMatrixReduceEXT

Jeroen Diederen <[email protected]>
Newsgroups gmane.linux.debian.devel.x
Message-ID <178757698372.260358.5999525537310967930.reportbug__17596.5603719064$1787577090$gmane$org@jeroen-ZenBook>
Package: spirv-tools
Version: 2026.3~rc1-1
Severity: normal
Tags: patch upstream

Dear Maintainer,

SPIRV-Tools 2026.3~rc1 does not fully handle the renamed
OpCooperativeMatrixReduceEXT instruction.

This became apparent when building SPIRV-Tools against a newer upstream
version of SPIR-V Headers. The newer headers define opcode 5366 as:

    OpCooperativeMatrixReduceEXT = 5366

with OpCooperativeMatrixReduceNV retained as an alias.

By contrast, the Debian-installed spirv-headers package
(1.6.1+1.4.357.0-1) still exposes the opcode primarily under the
OpCooperativeMatrixReduceNV name.

Parts of SPIRV-Tools 2026.3~rc1 still refer to opcode 5366 using the
obsolete OpCooperativeMatrixReduceNV name. This becomes a problem when
using the newer upstream SPIR-V Headers.

The issue is tracked upstream as SPIRV-Tools issue #6850:

https://github.com/KhronosGroup/SPIRV-Tools/issues/6850

I have attached a patch which updates the affected SPIRV-Tools code
from OpCooperativeMatrixReduceNV to OpCooperativeMatrixReduceEXT and
updates the corresponding validator regression tests.

The patch updates:

    source/operand.cpp
    source/opt/ir_context.cpp
    source/val/validate_arithmetics.cpp
    source/val/validate_function.cpp
    test/val/val_arithmetics_test.cpp

The patch is not architecture-specific.

Regards,
Jeroen Diederen

-- System Information:
Debian Release: forky/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: ppc64

Kernel: Linux 6.8.0-138-generic (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: unable to detect

Versions of packages spirv-tools depends on:
ii  libc6       2.43-3
ii  libstdc++6  16.2.0-1

spirv-tools recommends no packages.

spirv-tools suggests no packages.

-- no debconf information
fix-cooperative-matrix-reduce-ext-6850.patch (text/plain, 8.2 KB)
Description: Fix CooperativeMatrixReduce opcode rename to EXT
 Update SPIR-V Tools validation and operand handling from the obsolete
 CooperativeMatrixReduceNV opcode to CooperativeMatrixReduceEXT, and update
 the corresponding validator regression tests.
Bug: https://github.com/KhronosGroup/SPIRV-Tools/issues/6850
Forwarded: yes

Index: spirv-tools-debian-fixed/source/operand.cpp
===================================================================
--- spirv-tools-debian-fixed.orig/source/operand.cpp
+++ spirv-tools-debian-fixed/source/operand.cpp
@@ -583,7 +583,7 @@ std::function<bool(unsigned)> spvOperand
     case spv::Op::OpCooperativeMatrixPerElementOpNV:
       out = [](unsigned index) { return index == 3; };
       break;
-    case spv::Op::OpCooperativeMatrixReduceNV:
+    case spv::Op::OpCooperativeMatrixReduceEXT:
       out = [](unsigned index) { return index == 4; };
       break;
     case spv::Op::OpCooperativeMatrixLoadTensorNV:
Index: spirv-tools-debian-fixed/source/opt/ir_context.cpp
===================================================================
--- spirv-tools-debian-fixed.orig/source/opt/ir_context.cpp
+++ spirv-tools-debian-fixed/source/opt/ir_context.cpp
@@ -975,7 +975,7 @@ void IRContext::AddCalls(const Function*
         todo->push(ii->GetSingleWordInOperand(0));
       if (ii->opcode() == spv::Op::OpCooperativeMatrixPerElementOpNV)
         todo->push(ii->GetSingleWordInOperand(1));
-      if (ii->opcode() == spv::Op::OpCooperativeMatrixReduceNV)
+      if (ii->opcode() == spv::Op::OpCooperativeMatrixReduceEXT)
         todo->push(ii->GetSingleWordInOperand(2));
       if (ii->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) {
         const auto memory_operands_index = 3;
Index: spirv-tools-debian-fixed/source/val/validate_arithmetics.cpp
===================================================================
--- spirv-tools-debian-fixed.orig/source/val/validate_arithmetics.cpp
+++ spirv-tools-debian-fixed/source/val/validate_arithmetics.cpp
@@ -715,7 +715,7 @@ spv_result_t ValidateCooperativeMatrixMu
   return SPV_SUCCESS;
 }
 
-spv_result_t ValidateCooperativeMatrixReduceNV(ValidationState_t& _,
+spv_result_t ValidateCooperativeMatrixReduceEXT(ValidationState_t& _,
                                                const Instruction* inst) {
   const spv::Op opcode = inst->opcode();
   const uint32_t result_type = inst->type_id();
@@ -884,8 +884,8 @@ spv_result_t ArithmeticsPass(ValidationS
       return ValidateCooperativeMatrixMulAddNV(_, inst);
     case spv::Op::OpCooperativeMatrixMulAddKHR:
       return ValidateCooperativeMatrixMulAddKHR(_, inst);
-    case spv::Op::OpCooperativeMatrixReduceNV:
-      return ValidateCooperativeMatrixReduceNV(_, inst);
+    case spv::Op::OpCooperativeMatrixReduceEXT:
+      return ValidateCooperativeMatrixReduceEXT(_, inst);
 
     case spv::Op::OpSpecConstantOp: {
       switch (inst->GetOperandAs<spv::Op>(2u)) {
Index: spirv-tools-debian-fixed/source/val/validate_function.cpp
===================================================================
--- spirv-tools-debian-fixed.orig/source/val/validate_function.cpp
+++ spirv-tools-debian-fixed/source/val/validate_function.cpp
@@ -88,7 +88,7 @@ spv_result_t ValidateFunction(Validation
       spv::Op::OpGetKernelMaxNumSubgroups,
       spv::Op::OpName,
       spv::Op::OpCooperativeMatrixPerElementOpNV,
-      spv::Op::OpCooperativeMatrixReduceNV,
+      spv::Op::OpCooperativeMatrixReduceEXT,
       spv::Op::OpCooperativeMatrixLoadTensorNV,
       spv::Op::OpConditionalEntryPointINTEL,
       spv::Op::OpConstantFunctionPointerINTEL};
Index: spirv-tools-debian-fixed/test/val/val_arithmetics_test.cpp
===================================================================
--- spirv-tools-debian-fixed.orig/test/val/val_arithmetics_test.cpp
+++ spirv-tools-debian-fixed/test/val/val_arithmetics_test.cpp
@@ -1881,11 +1881,11 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC8 %f16mat_C_1 2x2 %reducefunc
-%val2 = OpCooperativeMatrixReduceNV %f16matC16x8 %f16mat_C_1 Row %reducefunc
-%val3 = OpCooperativeMatrixReduceNV %f16matC8x16 %f16mat_C_1 Column %reducefunc
-%val4 = OpCooperativeMatrixReduceNV %f16matC %f16mat_C_1 Row|Column %reducefunc
-%val5 = OpCooperativeMatrixReduceNV %f16matC8 %f16mat_C_1 Row|Column %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC8 %f16mat_C_1 2x2 %reducefunc
+%val2 = OpCooperativeMatrixReduceEXT %f16matC16x8 %f16mat_C_1 Row %reducefunc
+%val3 = OpCooperativeMatrixReduceEXT %f16matC8x16 %f16mat_C_1 Column %reducefunc
+%val4 = OpCooperativeMatrixReduceEXT %f16matC %f16mat_C_1 Row|Column %reducefunc
+%val5 = OpCooperativeMatrixReduceEXT %f16matC8 %f16mat_C_1 Row|Column %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -1907,7 +1907,7 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC %f16mat_C_1 2x2 %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC %f16mat_C_1 2x2 %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -1916,7 +1916,7 @@ OpFunctionEnd
             ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("For Reduce2x2, result rows/cols must be half of "
-                        "matrix rows/cols: CooperativeMatrixReduceNV"));
+                        "matrix rows/cols: CooperativeMatrixReduceEXT"));
 }
 
 TEST_F(ValidateArithmetics, CoopMat2ReduceRowDimFail) {
@@ -1935,7 +1935,7 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC8x16 %f16mat_C_1 Row %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC8x16 %f16mat_C_1 Row %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -1944,7 +1944,7 @@ OpFunctionEnd
             ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("For ReduceRow, result rows must match matrix rows: "
-                        "CooperativeMatrixReduceNV"));
+                        "CooperativeMatrixReduceEXT"));
 }
 
 TEST_F(ValidateArithmetics, CoopMat2ReduceColDimFail) {
@@ -1963,7 +1963,7 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC16x8 %f16mat_C_1 Column %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC16x8 %f16mat_C_1 Column %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -1972,7 +1972,7 @@ OpFunctionEnd
             ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("For ReduceColumn, result cols must match matrix cols: "
-                        "CooperativeMatrixReduceNV"));
+                        "CooperativeMatrixReduceEXT"));
 }
 
 TEST_F(ValidateArithmetics, CoopMat2ReduceMaskFail) {
@@ -1991,7 +1991,7 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC8 %f16mat_C_1 Row|Column|2x2 %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC8 %f16mat_C_1 Row|Column|2x2 %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -2000,7 +2000,7 @@ OpFunctionEnd
             ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("Reduce 2x2 must not be used with Row/Column: "
-                        "CooperativeMatrixReduceNV"));
+                        "CooperativeMatrixReduceEXT"));
 }
 
 TEST_F(ValidateArithmetics, CoopMat2ReduceFuncTypeFail) {
@@ -2017,7 +2017,7 @@ OpFunctionEnd
 
   )";
   const std::string body = R"(
-%val1 = OpCooperativeMatrixReduceNV %f16matC %f16mat_C_1 Row|Column %reducefunc
+%val1 = OpCooperativeMatrixReduceEXT %f16matC %f16mat_C_1 Row|Column %reducefunc
 )";
 
   CompileSuccessfully(GenerateCoopMatKHRCode(extra_types, body).c_str(),
@@ -2026,7 +2026,7 @@ OpFunctionEnd
             ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("CombineFunc return type and parameters must match "
-                        "matrix component type: CooperativeMatrixReduceNV"));
+                        "matrix component type: CooperativeMatrixReduceEXT"));
 }
 
 TEST_F(ValidateArithmetics, CoopMat2PerElementOpSuccess) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.