# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/spirv-tools/hotfix-opcodes.patch # Copyright (C) 2025 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- Removed all mentions to Nvidia specific opcodes as this does not build with standard spirv-headers and requires some extensions to be enabled. This should have been put behing a config flag and not assumed to be available by default. - NoTag --- SPIRV-Tools-2024.4.rc2/source/operand.cpp.vanilla 2025-01-25 22:15:28.853564506 +0100 +++ SPIRV-Tools-2024.4.rc2/source/operand.cpp 2025-01-25 22:51:13.914202904 +0100 @@ -607,16 +607,6 @@ case spv::Op::OpTypeArray: out = [](unsigned index) { return index == 1; }; break; - case spv::Op::OpCooperativeMatrixPerElementOpNV: - out = [](unsigned index) { return index == 3; }; - break; - case spv::Op::OpCooperativeMatrixReduceNV: - out = [](unsigned index) { return index == 4; }; - break; - case spv::Op::OpCooperativeMatrixLoadTensorNV: - // approximate, due to variable operands - out = [](unsigned index) { return index > 6; }; - break; default: out = [](unsigned) { return false; }; break; --- SPIRV-Tools-2024.4.rc2/source/opcode.cpp.vanilla 2025-01-25 22:30:14.362918172 +0100 +++ SPIRV-Tools-2024.4.rc2/source/opcode.cpp 2025-01-25 22:49:40.816209955 +0100 @@ -382,8 +382,6 @@ case spv::Op::OpTypeRayQueryKHR: case spv::Op::OpTypeHitObjectNV: case spv::Op::OpTypeUntypedPointerKHR: - case spv::Op::OpTypeTensorLayoutNV: - case spv::Op::OpTypeTensorViewNV: return true; default: // In particular, OpTypeForwardPointer does not generate a type, --- SPIRV-Tools-2024.4.rc2/source/val/validate_arithmetics.cpp.vanilla 2025-01-25 22:54:19.586848025 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_arithmetics.cpp 2025-01-25 22:55:02.970799346 +0100 @@ -672,128 +672,6 @@ break; } - case spv::Op::OpCooperativeMatrixReduceNV: { - if (!_.IsCooperativeMatrixKHRType(result_type)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type must be a cooperative matrix type: " - << spvOpcodeString(opcode); - } - - const auto result_comp_type_id = - _.FindDef(result_type)->GetOperandAs(1); - - const auto matrix_id = inst->GetOperandAs(2); - const auto matrix = _.FindDef(matrix_id); - const auto matrix_type_id = matrix->type_id(); - if (!_.IsCooperativeMatrixKHRType(matrix_type_id)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Matrix must have a cooperative matrix type: " - << spvOpcodeString(opcode); - } - const auto matrix_type = _.FindDef(matrix_type_id); - const auto matrix_comp_type_id = matrix_type->GetOperandAs(1); - if (matrix_comp_type_id != result_comp_type_id) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type and Matrix type must have the same component " - "type: " - << spvOpcodeString(opcode); - } - if (_.FindDef(result_type)->GetOperandAs(2) != - matrix_type->GetOperandAs(2)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type and Matrix type must have the same scope: " - << spvOpcodeString(opcode); - } - - if (!_.IsCooperativeMatrixAccType(result_type)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type must have UseAccumulator: " - << spvOpcodeString(opcode); - } - if (!_.IsCooperativeMatrixAccType(matrix_type_id)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Matrix type must have UseAccumulator: " - << spvOpcodeString(opcode); - } - - const auto reduce_value = inst->GetOperandAs(3); - - if ((reduce_value & - uint32_t( - spv::CooperativeMatrixReduceMask::CooperativeMatrixReduce2x2)) && - (reduce_value & uint32_t(spv::CooperativeMatrixReduceMask::Row | - spv::CooperativeMatrixReduceMask::Column))) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Reduce 2x2 must not be used with Row/Column: " - << spvOpcodeString(opcode); - } - - std::tuple result_rows, result_cols, matrix_rows, - matrix_cols; - result_rows = - _.EvalInt32IfConst(_.FindDef(result_type)->GetOperandAs(3)); - result_cols = - _.EvalInt32IfConst(_.FindDef(result_type)->GetOperandAs(4)); - matrix_rows = _.EvalInt32IfConst(matrix_type->GetOperandAs(3)); - matrix_cols = _.EvalInt32IfConst(matrix_type->GetOperandAs(4)); - - if (reduce_value & - uint32_t( - spv::CooperativeMatrixReduceMask::CooperativeMatrixReduce2x2)) { - if (std::get<1>(result_rows) && std::get<1>(result_cols) && - std::get<1>(matrix_rows) && std::get<1>(matrix_cols) && - (std::get<2>(result_rows) != std::get<2>(matrix_rows) / 2 || - std::get<2>(result_cols) != std::get<2>(matrix_cols) / 2)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "For Reduce2x2, result rows/cols must be half of matrix " - "rows/cols: " - << spvOpcodeString(opcode); - } - } - if (reduce_value == uint32_t(spv::CooperativeMatrixReduceMask::Row)) { - if (std::get<1>(result_rows) && std::get<1>(matrix_rows) && - std::get<2>(result_rows) != std::get<2>(matrix_rows)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "For ReduceRow, result rows must match matrix rows: " - << spvOpcodeString(opcode); - } - } - if (reduce_value == uint32_t(spv::CooperativeMatrixReduceMask::Column)) { - if (std::get<1>(result_cols) && std::get<1>(matrix_cols) && - std::get<2>(result_cols) != std::get<2>(matrix_cols)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "For ReduceColumn, result cols must match matrix cols: " - << spvOpcodeString(opcode); - } - } - - const auto combine_func_id = inst->GetOperandAs(4); - const auto combine_func = _.FindDef(combine_func_id); - if (!combine_func || combine_func->opcode() != spv::Op::OpFunction) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "CombineFunc must be a function: " << spvOpcodeString(opcode); - } - const auto function_type_id = combine_func->GetOperandAs(3); - const auto function_type = _.FindDef(function_type_id); - if (function_type->operands().size() != 4) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "CombineFunc must have two parameters: " - << spvOpcodeString(opcode); - } - for (uint32_t i = 0; i < 3; ++i) { - // checks return type and two params - const auto param_type_id = function_type->GetOperandAs(i + 1); - if (param_type_id != matrix_comp_type_id) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "CombineFunc return type and parameters must match matrix " - "component type: " - << spvOpcodeString(opcode); - } - } - - break; - } - default: break; } --- SPIRV-Tools-2024.4.rc2/source/val/validate_conversion.cpp.vanilla 2025-01-25 22:57:18.002722741 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_conversion.cpp 2025-01-25 22:57:34.592959001 +0100 @@ -568,43 +568,6 @@ break; } - case spv::Op::OpCooperativeMatrixConvertNV: - case spv::Op::OpCooperativeMatrixTransposeNV: { - if (!_.IsCooperativeMatrixType(result_type)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Expected cooperative matrix Result Type: " - << spvOpcodeString(opcode); - } - const uint32_t input_type = _.GetOperandTypeId(inst, 2); - if (!_.IsCooperativeMatrixType(input_type)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Expected cooperative matrix type for Matrix input: " - << spvOpcodeString(opcode); - } - - bool swap_row_col = (opcode == spv::Op::OpCooperativeMatrixTransposeNV); - if (auto error = _.CooperativeMatrixShapesMatch( - inst, result_type, input_type, true, swap_row_col)) - return error; - - if (opcode == spv::Op::OpCooperativeMatrixConvertNV) { - if (_.FindDef(result_type)->GetOperandAs(1) != - _.FindDef(input_type)->GetOperandAs(1)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type and Matrix component types mismatch: " - << spvOpcodeString(opcode); - } - } - - if (opcode == spv::Op::OpCooperativeMatrixTransposeNV) { - if (!_.IsCooperativeMatrixBType(result_type)) { - return _.diag(SPV_ERROR_INVALID_DATA, inst) - << "Result Type must have UseB: " << spvOpcodeString(opcode); - } - } - break; - } - default: break; } --- SPIRV-Tools-2024.4.rc2/source/val/validate_function.cpp.vanilla 2025-01-25 23:05:10.552786671 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_function.cpp 2025-01-25 23:05:45.296614810 +0100 @@ -86,10 +86,7 @@ spv::Op::OpGetKernelPreferredWorkGroupSizeMultiple, spv::Op::OpGetKernelLocalSizeForSubgroupCount, spv::Op::OpGetKernelMaxNumSubgroups, - spv::Op::OpName, - spv::Op::OpCooperativeMatrixPerElementOpNV, - spv::Op::OpCooperativeMatrixReduceNV, - spv::Op::OpCooperativeMatrixLoadTensorNV}; + spv::Op::OpName}; for (auto& pair : inst->uses()) { const auto* use = pair.first; if (std::find(acceptable.begin(), acceptable.end(), use->opcode()) == --- SPIRV-Tools-2024.4.rc2/source/val/validate_function.cpp.vanilla 2025-01-25 23:06:47.837505542 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_function.cpp 2025-01-25 23:07:29.951438753 +0100 @@ -428,10 +428,6 @@ case spv::Op::OpFunctionCall: if (auto error = ValidateFunctionCall(_, inst)) return error; break; - case spv::Op::OpCooperativeMatrixPerElementOpNV: - if (auto error = ValidateCooperativeMatrixPerElementOp(_, inst)) - return error; - break; default: break; } --- SPIRV-Tools-2024.4.rc2/source/val/validate_memory.cpp.vanilla 2025-01-25 23:09:49.430091847 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_memory.cpp 2025-01-25 23:12:42.792561005 +0100 @@ -232,18 +232,12 @@ spv::StorageClass dst_sc = spv::StorageClass::Max; spv::StorageClass src_sc = spv::StorageClass::Max; switch (inst->opcode()) { - case spv::Op::OpCooperativeMatrixLoadNV: - case spv::Op::OpCooperativeMatrixLoadTensorNV: - case spv::Op::OpCooperativeMatrixLoadKHR: case spv::Op::OpLoad: { auto load_pointer = _.FindDef(inst->GetOperandAs(2)); auto load_pointer_type = _.FindDef(load_pointer->type_id()); dst_sc = load_pointer_type->GetOperandAs(1); break; } - case spv::Op::OpCooperativeMatrixStoreNV: - case spv::Op::OpCooperativeMatrixStoreTensorNV: - case spv::Op::OpCooperativeMatrixStoreKHR: case spv::Op::OpStore: { auto store_pointer = _.FindDef(inst->GetOperandAs(0)); auto store_pointer_type = _.FindDef(store_pointer->type_id()); @@ -331,8 +325,6 @@ const uint32_t mask = inst->GetOperandAs(index); if (mask & uint32_t(spv::MemoryAccessMask::MakePointerAvailableKHR)) { if (inst->opcode() == spv::Op::OpLoad || - inst->opcode() == spv::Op::OpCooperativeMatrixLoadNV || - inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV || inst->opcode() == spv::Op::OpCooperativeMatrixLoadKHR) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "MakePointerAvailableKHR cannot be used with OpLoad."; @@ -2180,222 +2172,6 @@ } return SPV_SUCCESS; -} - -// Returns the number of instruction words taken up by a tensor addressing -// operands argument and its implied operands. -int TensorAddressingOperandsNumWords(spv::TensorAddressingOperandsMask mask) { - int result = 1; // Count the mask - if ((mask & spv::TensorAddressingOperandsMask::TensorView) != - spv::TensorAddressingOperandsMask::MaskNone) - ++result; - if ((mask & spv::TensorAddressingOperandsMask::DecodeFunc) != - spv::TensorAddressingOperandsMask::MaskNone) - ++result; - return result; -} - -spv_result_t ValidateCooperativeMatrixLoadStoreTensorNV( - ValidationState_t& _, const Instruction* inst) { - uint32_t type_id; - const char* opname; - if (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) { - type_id = inst->type_id(); - opname = "spv::Op::OpCooperativeMatrixLoadTensorNV"; - } else { - // get Object operand's type - type_id = _.FindDef(inst->GetOperandAs(1))->type_id(); - opname = "spv::Op::OpCooperativeMatrixStoreTensorNV"; - } - - auto matrix_type = _.FindDef(type_id); - - if (matrix_type->opcode() != spv::Op::OpTypeCooperativeMatrixKHR) { - if (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << "spv::Op::OpCooperativeMatrixLoadTensorNV Result Type " - << _.getIdName(type_id) << " is not a cooperative matrix type."; - } else { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << "spv::Op::OpCooperativeMatrixStoreTensorNV Object type " - << _.getIdName(type_id) << " is not a cooperative matrix type."; - } - } - - const auto pointer_index = - (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) ? 2u : 0u; - const auto pointer_id = inst->GetOperandAs(pointer_index); - const auto pointer = _.FindDef(pointer_id); - if (!pointer || - ((_.addressing_model() == spv::AddressingModel::Logical) && - ((!_.features().variable_pointers && - !spvOpcodeReturnsLogicalPointer(pointer->opcode())) || - (_.features().variable_pointers && - !spvOpcodeReturnsLogicalVariablePointer(pointer->opcode()))))) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " Pointer " << _.getIdName(pointer_id) - << " is not a logical pointer."; - } - - const auto pointer_type_id = pointer->type_id(); - const auto pointer_type = _.FindDef(pointer_type_id); - if (!pointer_type || pointer_type->opcode() != spv::Op::OpTypePointer) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " type for pointer " << _.getIdName(pointer_id) - << " is not a pointer type."; - } - - const auto storage_class_index = 1u; - const auto storage_class = - pointer_type->GetOperandAs(storage_class_index); - - if (storage_class != spv::StorageClass::Workgroup && - storage_class != spv::StorageClass::StorageBuffer && - storage_class != spv::StorageClass::PhysicalStorageBuffer) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << _.VkErrorID(8973) << opname - << " storage class for pointer type " - << _.getIdName(pointer_type_id) - << " is not Workgroup, StorageBuffer, or PhysicalStorageBuffer."; - } - - if (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) { - const auto object_index = 3; - const auto object_id = inst->GetOperandAs(object_index); - const auto object = _.FindDef(object_id); - if (!object || object->type_id() != type_id) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " Object " << _.getIdName(object_id) - << " type does not match Result Type."; - } - } - - const auto tensor_layout_index = - (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) ? 4u : 2u; - const auto tensor_layout_id = - inst->GetOperandAs(tensor_layout_index); - const auto tensor_layout = _.FindDef(tensor_layout_id); - if (!tensor_layout || _.FindDef(tensor_layout->type_id())->opcode() != - spv::Op::OpTypeTensorLayoutNV) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " TensorLayout " << _.getIdName(tensor_layout_id) - << " does not have a tensor layout type."; - } - - const auto memory_access_index = - (inst->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) ? 5u : 3u; - if (inst->operands().size() > memory_access_index) { - if (auto error = CheckMemoryAccess(_, inst, memory_access_index)) - return error; - } - - const auto memory_access_mask = - inst->GetOperandAs(memory_access_index); - const auto tensor_operands_index = - memory_access_index + MemoryAccessNumWords(memory_access_mask); - const auto tensor_operands = - inst->GetOperandAs( - tensor_operands_index); - - if (inst->operands().size() < - tensor_operands_index + - TensorAddressingOperandsNumWords(tensor_operands)) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " not enough tensor addressing operands."; - } - - uint32_t tensor_operand_index = tensor_operands_index + 1; - if ((tensor_operands & spv::TensorAddressingOperandsMask::TensorView) != - spv::TensorAddressingOperandsMask::MaskNone) { - const auto tensor_view_id = - inst->GetOperandAs(tensor_operand_index); - const auto tensor_view = _.FindDef(tensor_view_id); - if (!tensor_view || _.FindDef(tensor_view->type_id())->opcode() != - spv::Op::OpTypeTensorViewNV) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " TensorView " << _.getIdName(tensor_view_id) - << " does not have a tensor view type."; - } - - tensor_operand_index++; - } - - if ((tensor_operands & spv::TensorAddressingOperandsMask::DecodeFunc) != - spv::TensorAddressingOperandsMask::MaskNone) { - if (inst->opcode() == spv::Op::OpCooperativeMatrixStoreTensorNV) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << "OpCooperativeMatrixStoreTensorNV does not support DecodeFunc."; - } - const auto decode_func_id = - inst->GetOperandAs(tensor_operand_index); - const auto decode_func = _.FindDef(decode_func_id); - - if (!decode_func || decode_func->opcode() != spv::Op::OpFunction) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " DecodeFunc " << _.getIdName(decode_func_id) - << " is not a function."; - } - - const auto component_type_index = 1; - const auto component_type_id = - matrix_type->GetOperandAs(component_type_index); - - const auto function_type = - _.FindDef(decode_func->GetOperandAs(3)); - if (function_type->GetOperandAs(1) != component_type_id) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " DecodeFunc " << _.getIdName(decode_func_id) - << " return type must match matrix component type."; - } - - const auto decode_ptr_type_id = function_type->GetOperandAs(2); - const auto decode_ptr_type = _.FindDef(decode_ptr_type_id); - auto decode_storage_class = - decode_ptr_type->GetOperandAs(storage_class_index); - - if (decode_storage_class != spv::StorageClass::PhysicalStorageBuffer) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " DecodeFunc " << _.getIdName(decode_func_id) - << " first parameter must be pointer to PhysicalStorageBuffer."; - } - - const auto tensor_layout_type = _.FindDef(tensor_layout->type_id()); - - for (uint32_t param = 3; param < 5; ++param) { - const auto param_type_id = function_type->GetOperandAs(param); - const auto param_type = _.FindDef(param_type_id); - if (param_type->opcode() != spv::Op::OpTypeArray) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " DecodeFunc " << _.getIdName(decode_func_id) - << " second/third parameter must be array of 32-bit integer " - "with " - << " dimension equal to the tensor dimension."; - } - const auto length_index = 2u; - uint64_t array_length; - if (_.EvalConstantValUint64( - param_type->GetOperandAs(length_index), - &array_length)) { - const auto tensor_layout_dim_id = - tensor_layout_type->GetOperandAs(1); - uint64_t dim_value; - if (_.EvalConstantValUint64(tensor_layout_dim_id, &dim_value)) { - if (array_length != dim_value) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << opname << " DecodeFunc " - << _.getIdName(decode_func_id) - << " second/third parameter must be array of 32-bit integer " - "with " - << " dimension equal to the tensor dimension."; - } - } - } - } - - tensor_operand_index++; - } - - return SPV_SUCCESS; } spv_result_t ValidatePtrComparison(ValidationState_t& _, --- SPIRV-Tools-2024.4.rc2/source/val/validate_memory.cpp.vanilla 2025-01-25 23:15:04.657914825 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_memory.cpp 2025-01-25 23:17:00.042891392 +0100 @@ -344,9 +344,7 @@ if (mask & uint32_t(spv::MemoryAccessMask::MakePointerVisibleKHR)) { if (inst->opcode() == spv::Op::OpStore || - inst->opcode() == spv::Op::OpCooperativeMatrixStoreNV || - inst->opcode() == spv::Op::OpCooperativeMatrixStoreKHR || - inst->opcode() == spv::Op::OpCooperativeMatrixStoreTensorNV) { + inst->opcode() == spv::Op::OpCooperativeMatrixStoreKHR) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "MakePointerVisibleKHR cannot be used with OpStore."; } @@ -2282,11 +2280,6 @@ if (auto error = ValidateCooperativeMatrixLoadStoreKHR(_, inst)) return error; break; - case spv::Op::OpCooperativeMatrixLoadTensorNV: - case spv::Op::OpCooperativeMatrixStoreTensorNV: - if (auto error = ValidateCooperativeMatrixLoadStoreTensorNV(_, inst)) - return error; - break; case spv::Op::OpPtrEqual: case spv::Op::OpPtrNotEqual: case spv::Op::OpPtrDiff: --- SPIRV-Tools-2024.4.rc2/source/CMakeLists.txt.vanilla 2025-01-25 23:20:28.855865030 +0100 +++ SPIRV-Tools-2024.4.rc2/source/CMakeLists.txt 2025-01-25 23:20:34.232608244 +0100 @@ -334,7 +334,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_tracing_reorder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_scopes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_small_type_uses.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_tensor_layout.cpp ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_type.cpp ${CMAKE_CURRENT_SOURCE_DIR}/val/decoration.h ${CMAKE_CURRENT_SOURCE_DIR}/val/basic_block.cpp --- SPIRV-Tools-2024.4.rc2/source/val/validate_type.cpp.vanilla 2025-01-25 23:21:36.256824767 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_type.cpp 2025-01-25 23:23:51.545418070 +0100 @@ -669,89 +669,6 @@ return SPV_SUCCESS; } - -spv_result_t ValidateTypeTensorLayoutNV(ValidationState_t& _, - const Instruction* inst) { - if (auto error = ValidateTensorDim(_, inst)) return error; - - const auto clamp_index = 2; - const auto clamp_id = inst->GetOperandAs(clamp_index); - const auto clamp = _.FindDef(clamp_id); - if (!clamp || !_.IsIntScalarType(clamp->type_id()) || - _.GetBitWidth(clamp->type_id()) != 32) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) << " ClampMode " - << _.getIdName(clamp_id) << " is not a 32-bit integer."; - } - - uint64_t clamp_value; - if (_.EvalConstantValUint64(clamp_id, &clamp_value)) { - if (clamp_value > - static_cast(spv::TensorClampMode::RepeatMirrored)) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) << " ClampMode " - << _.getIdName(clamp_id) << " must be a valid TensorClampMode."; - } - } - - return SPV_SUCCESS; -} - -spv_result_t ValidateTypeTensorViewNV(ValidationState_t& _, - const Instruction* inst) { - if (auto error = ValidateTensorDim(_, inst)) return error; - - const auto has_dim_index = 2; - const auto has_dim_id = inst->GetOperandAs(has_dim_index); - const auto has_dim = _.FindDef(has_dim_id); - if (!has_dim || !_.IsBoolScalarType(has_dim->type_id())) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) << " HasDimensions " - << _.getIdName(has_dim_id) << " is not a boolean value."; - } - - uint32_t permutation_mask = 0; - bool all_constant = true; - const auto num_dim = inst->operands().size() - 3; - for (size_t p_index = 3; p_index < inst->operands().size(); ++p_index) { - auto p_id = inst->GetOperandAs(p_index); - const auto p = _.FindDef(p_id); - if (!p || !_.IsIntScalarType(p->type_id()) || - _.GetBitWidth(p->type_id()) != 32) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) << " Permutation " - << _.getIdName(p_id) << " is not a 32-bit integer."; - } - - uint64_t p_value; - if (_.EvalConstantValUint64(p_id, &p_value)) { - if (p_value >= num_dim) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) << " Permutation " - << _.getIdName(p_id) << " must be a valid dimension."; - } - permutation_mask |= 1 << p_value; - } else { - all_constant = false; - } - } - if (all_constant && permutation_mask != (1U << num_dim) - 1U) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) - << " Permutation values don't form a valid permutation."; - } - - uint64_t dim_value; - if (_.EvalConstantValUint64(inst->GetOperandAs(1), &dim_value)) { - if (dim_value != num_dim) { - return _.diag(SPV_ERROR_INVALID_ID, inst) - << spvOpcodeString(inst->opcode()) - << " Incorrect number of permutation values."; - } - } - - return SPV_SUCCESS; -} } // namespace spv_result_t TypePass(ValidationState_t& _, const Instruction* inst) { --- SPIRV-Tools-2024.4.rc2/source/val/validate_type.cpp.vanilla 2025-01-26 00:19:12.266430789 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_type.cpp 2025-01-26 00:19:26.186628346 +0100 @@ -710,19 +710,12 @@ case spv::Op::OpTypeForwardPointer: if (auto error = ValidateTypeForwardPointer(_, inst)) return error; break; - case spv::Op::OpTypeCooperativeMatrixNV: case spv::Op::OpTypeCooperativeMatrixKHR: if (auto error = ValidateTypeCooperativeMatrix(_, inst)) return error; break; case spv::Op::OpTypeUntypedPointerKHR: if (auto error = ValidateTypeUntypedPointerKHR(_, inst)) return error; break; - case spv::Op::OpTypeTensorLayoutNV: - if (auto error = ValidateTypeTensorLayoutNV(_, inst)) return error; - break; - case spv::Op::OpTypeTensorViewNV: - if (auto error = ValidateTypeTensorViewNV(_, inst)) return error; - break; default: break; } --- SPIRV-Tools-2024.4.rc2/source/opt/aggressive_dead_code_elim_pass.cpp.vanilla 2025-01-26 00:22:25.859178640 +0100 +++ SPIRV-Tools-2024.4.rc2/source/opt/aggressive_dead_code_elim_pass.cpp 2025-01-26 00:22:40.569387428 +0100 @@ -439,9 +439,7 @@ } break; } - case spv::Op::OpCooperativeMatrixLoadNV: case spv::Op::OpCooperativeMatrixLoadKHR: - case spv::Op::OpCooperativeMatrixLoadTensorNV: return GetVariableId( inst->GetSingleWordInOperand(kCooperativeMatrixLoadSourceAddrInIdx)); default: --- SPIRV-Tools-2024.4.rc2/source/opt/ir_context.cpp.vanilla 2025-01-26 00:23:25.530025612 +0100 +++ SPIRV-Tools-2024.4.rc2/source/opt/ir_context.cpp 2025-01-26 00:23:49.107026952 +0100 @@ -929,31 +929,6 @@ for (auto ii = bi->begin(); ii != bi->end(); ++ii) { if (ii->opcode() == spv::Op::OpFunctionCall) todo->push(ii->GetSingleWordInOperand(0)); - if (ii->opcode() == spv::Op::OpCooperativeMatrixPerElementOpNV) - todo->push(ii->GetSingleWordInOperand(1)); - if (ii->opcode() == spv::Op::OpCooperativeMatrixReduceNV) - todo->push(ii->GetSingleWordInOperand(2)); - if (ii->opcode() == spv::Op::OpCooperativeMatrixLoadTensorNV) { - const auto memory_operands_index = 3; - auto mask = ii->GetSingleWordInOperand(memory_operands_index); - - uint32_t count = 1; - if (mask & uint32_t(spv::MemoryAccessMask::Aligned)) ++count; - if (mask & uint32_t(spv::MemoryAccessMask::MakePointerAvailableKHR)) - ++count; - if (mask & uint32_t(spv::MemoryAccessMask::MakePointerVisibleKHR)) - ++count; - - const auto tensor_operands_index = memory_operands_index + count; - mask = ii->GetSingleWordInOperand(tensor_operands_index); - count = 1; - if (mask & uint32_t(spv::TensorAddressingOperandsMask::TensorView)) - ++count; - - if (mask & uint32_t(spv::TensorAddressingOperandsMask::DecodeFunc)) { - todo->push(ii->GetSingleWordInOperand(tensor_operands_index + count)); - } - } } } --- SPIRV-Tools-2024.4.rc2/source/val/validation_state.cpp.vanilla 2025-01-26 00:21:36.611813063 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validation_state.cpp 2025-01-26 00:21:41.138543966 +0100 @@ -1360,7 +1360,6 @@ if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value && // CooperativeMatrixConversionsNV allows conversions from Acc->A/B !(is_conversion && - HasCapability(spv::Capability::CooperativeMatrixConversionsNV) && m2_value == (uint32_t)spv::CooperativeMatrixUse::MatrixAccumulatorKHR)) { return diag(SPV_ERROR_INVALID_DATA, inst) --- SPIRV-Tools-2024.4.rc2/source/val/validate.cpp.vanilla 2025-01-26 00:25:42.315300671 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate.cpp 2025-01-26 00:25:50.085410973 +0100 @@ -366,7 +366,6 @@ if (auto error = RayTracingPass(*vstate, &instruction)) return error; if (auto error = RayReorderNVPass(*vstate, &instruction)) return error; if (auto error = MeshShadingPass(*vstate, &instruction)) return error; - if (auto error = TensorLayoutPass(*vstate, &instruction)) return error; } // Validate the preconditions involving adjacent instructions. e.g. --- SPIRV-Tools-2024.4.rc2/source/val/validate.h.vanilla 2025-01-26 00:25:57.508849664 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate.h 2025-01-26 00:26:03.648936827 +0100 @@ -226,9 +226,6 @@ /// Calculates the reachability of basic blocks. void ReachabilityPass(ValidationState_t& _); -/// Validates tensor layout and view instructions. -spv_result_t TensorLayoutPass(ValidationState_t& _, const Instruction* inst); - /// Validates execution limitations. /// /// Verifies execution models are allowed for all functionality they contain. --- SPIRV-Tools-2024.4.rc2/source/val/validate_tensor_layout.cpp.vanilla 2025-01-26 00:26:11.169043564 +0100 +++ SPIRV-Tools-2024.4.rc2/source/val/validate_tensor_layout.cpp 2025-01-26 00:26:33.239356847 +0100 @@ -142,43 +142,5 @@ } // namespace -spv_result_t TensorLayoutPass(ValidationState_t& _, const Instruction* inst) { - switch (inst->opcode()) { - case spv::Op::OpCreateTensorLayoutNV: - if (auto error = ValidateCreateTensorLayoutNV(_, inst)) return error; - break; - case spv::Op::OpCreateTensorViewNV: - if (auto error = ValidateCreateTensorViewNV(_, inst)) return error; - break; - case spv::Op::OpTensorLayoutSetBlockSizeNV: - case spv::Op::OpTensorLayoutSetDimensionNV: - case spv::Op::OpTensorLayoutSetStrideNV: - if (auto error = ValidateTensorTypeWithDimValuesNV(_, inst, DIM, false)) - return error; - break; - case spv::Op::OpTensorLayoutSliceNV: - if (auto error = ValidateTensorTypeWithDimValuesNV(_, inst, DIMx2, false)) - return error; - break; - case spv::Op::OpTensorLayoutSetClampValueNV: - if (auto error = ValidateTensorTypeWithDimValuesNV(_, inst, ONE, false)) - return error; - break; - case spv::Op::OpTensorViewSetDimensionNV: - case spv::Op::OpTensorViewSetStrideNV: - if (auto error = ValidateTensorTypeWithDimValuesNV(_, inst, DIM, true)) - return error; - break; - case spv::Op::OpTensorViewSetClipNV: - if (auto error = ValidateTensorTypeWithDimValuesNV(_, inst, FOUR, true)) - return error; - break; - default: - break; - } - - return SPV_SUCCESS; -} - } // namespace val } // namespace spvtools --- SPIRV-Tools-2024.4.rc2/source/opt/type_manager.cpp.vanilla 2025-01-26 00:27:52.257145391 +0100 +++ SPIRV-Tools-2024.4.rc2/source/opt/type_manager.cpp 2025-01-26 00:28:06.254010827 +0100 @@ -441,28 +441,6 @@ {SPV_OPERAND_TYPE_ID, {coop_mat->use_id()}}}); break; } - case Type::kTensorLayoutNV: { - auto tensor_layout = type->AsTensorLayoutNV(); - typeInst = MakeUnique( - context(), spv::Op::OpTypeTensorLayoutNV, 0, id, - std::initializer_list{ - {SPV_OPERAND_TYPE_ID, {tensor_layout->dim_id()}}, - {SPV_OPERAND_TYPE_ID, {tensor_layout->clamp_mode_id()}}}); - break; - } - case Type::kTensorViewNV: { - auto tensor_view = type->AsTensorViewNV(); - std::vector operands; - operands.push_back(Operand{SPV_OPERAND_TYPE_ID, {tensor_view->dim_id()}}); - operands.push_back( - Operand{SPV_OPERAND_TYPE_ID, {tensor_view->has_dimensions_id()}}); - for (auto p : tensor_view->perm()) { - operands.push_back(Operand{SPV_OPERAND_TYPE_ID, {p}}); - } - typeInst = MakeUnique(context(), spv::Op::OpTypeTensorViewNV, - 0, id, operands); - break; - } default: assert(false && "Unexpected type"); break; --- SPIRV-Tools-2024.4.rc2/source/opt/type_manager.cpp.vanilla 2025-01-26 00:34:46.216356362 +0100 +++ SPIRV-Tools-2024.4.rc2/source/opt/type_manager.cpp 2025-01-26 00:34:56.533169548 +0100 @@ -923,23 +923,6 @@ case spv::Op::OpTypeRayQueryKHR: type = new RayQueryKHR(); break; - case spv::Op::OpTypeHitObjectNV: - type = new HitObjectNV(); - break; - case spv::Op::OpTypeTensorLayoutNV: - type = new TensorLayoutNV(inst.GetSingleWordInOperand(0), - inst.GetSingleWordInOperand(1)); - break; - case spv::Op::OpTypeTensorViewNV: { - const auto count = inst.NumOperands(); - std::vector perm; - for (uint32_t i = 2; i < count; ++i) { - perm.push_back(inst.GetSingleWordOperand(i)); - } - type = new TensorViewNV(inst.GetSingleWordInOperand(0), - inst.GetSingleWordInOperand(1), perm); - break; - } default: assert(false && "Type not handled by the type manager."); break;