From 3dd5f5896ddda0ae7c53f0db25c9f95e4aae334d Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 28 Apr 2025 14:35:59 -0700 Subject: [PATCH 01/50] Add HLSL validation to coopvec builtins --- .../clang/Basic/DiagnosticSemaKinds.td | 8 + tools/clang/lib/Sema/SemaHLSL.cpp | 255 ++++++++++++++++++ utils/hct/hctdb.py | 4 +- 3 files changed, 265 insertions(+), 2 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index ae7e777180..a914f35778 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8015,6 +8015,14 @@ def err_hlsl_hitobject_unsupported_stage : Error< "dx::HitObject is unavailable in shader stage '%0' (requires 'raygeneration', 'closesthit' or 'miss')">; // HLSL Change Ends +// Linear Algebra Operations +def err_hlsl_linalg_param_must_be_const : Error<" '%0' must be a constant parameter">; +def err_hlsl_linalg_incorrect_type : Error<"%0 is incorrect type, must be 'unsigned int', 'signed int' or 'float'">; +def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %select{false|true}1 for a %2 vector type">; +def err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; + // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; def err_hlsl_vk_pointer_cast_alignment: Error< diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 6e58c0e872..666b9cb51c 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11663,6 +11663,258 @@ static bool CheckBarrierCall(Sema &S, FunctionDecl *FD, CallExpr *CE, return false; } +// MatVec Ops +static const unsigned kMatVecMulOutputVectorIdx = 0; +static const unsigned kMatVecMulOutputIsUnsignedIdx = 1; +static const unsigned kMatVecMulInputVectorIdx = 2; +static const unsigned kMatVecMulIsInputUnsignedIdx = 3; +static const unsigned kMatVecMulInputInterpretationIdx = 4; +static const unsigned kMatVecMulMatrixBufferIdx = 5; +static const unsigned kMatVecMulMatrixOffsetIdx = 6; +static const unsigned kMatVecMulMatrixInterpretationIdx = 7; +static const unsigned kMatVecMulMatrixMIdx = 8; +static const unsigned kMatVecMulMatrixKIdx = 9; +static const unsigned kMatVecMulMatrixLayoutIdx = 10; +static const unsigned kMatVecMulMatrixTransposeIdx = 11; +static const unsigned kMatVecMulMatrixStrideIdx = 12; +static const unsigned kMatVecMulIsOutputUnsignedIdx = 13; + +// MatVecAdd +const unsigned kMatVecMulAddBiasInterpretation = 15; +const unsigned kMatVecMulAddIsOutputUnsignedIdx = 16; + +static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, + unsigned InputVectorSize, + unsigned OutputVectorSize, + unsigned MatrixK, unsigned MatrixM, + bool isInputPacked) { + // Check is output vector size is equals to matrix dimension M + if (OutputVectorSize != MatrixM) { + S.Diags.Report( + CE->getExprLoc(), + diag::err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M); + return true; + } + + const unsigned PackingFactor = isInputPacked ? 4 : 1; + unsigned MinInputVectorSize = (MatrixK + PackingFactor - 1) / PackingFactor; + if (InputVectorSize != MinInputVectorSize) { + if (isInputPacked) { + S.Diags.Report(CE->getExprLoc(), + diag::err_hlsl_linalg_packed_input_vector_size_incorrect); + } else { + S.Diags.Report(CE->getExprLoc(), + diag::err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K); + } + return true; + } + return false; +} + +static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, + const hlsl::ShaderModel *SM) { + // Find OutputVectorType and Size and check IsUnsigned + bool IsOutputUnsignedFlagValue = false; + Expr *IsOutputUnsignedExpr = CE->getArg(kMatVecMulOutputIsUnsignedIdx); + llvm::APSInt IsOutputUnsignedExprVal; + if (IsOutputUnsignedExpr->isIntegerConstantExpr(IsOutputUnsignedExprVal, + S.Context)) { + IsOutputUnsignedFlagValue = IsOutputUnsignedExprVal.getBoolValue(); + } else { + S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "IsOutputUnsigned"; + return true; + } + + Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); + unsigned OutputVectorSizeValue = 0; + if (IsHLSLVecType(OutputVector->getType())) { + OutputVectorSizeValue = GetHLSLVecSize(OutputVector->getType()); + QualType OutputVectorType = GetHLSLVecElementType(OutputVector->getType()); + const Type *OutputVectorTypePtr = OutputVectorType.getTypePtr(); + if (!OutputVectorTypePtr->isUnsignedIntegerType() && + !OutputVectorTypePtr->isSignedIntegerType() && + !OutputVectorTypePtr->isFloatingType()) { + S.Diags.Report(OutputVector->getExprLoc(), + diag::err_hlsl_linalg_incorrect_type) + << "Output Vector"; + } + + if (IsOutputUnsignedFlagValue && + !OutputVectorTypePtr->isUnsignedIntegerType()) { + DXASSERT_NOMSG(OutputVectorTypePtr->isSignedIntegerType() || + OutputVectorTypePtr->isFloatingType()); + S.Diags.Report(OutputVector->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsOuputUnsigned" << false + << (OutputVectorTypePtr->isSignedIntegerType() ? "signed int" + : "float"); + return true; + + } else if (!IsOutputUnsignedFlagValue && + OutputVectorTypePtr->isUnsignedIntegerType()) { + S.Diags.Report(OutputVector->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsOuputUnsigned" << true << "unsigned int"; + return true; + } + } + + // Find InputVectorType and Size and check IsUnsigned + bool IsInputUnsignedFlagValue = false; + Expr *IsInputUnsignedExpr = CE->getArg(kMatVecMulIsInputUnsignedIdx); + llvm::APSInt IsInputUnsignedExprVal; + if (IsInputUnsignedExpr->isIntegerConstantExpr(IsInputUnsignedExprVal, + S.Context)) { + IsInputUnsignedFlagValue = IsInputUnsignedExprVal.getBoolValue(); + } else { + S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "IsInputUnsigned"; + return true; + } + + Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); + unsigned InputVectorSizeValue = 0; + if (IsHLSLVecType(InputVector->getType())) { + InputVectorSizeValue = GetHLSLVecSize(InputVector->getType()); + QualType InputVectorType = GetHLSLVecElementType(InputVector->getType()); + const Type *InputVectorTypePtr = InputVectorType.getTypePtr(); + if (!InputVectorTypePtr->isUnsignedIntegerType() && + !InputVectorTypePtr->isSignedIntegerType() && + !InputVectorTypePtr->isFloatingType()) { + S.Diags.Report(InputVector->getExprLoc(), + diag::err_hlsl_linalg_incorrect_type) + << "Input Vector"; + } + + if (IsInputUnsignedFlagValue && + !InputVectorTypePtr->isUnsignedIntegerType()) { + DXASSERT_NOMSG(InputVectorTypePtr->isSignedIntegerType() || + InputVectorTypePtr->isFloatingType()); + S.Diags.Report(InputVector->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsInputUnsigned" << false + << (InputVectorTypePtr->isSignedIntegerType() ? "signed int" + : "float"); + return true; + + } else if (!IsInputUnsignedFlagValue && + InputVectorTypePtr->isUnsignedIntegerType()) { + S.Diags.Report(InputVector->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsInputUnsigned" << true << "unsigned int"; + return true; + } + } + // Get Matrix Dimensions M and K, check if they are constants + Expr *MatrixKExpr = CE->getArg(kMatVecMulMatrixKIdx); + llvm::APSInt MatrixKExprVal; + unsigned MatrixKValue = 0; + if (MatrixKExpr->isIntegerConstantExpr(MatrixKExprVal, S.Context)) { + MatrixKValue = MatrixKExprVal.getLimitedValue(); + } else { + S.Diags.Report(MatrixKExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixK"; + return true; + } + + Expr *MatrixMExpr = CE->getArg(kMatVecMulMatrixMIdx); + llvm::APSInt MatrixMExprVal; + unsigned MatrixMValue = 0; + if (MatrixMExpr->isIntegerConstantExpr(MatrixMExprVal, S.Context)) { + MatrixMValue = MatrixMExprVal.getLimitedValue(); + } else { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixM"; + return true; + } + + // Get InputInterpretation, check if it is constant + Expr *InputInterpretationExpr = CE->getArg(kMatVecMulInputInterpretationIdx); + llvm::APSInt InputInterpretationExprVal; + unsigned InputInterpretationValue = 0; + if (InputInterpretationExpr->isIntegerConstantExpr(InputInterpretationExprVal, S.Context)) { + InputInterpretationValue = InputInterpretationExprVal.getLimitedValue(); + } else { + S.Diags.Report(InputInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "InputInterpretation"; + return true; + } + + bool isInputPacked = false; + + CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, MatrixMValue, isInputPacked); + + //Get MatrixInterpretation, check if it is constant + Expr *MatrixInterpretationExpr = CE->getArg(kMatVecMulMatrixInterpretationIdx); + llvm::APSInt MatrixInterpretationExprVal; + unsigned MatrixInterpretationValue = 0; + if (MatrixInterpretationExpr->isIntegerConstantExpr(MatrixInterpretationExprVal, S.Context)) { + MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); + } else { + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixInterpretation"; + return true; + } + + // Get MatrixLayout, check if it is constant + Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); + llvm::APSInt MatrixLayoutExprVal; + unsigned MatrixLayoutValue = 0; + if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { + MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); + } else { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixLayout"; + return true; + } + + // Get MatrixTranspose, check if it is constant + Expr *MatrixTransposeExpr = CE->getArg(kMatVecMulMatrixTransposeIdx); + llvm::APSInt MatrixTransposeExprVal; + unsigned MatrixTransposeValue = 0; + if (MatrixTransposeExpr->isIntegerConstantExpr(MatrixTransposeExprVal, S.Context)) { + MatrixTransposeValue = MatrixTransposeExprVal.getLimitedValue(); + } else { + S.Diags.Report(MatrixTransposeExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixTranspose"; + return true; + } + + return false; +} + +static bool CheckMulCall(Sema &S, FunctionDecl *FD, CallExpr *CE, + const hlsl::ShaderModel *SM) { + CheckCommonMulandMulAddParameters(S, CE, SM); + + return false; +} + +static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, + const hlsl::ShaderModel *SM) { + return false; +} + +static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, + const hlsl::ShaderModel *SM) { + return false; +} + +static bool CheckVectorAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, + const hlsl::ShaderModel *SM) { + + return false; +} + #ifdef ENABLE_SPIRV_CODEGEN static bool CheckVKBufferPointerCast(Sema &S, FunctionDecl *FD, CallExpr *CE, bool isStatic) { @@ -11710,6 +11962,9 @@ void Sema::CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, case hlsl::IntrinsicOp::IOP_Barrier: CheckBarrierCall(*this, FDecl, TheCall, SM); break; + case hlsl::IntrinsicOp::IOP___builtin_MatVecMul: + CheckMulCall(*this, FDecl, TheCall, SM); + break; #ifdef ENABLE_SPIRV_CODEGEN case hlsl::IntrinsicOp::IOP_Vkreinterpret_pointer_cast: CheckVKBufferPointerCast(*this, FDecl, TheCall, false); diff --git a/utils/hct/hctdb.py b/utils/hct/hctdb.py index 57f2574005..e8cd186628 100644 --- a/utils/hct/hctdb.py +++ b/utils/hct/hctdb.py @@ -8414,13 +8414,13 @@ def build_valrules(self): self.add_valrule_msg( "Instr.MatVecOpIsUnsignedFlagsAreConst", "In Linalg Mul/MulAdd functions, IsUnsigned flag is a constant.", - "'%1' is not a constant value", + "%0 is not a constant value", ) self.add_valrule_msg( "Instr.LinalgInterpretationParamAreConst", "In Linalg operations, Interpretation value is a constant.", - "'%1' is not a constant value", + "%0 is not a constant value", ) self.add_valrule_msg( From 70119f835e63e3d57fe1401eda56fe60a11c3f4a Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 29 Apr 2025 06:34:02 -0700 Subject: [PATCH 02/50] Add more HLSL validation --- .../clang/Basic/DiagnosticSemaKinds.td | 2 + tools/clang/lib/Sema/SemaHLSL.cpp | 140 ++++++++++++++---- 2 files changed, 116 insertions(+), 26 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index a914f35778..7c01f6a6e8 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8022,6 +8022,8 @@ def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %sel def err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; def err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; +def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretaion value">; +def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 666b9cb51c..722780304d 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11683,6 +11683,66 @@ static const unsigned kMatVecMulIsOutputUnsignedIdx = 13; const unsigned kMatVecMulAddBiasInterpretation = 15; const unsigned kMatVecMulAddIsOutputUnsignedIdx = 16; +enum MatrixLayout { + MATRIX_LAYOUT_ROW_MAJOR = 0, + MATRIX_LAYOUT_COLUMN_MAJOR = 1, + MATRIX_LAYOUT_MUL_OPTIMAL = 2, + MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 +}; + +bool CheckMatrixLayoutForMulandMulAddOps(unsigned Layout) { + return Layout <= static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); +} + +bool CheckMatrixLayoutForOuterProductAccummulate(unsigned Layout) { + return Layout == static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); +} + +enum DataType { + DATA_TYPE_SINT16 = 2, // ComponentType::I16 + DATA_TYPE_UINT16 = 3, // ComponentType::U16 + DATA_TYPE_SINT32 = 4, // ComponentType::I32 + DATA_TYPE_UINT32 = 5, // ComponentType::U32 + DATA_TYPE_FLOAT16 = 8, // ComponentType::F16 + DATA_TYPE_FLOAT32 = 9, // ComponentType::F32 + DATA_TYPE_SINT8_T4_PACKED = 17, // ComponentType::PackedS8x32 + DATA_TYPE_UINT8_T4_PACKED = 18, // ComponentType::PackedU8x32 + DATA_TYPE_UINT8 = 19, // ComponentType::U8 + DATA_TYPE_SINT8 = 20, // ComponentType::I8 + DATA_TYPE_FLOAT8_E4M3 = 21, // ComponentType::F8_E4M3 + // (1 sign, 4 exp, 3 mantissa bits) + DATA_TYPE_FLOAT8_E5M2 = 22, // ComponentType::F8_E5M2 + // (1 sign, 5 exp, 2 mantissa bits) +}; + +bool IsPackedType(DataType type) { + return (type == DATA_TYPE_SINT8_T4_PACKED || type == DATA_TYPE_UINT8_T4_PACKED); +} + +static bool CheckLinalgTypeInterpretation(uint32_t Input, bool InRegister) { + + switch (Input) { + case DATA_TYPE_SINT16: + case DATA_TYPE_UINT16: + case DATA_TYPE_SINT32: + case DATA_TYPE_UINT32: + case DATA_TYPE_FLOAT16: + case DATA_TYPE_FLOAT32: + case DATA_TYPE_UINT8: + case DATA_TYPE_SINT8: + case DATA_TYPE_FLOAT8_E4M3: + case DATA_TYPE_FLOAT8_E5M2: + return true; + case DATA_TYPE_SINT8_T4_PACKED: + case DATA_TYPE_UINT8_T4_PACKED: + return InRegister; + default: + return false; + } +} + static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, unsigned InputVectorSize, unsigned OutputVectorSize, @@ -11825,7 +11885,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, llvm::APSInt MatrixMExprVal; unsigned MatrixMValue = 0; if (MatrixMExpr->isIntegerConstantExpr(MatrixMExprVal, S.Context)) { - MatrixMValue = MatrixMExprVal.getLimitedValue(); + MatrixMValue = MatrixMExprVal.getLimitedValue(); } else { S.Diags.Report(MatrixMExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) @@ -11837,8 +11897,18 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, Expr *InputInterpretationExpr = CE->getArg(kMatVecMulInputInterpretationIdx); llvm::APSInt InputInterpretationExprVal; unsigned InputInterpretationValue = 0; - if (InputInterpretationExpr->isIntegerConstantExpr(InputInterpretationExprVal, S.Context)) { + if (InputInterpretationExpr->isIntegerConstantExpr(InputInterpretationExprVal, + S.Context)) { InputInterpretationValue = InputInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = true; + if (!CheckLinalgTypeInterpretation(InputInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(InputInterpretationValue) + << InRegisterInterpretation; + return true; + } } else { S.Diags.Report(InputInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) @@ -11846,35 +11916,53 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return true; } - bool isInputPacked = false; + bool isInputPacked = IsPackedType(static_cast(InputInterpretationValue)); CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, MatrixMValue, isInputPacked); - //Get MatrixInterpretation, check if it is constant - Expr *MatrixInterpretationExpr = CE->getArg(kMatVecMulMatrixInterpretationIdx); - llvm::APSInt MatrixInterpretationExprVal; - unsigned MatrixInterpretationValue = 0; - if (MatrixInterpretationExpr->isIntegerConstantExpr(MatrixInterpretationExprVal, S.Context)) { - MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); - } else { - S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixInterpretation"; - return true; - } + // Get MatrixInterpretation, check if it is constant + Expr *MatrixInterpretationExpr = CE->getArg(kMatVecMulMatrixInterpretationIdx); + llvm::APSInt MatrixInterpretationExprVal; + unsigned MatrixInterpretationValue = 0; + if (MatrixInterpretationExpr->isIntegerConstantExpr( + MatrixInterpretationExprVal, S.Context)) { + MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = false; + if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(MatrixInterpretationValue) << InRegisterInterpretation; + return true; + } + } else { + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixInterpretation"; + return true; + } // Get MatrixLayout, check if it is constant - Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); - llvm::APSInt MatrixLayoutExprVal; - unsigned MatrixLayoutValue = 0; - if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { - MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - } else { - S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixLayout"; - return true; - } + Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); + llvm::APSInt MatrixLayoutExprVal; + unsigned MatrixLayoutValue = 0; + if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { + MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); + if (!CheckMatrixLayoutForMulandMulAddOps(MatrixInterpretationValue)) { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_matrix_layout_for_mul_ops_invalid) + << std::to_string(MatrixLayoutValue) + << std::to_string( + static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) + << std::to_string(static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + } + } else { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixLayout"; + return true; + } // Get MatrixTranspose, check if it is constant Expr *MatrixTransposeExpr = CE->getArg(kMatVecMulMatrixTransposeIdx); From 737e65b11fb093ff50ef746e9cc127b0e2560d83 Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 29 Apr 2025 11:13:37 -0700 Subject: [PATCH 03/50] Add IsTransposable check for matrix layouts --- .../clang/Basic/DiagnosticSemaKinds.td | 1 + tools/clang/lib/Sema/SemaHLSL.cpp | 120 +++++++++++------- 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7c01f6a6e8..93074eaaf4 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8024,6 +8024,7 @@ def err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"u def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretaion value">; def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; +def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 722780304d..d03d6bd35d 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11700,6 +11700,17 @@ bool CheckMatrixLayoutForOuterProductAccummulate(unsigned Layout) { MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); } +bool CheckTransposeForMatrixLayout(unsigned Layout, bool Transposed) { + switch (static_cast(Layout)) { + case MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR: + case MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR: + return !Transposed; + + default: + return true; + } +} + enum DataType { DATA_TYPE_SINT16 = 2, // ComponentType::I16 DATA_TYPE_UINT16 = 3, // ComponentType::U16 @@ -11718,7 +11729,8 @@ enum DataType { }; bool IsPackedType(DataType type) { - return (type == DATA_TYPE_SINT8_T4_PACKED || type == DATA_TYPE_UINT8_T4_PACKED); + return (type == DATA_TYPE_SINT8_T4_PACKED || + type == DATA_TYPE_UINT8_T4_PACKED); } static bool CheckLinalgTypeInterpretation(uint32_t Input, bool InRegister) { @@ -11885,7 +11897,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, llvm::APSInt MatrixMExprVal; unsigned MatrixMValue = 0; if (MatrixMExpr->isIntegerConstantExpr(MatrixMExprVal, S.Context)) { - MatrixMValue = MatrixMExprVal.getLimitedValue(); + MatrixMValue = MatrixMExprVal.getLimitedValue(); } else { S.Diags.Report(MatrixMExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) @@ -11915,61 +11927,73 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << "InputInterpretation"; return true; } - - bool isInputPacked = IsPackedType(static_cast(InputInterpretationValue)); - CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, MatrixMValue, isInputPacked); + bool isInputPacked = + IsPackedType(static_cast(InputInterpretationValue)); + + CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, + OutputVectorSizeValue, MatrixKValue, + MatrixMValue, isInputPacked); // Get MatrixInterpretation, check if it is constant - Expr *MatrixInterpretationExpr = CE->getArg(kMatVecMulMatrixInterpretationIdx); - llvm::APSInt MatrixInterpretationExprVal; - unsigned MatrixInterpretationValue = 0; - if (MatrixInterpretationExpr->isIntegerConstantExpr( - MatrixInterpretationExprVal, S.Context)) { - MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); - const bool InRegisterInterpretation = false; - if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, - InRegisterInterpretation)) { - S.Diags.Report(MatrixMExpr->getExprLoc(), - diag::err_hlsl_linalg_interpretation_value_incorrect) - << std::to_string(MatrixInterpretationValue) << InRegisterInterpretation; - return true; - } - } else { - S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixInterpretation"; - return true; - } + Expr *MatrixInterpretationExpr = + CE->getArg(kMatVecMulMatrixInterpretationIdx); + llvm::APSInt MatrixInterpretationExprVal; + unsigned MatrixInterpretationValue = 0; + if (MatrixInterpretationExpr->isIntegerConstantExpr( + MatrixInterpretationExprVal, S.Context)) { + MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = false; + if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(MatrixInterpretationValue) + << InRegisterInterpretation; + return true; + } + } else { + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixInterpretation"; + return true; + } // Get MatrixLayout, check if it is constant - Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); - llvm::APSInt MatrixLayoutExprVal; - unsigned MatrixLayoutValue = 0; - if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { - MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - if (!CheckMatrixLayoutForMulandMulAddOps(MatrixInterpretationValue)) { - S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_matrix_layout_for_mul_ops_invalid) - << std::to_string(MatrixLayoutValue) - << std::to_string( - static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) - << std::to_string(static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); - } - } else { - S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixLayout"; - return true; - } + Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); + llvm::APSInt MatrixLayoutExprVal; + unsigned MatrixLayoutValue = 0; + if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { + MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); + if (!CheckMatrixLayoutForMulandMulAddOps(MatrixInterpretationValue)) { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_matrix_layout_for_mul_ops_invalid) + << std::to_string(MatrixLayoutValue) + << std::to_string( + static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) + << std::to_string(static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + } + } else { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixLayout"; + return true; + } // Get MatrixTranspose, check if it is constant Expr *MatrixTransposeExpr = CE->getArg(kMatVecMulMatrixTransposeIdx); llvm::APSInt MatrixTransposeExprVal; - unsigned MatrixTransposeValue = 0; - if (MatrixTransposeExpr->isIntegerConstantExpr(MatrixTransposeExprVal, S.Context)) { - MatrixTransposeValue = MatrixTransposeExprVal.getLimitedValue(); + unsigned MatrixTransposeValue = 0; + if (MatrixTransposeExpr->isIntegerConstantExpr(MatrixTransposeExprVal, + S.Context)) { + MatrixTransposeValue = MatrixTransposeExprVal.getBoolValue(); + if (!CheckTransposeForMatrixLayout(MatrixLayoutValue, + MatrixTransposeValue)) { + + S.Diags.Report(MatrixTransposeExpr->getExprLoc(), + diag::err_hlsl_linalg_matrix_layout_is_not_transposable); + } } else { S.Diags.Report(MatrixTransposeExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) From e4eab81ff1585d445d510994e6e0fdd0ef88a710 Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 29 Apr 2025 12:44:49 -0700 Subject: [PATCH 04/50] Check validation of Bias Interpretation parameters --- tools/clang/lib/Sema/SemaHLSL.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index d03d6bd35d..febfba1ec1 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11999,8 +11999,8 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, diag::err_hlsl_linalg_param_must_be_const) << "MatrixTranspose"; return true; - } - + } + return false; } @@ -12012,7 +12012,31 @@ static bool CheckMulCall(Sema &S, FunctionDecl *FD, CallExpr *CE, } static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, - const hlsl::ShaderModel *SM) { + const hlsl::ShaderModel *SM) { + CheckCommonMulandMulAddParameters(S, CE, SM); + + // Check Bias Parameters + Expr *BiasInterpretationExpr = CE->getArg(kMatVecMulAddBiasInterpretation); + llvm::APSInt BiasInterpretationExprVal; + unsigned BiasInterpretationValue = 0; + if (BiasInterpretationExpr->isIntegerConstantExpr(BiasInterpretationExprVal, + S.Context)) { + BiasInterpretationValue = BiasInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = false; + if (!CheckLinalgTypeInterpretation(BiasInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(BiasInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(BiasInterpretationValue) + << InRegisterInterpretation; + return true; + } + } else { + S.Diags.Report(BiasInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "BiasInterpretation"; + return true; + } return false; } From 392322dde608ce19e6a4d6cfbdab1f3099fa34e5 Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 29 Apr 2025 15:01:29 -0700 Subject: [PATCH 05/50] Add diagnostics for OuterProoductAccumulate --- .../clang/Basic/DiagnosticSemaKinds.td | 3 + tools/clang/lib/Sema/SemaHLSL.cpp | 96 ++++++++++++++++++- 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 93074eaaf4..7cb5f2bb8e 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8025,6 +8025,9 @@ def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vec def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretaion value">; def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; +def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"Both the InputVectors must have the same element type ">; +def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout must be outerproductaccumulate optimal">; +def err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero : Error<"matrix stride must be zero outerproductaccumulate optimal matrix layout">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index febfba1ec1..de72b3cd40 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11695,7 +11695,7 @@ bool CheckMatrixLayoutForMulandMulAddOps(unsigned Layout) { MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); } -bool CheckMatrixLayoutForOuterProductAccummulate(unsigned Layout) { +bool CheckMatrixLayoutForOuterProductAccumulate(unsigned Layout) { return Layout == static_cast( MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); } @@ -12040,8 +12040,98 @@ static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, return false; } -static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, - const hlsl::ShaderModel *SM) { +// Linalg Outer Product Accumulate +// OuterProductAccumulate builtin function parameters +static const unsigned kOuterProdAccInputVector1Idx = 0; +static const unsigned kOuterProdAccInputVector2Idx = 1; +static const unsigned kOuterProdAccMatrixBufferIdx = 2; +static const unsigned kOuterProdAccMatrixOffsetIdx = 3; +static const unsigned kOuterProdAccMatrixInterpretationIdx = 4; +static const unsigned kOuterProdAccMatrixLayoutIdx = 5; +static const unsigned kOuterProdAccMatrixStrideIdx = 6; + + + +static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, + CallExpr *CE) { + // Check InputVector1 and InputVector2 are the same type + const Expr *InputVector1Expr = CE->getArg(kOuterProdAccInputVector1Idx); + const Expr *InputVector2Expr = CE->getArg(kOuterProdAccInputVector2Idx); + QualType InputVector1Type = InputVector1Expr->getType(); + QualType InputVector2Type = InputVector2Expr->getType(); + + // Get the element types of the vectors + const QualType InputVector1ElementType = + GetHLSLVecElementType(InputVector1Type); + const QualType InputVector2ElementType = + GetHLSLVecElementType(InputVector2Type); + + if (!S.Context.hasSameType(InputVector1ElementType, InputVector2Type)) { + S.Diags.Report(CE->getExprLoc(), + diag::err_hlsl_linalg_outer_prod_acc_vector_type_mismatch); + return true; + } + + // Check Matrix Interpretation is a constant and valid + Expr *MatrixInterpretationExpr = CE->getArg(kOuterProdAccMatrixInterpretationIdx); + llvm::APSInt MatrixInterpretationExprVal; + unsigned MatrixInterpretationValue = 0; + if (MatrixInterpretationExpr->isIntegerConstantExpr(MatrixInterpretationExprVal, + S.Context)) { + MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = false; + if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(MatrixInterpretationValue) + << InRegisterInterpretation; + return true; + } + } else { + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixInterpretation"; + return true; + } + + // Check Matrix Layout is constant and valid + Expr *MatrixLayoutExpr = CE->getArg(kOuterProdAccMatrixLayoutIdx); + llvm::APSInt MatrixLayoutExprVal; + unsigned MatrixLayoutValue = 0; + if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { + MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); + if (!CheckMatrixLayoutForOuterProductAccumulate( + MatrixInterpretationValue)) { + S.Diags.Report( + MatrixLayoutExpr->getExprLoc(), + diag:: + err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal); + } + } else { + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "MatrixLayout"; + return true; + } + + // Check Matrix Stide is zero (Training Optimal) + Expr *MatrixStrideExpr = CE->getArg(kOuterProdAccMatrixStrideIdx); + llvm::APSInt MatrixStrideExprVal; + unsigned MatrixStrideValue = 0; + if (MatrixStrideExpr->isIntegerConstantExpr(MatrixStrideExprVal, S.Context)) { + MatrixStrideValue = MatrixStrideExprVal.getLimitedValue(); + if (MatrixStrideValue != 0) { + S.Diags.Report(MatrixStrideExpr->getExprLoc(), + diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); + return true; + } + } else { + S.Diags.Report(MatrixStrideExpr->getExprLoc(), + diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); + return true; + } + return false; } From 18318112270870eb1f04b7988c4dee717b2edb04 Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 29 Apr 2025 16:42:40 -0700 Subject: [PATCH 06/50] Updated error message --- tools/clang/lib/Sema/SemaHLSL.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index de72b3cd40..dc6e47f727 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -12050,8 +12050,6 @@ static const unsigned kOuterProdAccMatrixInterpretationIdx = 4; static const unsigned kOuterProdAccMatrixLayoutIdx = 5; static const unsigned kOuterProdAccMatrixStrideIdx = 6; - - static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE) { // Check InputVector1 and InputVector2 are the same type @@ -12073,11 +12071,12 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, } // Check Matrix Interpretation is a constant and valid - Expr *MatrixInterpretationExpr = CE->getArg(kOuterProdAccMatrixInterpretationIdx); + Expr *MatrixInterpretationExpr = + CE->getArg(kOuterProdAccMatrixInterpretationIdx); llvm::APSInt MatrixInterpretationExprVal; unsigned MatrixInterpretationValue = 0; - if (MatrixInterpretationExpr->isIntegerConstantExpr(MatrixInterpretationExprVal, - S.Context)) { + if (MatrixInterpretationExpr->isIntegerConstantExpr( + MatrixInterpretationExprVal, S.Context)) { MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); const bool InRegisterInterpretation = false; if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, @@ -12122,16 +12121,18 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, if (MatrixStrideExpr->isIntegerConstantExpr(MatrixStrideExprVal, S.Context)) { MatrixStrideValue = MatrixStrideExprVal.getLimitedValue(); if (MatrixStrideValue != 0) { - S.Diags.Report(MatrixStrideExpr->getExprLoc(), - diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); + S.Diags.Report( + MatrixStrideExpr->getExprLoc(), + diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); return true; } } else { - S.Diags.Report(MatrixStrideExpr->getExprLoc(), - diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); + S.Diags.Report( + MatrixStrideExpr->getExprLoc(), + diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); return true; } - + return false; } From d1fe8697b49372db72763c479fab7e265d273e10 Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 30 Apr 2025 12:03:06 -0700 Subject: [PATCH 07/50] Minor Fixes --- .../clang/Basic/DiagnosticSemaKinds.td | 6 ++--- tools/clang/lib/Sema/SemaHLSL.cpp | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7cb5f2bb8e..60542f2089 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8025,9 +8025,9 @@ def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vec def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretaion value">; def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; -def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"Both the InputVectors must have the same element type ">; -def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout must be outerproductaccumulate optimal">; -def err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero : Error<"matrix stride must be zero outerproductaccumulate optimal matrix layout">; +def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"input vectors of outerproductaccumulate must have the same element type">; +def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout for outerproductaccumulate must be %0">; +def err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero : Error<"matrix stride must be zero for outerproductaccumulate optimal matrix layout">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index dc6e47f727..cc11b9787a 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -12064,13 +12064,13 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, const QualType InputVector2ElementType = GetHLSLVecElementType(InputVector2Type); - if (!S.Context.hasSameType(InputVector1ElementType, InputVector2Type)) { - S.Diags.Report(CE->getExprLoc(), + if (!S.Context.hasSameType(InputVector1ElementType, InputVector2ElementType)) { + S.Diags.Report(InputVector1Expr->getExprLoc(), diag::err_hlsl_linalg_outer_prod_acc_vector_type_mismatch); return true; } - // Check Matrix Interpretation is a constant and valid + // Check Matrix Interpretation is a constant and a valid value Expr *MatrixInterpretationExpr = CE->getArg(kOuterProdAccMatrixInterpretationIdx); llvm::APSInt MatrixInterpretationExprVal; @@ -12094,18 +12094,19 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, return true; } - // Check Matrix Layout is constant and valid + // Check Matrix Layout must be a constant and Training Optimal Expr *MatrixLayoutExpr = CE->getArg(kOuterProdAccMatrixLayoutIdx); llvm::APSInt MatrixLayoutExprVal; unsigned MatrixLayoutValue = 0; if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - if (!CheckMatrixLayoutForOuterProductAccumulate( - MatrixInterpretationValue)) { + if (!CheckMatrixLayoutForOuterProductAccumulate(MatrixLayoutValue)) { S.Diags.Report( MatrixLayoutExpr->getExprLoc(), diag:: - err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal); + err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal) + << std::to_string(static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); } } else { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), @@ -12114,7 +12115,7 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, return true; } - // Check Matrix Stide is zero (Training Optimal) + // Matrix Stride must be zero (Training Optimal matrix layout) Expr *MatrixStrideExpr = CE->getArg(kOuterProdAccMatrixStrideIdx); llvm::APSInt MatrixStrideExprVal; unsigned MatrixStrideValue = 0; @@ -12192,6 +12193,12 @@ void Sema::CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, case hlsl::IntrinsicOp::IOP___builtin_MatVecMul: CheckMulCall(*this, FDecl, TheCall, SM); break; + case hlsl::IntrinsicOp::IOP___builtin_MatVecMulAdd: + CheckMulAddCall(*this, FDecl, TheCall, SM); + break; + case hlsl::IntrinsicOp::IOP___builtin_OuterProductAccumulate: + CheckOuterProductAccumulateCall(*this, FDecl, TheCall); + break; #ifdef ENABLE_SPIRV_CODEGEN case hlsl::IntrinsicOp::IOP_Vkreinterpret_pointer_cast: CheckVKBufferPointerCast(*this, FDecl, TheCall, false); From 4d751a78e91d119649a2555ba31962c547d6219d Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 30 Apr 2025 12:03:50 -0700 Subject: [PATCH 08/50] Clang Format --- tools/clang/lib/Sema/SemaHLSL.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index cc11b9787a..d6d4eba7a8 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -12064,7 +12064,8 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, const QualType InputVector2ElementType = GetHLSLVecElementType(InputVector2Type); - if (!S.Context.hasSameType(InputVector1ElementType, InputVector2ElementType)) { + if (!S.Context.hasSameType(InputVector1ElementType, + InputVector2ElementType)) { S.Diags.Report(InputVector1Expr->getExprLoc(), diag::err_hlsl_linalg_outer_prod_acc_vector_type_mismatch); return true; From 02cb085a3aac9764976b0b09bbc2abc0e2b881a8 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 2 May 2025 07:45:53 -0700 Subject: [PATCH 09/50] Fix error location and add tests --- tools/clang/lib/Sema/SemaHLSL.cpp | 44 +++--- .../SemaHLSL/hlsl/linalg/builtins/mul.hlsl | 139 ++++++++++++++++++ 2 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index d6d4eba7a8..26fac9ca92 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11695,11 +11695,6 @@ bool CheckMatrixLayoutForMulandMulAddOps(unsigned Layout) { MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); } -bool CheckMatrixLayoutForOuterProductAccumulate(unsigned Layout) { - return Layout == static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); -} - bool CheckTransposeForMatrixLayout(unsigned Layout, bool Transposed) { switch (static_cast(Layout)) { case MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR: @@ -11728,9 +11723,9 @@ enum DataType { // (1 sign, 5 exp, 2 mantissa bits) }; -bool IsPackedType(DataType type) { - return (type == DATA_TYPE_SINT8_T4_PACKED || - type == DATA_TYPE_UINT8_T4_PACKED); +bool IsPackedType(unsigned type) { + return (type == static_cast(DATA_TYPE_SINT8_T4_PACKED) || + type == static_cast(DATA_TYPE_UINT8_T4_PACKED)); } static bool CheckLinalgTypeInterpretation(uint32_t Input, bool InRegister) { @@ -11762,8 +11757,9 @@ static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, bool isInputPacked) { // Check is output vector size is equals to matrix dimension M if (OutputVectorSize != MatrixM) { + Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); S.Diags.Report( - CE->getExprLoc(), + OutputVector->getExprLoc(), diag::err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M); return true; } @@ -11771,12 +11767,15 @@ static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, const unsigned PackingFactor = isInputPacked ? 4 : 1; unsigned MinInputVectorSize = (MatrixK + PackingFactor - 1) / PackingFactor; if (InputVectorSize != MinInputVectorSize) { + Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); if (isInputPacked) { - S.Diags.Report(CE->getExprLoc(), + S.Diags.Report(InputVector->getExprLoc(), diag::err_hlsl_linalg_packed_input_vector_size_incorrect); } else { - S.Diags.Report(CE->getExprLoc(), - diag::err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K); + S.Diags.Report( + InputVector->getExprLoc(), + diag:: + err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K); } return true; } @@ -11785,7 +11784,7 @@ static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, const hlsl::ShaderModel *SM) { - // Find OutputVectorType and Size and check IsUnsigned + // Check if IsOutputUnsigned is a const parameter bool IsOutputUnsignedFlagValue = false; Expr *IsOutputUnsignedExpr = CE->getArg(kMatVecMulOutputIsUnsignedIdx); llvm::APSInt IsOutputUnsignedExprVal; @@ -11798,7 +11797,8 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << "IsOutputUnsigned"; return true; } - + // Check if IsOutputUnsigned flag matches output vector type. + // Must be true for unsigned int outputs, false for signed int/float outputs. Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); unsigned OutputVectorSizeValue = 0; if (IsHLSLVecType(OutputVector->getType())) { @@ -11823,7 +11823,6 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << (OutputVectorTypePtr->isSignedIntegerType() ? "signed int" : "float"); return true; - } else if (!IsOutputUnsignedFlagValue && OutputVectorTypePtr->isUnsignedIntegerType()) { S.Diags.Report(OutputVector->getExprLoc(), @@ -11915,7 +11914,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, const bool InRegisterInterpretation = true; if (!CheckLinalgTypeInterpretation(InputInterpretationValue, InRegisterInterpretation)) { - S.Diags.Report(MatrixMExpr->getExprLoc(), + S.Diags.Report(InputInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(InputInterpretationValue) << InRegisterInterpretation; @@ -11928,8 +11927,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return true; } - bool isInputPacked = - IsPackedType(static_cast(InputInterpretationValue)); + bool isInputPacked = IsPackedType(InputInterpretationValue); CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, @@ -11946,7 +11944,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, const bool InRegisterInterpretation = false; if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, InRegisterInterpretation)) { - S.Diags.Report(MatrixMExpr->getExprLoc(), + S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(MatrixInterpretationValue) << InRegisterInterpretation; @@ -12015,7 +12013,7 @@ static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, const hlsl::ShaderModel *SM) { CheckCommonMulandMulAddParameters(S, CE, SM); - // Check Bias Parameters + // Check if BiasInterpretation is constant and a valid value Expr *BiasInterpretationExpr = CE->getArg(kMatVecMulAddBiasInterpretation); llvm::APSInt BiasInterpretationExprVal; unsigned BiasInterpretationValue = 0; @@ -12066,7 +12064,7 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, if (!S.Context.hasSameType(InputVector1ElementType, InputVector2ElementType)) { - S.Diags.Report(InputVector1Expr->getExprLoc(), + S.Diags.Report(InputVector2Expr->getExprLoc(), diag::err_hlsl_linalg_outer_prod_acc_vector_type_mismatch); return true; } @@ -12101,7 +12099,9 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, unsigned MatrixLayoutValue = 0; if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - if (!CheckMatrixLayoutForOuterProductAccumulate(MatrixLayoutValue)) { + if (MatrixLayoutValue != + static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)) { S.Diags.Report( MatrixLayoutExpr->getExprLoc(), diag:: diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl new file mode 100644 index 0000000000..57de3864a6 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl @@ -0,0 +1,139 @@ +// RUN: %dxc -T lib_6_ -E main %s | FileCheck %s + +ByteAddressBuffer input_vector_buffer; +ByteAddressBuffer matrix_buffer; +RWByteAddressBuffer output_vector_buffer; + +// CHECK: error: __builtin_MatVecMul: first parameter must be numeric vector +void test_mul_non_numeric() { + vector output_vector; // Changed from bool to int vector + vector input_vector = input_vector_buffer.Load>(0); + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: first parameter must be numeric vector}} +} + +// CHECK: error: __builtin_MatVecMul: input vector must be numeric +void test_mul_non_numeric2() { + vector output_vector; + vector input_vector; // Using bool vector to trigger error + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: input vector must be numeric}} +} + +// CHECK: error: __builtin_MatVecMul: matrix buffer must be valid +struct MyStruct { int x; }; +void test_mul_invalid_buffer() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); + MyStruct s; + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, s, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix buffer must be valid}} +} + +// CHECK: error: __builtin_MatVecMul: matrix dimensions must be positive +void test_mul_invalid_dims() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 0; + const uint matrix_dimK = 0; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix dimensions must be positive}} +} + +// CHECK: error: __builtin_MatVecMul: matrix stride must be positive +void test_mul_invalid_stride() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix stride must be positive}} +} + +[numthreads(1,1,1)] +void main() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); + output_vector_buffer.Store(0, output_vector); +} + + + + + From 969d7e64e0a93f9fa4b88669886d241eb8868726 Mon Sep 17 00:00:00 2001 From: anupamac Date: Sun, 4 May 2025 16:26:45 -0700 Subject: [PATCH 10/50] More validation tests --- .../clang/Basic/DiagnosticSemaKinds.td | 6 +- tools/clang/lib/Sema/SemaHLSL.cpp | 202 +++++++---- .../SemaHLSL/hlsl/linalg/builtins/mul.hlsl | 139 -------- .../hlsl/linalg/builtins/mul_invalid.hlsl | 330 ++++++++++++++++++ .../hlsl/linalg/builtins/mul_valid.hlsl | 119 +++++++ 5 files changed, 587 insertions(+), 209 deletions(-) delete mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 60542f2089..5087953a57 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8017,7 +8017,7 @@ def err_hlsl_hitobject_unsupported_stage : Error< // Linear Algebra Operations def err_hlsl_linalg_param_must_be_const : Error<" '%0' must be a constant parameter">; -def err_hlsl_linalg_incorrect_type : Error<"%0 is incorrect type, must be 'unsigned int', 'signed int' or 'float'">; +def err_hlsl_linalg_incorrect_type : Error<"%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'">; def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %select{false|true}1 for a %2 vector type">; def err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; def err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; @@ -8027,7 +8027,9 @@ def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"input vectors of outerproductaccumulate must have the same element type">; def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout for outerproductaccumulate must be %0">; -def err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero : Error<"matrix stride must be zero for outerproductaccumulate optimal matrix layout">; +def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error<"for optimal matrix layout, matrix stride must be zero">; +def err_hlsl_linalg_exceeds_max_matrix_dim: Error<"matrix dimension for linalg operations must be less than %0">; +def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error<"matrix dimension must not be zero">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 26fac9ca92..a4eb3bbf66 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11690,12 +11690,19 @@ enum MatrixLayout { MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 }; -bool CheckMatrixLayoutForMulandMulAddOps(unsigned Layout) { +bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) { return Layout <= static_cast( MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); } -bool CheckTransposeForMatrixLayout(unsigned Layout, bool Transposed) { +bool IsOptimalTypeMatrixLayout(unsigned Layout) { + return Layout == + (static_cast(MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL) || + Layout == (static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL))); +} + +bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) { switch (static_cast(Layout)) { case MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR: case MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR: @@ -11728,7 +11735,7 @@ bool IsPackedType(unsigned type) { type == static_cast(DATA_TYPE_UINT8_T4_PACKED)); } -static bool CheckLinalgTypeInterpretation(uint32_t Input, bool InRegister) { +static bool IsValidLinalgTypeInterpretation(uint32_t Input, bool InRegister) { switch (Input) { case DATA_TYPE_SINT16: @@ -11750,18 +11757,18 @@ static bool CheckLinalgTypeInterpretation(uint32_t Input, bool InRegister) { } } -static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, - unsigned InputVectorSize, - unsigned OutputVectorSize, - unsigned MatrixK, unsigned MatrixM, - bool isInputPacked) { +static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, + unsigned InputVectorSize, + unsigned OutputVectorSize, + unsigned MatrixK, unsigned MatrixM, + bool isInputPacked) { // Check is output vector size is equals to matrix dimension M if (OutputVectorSize != MatrixM) { Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); S.Diags.Report( OutputVector->getExprLoc(), diag::err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M); - return true; + return false; } const unsigned PackingFactor = isInputPacked ? 4 : 1; @@ -11771,18 +11778,20 @@ static bool CheckVectorAndMatrixDimensions(Sema &S, CallExpr *CE, if (isInputPacked) { S.Diags.Report(InputVector->getExprLoc(), diag::err_hlsl_linalg_packed_input_vector_size_incorrect); + return false; } else { S.Diags.Report( InputVector->getExprLoc(), diag:: err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K); + return false; } - return true; } - return false; + + return true; } -static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, +static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, const hlsl::ShaderModel *SM) { // Check if IsOutputUnsigned is a const parameter bool IsOutputUnsignedFlagValue = false; @@ -11795,7 +11804,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "IsOutputUnsigned"; - return true; + return; } // Check if IsOutputUnsigned flag matches output vector type. // Must be true for unsigned int outputs, false for signed int/float outputs. @@ -11811,6 +11820,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(OutputVector->getExprLoc(), diag::err_hlsl_linalg_incorrect_type) << "Output Vector"; + return; } if (IsOutputUnsignedFlagValue && @@ -11822,13 +11832,13 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << "IsOuputUnsigned" << false << (OutputVectorTypePtr->isSignedIntegerType() ? "signed int" : "float"); - return true; + return; } else if (!IsOutputUnsignedFlagValue && OutputVectorTypePtr->isUnsignedIntegerType()) { S.Diags.Report(OutputVector->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsOuputUnsigned" << true << "unsigned int"; - return true; + return; } } @@ -11843,7 +11853,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "IsInputUnsigned"; - return true; + return; } Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); @@ -11851,6 +11861,17 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (IsHLSLVecType(InputVector->getType())) { InputVectorSizeValue = GetHLSLVecSize(InputVector->getType()); QualType InputVectorType = GetHLSLVecElementType(InputVector->getType()); + unsigned BitWidth = S.Context.getTypeSize(InputVectorType); + bool Is16Bit = (BitWidth == 16); + bool Is32Bit = (BitWidth == 32); + + if (!Is16Bit && !Is32Bit) { + S.Diags.Report(InputVector->getExprLoc(), + diag::err_hlsl_linalg_incorrect_type) + << "Input Vector"; + return; + } + const Type *InputVectorTypePtr = InputVectorType.getTypePtr(); if (!InputVectorTypePtr->isUnsignedIntegerType() && !InputVectorTypePtr->isSignedIntegerType() && @@ -11858,27 +11879,28 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(InputVector->getExprLoc(), diag::err_hlsl_linalg_incorrect_type) << "Input Vector"; + return; } if (IsInputUnsignedFlagValue && !InputVectorTypePtr->isUnsignedIntegerType()) { DXASSERT_NOMSG(InputVectorTypePtr->isSignedIntegerType() || InputVectorTypePtr->isFloatingType()); - S.Diags.Report(InputVector->getExprLoc(), + S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsInputUnsigned" << false << (InputVectorTypePtr->isSignedIntegerType() ? "signed int" : "float"); - return true; - + return; } else if (!IsInputUnsignedFlagValue && InputVectorTypePtr->isUnsignedIntegerType()) { - S.Diags.Report(InputVector->getExprLoc(), + S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsInputUnsigned" << true << "unsigned int"; - return true; + return; } } + // Get Matrix Dimensions M and K, check if they are constants Expr *MatrixKExpr = CE->getArg(kMatVecMulMatrixKIdx); llvm::APSInt MatrixKExprVal; @@ -11889,7 +11911,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(MatrixKExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixK"; - return true; + return; } Expr *MatrixMExpr = CE->getArg(kMatVecMulMatrixMIdx); @@ -11901,9 +11923,41 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(MatrixMExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixM"; - return true; + return; + } + + // Check MatrixM and MatrixK values are non-zero + if (MatrixMValue == 0) { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_matrix_dim_must_not_be_zero) + << std::to_string(DXIL::kSM69MaxVectorLength); + return; + } + + if (MatrixKValue == 0) { + S.Diags.Report(MatrixKExpr->getExprLoc(), + diag::err_hlsl_linalg_matrix_dim_must_not_be_zero) + << std::to_string(DXIL::kSM69MaxVectorLength); + return; + } + + // Check MatrixM and MatrixK values are less than max + // Matrix dimension cannot exceed largest vector length in a Mul/MulAdd + // operation + if (MatrixMValue > DXIL::kSM69MaxVectorLength) { + S.Diags.Report(MatrixMExpr->getExprLoc(), + diag::err_hlsl_linalg_exceeds_max_matrix_dim) + << std::to_string(DXIL::kSM69MaxVectorLength); + return; + } + + if (MatrixKValue > DXIL::kSM69MaxVectorLength) { + S.Diags.Report(MatrixKExpr->getExprLoc(), + diag::err_hlsl_linalg_exceeds_max_matrix_dim) + << std::to_string(DXIL::kSM69MaxVectorLength); + return; } - + // Get InputInterpretation, check if it is constant Expr *InputInterpretationExpr = CE->getArg(kMatVecMulInputInterpretationIdx); llvm::APSInt InputInterpretationExprVal; @@ -11912,26 +11966,28 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Context)) { InputInterpretationValue = InputInterpretationExprVal.getLimitedValue(); const bool InRegisterInterpretation = true; - if (!CheckLinalgTypeInterpretation(InputInterpretationValue, - InRegisterInterpretation)) { + if (!IsValidLinalgTypeInterpretation(InputInterpretationValue, + InRegisterInterpretation)) { S.Diags.Report(InputInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(InputInterpretationValue) << InRegisterInterpretation; - return true; + return; } } else { S.Diags.Report(InputInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "InputInterpretation"; - return true; + return; } bool isInputPacked = IsPackedType(InputInterpretationValue); - CheckVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, - OutputVectorSizeValue, MatrixKValue, - MatrixMValue, isInputPacked); + if (!IsValidVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, + OutputVectorSizeValue, MatrixKValue, + MatrixMValue, isInputPacked)) { + return; + } // Get MatrixInterpretation, check if it is constant Expr *MatrixInterpretationExpr = @@ -11942,19 +11998,19 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, MatrixInterpretationExprVal, S.Context)) { MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); const bool InRegisterInterpretation = false; - if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, - InRegisterInterpretation)) { + if (!IsValidLinalgTypeInterpretation(MatrixInterpretationValue, + InRegisterInterpretation)) { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(MatrixInterpretationValue) << InRegisterInterpretation; - return true; + return; } } else { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixInterpretation"; - return true; + return; } // Get MatrixLayout, check if it is constant @@ -11963,7 +12019,7 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, unsigned MatrixLayoutValue = 0; if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - if (!CheckMatrixLayoutForMulandMulAddOps(MatrixInterpretationValue)) { + if (!IsValidMatrixLayoutForMulandMulAddOps(MatrixLayoutValue)) { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_hlsl_linalg_matrix_layout_for_mul_ops_invalid) << std::to_string(MatrixLayoutValue) @@ -11971,12 +12027,13 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) << std::to_string(static_cast( MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + return; } } else { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixLayout"; - return true; + return; } // Get MatrixTranspose, check if it is constant @@ -11986,30 +12043,43 @@ static bool CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (MatrixTransposeExpr->isIntegerConstantExpr(MatrixTransposeExprVal, S.Context)) { MatrixTransposeValue = MatrixTransposeExprVal.getBoolValue(); - if (!CheckTransposeForMatrixLayout(MatrixLayoutValue, - MatrixTransposeValue)) { + if (!IsValidTransposeForMatrixLayout(MatrixLayoutValue, + MatrixTransposeValue)) { S.Diags.Report(MatrixTransposeExpr->getExprLoc(), diag::err_hlsl_linalg_matrix_layout_is_not_transposable); + return; } } else { S.Diags.Report(MatrixTransposeExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixTranspose"; - return true; + return; } - return false; + // Get MatrixStride, check if it is constant + Expr *MatrixStrideExpr = CE->getArg(kMatVecMulMatrixStrideIdx); + llvm::APSInt MatrixStrideExprVal; + unsigned MatrixStrideValue = 0; + if (MatrixStrideExpr->isIntegerConstantExpr(MatrixStrideExprVal, S.Context)) { + MatrixStrideValue = MatrixStrideExprVal.getLimitedValue(); + if (IsOptimalTypeMatrixLayout(MatrixLayoutValue) && + MatrixStrideValue != 0) { + S.Diags.Report( + MatrixStrideExpr->getExprLoc(), + diag:: + err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero); + return; + } + } } -static bool CheckMulCall(Sema &S, FunctionDecl *FD, CallExpr *CE, +static void CheckMulCall(Sema &S, FunctionDecl *FD, CallExpr *CE, const hlsl::ShaderModel *SM) { CheckCommonMulandMulAddParameters(S, CE, SM); - - return false; } -static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, +static void CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, const hlsl::ShaderModel *SM) { CheckCommonMulandMulAddParameters(S, CE, SM); @@ -12021,21 +12091,20 @@ static bool CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, S.Context)) { BiasInterpretationValue = BiasInterpretationExprVal.getLimitedValue(); const bool InRegisterInterpretation = false; - if (!CheckLinalgTypeInterpretation(BiasInterpretationValue, - InRegisterInterpretation)) { + if (!IsValidLinalgTypeInterpretation(BiasInterpretationValue, + InRegisterInterpretation)) { S.Diags.Report(BiasInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(BiasInterpretationValue) << InRegisterInterpretation; - return true; + return; } } else { S.Diags.Report(BiasInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "BiasInterpretation"; - return true; + return; } - return false; } // Linalg Outer Product Accumulate @@ -12048,7 +12117,7 @@ static const unsigned kOuterProdAccMatrixInterpretationIdx = 4; static const unsigned kOuterProdAccMatrixLayoutIdx = 5; static const unsigned kOuterProdAccMatrixStrideIdx = 6; -static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, +static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE) { // Check InputVector1 and InputVector2 are the same type const Expr *InputVector1Expr = CE->getArg(kOuterProdAccInputVector1Idx); @@ -12066,7 +12135,7 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, InputVector2ElementType)) { S.Diags.Report(InputVector2Expr->getExprLoc(), diag::err_hlsl_linalg_outer_prod_acc_vector_type_mismatch); - return true; + return; } // Check Matrix Interpretation is a constant and a valid value @@ -12078,19 +12147,19 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, MatrixInterpretationExprVal, S.Context)) { MatrixInterpretationValue = MatrixInterpretationExprVal.getLimitedValue(); const bool InRegisterInterpretation = false; - if (!CheckLinalgTypeInterpretation(MatrixInterpretationValue, - InRegisterInterpretation)) { + if (!IsValidLinalgTypeInterpretation(MatrixInterpretationValue, + InRegisterInterpretation)) { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_interpretation_value_incorrect) << std::to_string(MatrixInterpretationValue) << InRegisterInterpretation; - return true; + return; } } else { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixInterpretation"; - return true; + return; } // Check Matrix Layout must be a constant and Training Optimal @@ -12108,12 +12177,13 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal) << std::to_string(static_cast( MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + return; } } else { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_hlsl_linalg_param_must_be_const) << "MatrixLayout"; - return true; + return; } // Matrix Stride must be zero (Training Optimal matrix layout) @@ -12125,24 +12195,20 @@ static bool CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, if (MatrixStrideValue != 0) { S.Diags.Report( MatrixStrideExpr->getExprLoc(), - diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); - return true; + diag:: + err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero); + return; } } else { S.Diags.Report( MatrixStrideExpr->getExprLoc(), - diag::err_hlsl_linalg_outer_prod_acc_matrix_stride_must_be_zero); - return true; + diag::err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero); + return; } - - return false; } -static bool CheckVectorAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, - const hlsl::ShaderModel *SM) { - - return false; -} +static void CheckVectorAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, + const hlsl::ShaderModel *SM) {} #ifdef ENABLE_SPIRV_CODEGEN static bool CheckVKBufferPointerCast(Sema &S, FunctionDecl *FD, CallExpr *CE, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl deleted file mode 100644 index 57de3864a6..0000000000 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul.hlsl +++ /dev/null @@ -1,139 +0,0 @@ -// RUN: %dxc -T lib_6_ -E main %s | FileCheck %s - -ByteAddressBuffer input_vector_buffer; -ByteAddressBuffer matrix_buffer; -RWByteAddressBuffer output_vector_buffer; - -// CHECK: error: __builtin_MatVecMul: first parameter must be numeric vector -void test_mul_non_numeric() { - vector output_vector; // Changed from bool to int vector - vector input_vector = input_vector_buffer.Load>(0); - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: first parameter must be numeric vector}} -} - -// CHECK: error: __builtin_MatVecMul: input vector must be numeric -void test_mul_non_numeric2() { - vector output_vector; - vector input_vector; // Using bool vector to trigger error - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: input vector must be numeric}} -} - -// CHECK: error: __builtin_MatVecMul: matrix buffer must be valid -struct MyStruct { int x; }; -void test_mul_invalid_buffer() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); - MyStruct s; - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, s, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix buffer must be valid}} -} - -// CHECK: error: __builtin_MatVecMul: matrix dimensions must be positive -void test_mul_invalid_dims() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 0; - const uint matrix_dimK = 0; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix dimensions must be positive}} -} - -// CHECK: error: __builtin_MatVecMul: matrix stride must be positive -void test_mul_invalid_stride() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 0; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); // expected-error {{__builtin_MatVecMul: matrix stride must be positive}} -} - -[numthreads(1,1,1)] -void main() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); - output_vector_buffer.Store(0, output_vector); -} - - - - - diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl new file mode 100644 index 0000000000..3fb0791845 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -0,0 +1,330 @@ +// RUN: %dxc -T lib_6_ -E main %s | FileCheck %s + +ByteAddressBuffer input_vector_buffer; +ByteAddressBuffer matrix_buffer; +RWByteAddressBuffer output_vector_buffer; +ByteAddressBuffer constants_buffer; + +// Output vector, isUnsigned mismatch +void test_invalid_output_vector_type() { + + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector output_vector_0; + const uint is_output_unsigned_0 = 0; + + // expected-error@+1 {{IsOuputUnsigned must be true for a unsigned int vector type}} + __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector output_vector_1; + const uint is_output_unsigned_1 = 1; + + // expected-error@+1 {{IsOuputUnsigned must be false for a signed int vector type}} + __builtin_MatVecMul(output_vector_1, is_output_unsigned_1, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector output_vector_2; + const uint is_output_unsigned_2 = 1; + + // expected-error@+1 {{IsOuputUnsigned must be false for a float vector type}} + __builtin_MatVecMul(output_vector_2, is_output_unsigned_2, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// IsOutputUnsigned is not a constant parameter +void test_invalid_is_output_unsigned_non_const() { + + vector output_vector_0; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint is_output_unsigned_0 = constants_buffer.Load(0); + + // expected-error@+1 {{IsOutputUnsigned' must be a constant parameter}} + __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Input vector is incorrect type - 64 bit types +void test_invalid_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Input vector type/isInputUnsigned mismatch +void test_invalid_input_vector_type_mismatch() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for a unsigned int vector type}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-error@+2 {{IsInputUnsigned must be false for a signed int vector type}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 1; + + // expected-error@+2 {{IsInputUnsigned must be false for a float vector type}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check is Matrix M dimension is a constant parameter +void test_invalid_matrix_M_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_dimM = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixM' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check is Matrix K dimension is a constant parameter +void test_invalid_matrix_K_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_dimK = constants_buffer.Load(0); + + // expected-error@+4 {{'MatrixK' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} +/* +// + +// CHECK: error: __builtin_MatVecMul: input vector must be numeric +void test_mul_non_numeric2() { + vector output_vector; + vector input_vector; // Using bool vector to trigger error + const uint is_output_unsigned = 0; + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); +} + +// CHECK: error: __builtin_MatVecMul: matrix buffer must be valid +struct MyStruct { int x; }; +void test_mul_invalid_buffer() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); MyStruct s; const uint is_output_unsigned = 0; const uint +is_input_unsigned = 0; const uint input_interpretation = 9; // F32 const uint +matrix_offset = 0; const uint matrix_interpretation = 9; // F32 const uint +matrix_dimM = 4; const uint matrix_dimK = 4; const uint matrix_layout = 0; // +RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, s, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); +} + +// CHECK: error: __builtin_MatVecMul: matrix dimensions must be positive +void test_mul_invalid_dims() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 0; + const uint matrix_dimK = 0; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); +} + +// CHECK: error: __builtin_MatVecMul: matrix stride must be positive +void test_mul_invalid_stride() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); +} + +[numthreads(1,1,1)] +void main() { + vector output_vector; + vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); + output_vector_buffer.Store(0, output_vector); +} + +#endif // 0 +*/ diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl new file mode 100644 index 0000000000..c6218a88c0 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -0,0 +1,119 @@ +ByteAddressBuffer input_vector_buffer; +ByteAddressBuffer matrix_buffer; +RWByteAddressBuffer output_vector_buffer; +ByteAddressBuffer const_buffer; + +// Output vector, isUnsigned mismatch +void test_invalid_output_vector_type() { + + vector input_vector = input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector output_vector_0; + const uint is_output_unsigned_0 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); + + vector output_vector_1; + const uint is_output_unsigned_1 = 0; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector_1, is_output_unsigned_1, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); + + vector output_vector_2; + const uint is_output_unsigned_2 = 0; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector_2, is_output_unsigned_2, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, + matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, + matrix_is_transposed, matrix_stride); +} + +void test_invalid_is_output_unsigned_non_const() { + + vector output_vector_0; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint is_output_unsigned_0 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Input vector is incorrect type +void test_valid_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} From f132c60979ab3926b81658407d413cdbf498c197 Mon Sep 17 00:00:00 2001 From: anupamac Date: Sun, 4 May 2025 16:34:38 -0700 Subject: [PATCH 11/50] Check Matrix dimensions are not zero --- .../hlsl/linalg/builtins/mul_invalid.hlsl | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 3fb0791845..c4d09ea7b5 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -224,9 +224,58 @@ void test_invalid_matrix_K_dimension() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); } -/* -// +// Check is Matrix M dimension is non-zero +void test_invalid_matrix_M_dimension_non_zero() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimK = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_dimM = 0; + // expected-error@+3 {{matrix dimension must not be zero}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check is Matrix K dimension is non-zero +void test_invalid_matrix_K_dimension_non_zero() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = 9; // F32 + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = 9; // F32 + const uint matrix_dimM = 4; + const uint matrix_layout = 0; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_dimK = 0; + // expected-error@+4 {{matrix dimension must not be zero}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +/* // CHECK: error: __builtin_MatVecMul: input vector must be numeric void test_mul_non_numeric2() { vector output_vector; From 3c192971baefb3680fd493b7728d8d53e6cab0c7 Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 5 May 2025 04:52:00 -0700 Subject: [PATCH 12/50] More tests --- .../clang/Basic/DiagnosticSemaKinds.td | 18 +- tools/clang/lib/Sema/SemaHLSL.cpp | 41 +- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 239 +++++++ .../hlsl/linalg/builtins/mul_invalid.hlsl | 655 ++++++++++++++---- .../hlsl/linalg/builtins/mul_valid.hlsl | 8 +- .../outer_product_accumulate_invalid.hlsl | 287 ++++++++ .../outer_product_accumulate_valid.hlsl | 97 +++ 7 files changed, 1197 insertions(+), 148 deletions(-) create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5087953a57..b762a691a0 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8017,19 +8017,21 @@ def err_hlsl_hitobject_unsupported_stage : Error< // Linear Algebra Operations def err_hlsl_linalg_param_must_be_const : Error<" '%0' must be a constant parameter">; -def err_hlsl_linalg_incorrect_type : Error<"%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'">; +def err_hlsl_linalg_vector_incorrect_type : Error<"%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'">; def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %select{false|true}1 for a %2 vector type">; -def err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; -def err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; -def err_hlsl_linalg_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; -def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretaion value">; -def err_hlsl_linalg_matrix_layout_for_mul_ops_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; +def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretation value">; def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; -def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"input vectors of outerproductaccumulate must have the same element type">; -def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout for outerproductaccumulate must be %0">; def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error<"for optimal matrix layout, matrix stride must be zero">; def err_hlsl_linalg_exceeds_max_matrix_dim: Error<"matrix dimension for linalg operations must be less than %0">; def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error<"matrix dimension must not be zero">; +def err_hlsl_linalg_matrix_layout_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; + +def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; + +def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"input vectors of outerproductaccumulate must have the same element type">; +def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout for outerproductaccumulate must be %0">; // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index a4eb3bbf66..3b8ea9a306 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11696,10 +11696,10 @@ bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) { } bool IsOptimalTypeMatrixLayout(unsigned Layout) { - return Layout == - (static_cast(MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL) || - Layout == (static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL))); + return (Layout == (static_cast( + MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL)) || + (Layout == (static_cast( + MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)))); } bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) { @@ -11767,7 +11767,8 @@ static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); S.Diags.Report( OutputVector->getExprLoc(), - diag::err_hlsl_linalg_output_vector_size_not_equal_to_matrix_M); + diag:: + err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M); return false; } @@ -11776,14 +11777,15 @@ static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, if (InputVectorSize != MinInputVectorSize) { Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); if (isInputPacked) { - S.Diags.Report(InputVector->getExprLoc(), - diag::err_hlsl_linalg_packed_input_vector_size_incorrect); + S.Diags.Report( + InputVector->getExprLoc(), + diag::err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect); return false; } else { S.Diags.Report( InputVector->getExprLoc(), diag:: - err_hlsl_linalg_unpacked_input_vector_size_not_equal_to_matrix_K); + err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K); return false; } } @@ -11818,7 +11820,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, !OutputVectorTypePtr->isSignedIntegerType() && !OutputVectorTypePtr->isFloatingType()) { S.Diags.Report(OutputVector->getExprLoc(), - diag::err_hlsl_linalg_incorrect_type) + diag::err_hlsl_linalg_vector_incorrect_type) << "Output Vector"; return; } @@ -11867,7 +11869,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (!Is16Bit && !Is32Bit) { S.Diags.Report(InputVector->getExprLoc(), - diag::err_hlsl_linalg_incorrect_type) + diag::err_hlsl_linalg_vector_incorrect_type) << "Input Vector"; return; } @@ -11877,7 +11879,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, !InputVectorTypePtr->isSignedIntegerType() && !InputVectorTypePtr->isFloatingType()) { S.Diags.Report(InputVector->getExprLoc(), - diag::err_hlsl_linalg_incorrect_type) + diag::err_hlsl_linalg_vector_incorrect_type) << "Input Vector"; return; } @@ -11983,6 +11985,10 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, bool isInputPacked = IsPackedType(InputInterpretationValue); + // FIXME: Add check for if input vector is packed type then + // input interpretation has to be the corresponding pack type. + // Packed type show up as floats? + if (!IsValidVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, MatrixMValue, isInputPacked)) { @@ -12021,7 +12027,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); if (!IsValidMatrixLayoutForMulandMulAddOps(MatrixLayoutValue)) { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_matrix_layout_for_mul_ops_invalid) + diag::err_hlsl_linalg_matrix_layout_invalid) << std::to_string(MatrixLayoutValue) << std::to_string( static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) @@ -12057,7 +12063,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } - // Get MatrixStride, check if it is constant + // Get MatrixStride, check if it is constant, if yes it should be zero + // for optimal layouts Expr *MatrixStrideExpr = CE->getArg(kMatVecMulMatrixStrideIdx); llvm::APSInt MatrixStrideExprVal; unsigned MatrixStrideValue = 0; @@ -12199,17 +12206,9 @@ static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero); return; } - } else { - S.Diags.Report( - MatrixStrideExpr->getExprLoc(), - diag::err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero); - return; } } -static void CheckVectorAccumulateCall(Sema &S, FunctionDecl *FD, CallExpr *CE, - const hlsl::ShaderModel *SM) {} - #ifdef ENABLE_SPIRV_CODEGEN static bool CheckVKBufferPointerCast(Sema &S, FunctionDecl *FD, CallExpr *CE, bool isStatic) { diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl new file mode 100644 index 0000000000..14e24be8a3 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -0,0 +1,239 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify + +enum CompType { + Invalid = 0, + I1 = 1, + I16 = 2, + U16 = 3, + I32 = 4, + U32 = 5, + I64 = 6, + U64 = 7, + F16 = 8, + F32 = 9, + F64 = 10, + SNormF16 = 11, + UNormF16 = 12, + SNormF32 = 13, + UNormF32 = 14, + SNormF64 = 15, + UNormF64 = 16, + PackedS8x32 = 17, + PackedU8x32 = 18, + + // BEGIN NEW FOR SM 6.9 + U8 = 19, + I8 = 20, + F8_E4M3 = 21, + F8_E5M2 = 22, +}; + +enum MatLayout { + RowMajor = 0, + ColumnMajor = 1, + MulOptimal = 2, + OuterProductOptimal = 3, +}; + +ByteAddressBuffer input_vector_buffer; +ByteAddressBuffer matrix_buffer; +ByteAddressBuffer bias_buffer; +RWByteAddressBuffer output_vector_buffer; +ByteAddressBuffer constants_buffer; + +// Check bias interpretation is not a constant value +void test_invalid_bias_interpretation() { + vector output_vector; + const uint is_output_unsigned = 0; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_is_transposed = 0; + const uint matrix_stride = 0; + const uint bias_offset = 0; + + const uint bias_interpretation_0 = constants_buffer.Load(0); + + // expected-error@+6 {{'BiasInterpretation' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_0); +} + +// Check bias interpretation is not a valid value +void test_invalid_bias_interpretation_value() { + vector output_vector; + const uint is_output_unsigned = 0; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_is_transposed = 0; + const uint matrix_stride = 0; + const uint bias_offset = 0; + + const uint bias_interpretation_0 = CompType::Invalid; + + // expected-error@+6 {{0 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_0); + + const uint bias_interpretation_1 = CompType::I1; + + // expected-error@+6 {{1 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_1); + + const uint bias_interpretation_2 = CompType::I64; + + // expected-error@+6 {{6 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_2); + + const uint bias_interpretation_3 = CompType::U64; + + // expected-error@+6 {{7 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_3); + + const uint bias_interpretation_4 = CompType::F64; + + // expected-error@+6 {{10 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_4); + + const uint bias_interpretation_5 = CompType::SNormF16; + + // expected-error@+6 {{11 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_5); + + const uint bias_interpretation_6 = CompType::UNormF16; + + // expected-error@+6 {{12 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_6); + + const uint bias_interpretation_7 = CompType::SNormF32; + + // expected-error@+6 {{13 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_7); + + const uint bias_interpretation_8 = CompType::UNormF32; + + // expected-error@+6 {{14 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_8); + + const uint bias_interpretation_9 = CompType::SNormF64; + + // expected-error@+6 {{15 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_9); + + const uint bias_interpretation_10 = CompType::UNormF64; + + + // expected-error@+6 {{16 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_10); + + const uint bias_interpretation_11 = CompType::PackedS8x32; + + // expected-error@+6 {{17 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_11); + + const uint bias_interpretation_12 = CompType::PackedU8x32; + + // expected-error@+6 {{18 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_12); + + const uint bias_interpretation_13 = 23; + + // expected-error@+6 {{23 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_13); + + const uint bias_interpretation_14 = 100; + + // expected-error@+6 {{100 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, + bias_interpretation_14); + } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index c4d09ea7b5..aa70ed3f8d 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -1,4 +1,39 @@ -// RUN: %dxc -T lib_6_ -E main %s | FileCheck %s +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify + +enum CompType { + Invalid = 0, + I1 = 1, + I16 = 2, + U16 = 3, + I32 = 4, + U32 = 5, + I64 = 6, + U64 = 7, + F16 = 8, + F32 = 9, + F64 = 10, + SNormF16 = 11, + UNormF16 = 12, + SNormF32 = 13, + UNormF32 = 14, + SNormF64 = 15, + UNormF64 = 16, + PackedS8x32 = 17, + PackedU8x32 = 18, + + // BEGIN NEW FOR SM 6.9 + U8 = 19, + I8 = 20, + F8_E4M3 = 21, + F8_E5M2 = 22, +}; + +enum MatLayout { + RowMajor = 0, + ColumnMajor = 1, + MulOptimal = 2, + OuterProductOptimal = 3, +}; ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; @@ -11,12 +46,12 @@ void test_invalid_output_vector_type() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -58,12 +93,12 @@ void test_invalid_is_output_unsigned_non_const() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -82,12 +117,12 @@ void test_invalid_input_vector_type() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -132,10 +167,10 @@ void test_invalid_input_vector_type_mismatch() { const uint is_output_unsigned = 1; const uint input_interpretation = 9; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -178,14 +213,14 @@ void test_invalid_matrix_M_dimension() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -207,11 +242,11 @@ void test_invalid_matrix_K_dimension() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -230,14 +265,14 @@ void test_invalid_matrix_M_dimension_non_zero() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -255,14 +290,14 @@ void test_invalid_matrix_K_dimension_non_zero() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = CompType::F32; // F32 vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -275,105 +310,493 @@ void test_invalid_matrix_K_dimension_non_zero() { matrix_stride); } -/* -// CHECK: error: __builtin_MatVecMul: input vector must be numeric -void test_mul_non_numeric2() { - vector output_vector; - vector input_vector; // Using bool vector to trigger error - const uint is_output_unsigned = 0; - const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); +//Check if InputInterpretation is a constant parameter +void test_invalid_input_interpretation_non_const() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint input_interpretation = constants_buffer.Load(0); + + // expected-error@+2 {{'InputInterpretation' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } -// CHECK: error: __builtin_MatVecMul: matrix buffer must be valid -struct MyStruct { int x; }; -void test_mul_invalid_buffer() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); MyStruct s; const uint is_output_unsigned = 0; const uint -is_input_unsigned = 0; const uint input_interpretation = 9; // F32 const uint -matrix_offset = 0; const uint matrix_interpretation = 9; // F32 const uint -matrix_dimM = 4; const uint matrix_dimK = 4; const uint matrix_layout = 0; // -RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, s, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); +// Check if InputInterpretation is a valid value +void test_invalid_input_interpretation_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint input_interpretation_0 = 10; // Invalid value + + // expected-error@+2 {{10 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_1 = 11; // FIXME Packed interpretation + + // expected-error@+2 {{11 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } -// CHECK: error: __builtin_MatVecMul: matrix dimensions must be positive -void test_mul_invalid_dims() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 0; - const uint matrix_dimK = 0; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); +// Check if Input and Output vector dimensions are valid -non packed +void test_invalid_input_output_vector_dimensions_non_packed_square_matrix() { + + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 32; + const uint matrix_dimK = 32; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector output_vector_0; + vector input_vector_0 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_0, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector output_vector_1; + vector input_vector_1 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_1, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } -// CHECK: error: __builtin_MatVecMul: matrix stride must be positive -void test_mul_invalid_stride() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 0; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); +// Check if Input and Output vector dimensions are valid -non packed +void test_invalid_input_output_vector_dimensions_non_packed_rectangle_matrix() { + + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 16; + const uint matrix_dimK = 32; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + // Use dimension of Matrix K to trigger error + vector output_vector_0; + vector input_vector_0 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_0, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Check off by 1 errors + vector output_vector_1; + vector input_vector_1 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_1, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Check off by 1 errors + vector output_vector_2; + vector input_vector_2 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_2, is_output_unsigned, input_vector_2, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Use dimension of Matrix M to trigger error + vector output_vector_3; + vector input_vector_3 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_3, is_output_unsigned, input_vector_3, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Check off by 1 errors + vector output_vector_4; + vector input_vector_4 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_4, is_output_unsigned, input_vector_4, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Check off by 1 errors + vector output_vector_5; + vector input_vector_5 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_5, is_output_unsigned, input_vector_5, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + // Swap dimensions to trigger error + vector output_vector_6; + vector input_vector_6 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector_6, is_output_unsigned, input_vector_6, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } -[numthreads(1,1,1)] -void main() { - vector output_vector; - vector input_vector = input_vector_buffer.Load>(0); const uint is_output_unsigned = 0; const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 - const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 - const uint matrix_dimM = 4; - const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor - const bool matrix_is_transposed = false; - const uint matrix_stride = 64; - - __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, - matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, - matrix_is_transposed, matrix_stride); - output_vector_buffer.Store(0, output_vector); +// Check if matrtrix interpretation is a constant value +void test_invalid_matrix_interpretation_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_interpretation_0 = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_0, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } -#endif // 0 -*/ +// Check for invalid matrix interpretation value +void test_invalid_matrix_interpretation_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_interpretation_0 = CompType::Invalid; // Invalid value + + // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_0, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_1 = CompType::I1; + + // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_1, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_2 = CompType::I64; + + // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_2, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_3 = CompType::U64; + + // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_3, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_4 = CompType::F64; + + // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_4, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_5 = CompType::SNormF16; + + // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_5, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_6 = CompType::UNormF16; + + // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_6, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_7 = CompType::PackedS8x32; + + // expected-error@+3 {{17 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_7, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_8 = CompType::PackedU8x32; + + // expected-error@+3 {{18 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_8, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_9 = 23; + + // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_9, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_10 = 100; + + // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_10, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check if matrix Layout is a constant value +void test_invalid_matrix_layout_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_layout = constants_buffer.Load(0); + + // expected-error@+4 {{'MatrixLayout' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check invalid matrix layout value +void test_invalid_matrix_layout_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint matrix_layout_0 = 4; + + // expected-error@+4 {{matrix layout 4 is not valid, must be in the range 0 - 3}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed, + matrix_stride); +} + +// Check if matrix is transposed is a constant value +void test_invalid_matrix_transposed_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed = constants_buffer.Load(0); + const uint matrix_stride = 64; + + // expected-error@+4 {{'MatrixTranspose' must be a constant parameter}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check if invalid matrix transpose value is used +void test_invalid_matrix_transpose_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_stride = 64; + + const uint matrix_layout_0 = MatLayout::RowMajor; // RowMajor + const bool matrix_is_transposed_0 = true; + + // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed_0, + matrix_stride); + + const uint matrix_layout_1 = MatLayout::ColumnMajor; // ColumnMajor + const bool matrix_is_transposed_1 = true; + + // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_1, matrix_is_transposed_1, + matrix_stride); +} + + +// Check invalid matrix stride value for optimal matrix layout +void test_invalid_matrix_stride_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = CompType::F32; // F32 + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + + const uint matrix_layout_0 = MatLayout::MulOptimal; + const uint matrix_stride_0 = 64; + + // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed, + matrix_stride_0); + + const uint matrix_layout_1 = MatLayout::OuterProductOptimal; + const uint matrix_stride_1 = 64; + + // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_1, matrix_is_transposed, + matrix_stride_1); +} diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index c6218a88c0..d9f65f6305 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -1,3 +1,5 @@ +// RUN:dxc + ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; RWByteAddressBuffer output_vector_buffer; @@ -88,7 +90,7 @@ void test_valid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + // expected-no-diagnostics@+1 __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -99,7 +101,7 @@ void test_valid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 1; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + // expected-no-diagnostics@+1 __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -110,7 +112,7 @@ void test_valid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + // expected-no-diagnostics@+1 __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl new file mode 100644 index 0000000000..94976566ac --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -0,0 +1,287 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify + +enum CompType { + Invalid = 0, + I1 = 1, + I16 = 2, + U16 = 3, + I32 = 4, + U32 = 5, + I64 = 6, + U64 = 7, + F16 = 8, + F32 = 9, + F64 = 10, + SNormF16 = 11, + UNormF16 = 12, + SNormF32 = 13, + UNormF32 = 14, + SNormF64 = 15, + UNormF64 = 16, + PackedS8x32 = 17, + PackedU8x32 = 18, + + // BEGIN NEW FOR SM 6.9 + U8 = 19, + I8 = 20, + F8_E4M3 = 21, + F8_E5M2 = 22, +}; + +enum MatLayout { + RowMajor = 0, + ColumnMajor = 1, + MulOptimal = 2, + OuterProductOptimal = 3, +}; + +ByteAddressBuffer input_vector_buffer; +RWByteAddressBuffer accumulate_buffer; +ByteAddressBuffer constants_buffer; + +// Check ofr input vectors aren't the same component type +void test_invalid_input_vector_component_type() { + + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_stride = 0; + + vector input_vector_0_0 = input_vector_buffer.Load >(0); + vector input_vector_1_0 = input_vector_buffer.Load >(0); + + // expected-error@+1 {{input vectors of outerproductaccumulate must have the same element type}} + __builtin_OuterProductAccumulate(input_vector_0_0, input_vector_1_0, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); + + vector input_vector_0_1 = input_vector_buffer.Load >(0); + vector input_vector_1_1 = input_vector_buffer.Load >(0); + + // expected-error@+1 {{input vectors of outerproductaccumulate must have the same element type}} + __builtin_OuterProductAccumulate(input_vector_0_1, input_vector_1_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} + +// Check for non constant matrix interpretation +void test_non_constant_matrix_interpretation() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_stride = 0; + + const uint matrix_interpretation = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} + +// Check for matrix interpretation is not a valid value +void test_invalid_matrix_interpretation() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_stride = 0; + + const uint matrix_interpretation = CompType::Invalid; + + // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_2 = CompType::I1; + + // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_2, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_3 = CompType::I64; + + // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_3, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_4 = CompType::U64; + + // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_4, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_5 = CompType::F64; + + // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_5, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_6 = CompType::SNormF16; + + // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_6, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_7 = CompType::UNormF16; + + // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_7, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_8 = CompType::SNormF32; + + // expected-error@+3 {{13 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_8, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_9 = CompType::UNormF32; + + // expected-error@+3 {{14 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_9, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_10 = CompType::SNormF64; + + // expected-error@+3 {{15 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_10, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_11 = CompType::UNormF64; + + // expected-error@+3 {{16 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_11, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_12 = CompType::PackedS8x32; + + // expected-error@+3 {{17 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_12, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_13 = CompType::PackedU8x32; + + // expected-error@+3 {{18 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_13, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_14 = 23; + + // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_14, matrix_layout, + matrix_stride); + + const uint matrix_interpretation_15 = 100; + + // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation_15, matrix_layout, + matrix_stride); + +} + +// Check for matrix layout is not a constant parameter +void test_non_constant_matrix_layout() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_stride = 0; + + const uint matrix_layout = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixLayout' must be a constant parameter}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} + +// Check for matrix layout is not a valid value +void test_invalid_matrix_layout() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_stride = 0; + + const uint matrix_layout = MatLayout::RowMajor; + + // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); + + const uint matrix_layout_2 = MatLayout::ColumnMajor; + + // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout_2, + matrix_stride); + + const uint matrix_layout_3 = MatLayout::MulOptimal; + + // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout_3, + matrix_stride); + +} + +// Check for matrix stride is zero, if constant +void test_zero_matrix_stride() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_layout = MatLayout::OuterProductOptimal; + + const uint matrix_stride = 16; + + // expected-error@+4 {{for optimal matrix layout, matrix stride must be zero}} + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl new file mode 100644 index 0000000000..317a8c6e78 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl @@ -0,0 +1,97 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify + +enum CompType { + Invalid = 0, + I1 = 1, + I16 = 2, + U16 = 3, + I32 = 4, + U32 = 5, + I64 = 6, + U64 = 7, + F16 = 8, + F32 = 9, + F64 = 10, + SNormF16 = 11, + UNormF16 = 12, + SNormF32 = 13, + UNormF32 = 14, + SNormF64 = 15, + UNormF64 = 16, + PackedS8x32 = 17, + PackedU8x32 = 18, + + // BEGIN NEW FOR SM 6.9 + U8 = 19, + I8 = 20, + F8_E4M3 = 21, + F8_E5M2 = 22, +}; + +enum MatLayout { + RowMajor = 0, + ColumnMajor = 1, + MulOptimal = 2, + OuterProductOptimal = 3, +}; + +ByteAddressBuffer input_vector_buffer; +RWByteAddressBuffer accumulate_buffer; +ByteAddressBuffer constants_buffer; + +// Check ofr input vectors aren't the same component type +void test_invalid_input_vector_component_type() { + + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_stride = 0; + + vector input_vector_0_0 = input_vector_buffer.Load >(0); + vector input_vector_1_0 = input_vector_buffer.Load >(0); + + // expected-no-diagnostics@+1 + __builtin_OuterProductAccumulate(input_vector_0_0, input_vector_1_0, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); + + vector input_vector_0_1 = input_vector_buffer.Load >(0); + vector input_vector_1_1 = input_vector_buffer.Load >(0); + + // expected-no-diagnostics@+1 + __builtin_OuterProductAccumulate(input_vector_0_1, input_vector_1_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); + + vector input_vector_0_2 = input_vector_buffer.Load >(0); + vector input_vector_1_2 = input_vector_buffer.Load >(0); + + // expected-no-diagnostics@+1 + __builtin_OuterProductAccumulate(input_vector_0_2, input_vector_1_2, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} + +// Check for non constant matrix stride +void test_non_constant_matrix_stride() { + + vector input_vector_0 = input_vector_buffer.Load >(0); + vector input_vector_1 = input_vector_buffer.Load >(0); + const uint matrix_offset = 0; + const uint matrix_interpretation = CompType::F32; + const uint matrix_layout = MatLayout::OuterProductOptimal; + + const uint matrix_stride = constants_buffer.Load(0); + + // expected-no-diagnostics@+4 + __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, + accumulate_buffer, matrix_offset, + matrix_interpretation, matrix_layout, + matrix_stride); +} + +// Check for matrix stride is not a valid value + From 3da387238e90cdb621889b79f31b9f83a0c62ba2 Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 5 May 2025 04:59:38 -0700 Subject: [PATCH 13/50] Remove unnecessary space --- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index b762a691a0..6c6a61daf9 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8016,7 +8016,7 @@ def err_hlsl_hitobject_unsupported_stage : Error< // HLSL Change Ends // Linear Algebra Operations -def err_hlsl_linalg_param_must_be_const : Error<" '%0' must be a constant parameter">; +def err_hlsl_linalg_param_must_be_const : Error<"'%0' must be a constant parameter">; def err_hlsl_linalg_vector_incorrect_type : Error<"%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'">; def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %select{false|true}1 for a %2 vector type">; def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretation value">; From 16a5ab8576b1fa40ddb3c381c9bfe7241675552c Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 5 May 2025 05:16:20 -0700 Subject: [PATCH 14/50] Fix run command --- tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index d9f65f6305..5d5c688b45 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -1,4 +1,4 @@ -// RUN:dxc +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; From 2132e010eeb9438c0e9af972cd5e7496eef630c0 Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 5 May 2025 08:52:39 -0700 Subject: [PATCH 15/50] Updated Comments --- tools/clang/lib/Sema/SemaHLSL.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 3b8ea9a306..ecbda02c38 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11762,7 +11762,7 @@ static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, unsigned OutputVectorSize, unsigned MatrixK, unsigned MatrixM, bool isInputPacked) { - // Check is output vector size is equals to matrix dimension M + // Check if output vector size equals to matrix dimension M if (OutputVectorSize != MatrixM) { Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); S.Diags.Report( @@ -11772,6 +11772,10 @@ static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, return false; } + // Check if input vector size equals to matrix dimension K in the unpacked + // case. + // Check if input vector size equals the smallest number that can hold + // matrix dimension K values const unsigned PackingFactor = isInputPacked ? 4 : 1; unsigned MinInputVectorSize = (MatrixK + PackingFactor - 1) / PackingFactor; if (InputVectorSize != MinInputVectorSize) { @@ -11808,8 +11812,9 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << "IsOutputUnsigned"; return; } - // Check if IsOutputUnsigned flag matches output vector type. - // Must be true for unsigned int outputs, false for signed int/float outputs. + + // Check if output vector is unsigned int, signed int or float + // Check if the isUnsigned flag is set correctly Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); unsigned OutputVectorSizeValue = 0; if (IsHLSLVecType(OutputVector->getType())) { @@ -11824,7 +11829,9 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, << "Output Vector"; return; } - + // Check if IsOutputUnsigned flag matches output vector type. + // Must be true for unsigned int outputs, false for signed int/float + // outputs. if (IsOutputUnsignedFlagValue && !OutputVectorTypePtr->isUnsignedIntegerType()) { DXASSERT_NOMSG(OutputVectorTypePtr->isSignedIntegerType() || @@ -11844,7 +11851,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, } } - // Find InputVectorType and Size and check IsUnsigned + // Check if isInputUnsigned parameter is a constant bool IsInputUnsignedFlagValue = false; Expr *IsInputUnsignedExpr = CE->getArg(kMatVecMulIsInputUnsignedIdx); llvm::APSInt IsInputUnsignedExprVal; @@ -11858,6 +11865,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } + // Check if input vector32/16bit is unsigned int, signed int or float Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); unsigned InputVectorSizeValue = 0; if (IsHLSLVecType(InputVector->getType())) { @@ -11884,6 +11892,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } + // Check if the isUnsigned flag is set correctly if (IsInputUnsignedFlagValue && !InputVectorTypePtr->isUnsignedIntegerType()) { DXASSERT_NOMSG(InputVectorTypePtr->isSignedIntegerType() || @@ -11996,6 +12005,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, } // Get MatrixInterpretation, check if it is constant + // Make sure it is a valid value Expr *MatrixInterpretationExpr = CE->getArg(kMatVecMulMatrixInterpretationIdx); llvm::APSInt MatrixInterpretationExprVal; @@ -12019,7 +12029,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } - // Get MatrixLayout, check if it is constant + // Get MatrixLayout, check if it is constant and valid value Expr *MatrixLayoutExpr = CE->getArg(kMatVecMulMatrixLayoutIdx); llvm::APSInt MatrixLayoutExprVal; unsigned MatrixLayoutValue = 0; From 182baae6af90b2a0dd4a565669a28ffcd01d09b4 Mon Sep 17 00:00:00 2001 From: anupamac Date: Mon, 5 May 2025 09:06:49 -0700 Subject: [PATCH 16/50] Update invalid checks for input interpretation --- .../hlsl/linalg/builtins/mul_invalid.hlsl | 112 ++++++++++++++++-- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index aa70ed3f8d..665be77b89 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -345,32 +345,130 @@ void test_invalid_input_interpretation_value() { input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = CompType::F32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatLayout::RowMajor; const bool matrix_is_transposed = false; const uint matrix_stride = 64; - const uint input_interpretation_0 = 10; // Invalid value + const uint input_interpretation_0 = CompType::Invalid; - // expected-error@+2 {{10 is an invalid Register Interpretation value}} + // expected-error@+2 {{0 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_0, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_1 = 11; // FIXME Packed interpretation + const uint input_interpretation_1 = CompType::I1; - // expected-error@+2 {{11 is an invalid Register Interpretation value}} + // expected-error@+2 {{1 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_1, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); -} + const uint input_interpretation_2 = CompType::I64; + + // expected-error@+2 {{6 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_2, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_3 = CompType::U64; + + // expected-error@+2 {{7 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_3, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_4 = CompType::F64; + + // expected-error@+2 {{10 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_4, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_5 = CompType::SNormF16; + + // expected-error@+2 {{11 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_5, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_6 = CompType::UNormF16; + + // expected-error@+2 {{12 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_6, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_8 = CompType::SNormF32; + + // expected-error@+2 {{13 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_8, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_9 = CompType::UNormF32; + + // expected-error@+2 {{14 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_9, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_10 = CompType::SNormF64; + + // expected-error@+2 {{15 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_10, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_11 = CompType::UNormF64; + + // expected-error@+2 {{16 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_11, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_12 = 23; + + // expected-error@+2 {{23 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_12, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_13 = 100; + + // expected-error@+2 {{100 is an invalid Register Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_13, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} // Check if Input and Output vector dimensions are valid -non packed void test_invalid_input_output_vector_dimensions_non_packed_square_matrix() { From 974f2d4ba8a03d56bd6bdd89b5b82c4b353a205c Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 6 May 2025 10:07:49 -0700 Subject: [PATCH 17/50] Fix Build errors --- .../clang/Basic/DiagnosticSemaKinds.td | 50 +++++++---- .../mat-vec-mul_multioverload.hlsl | 84 +++++++++++-------- 2 files changed, 82 insertions(+), 52 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6c6a61daf9..2ecfe6dcbf 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8013,25 +8013,41 @@ def err_hlsl_reorder_unsupported_stage : Error< "dx::MaybeReorderThread is unavailable in shader stage '%0' (requires 'raygeneration')">; def err_hlsl_hitobject_unsupported_stage : Error< "dx::HitObject is unavailable in shader stage '%0' (requires 'raygeneration', 'closesthit' or 'miss')">; -// HLSL Change Ends // Linear Algebra Operations -def err_hlsl_linalg_param_must_be_const : Error<"'%0' must be a constant parameter">; -def err_hlsl_linalg_vector_incorrect_type : Error<"%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'">; -def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error<"%0 must be %select{false|true}1 for a %2 vector type">; -def err_hlsl_linalg_interpretation_value_incorrect : Error<"%0 is an invalid %select{Memory|Register}1 Interpretation value">; -def err_hlsl_linalg_matrix_layout_is_not_transposable : Error<"RowMajor and ColumnMajor matrices are not transposable">; -def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error<"for optimal matrix layout, matrix stride must be zero">; -def err_hlsl_linalg_exceeds_max_matrix_dim: Error<"matrix dimension for linalg operations must be less than %0">; -def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error<"matrix dimension must not be zero">; -def err_hlsl_linalg_matrix_layout_invalid : Error<"matrix layout %0 is not valid, must be in the range %1 - %2">; - -def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error<"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; -def err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K : Error<"unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; -def err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect : Error<"packed input vector length must be the smallest number that can hold K values of the packed type">; - -def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error<"input vectors of outerproductaccumulate must have the same element type">; -def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error<"matrix layout for outerproductaccumulate must be %0">; +def err_hlsl_linalg_param_must_be_const : Error< + "'%0' must be a constant parameter">; +def err_hlsl_linalg_vector_incorrect_type : Error< + "%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', " + "'signed int' or 'float'">; +def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error< + "%0 must be %select{false|true}1 for a %2 vector type">; +def err_hlsl_linalg_interpretation_value_incorrect : Error< + "%0 is an invalid %select{Memory|Register}1 Interpretation value">; +def err_hlsl_linalg_matrix_layout_is_not_transposable : Error< + "RowMajor and ColumnMajor matrices are not transposable">; +def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error< + "for optimal matrix layout, matrix stride must be zero">; +def err_hlsl_linalg_exceeds_max_matrix_dim: Error< + "matrix dimension for linalg operations must be less than %0">; +def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error< + "matrix dimension must not be zero">; +def err_hlsl_linalg_matrix_layout_invalid : Error< + "matrix layout %0 is not valid, must be in the range %1 - %2">; + +def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error< + "output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K : Error< + "unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect : Error< + "packed input vector length must be the smallest number that can hold K values of the packed type">; + +def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< + "input vectors of outerproductaccumulate must have the same element type">; +def err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal : Error< + "matrix layout for outerproductaccumulate must be %0">; + +// HLSL Change Ends // SPIRV Change Starts def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl index 2ca2648503..b9fd94015d 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl @@ -1,42 +1,56 @@ -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 | FileCheck %s --check-prefixes COMMON,DXIL-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 | FileCheck %s --check-prefixes COMMON,DXIL-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 | FileCheck %s --check-prefixes COMMON,DXIL-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 | FileCheck %s --check-prefixes COMMON,DXIL-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 | FileCheck %s --check-prefixes COMMON,DXIL-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 | FileCheck %s --check-prefixes COMMON,DXIL-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 | FileCheck %s --check-prefixes COMMON,DXIL-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 | FileCheck %s --check-prefixes COMMON,DXIL-7 - -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0| FileCheck %s --check-prefixes COMMON,DXIL-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DMST64 | FileCheck %s --check-prefixes COMMON,DXIL-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-7 + +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 // COMMON: define void @main() // Test minimum support set of combinations for matVecMul -// HLOP-0: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) -// DXIL-0: call <4 x half> @dx.op.matVecMul.v4f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 8, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-1: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 64) -// DXIL-1: call <4 x half> @dx.op.matVecMul.v4f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 21, %dx.types.Handle {{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-2: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 64) -// DXIL-2: call <4 x half> @dx.op.matVecMul.v4f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 22, %dx.types.Handle {{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-3: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 64) -// DXIL-3: call <4 x i32> @dx.op.matVecMul.v4i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 false, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-4: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64) -// DXIL-4: call <4 x i32> @dx.op.matVecMul.v4i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) +// HLOP-0: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) + +// DXIL-0: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 8, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-1: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0) + +// DXIL-1: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 21, %dx.types.Handle {{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-2: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0) + +// DXIL-2: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 22, %dx.types.Handle {{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-3: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0) + +// DXIL-3: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 true, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-4: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64) + +// DXIL-4: call <8 x i32> @dx.op.matVecMul.v8i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) // Test unsigned variations -// HLOP-5: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) -// DXIL-5: call <4 x i32> @dx.op.matVecMul.v4i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 true) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-6: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64) -// DXIL-6: call <4 x i32> @dx.op.matVecMul.v4i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 true, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-7: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 64) -// DXIL-7: call <4 x i32> @dx.op.matVecMul.v4i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 false, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) +// HLOP-5: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) + +// DXIL-5: call <8 x i32> @dx.op.matVecMul.v8i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 true) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-6: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64) + +// DXIL-6: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 true, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) + +// HLOP-7: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0) + +// DXIL-7: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 false, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) ByteAddressBuffer input_vector_buffer; @@ -83,7 +97,7 @@ enum MatLayout { [NumThreads(1,1,1)] void main() { - vector output_vector; + vector output_vector; static const uint is_output_unsigned = OU; vector input_vector = input_vector_buffer.Load >(0); @@ -96,7 +110,7 @@ void main() const uint matrix_dimK = 8; const uint matrix_layout = ML; const bool matrix_is_transposed = (bool) MT; - const uint matrix_stride = 64; + const uint matrix_stride = MST; __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); From 64a01e9e61efee61b94adef98989ff329e84b2bf Mon Sep 17 00:00:00 2001 From: anupamac Date: Tue, 6 May 2025 14:40:10 -0700 Subject: [PATCH 18/50] Fix Build failures: tests not per spec --- .../linalg_builtins/check-shader-stages.hlsl | 2 +- .../linalg_builtins/linalg-builtins.hlsl | 4 +- .../mat-vec-mul-add_multioverload.hlsl | 86 +++++++++++-------- .../mat-vec-mul_multioverload.hlsl | 54 ++++++------ ...uter-product-accumulate-multioverload.hlsl | 18 ++-- 5 files changed, 89 insertions(+), 75 deletions(-) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/check-shader-stages.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/check-shader-stages.hlsl index 74cb51260c..75e7c8a5cd 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/check-shader-stages.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/check-shader-stages.hlsl @@ -43,7 +43,7 @@ void UseCoopVec() { const uint opa_matrix_offset = 0; const uint opa_matrix_interpretation = 5; /*U32*/ const uint opa_matrix_layout = 3; /*OuterProductOptimal*/ - const uint opa_matrix_stride = 64; + const uint opa_matrix_stride = 0; __builtin_OuterProductAccumulate(input_vector1, input_vector2, rw_matrix_buffer, opa_matrix_offset, opa_matrix_interpretation, diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/linalg-builtins.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/linalg-builtins.hlsl index c3b4a3a8d7..f1badb9101 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/linalg-builtins.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/linalg-builtins.hlsl @@ -58,12 +58,12 @@ void cs_main() const uint opa_matrix_offset = 0; const uint opa_matrix_interpretation = 5; /*U32*/ const uint opa_matrix_layout = 3; /*OuterProductOptimal*/ - const uint opa_matrix_stride = 64; + const uint opa_matrix_stride = 0; // CHECK: %[[MLD2:[^ ]+]] = load %struct.RWByteAddressBuffer, %struct.RWByteAddressBuffer* @"\01?rw_matrix_buffer@@3URWByteAddressBuffer@@A" // CHECK: %[[MCH2:[^ ]+]] = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32 0, %struct.RWByteAddressBuffer %[[MLD2]]) // CHECK: %[[MAH2:[^ ]+]] = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32 14, %dx.types.Handle %[[MCH2]], %dx.types.ResourceProperties { i32 4107, i32 0 }, %struct.RWByteAddressBuffer undef) - // CHECK: call void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %[[MAH2]], i32 0, i32 5, i32 3, i32 64) + // CHECK: call void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %[[MAH2]], i32 0, i32 5, i32 3, i32 0) __builtin_OuterProductAccumulate(input_vector1, input_vector2, rw_matrix_buffer, opa_matrix_offset, opa_matrix_interpretation, opa_matrix_layout, opa_matrix_stride); diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul-add_multioverload.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul-add_multioverload.hlsl index 98a568fa22..de811982d6 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul-add_multioverload.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul-add_multioverload.hlsl @@ -1,43 +1,57 @@ -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=F16 | FileCheck %s --check-prefixes COMMON,DXIL-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DBI=F16 | FileCheck %s --check-prefixes COMMON,DXIL-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DBI=F16 | FileCheck %s --check-prefixes COMMON,DXIL-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DBI=I32 | FileCheck %s --check-prefixes COMMON,DXIL-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DBI=I32 | FileCheck %s --check-prefixes COMMON,DXIL-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=I8 | FileCheck %s --check-prefixes COMMON,DXIL-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DBI=I8 | FileCheck %s --check-prefixes COMMON,DXIL-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DBI=I8 | FileCheck %s --check-prefixes COMMON,DXIL-7 - -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=F16 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DBI=F16 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DBI=F16 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DBI=I32 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DBI=I32 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=I8 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DBI=I8 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DBI=I8 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=F16 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DBI=F16 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DBI=F16 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=2 -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DBI=I32 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DBI=I32 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=I8 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=8 -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DBI=I8 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DINUM=8 -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DBI=I8 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-7 + +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=F16 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DBI=F16 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DBI=F16 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=2 -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DBI=I32 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DBI=I32 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DBI=I8 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=8 -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DBI=I8 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DINUM=8 -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DBI=I8 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 // COMMON: define void @main() // Test minimum support set of combinations for matVecMul -// HLOP-0: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) -// DXIL-0: call <4 x half> @dx.op.matVecMulAdd.v4f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 8, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-1: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) -// DXIL-1: call <4 x half> @dx.op.matVecMulAdd.v4f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 21, %dx.types.Handle {{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-2: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) -// DXIL-2: call <4 x half> @dx.op.matVecMulAdd.v4f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 22, %dx.types.Handle {{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-3: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 4) -// DXIL-3: call <4 x i32> @dx.op.matVecMulAdd.v4i32.v8i32(i32 306, <8 x i32> {{[^ ]+}}, i1 false, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 4, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-4: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 4) -// DXIL-4: call <4 x i32> @dx.op.matVecMulAdd.v4i32.v8f32(i32 306, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 4, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) +// HLOP-0: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) + +// DXIL-0: call <8 x half> @dx.op.matVecMulAdd.v8f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 8, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-1: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) + +// DXIL-1: call <8 x half> @dx.op.matVecMulAdd.v8f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 21, %dx.types.Handle {{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-2: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8) + +// DXIL-2: call <8 x half> @dx.op.matVecMulAdd.v8f16.v8f16(i32 306, <8 x half> {{[^ ]+}}, i1 false, i32 22, %dx.types.Handle {{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-3: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <2 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x i32>* %output_vector, i1 false, <2 x i32> %{{[^ ]+}}, i1 true, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 4) + +// DXIL-3: call <8 x i32> @dx.op.matVecMulAdd.v8i32.v2i32(i32 306, <2 x i32> {{[^ ]+}}, i1 true, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0, %dx.types.Handle {{[^ ]+}}, i32 0, i32 4, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-4: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 4) + +// DXIL-4: call <8 x i32> @dx.op.matVecMulAdd.v8i32.v8f32(i32 306, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 4, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) // Test unsigned variations -// HLOP-5: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) -// DXIL-5: call <4 x i32> @dx.op.matVecMulAdd.v4i32.v8f32(i32 306, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 true) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-6: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) -// DXIL-6: call <4 x i32> @dx.op.matVecMulAdd.v4i32.v8i32(i32 306, <8 x i32> {{[^ ]+}}, i1 true, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) -// HLOP-7: call void @"dx.hl.op..void (i32, <4 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) -// DXIL-7: call <4 x i32> @dx.op.matVecMulAdd.v4i32.v8i32(i32 306, <8 x i32> {{[^ ]+}}, i1 false, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) +// HLOP-5: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) + +// DXIL-5: call <8 x i32> @dx.op.matVecMulAdd.v8i32.v8f32(i32 306, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 true) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-6: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) + +// DXIL-6: call <8 x i32> @dx.op.matVecMulAdd.v8i32.v8i32(i32 306, <8 x i32> {{[^ ]+}}, i1 true, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) + +// HLOP-7: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 391, <8 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20) + +// DXIL-7: call <8 x i32> @dx.op.matVecMulAdd.v8i32.v8i32(i32 306, <8 x i32> {{[^ ]+}}, i1 false, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i1 false) ; MatVecMulAdd(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,biasBuffer,biasOffset,biasIntepretation,isOutputUnsigned) ByteAddressBuffer input_vector_buffer; @@ -84,10 +98,10 @@ enum MatLayout { [NumThreads(1,1,1)] void main() { - vector output_vector; + vector output_vector; static const uint is_output_unsigned = OU; - vector input_vector = input_vector_buffer.Load >(0); + vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = IU; const uint input_interpretation = II; @@ -97,7 +111,7 @@ void main() const uint matrix_dimK = 8; const uint matrix_layout = ML; const bool matrix_is_transposed = (bool) MT; - const uint matrix_stride = 64; + const uint matrix_stride = MST; const uint bias_offset = 0; const uint bias_interpretation = BI; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl index b9fd94015d..8b14fb4cf1 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/mat-vec-mul_multioverload.hlsl @@ -1,54 +1,54 @@ -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0| FileCheck %s --check-prefixes COMMON,DXIL-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DMST64 | FileCheck %s --check-prefixes COMMON,DXIL-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-7 - -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0| FileCheck %s --check-prefixes COMMON,DXIL-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DII=PackedS8x32 -DINUM=2 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=F16 -DINUM=8 -DML=RowMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=8 -DII=U8 -DMI=I8 -DINUM=8 -DML=ColumnMajor -DMT=0 -DMST=64 | FileCheck %s --check-prefixes COMMON,DXIL-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DINUM=8 -DII=U8 -DMI=U8 -DINUM=8 -DML=MulOptimal -DMT=1 -DMST=0 | FileCheck %s --check-prefixes COMMON,DXIL-7 + +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F16 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E4M3 -DMI=F8_E4M3 -DML=MulOptimal -DMT=0 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=float16_t -DIU=0 -DITY=float16_t -DINUM=8 -DII=F8_E5M2 -DMI=F8_E5M2 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=2 -DII=PackedS8x32 -DMI=I8 -DML=OuterProductOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-3 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=I8 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-4 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=1 -DOTY=uint -DIU=0 -DITY=float -DINUM=8 -DII=I8 -DMI=F16 -DML=RowMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-5 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=1 -DITY=uint -DINUM=8 -DII=U8 -DMI=I8 -DML=ColumnMajor -DMT=0 -DMST=64 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-6 +// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DOU=0 -DOTY=int -DIU=0 -DITY=int -DINUM=8 -DII=U8 -DMI=U8 -DML=MulOptimal -DMT=1 -DMST=0 -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-7 // COMMON: define void @main() // Test minimum support set of combinations for matVecMul -// HLOP-0: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) +// HLOP-0: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 8, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) // DXIL-0: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 8, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-1: call void @"dx.hl.op..void (i32, <4 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0) +// HLOP-1: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 21, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0) // DXIL-1: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 21, %dx.types.Handle {{[^ ]+}}, i32 0, i32 21, i32 8, i32 8, i32 2, i1 false, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-2: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0) +// HLOP-2: call void @"dx.hl.op..void (i32, <8 x half>*, i1, <8 x half>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x half>* %output_vector, i1 false, <8 x half> %{{[^ ]+}}, i1 false, i32 22, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0) // DXIL-2: call <8 x half> @dx.op.matVecMul.v8f16.v8f16(i32 305, <8 x half> {{[^ ]+}}, i1 false, i32 22, %dx.types.Handle {{[^ ]+}}, i32 0, i32 22, i32 8, i32 8, i32 2, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-3: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0) +// HLOP-3: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <2 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x i32>* %output_vector, i1 false, <2 x i32> %{{[^ ]+}}, i1 true, i32 17, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0) -// DXIL-3: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 true, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) +// DXIL-3: call <8 x i32> @dx.op.matVecMul.v8i32.v2i32(i32 305, <2 x i32> {{[^ ]+}}, i1 true, i32 17, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 3, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-4: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64) +// HLOP-4: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x i32>* %output_vector, i1 false, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64) // DXIL-4: call <8 x i32> @dx.op.matVecMul.v8i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 0, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) // Test unsigned variations -// HLOP-5: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) +// HLOP-5: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x i32>* %output_vector, i1 true, <8 x float> %{{[^ ]+}}, i1 false, i32 20, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64) // DXIL-5: call <8 x i32> @dx.op.matVecMul.v8i32.v8f32(i32 305, <8 x float> {{[^ ]+}}, i1 false, i32 20, %dx.types.Handle {{[^ ]+}}, i32 0, i32 8, i32 8, i32 8, i32 0, i1 false, i32 64, i1 true) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-6: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64) +// HLOP-6: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 true, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64) // DXIL-6: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 true, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 20, i32 8, i32 8, i32 1, i1 false, i32 64, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) -// HLOP-7: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <4 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0) +// HLOP-7: call void @"dx.hl.op..void (i32, <8 x i32>*, i1, <8 x i32>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 390, <8 x i32>* %output_vector, i1 false, <8 x i32> %{{[^ ]+}}, i1 false, i32 19, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0) // DXIL-7: call <8 x i32> @dx.op.matVecMul.v8i32.v8i32(i32 305, <8 x i32> {{[^ ]+}}, i1 false, i32 19, %dx.types.Handle {{[^ ]+}}, i32 0, i32 19, i32 8, i32 8, i32 2, i1 true, i32 0, i1 false) ; MatVecMul(inputVector,isInputUnsigned,inputInterpretation,matrixBuffer,matrixOffset,matrixIntepretation,matrixM,matrixK,matrixLayout,matrixTranspose,matrixStride,isOutputUnsigned) @@ -100,7 +100,7 @@ void main() vector output_vector; static const uint is_output_unsigned = OU; - vector input_vector = input_vector_buffer.Load >(0); + vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = IU; const uint input_interpretation = II; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/outer-product-accumulate-multioverload.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/outer-product-accumulate-multioverload.hlsl index 40bbe62284..127e2d7909 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/outer-product-accumulate-multioverload.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/intrinsics/linalg_builtins/outer-product-accumulate-multioverload.hlsl @@ -1,8 +1,6 @@ -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=float16_t -DMI=F16 -DML=RowMajor | FileCheck %s --check-prefixes COMMON,DXIL-0 // RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=float16_t -DMI=F8_E4M3 -DML=OuterProductOptimal | FileCheck %s --check-prefixes COMMON,DXIL-1 // RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=uint -DMI=U8 -DML=OuterProductOptimal | FileCheck %s --check-prefixes COMMON,DXIL-2 -// RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=float16_t -DMI=F16 -DML=RowMajor -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-0 // RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=float16_t -DMI=F8_E4M3 -DML=OuterProductOptimal -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-1 // RUN: %dxc -T cs_6_9 %s -enable-16bit-types -DITY=uint -DMI=U8 -DML=OuterProductOptimal -fcgl | FileCheck %s --check-prefixes COMMON,HLOP-2 @@ -11,12 +9,14 @@ ByteAddressBuffer input_vector_buffer2; RWByteAddressBuffer matrix_buffer; // COMMON: define void @main() -// DXIL-0: call void @dx.op.outerProductAccumulate.v8f16.v8f16(i32 307, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 0, i32 64) ; OuterProductAccumulate(inputVector1,inputVector2,matrixBuffer,matrixOffset,matrixIntepretation,matrixLayout,matrixStride) -// HLOP-0: call void @"dx.hl.op..void (i32, <8 x half>, <8 x half>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 8, i32 0, i32 64) -// DXIL-1: call void @dx.op.outerProductAccumulate.v8f16.v8f16(i32 307, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 3, i32 64) ; OuterProductAccumulate(inputVector1,inputVector2,matrixBuffer,matrixOffset,matrixIntepretation,matrixLayout,matrixStride) -// HLOP-1: call void @"dx.hl.op..void (i32, <8 x half>, <8 x half>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 3, i32 64) -// DXIL-2: call void @dx.op.outerProductAccumulate.v8i32.v8i32(i32 307, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 3, i32 64) ; OuterProductAccumulate(inputVector1,inputVector2,matrixBuffer,matrixOffset,matrixIntepretation,matrixLayout,matrixStride) -// HLOP-2: call void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 3, i32 64) + +// DXIL-1: call void @dx.op.outerProductAccumulate.v8f16.v8f16(i32 307, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 3, i32 0) ; OuterProductAccumulate(inputVector1,inputVector2,matrixBuffer,matrixOffset,matrixIntepretation,matrixLayout,matrixStride) + +// HLOP-1: call void @"dx.hl.op..void (i32, <8 x half>, <8 x half>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x half> %{{[^ ]+}}, <8 x half> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 21, i32 3, i32 0) + +// DXIL-2: call void @dx.op.outerProductAccumulate.v8i32.v8i32(i32 307, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 3, i32 0) ; OuterProductAccumulate(inputVector1,inputVector2,matrixBuffer,matrixOffset,matrixIntepretation,matrixLayout,matrixStride) + +// HLOP-2: call void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32 392, <8 x i32> %{{[^ ]+}}, <8 x i32> %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 19, i32 3, i32 0) enum CompType { Invalid = 0, @@ -63,7 +63,7 @@ void main() const uint matrix_interpretation = MI; const uint matrix_layout = ML; const uint matrix_offset = 0; - const uint matrix_stride = 64; + const uint matrix_stride = 0; __builtin_OuterProductAccumulate(input_vector1, input_vector2, matrix_buffer, matrix_offset, matrix_interpretation, matrix_layout, matrix_stride); From f36758f660789179a05574e8c97cbb7e2f88861d Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 08:15:48 -0700 Subject: [PATCH 19/50] Fix build errors --- .../clang/Basic/DiagnosticSemaKinds.td | 2 ++ tools/clang/lib/Sema/SemaHLSL.cpp | 30 +++++++++++++++++++ .../hlsl/linalg/unavailable-pre-sm69.hlsl | 8 ++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 2ecfe6dcbf..d4e0ce46ef 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8034,6 +8034,8 @@ def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error< "matrix dimension must not be zero">; def err_hlsl_linalg_matrix_layout_invalid : Error< "matrix layout %0 is not valid, must be in the range %1 - %2">; +def err_hlsl_linalg_function_requires_shader_model_6_9_or_above : Error< + "intrinsic function %0 requires shader model 6.9 or greater">; def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error< "output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index ecbda02c38..94772bcca2 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -12267,14 +12267,44 @@ void Sema::CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, CheckBarrierCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_MatVecMul: + if (!SM->IsSM69Plus()) { + Diags.Report( + TheCall->getExprLoc(), + diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) + << FDecl->getNameAsString(); + return; + } CheckMulCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_MatVecMulAdd: + if (!SM->IsSM69Plus()) { + Diags.Report( + TheCall->getExprLoc(), + diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) + << FDecl->getNameAsString(); + return; + } CheckMulAddCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_OuterProductAccumulate: + if (!SM->IsSM69Plus()) { + Diags.Report( + TheCall->getExprLoc(), + diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) + << FDecl->getNameAsString(); + return; + } CheckOuterProductAccumulateCall(*this, FDecl, TheCall); break; + case hlsl::IntrinsicOp::IOP___builtin_VectorAccumulate: + if (!SM->IsSM69Plus()) { + Diags.Report( + TheCall->getExprLoc(), + diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) + << FDecl->getNameAsString(); + return; + } + break; #ifdef ENABLE_SPIRV_CODEGEN case hlsl::IntrinsicOp::IOP_Vkreinterpret_pointer_cast: CheckVKBufferPointerCast(*this, FDecl, TheCall, false); diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl index d5e251ae8b..66e9da4b99 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl @@ -23,7 +23,7 @@ void cs_main() const bool matrix_is_transposed = false; const uint matrix_stride = 64; - //expected-error@+1{{intrinsic __builtin_MatVecMul potentially used by 'cs_main' requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic function __builtin_MatVecMul requires shader model 6.9 or greater}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, @@ -32,7 +32,7 @@ void cs_main() const uint bias_offset = 0; const uint bias_interpretation = 9; /*F32*/ - //expected-error@+1{{intrinsic __builtin_MatVecMulAdd potentially used by 'cs_main' requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic function __builtin_MatVecMulAdd requires shader model 6.9 or greater}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, @@ -46,14 +46,14 @@ void cs_main() const uint opa_matrix_layout = 3; /*OuterProductOptimal*/ const uint opa_matrix_stride = 64; - //expected-error@+1{{intrinsic __builtin_OuterProductAccumulate potentially used by 'cs_main' requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic function __builtin_OuterProductAccumulate requires shader model 6.9 or greater}} __builtin_OuterProductAccumulate(input_vector1, input_vector2, rw_matrix_buffer, opa_matrix_offset, opa_matrix_interpretation, opa_matrix_layout, opa_matrix_stride); const uint va_matrix_offset = 0; - //expected-error@+1{{intrinsic __builtin_VectorAccumulate potentially used by 'cs_main' requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic function __builtin_VectorAccumulate requires shader model 6.9 or greater}} __builtin_VectorAccumulate(input_vector1, rw_matrix_buffer, va_matrix_offset); } \ No newline at end of file From 9f24be753e6d50046713be4e142d3960badd00e0 Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 12:12:20 -0700 Subject: [PATCH 20/50] Change linalg.h to use IsUnsigned type trait pattern than function template and updated the linalg test line numbers --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 34 +++++++++++++------ .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 +-- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../linalg/outerproductaccumulate-errors.hlsl | 6 ++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 51e662bbc9..30e08f1d95 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -43,14 +43,28 @@ enum MatrixLayout { // Helper for signedness // namespace details { -template bool IsUnsigned() { return false; } -#ifdef __HLSL_ENABLE_16_BIT -template <> bool IsUnsigned() { return true; } -#endif +template + struct IsUnsigned { + static const bool value = false; + }; + +template <> + struct IsUnsigned { + static const bool value = true; + }; -template <> bool IsUnsigned() { return true; } -template <> bool IsUnsigned() { return true; } +template <> + struct IsUnsigned { + static const bool value = true; + }; + +#ifdef __HLSL_ENABLE_16_BIT + template <> + struct IsUnsigned { + static const bool value = true; + }; +#endif //__HLSL_ENABLE_16_BIT } // namespace details // @@ -116,8 +130,8 @@ Mul(MatrixRefImpl OutputVector; __builtin_MatVecMul( - /*out*/ OutputVector, details::IsUnsigned(), InputVector.Data, - details::IsUnsigned(), InputDT, Matrix.Buffer, + /*out*/ OutputVector, details::IsUnsigned::value, InputVector.Data, + details::IsUnsigned::value, InputDT, Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, MatrixTranspose, Matrix.Stride); @@ -143,8 +157,8 @@ MulAdd(MatrixRefImpl OutputVector; __builtin_MatVecMulAdd( - /*out*/ OutputVector, details::IsUnsigned(), InputVector.Data, - details::IsUnsigned(), InputDT, Matrix.Buffer, + /*out*/ OutputVector, details::IsUnsigned::value, InputVector.Data, + details::IsUnsigned::value, InputDT, Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, BiasVectorDT); diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index 9f2793d417..637db744b1 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:97{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:111{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:97{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:111{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index 2d5a11e83e..d2570c6183 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:111{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:125{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index f444f81c3a..52ad3d0650 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:137{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:151{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index 6f503b367b..318f889350 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:161{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:175{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:161{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:175{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:161{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:175{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From e715df4745ba78464ff29f002d53e6131af5961a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 7 May 2025 19:27:48 +0000 Subject: [PATCH 21/50] chore: autopublish 2025-05-07T19:27:48Z --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 46 +++++++++++------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 30e08f1d95..d9020d74d0 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -44,26 +44,22 @@ enum MatrixLayout { // namespace details { -template - struct IsUnsigned { - static const bool value = false; - }; +template struct IsUnsigned { + static const bool value = false; +}; -template <> - struct IsUnsigned { - static const bool value = true; - }; +template <> struct IsUnsigned { + static const bool value = true; +}; -template <> - struct IsUnsigned { - static const bool value = true; - }; +template <> struct IsUnsigned { + static const bool value = true; +}; #ifdef __HLSL_ENABLE_16_BIT - template <> - struct IsUnsigned { - static const bool value = true; - }; +template <> struct IsUnsigned { + static const bool value = true; +}; #endif //__HLSL_ENABLE_16_BIT } // namespace details @@ -130,10 +126,10 @@ Mul(MatrixRefImpl OutputVector; __builtin_MatVecMul( - /*out*/ OutputVector, details::IsUnsigned::value, InputVector.Data, - details::IsUnsigned::value, InputDT, Matrix.Buffer, - Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, - MatrixTranspose, Matrix.Stride); + /*out*/ OutputVector, details::IsUnsigned::value, + InputVector.Data, details::IsUnsigned::value, InputDT, + Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, + MatrixLayout, MatrixTranspose, Matrix.Stride); return OutputVector; } @@ -157,11 +153,11 @@ MulAdd(MatrixRefImpl OutputVector; __builtin_MatVecMulAdd( - /*out*/ OutputVector, details::IsUnsigned::value, InputVector.Data, - details::IsUnsigned::value, InputDT, Matrix.Buffer, - Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, - MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, - BiasVectorDT); + /*out*/ OutputVector, details::IsUnsigned::value, + InputVector.Data, details::IsUnsigned::value, InputDT, + Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, + MatrixLayout, MatrixTranspose, Matrix.Stride, BiasVector.Buffer, + BiasVector.StartOffset, BiasVectorDT); return OutputVector; } From 2d3f2624844832ad503d94aed47d4748a78dedda Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 12:53:08 -0700 Subject: [PATCH 22/50] Remove/comment unused variables: build errors --- tools/clang/lib/Sema/SemaHLSL.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 94772bcca2..0dd5376763 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11669,19 +11669,17 @@ static const unsigned kMatVecMulOutputIsUnsignedIdx = 1; static const unsigned kMatVecMulInputVectorIdx = 2; static const unsigned kMatVecMulIsInputUnsignedIdx = 3; static const unsigned kMatVecMulInputInterpretationIdx = 4; -static const unsigned kMatVecMulMatrixBufferIdx = 5; -static const unsigned kMatVecMulMatrixOffsetIdx = 6; +//static const unsigned kMatVecMulMatrixBufferIdx = 5; +//static const unsigned kMatVecMulMatrixOffsetIdx = 6; static const unsigned kMatVecMulMatrixInterpretationIdx = 7; static const unsigned kMatVecMulMatrixMIdx = 8; static const unsigned kMatVecMulMatrixKIdx = 9; static const unsigned kMatVecMulMatrixLayoutIdx = 10; static const unsigned kMatVecMulMatrixTransposeIdx = 11; static const unsigned kMatVecMulMatrixStrideIdx = 12; -static const unsigned kMatVecMulIsOutputUnsignedIdx = 13; // MatVecAdd const unsigned kMatVecMulAddBiasInterpretation = 15; -const unsigned kMatVecMulAddIsOutputUnsignedIdx = 16; enum MatrixLayout { MATRIX_LAYOUT_ROW_MAJOR = 0, @@ -12128,8 +12126,8 @@ static void CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, // OuterProductAccumulate builtin function parameters static const unsigned kOuterProdAccInputVector1Idx = 0; static const unsigned kOuterProdAccInputVector2Idx = 1; -static const unsigned kOuterProdAccMatrixBufferIdx = 2; -static const unsigned kOuterProdAccMatrixOffsetIdx = 3; +//static const unsigned kOuterProdAccMatrixBufferIdx = 2; +//static const unsigned kOuterProdAccMatrixOffsetIdx = 3; static const unsigned kOuterProdAccMatrixInterpretationIdx = 4; static const unsigned kOuterProdAccMatrixLayoutIdx = 5; static const unsigned kOuterProdAccMatrixStrideIdx = 6; From bf5c62f1b2517fd5fb79c943dc034c8ec2fa5742 Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 14:06:18 -0700 Subject: [PATCH 23/50] Use linalg headers in the hlsl validation tests --- tools/clang/lib/Sema/SemaHLSL.cpp | 8 +- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 72 ++---- .../hlsl/linalg/builtins/mul_invalid.hlsl | 235 ++++++++---------- .../hlsl/linalg/builtins/mul_valid.hlsl | 24 +- .../outer_product_accumulate_invalid.hlsl | 89 +++---- .../outer_product_accumulate_valid.hlsl | 51 +--- 6 files changed, 191 insertions(+), 288 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 0dd5376763..0ee5a0ccc3 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11669,8 +11669,8 @@ static const unsigned kMatVecMulOutputIsUnsignedIdx = 1; static const unsigned kMatVecMulInputVectorIdx = 2; static const unsigned kMatVecMulIsInputUnsignedIdx = 3; static const unsigned kMatVecMulInputInterpretationIdx = 4; -//static const unsigned kMatVecMulMatrixBufferIdx = 5; -//static const unsigned kMatVecMulMatrixOffsetIdx = 6; +// static const unsigned kMatVecMulMatrixBufferIdx = 5; +// static const unsigned kMatVecMulMatrixOffsetIdx = 6; static const unsigned kMatVecMulMatrixInterpretationIdx = 7; static const unsigned kMatVecMulMatrixMIdx = 8; static const unsigned kMatVecMulMatrixKIdx = 9; @@ -12126,8 +12126,8 @@ static void CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, // OuterProductAccumulate builtin function parameters static const unsigned kOuterProdAccInputVector1Idx = 0; static const unsigned kOuterProdAccInputVector2Idx = 1; -//static const unsigned kOuterProdAccMatrixBufferIdx = 2; -//static const unsigned kOuterProdAccMatrixOffsetIdx = 3; +// static const unsigned kOuterProdAccMatrixBufferIdx = 2; +// static const unsigned kOuterProdAccMatrixOffsetIdx = 3; static const unsigned kOuterProdAccMatrixInterpretationIdx = 4; static const unsigned kOuterProdAccMatrixLayoutIdx = 5; static const unsigned kOuterProdAccMatrixStrideIdx = 6; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 14e24be8a3..b10ef48ce4 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -1,32 +1,6 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify - -enum CompType { - Invalid = 0, - I1 = 1, - I16 = 2, - U16 = 3, - I32 = 4, - U32 = 5, - I64 = 6, - U64 = 7, - F16 = 8, - F32 = 9, - F64 = 10, - SNormF16 = 11, - UNormF16 = 12, - SNormF32 = 13, - UNormF32 = 14, - SNormF64 = 15, - UNormF64 = 16, - PackedS8x32 = 17, - PackedU8x32 = 18, - - // BEGIN NEW FOR SM 6.9 - U8 = 19, - I8 = 20, - F8_E4M3 = 21, - F8_E5M2 = 22, -}; +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include enum MatLayout { RowMajor = 0, @@ -35,6 +9,8 @@ enum MatLayout { OuterProductOptimal = 3, }; +using namespace dx::linalg; + ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; ByteAddressBuffer bias_buffer; @@ -48,12 +24,12 @@ void test_invalid_bias_interpretation() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const uint matrix_is_transposed = 0; const uint matrix_stride = 0; const uint bias_offset = 0; @@ -76,17 +52,17 @@ void test_invalid_bias_interpretation_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const uint matrix_is_transposed = 0; const uint matrix_stride = 0; const uint bias_offset = 0; - const uint bias_interpretation_0 = CompType::Invalid; + const uint bias_interpretation_0 = 0; // expected-error@+6 {{0 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -96,7 +72,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_0); - const uint bias_interpretation_1 = CompType::I1; + const uint bias_interpretation_1 = 1; // expected-error@+6 {{1 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -106,7 +82,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_1); - const uint bias_interpretation_2 = CompType::I64; + const uint bias_interpretation_2 = 6; // expected-error@+6 {{6 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -116,7 +92,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_2); - const uint bias_interpretation_3 = CompType::U64; + const uint bias_interpretation_3 = 7; // expected-error@+6 {{7 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -126,7 +102,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_3); - const uint bias_interpretation_4 = CompType::F64; + const uint bias_interpretation_4 = 10; // expected-error@+6 {{10 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -136,7 +112,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_4); - const uint bias_interpretation_5 = CompType::SNormF16; + const uint bias_interpretation_5 = 11; // expected-error@+6 {{11 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -146,7 +122,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_5); - const uint bias_interpretation_6 = CompType::UNormF16; + const uint bias_interpretation_6 = 12; // expected-error@+6 {{12 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -156,7 +132,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_6); - const uint bias_interpretation_7 = CompType::SNormF32; + const uint bias_interpretation_7 = 13; // expected-error@+6 {{13 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -166,7 +142,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_7); - const uint bias_interpretation_8 = CompType::UNormF32; + const uint bias_interpretation_8 = 14; // expected-error@+6 {{14 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -176,7 +152,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_8); - const uint bias_interpretation_9 = CompType::SNormF64; + const uint bias_interpretation_9 = 15; // expected-error@+6 {{15 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -186,7 +162,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_9); - const uint bias_interpretation_10 = CompType::UNormF64; + const uint bias_interpretation_10 = 16; // expected-error@+6 {{16 is an invalid Memory Interpretation value}} @@ -197,7 +173,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_10); - const uint bias_interpretation_11 = CompType::PackedS8x32; + const uint bias_interpretation_11 = DataType::DATA_TYPE_SINT8_T4_PACKED; // expected-error@+6 {{17 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, @@ -207,7 +183,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_11); - const uint bias_interpretation_12 = CompType::PackedU8x32; + const uint bias_interpretation_12 = DataType::DATA_TYPE_UINT8_T4_PACKED; // expected-error@+6 {{18 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 665be77b89..fc6dc9bae1 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -1,39 +1,8 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify - -enum CompType { - Invalid = 0, - I1 = 1, - I16 = 2, - U16 = 3, - I32 = 4, - U32 = 5, - I64 = 6, - U64 = 7, - F16 = 8, - F32 = 9, - F64 = 10, - SNormF16 = 11, - UNormF16 = 12, - SNormF32 = 13, - UNormF32 = 14, - SNormF64 = 15, - UNormF64 = 16, - PackedS8x32 = 17, - PackedU8x32 = 18, - - // BEGIN NEW FOR SM 6.9 - U8 = 19, - I8 = 20, - F8_E4M3 = 21, - F8_E5M2 = 22, -}; - -enum MatLayout { - RowMajor = 0, - ColumnMajor = 1, - MulOptimal = 2, - OuterProductOptimal = 3, -}; +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include + +using namespace dx::linalg; ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; @@ -46,12 +15,12 @@ void test_invalid_output_vector_type() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -93,12 +62,12 @@ void test_invalid_is_output_unsigned_non_const() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -117,12 +86,12 @@ void test_invalid_input_vector_type() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -165,12 +134,12 @@ void test_invalid_input_vector_type_mismatch() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -213,14 +182,14 @@ void test_invalid_matrix_M_dimension() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -242,11 +211,11 @@ void test_invalid_matrix_K_dimension() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -265,14 +234,14 @@ void test_invalid_matrix_M_dimension_non_zero() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -290,14 +259,14 @@ void test_invalid_matrix_K_dimension_non_zero() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -319,10 +288,10 @@ void test_invalid_input_interpretation_non_const() { input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -345,14 +314,14 @@ void test_invalid_input_interpretation_value() { input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; - const uint input_interpretation_0 = CompType::Invalid; + const uint input_interpretation_0 = 0; // expected-error@+2 {{0 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -361,7 +330,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_1 = CompType::I1; + const uint input_interpretation_1 = 1; // expected-error@+2 {{1 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -370,7 +339,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_2 = CompType::I64; + const uint input_interpretation_2 = 6; // expected-error@+2 {{6 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -379,7 +348,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_3 = CompType::U64; + const uint input_interpretation_3 = 7; // expected-error@+2 {{7 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -388,7 +357,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_4 = CompType::F64; + const uint input_interpretation_4 = 10; // expected-error@+2 {{10 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -397,7 +366,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_5 = CompType::SNormF16; + const uint input_interpretation_5 = 11; // expected-error@+2 {{11 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -406,7 +375,7 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_6 = CompType::UNormF16; + const uint input_interpretation_6 = 12; // expected-error@+2 {{12 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -415,56 +384,56 @@ void test_invalid_input_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_8 = CompType::SNormF32; + const uint input_interpretation_7 = 13; // expected-error@+2 {{13 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_8, matrix_buffer, + is_input_unsigned, input_interpretation_7, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_9 = CompType::UNormF32; + const uint input_interpretation_8 = 14; // expected-error@+2 {{14 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_9, matrix_buffer, + is_input_unsigned, input_interpretation_8, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_10 = CompType::SNormF64; + const uint input_interpretation_9 = 15; // expected-error@+2 {{15 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_10, matrix_buffer, + is_input_unsigned, input_interpretation_9, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_11 = CompType::UNormF64; + const uint input_interpretation_10 = 16; // expected-error@+2 {{16 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_11, matrix_buffer, + is_input_unsigned, input_interpretation_10, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_12 = 23; + const uint input_interpretation_11 = 23; // expected-error@+2 {{23 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_12, matrix_buffer, + is_input_unsigned, input_interpretation_11, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint input_interpretation_13 = 100; + const uint input_interpretation_12 = 100; // expected-error@+2 {{100 is an invalid Register Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, - is_input_unsigned, input_interpretation_13, matrix_buffer, + is_input_unsigned, input_interpretation_12, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); @@ -474,12 +443,12 @@ void test_invalid_input_output_vector_dimensions_non_packed_square_matrix() { const uint is_output_unsigned = 1; const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 const uint matrix_dimM = 32; const uint matrix_dimK = 32; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -511,12 +480,12 @@ void test_invalid_input_output_vector_dimensions_non_packed_rectangle_matrix() { const uint is_output_unsigned = 1; const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 16; const uint matrix_dimK = 32; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -613,12 +582,12 @@ void test_invalid_matrix_interpretation_constant_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -640,16 +609,15 @@ void test_invalid_matrix_interpretation_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; - const uint matrix_interpretation_0 = CompType::Invalid; // Invalid value + const uint matrix_interpretation_0 = 0; // expected-error@+3 {{0 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -658,7 +626,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_1 = CompType::I1; + const uint matrix_interpretation_1 = 1; // expected-error@+3 {{1 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -667,7 +635,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_2 = CompType::I64; + const uint matrix_interpretation_2 = 6; // expected-error@+3 {{6 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -676,7 +644,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_3 = CompType::U64; + const uint matrix_interpretation_3 = 7; // expected-error@+3 {{7 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -685,7 +653,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_4 = CompType::F64; + const uint matrix_interpretation_4 = 10; // expected-error@+3 {{10 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -694,7 +662,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_5 = CompType::SNormF16; + const uint matrix_interpretation_5 = 11; // expected-error@+3 {{11 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -703,7 +671,7 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_6 = CompType::UNormF16; + const uint matrix_interpretation_6 = 12; // expected-error@+3 {{12 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, @@ -712,41 +680,58 @@ void test_invalid_matrix_interpretation_value() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_7 = CompType::PackedS8x32; + const uint matrix_interpretation_7 = 13; - // expected-error@+3 {{17 is an invalid Memory Interpretation value}} + // expected-error@+3 {{13 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_7, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_8 = CompType::PackedU8x32; + const uint matrix_interpretation_8 = 14; - // expected-error@+3 {{18 is an invalid Memory Interpretation value}} + // expected-error@+3 {{14 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_8, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_9 = 23; + const uint matrix_interpretation_9 = 15; - // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + // expected-error@+3 {{15 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_9, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - const uint matrix_interpretation_10 = 100; + const uint matrix_interpretation_10 = 16; - // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + // expected-error@+3 {{16 is an invalid Memory Interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_10, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); + + const uint matrix_interpretation_11 = 23; + // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_11, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint matrix_interpretation_12 = 100; + + // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_12, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); } // Check if matrix Layout is a constant value @@ -757,9 +742,9 @@ void test_invalid_matrix_layout_constant_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; const bool matrix_is_transposed = false; @@ -783,9 +768,9 @@ void test_invalid_matrix_layout_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; const bool matrix_is_transposed = false; @@ -809,12 +794,12 @@ void test_invalid_matrix_transposed_constant_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatLayout::RowMajor; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = constants_buffer.Load(0); const uint matrix_stride = 64; @@ -834,14 +819,14 @@ void test_invalid_matrix_transpose_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; const uint matrix_stride = 64; - const uint matrix_layout_0 = MatLayout::RowMajor; // RowMajor + const uint matrix_layout_0 = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed_0 = true; // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} @@ -851,7 +836,7 @@ void test_invalid_matrix_transpose_value() { matrix_dimK, matrix_layout_0, matrix_is_transposed_0, matrix_stride); - const uint matrix_layout_1 = MatLayout::ColumnMajor; // ColumnMajor + const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR; const bool matrix_is_transposed_1 = true; // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} @@ -871,14 +856,14 @@ void test_invalid_matrix_stride_constant_value() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = CompType::F32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; const bool matrix_is_transposed = false; - const uint matrix_layout_0 = MatLayout::MulOptimal; + const uint matrix_layout_0 = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; const uint matrix_stride_0 = 64; // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} @@ -888,7 +873,7 @@ void test_invalid_matrix_stride_constant_value() { matrix_dimK, matrix_layout_0, matrix_is_transposed, matrix_stride_0); - const uint matrix_layout_1 = MatLayout::OuterProductOptimal; + const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride_1 = 64; // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index 5d5c688b45..d05e1242b9 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -1,4 +1,8 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include + +using namespace dx::linalg; ByteAddressBuffer input_vector_buffer; ByteAddressBuffer matrix_buffer; @@ -10,12 +14,12 @@ void test_invalid_output_vector_type() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -53,12 +57,12 @@ void test_invalid_is_output_unsigned_non_const() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -77,12 +81,12 @@ void test_valid_input_vector_type() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = 9; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = 9; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = 0; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl index 94976566ac..7ffc15a225 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -1,39 +1,8 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify - -enum CompType { - Invalid = 0, - I1 = 1, - I16 = 2, - U16 = 3, - I32 = 4, - U32 = 5, - I64 = 6, - U64 = 7, - F16 = 8, - F32 = 9, - F64 = 10, - SNormF16 = 11, - UNormF16 = 12, - SNormF32 = 13, - UNormF32 = 14, - SNormF64 = 15, - UNormF64 = 16, - PackedS8x32 = 17, - PackedU8x32 = 18, - - // BEGIN NEW FOR SM 6.9 - U8 = 19, - I8 = 20, - F8_E4M3 = 21, - F8_E5M2 = 22, -}; - -enum MatLayout { - RowMajor = 0, - ColumnMajor = 1, - MulOptimal = 2, - OuterProductOptimal = 3, -}; +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include + +using namespace dx::linalg; ByteAddressBuffer input_vector_buffer; RWByteAddressBuffer accumulate_buffer; @@ -43,8 +12,8 @@ ByteAddressBuffer constants_buffer; void test_invalid_input_vector_component_type() { const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = 0; vector input_vector_0_0 = input_vector_buffer.Load >(0); @@ -72,7 +41,7 @@ void test_non_constant_matrix_interpretation() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = 0; const uint matrix_interpretation = constants_buffer.Load(0); @@ -90,10 +59,10 @@ void test_invalid_matrix_interpretation() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = 0; - const uint matrix_interpretation = CompType::Invalid; + const uint matrix_interpretation = 0; // expected-error@+3 {{0 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -101,7 +70,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation, matrix_layout, matrix_stride); - const uint matrix_interpretation_2 = CompType::I1; + const uint matrix_interpretation_2 = 1; // expected-error@+3 {{1 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -109,7 +78,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_2, matrix_layout, matrix_stride); - const uint matrix_interpretation_3 = CompType::I64; + const uint matrix_interpretation_3 = 6; // expected-error@+3 {{6 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -117,7 +86,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_3, matrix_layout, matrix_stride); - const uint matrix_interpretation_4 = CompType::U64; + const uint matrix_interpretation_4 = 7; // expected-error@+3 {{7 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -125,7 +94,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_4, matrix_layout, matrix_stride); - const uint matrix_interpretation_5 = CompType::F64; + const uint matrix_interpretation_5 = 10; // expected-error@+3 {{10 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -133,7 +102,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_5, matrix_layout, matrix_stride); - const uint matrix_interpretation_6 = CompType::SNormF16; + const uint matrix_interpretation_6 = 11; // expected-error@+3 {{11 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -141,7 +110,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_6, matrix_layout, matrix_stride); - const uint matrix_interpretation_7 = CompType::UNormF16; + const uint matrix_interpretation_7 = 12; // expected-error@+3 {{12 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -149,7 +118,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_7, matrix_layout, matrix_stride); - const uint matrix_interpretation_8 = CompType::SNormF32; + const uint matrix_interpretation_8 = 13; // expected-error@+3 {{13 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -157,7 +126,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_8, matrix_layout, matrix_stride); - const uint matrix_interpretation_9 = CompType::UNormF32; + const uint matrix_interpretation_9 = 14; // expected-error@+3 {{14 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -165,7 +134,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_9, matrix_layout, matrix_stride); - const uint matrix_interpretation_10 = CompType::SNormF64; + const uint matrix_interpretation_10 = 15; // expected-error@+3 {{15 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -173,7 +142,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_10, matrix_layout, matrix_stride); - const uint matrix_interpretation_11 = CompType::UNormF64; + const uint matrix_interpretation_11 = 16; // expected-error@+3 {{16 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -181,7 +150,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_11, matrix_layout, matrix_stride); - const uint matrix_interpretation_12 = CompType::PackedS8x32; + const uint matrix_interpretation_12 = DataType::DATA_TYPE_SINT8_T4_PACKED; // expected-error@+3 {{17 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -189,7 +158,7 @@ void test_invalid_matrix_interpretation() { matrix_interpretation_12, matrix_layout, matrix_stride); - const uint matrix_interpretation_13 = CompType::PackedU8x32; + const uint matrix_interpretation_13 = DataType::DATA_TYPE_UINT8_T4_PACKED; // expected-error@+3 {{18 is an invalid Memory Interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -221,7 +190,7 @@ void test_non_constant_matrix_layout() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_stride = 0; const uint matrix_layout = constants_buffer.Load(0); @@ -239,10 +208,10 @@ void test_invalid_matrix_layout() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_stride = 0; - const uint matrix_layout = MatLayout::RowMajor; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -250,7 +219,7 @@ void test_invalid_matrix_layout() { matrix_interpretation, matrix_layout, matrix_stride); - const uint matrix_layout_2 = MatLayout::ColumnMajor; + const uint matrix_layout_2 = MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR; // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -258,7 +227,7 @@ void test_invalid_matrix_layout() { matrix_interpretation, matrix_layout_2, matrix_stride); - const uint matrix_layout_3 = MatLayout::MulOptimal; + const uint matrix_layout_3 = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; // expected-error@+3 {{matrix layout for outerproductaccumulate must be 3}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, @@ -274,8 +243,8 @@ void test_zero_matrix_stride() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = 16; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl index 317a8c6e78..85298e2dbb 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_valid.hlsl @@ -1,50 +1,19 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s -verify - -enum CompType { - Invalid = 0, - I1 = 1, - I16 = 2, - U16 = 3, - I32 = 4, - U32 = 5, - I64 = 6, - U64 = 7, - F16 = 8, - F32 = 9, - F64 = 10, - SNormF16 = 11, - UNormF16 = 12, - SNormF32 = 13, - UNormF32 = 14, - SNormF64 = 15, - UNormF64 = 16, - PackedS8x32 = 17, - PackedU8x32 = 18, - - // BEGIN NEW FOR SM 6.9 - U8 = 19, - I8 = 20, - F8_E4M3 = 21, - F8_E5M2 = 22, -}; - -enum MatLayout { - RowMajor = 0, - ColumnMajor = 1, - MulOptimal = 2, - OuterProductOptimal = 3, -}; +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include + +using namespace dx::linalg; ByteAddressBuffer input_vector_buffer; RWByteAddressBuffer accumulate_buffer; ByteAddressBuffer constants_buffer; -// Check ofr input vectors aren't the same component type +// Check for input vectors aren't the same component type void test_invalid_input_vector_component_type() { const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = 0; vector input_vector_0_0 = input_vector_buffer.Load >(0); @@ -81,8 +50,8 @@ void test_non_constant_matrix_stride() { vector input_vector_0 = input_vector_buffer.Load >(0); vector input_vector_1 = input_vector_buffer.Load >(0); const uint matrix_offset = 0; - const uint matrix_interpretation = CompType::F32; - const uint matrix_layout = MatLayout::OuterProductOptimal; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride = constants_buffer.Load(0); From be4c02f0559555c82c8b03bc91cbe480d80d0054 Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 15:11:50 -0700 Subject: [PATCH 24/50] Ugh..line number change from updating the linalg headers --- .../test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl | 3 +-- .../test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl | 4 ++-- .../clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl | 6 +++--- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index b10ef48ce4..833c2838e7 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -162,8 +162,7 @@ void test_invalid_bias_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation_9); - const uint bias_interpretation_10 = 16; - + const uint bias_interpretation_10 = 16; // expected-error@+6 {{16 is an invalid Memory Interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index 637db744b1..b647478e4a 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:111{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:107{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:111{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:107{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index d2570c6183..bf4f52304c 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:125{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:121{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 52ad3d0650..ca4113b1c6 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:151{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:147{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index 318f889350..f0e34522f0 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:175{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:175{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:175{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:171{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From c4233f07aaebdd57a5b0271c12b8a206e02e43a6 Mon Sep 17 00:00:00 2001 From: Anupama Chandrasekhar Date: Wed, 7 May 2025 15:18:38 -0700 Subject: [PATCH 25/50] Update tools/clang/lib/Headers/hlsl/dx/linalg.h Co-authored-by: Damyan Pepper --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index d9020d74d0..ea6e7aa20a 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -45,7 +45,7 @@ enum MatrixLayout { namespace details { template struct IsUnsigned { - static const bool value = false; + static const bool Value = false; }; template <> struct IsUnsigned { From 4295c84266e395b6e101ec8f92f96dc5fb54aadb Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 16:21:53 -0700 Subject: [PATCH 26/50] Update variable name missed --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index ea6e7aa20a..c536deffc8 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -49,7 +49,7 @@ template struct IsUnsigned { }; template <> struct IsUnsigned { - static const bool value = true; + static const bool Value = true; }; template <> struct IsUnsigned { @@ -126,8 +126,8 @@ Mul(MatrixRefImpl OutputVector; __builtin_MatVecMul( - /*out*/ OutputVector, details::IsUnsigned::value, - InputVector.Data, details::IsUnsigned::value, InputDT, + /*out*/ OutputVector, details::IsUnsigned::Value, + InputVector.Data, details::IsUnsigned::Value, InputDT, Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, MatrixTranspose, Matrix.Stride); @@ -153,8 +153,8 @@ MulAdd(MatrixRefImpl OutputVector; __builtin_MatVecMulAdd( - /*out*/ OutputVector, details::IsUnsigned::value, - InputVector.Data, details::IsUnsigned::value, InputDT, + /*out*/ OutputVector, details::IsUnsigned::Value, + InputVector.Data, details::IsUnsigned::Value, InputDT, Matrix.Buffer, Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, BiasVectorDT); From 17b810eae38fee18e362bcb70bbf5faaa046424d Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 20:54:46 -0700 Subject: [PATCH 27/50] Use ComponentType and MatrixLayout from DxilConstants.h --- tools/clang/lib/Sema/SemaHLSL.cpp | 88 +++++++++++-------------------- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 0ee5a0ccc3..a2767d3f68 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -15,6 +15,7 @@ #include "clang/Sema/SemaHLSL.h" #include "VkConstantsTables.h" +#include "dxc/DXIL/DxilConstants.h" #include "dxc/DXIL/DxilFunctionProps.h" #include "dxc/DXIL/DxilShaderModel.h" #include "dxc/DXIL/DxilUtil.h" @@ -11681,29 +11682,22 @@ static const unsigned kMatVecMulMatrixStrideIdx = 12; // MatVecAdd const unsigned kMatVecMulAddBiasInterpretation = 15; -enum MatrixLayout { - MATRIX_LAYOUT_ROW_MAJOR = 0, - MATRIX_LAYOUT_COLUMN_MAJOR = 1, - MATRIX_LAYOUT_MUL_OPTIMAL = 2, - MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 -}; - -bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) { - return Layout <= static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL); +static bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) { + return Layout <= + static_cast(DXIL::LinalgMatrixLayout::OuterProductOptimal); } -bool IsOptimalTypeMatrixLayout(unsigned Layout) { - return (Layout == (static_cast( - MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL)) || - (Layout == (static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)))); +static bool IsOptimalTypeMatrixLayout(unsigned Layout) { + return ( + Layout == (static_cast(DXIL::LinalgMatrixLayout::MulOptimal)) || + (Layout == + (static_cast(DXIL::LinalgMatrixLayout::OuterProductOptimal)))); } -bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) { - switch (static_cast(Layout)) { - case MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR: - case MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR: +static bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) { + switch (static_cast(Layout)) { + case DXIL::LinalgMatrixLayout::RowMajor: + case DXIL::LinalgMatrixLayout::ColumnMajor: return !Transposed; default: @@ -11711,44 +11705,27 @@ bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) { } } -enum DataType { - DATA_TYPE_SINT16 = 2, // ComponentType::I16 - DATA_TYPE_UINT16 = 3, // ComponentType::U16 - DATA_TYPE_SINT32 = 4, // ComponentType::I32 - DATA_TYPE_UINT32 = 5, // ComponentType::U32 - DATA_TYPE_FLOAT16 = 8, // ComponentType::F16 - DATA_TYPE_FLOAT32 = 9, // ComponentType::F32 - DATA_TYPE_SINT8_T4_PACKED = 17, // ComponentType::PackedS8x32 - DATA_TYPE_UINT8_T4_PACKED = 18, // ComponentType::PackedU8x32 - DATA_TYPE_UINT8 = 19, // ComponentType::U8 - DATA_TYPE_SINT8 = 20, // ComponentType::I8 - DATA_TYPE_FLOAT8_E4M3 = 21, // ComponentType::F8_E4M3 - // (1 sign, 4 exp, 3 mantissa bits) - DATA_TYPE_FLOAT8_E5M2 = 22, // ComponentType::F8_E5M2 - // (1 sign, 5 exp, 2 mantissa bits) -}; - -bool IsPackedType(unsigned type) { - return (type == static_cast(DATA_TYPE_SINT8_T4_PACKED) || - type == static_cast(DATA_TYPE_UINT8_T4_PACKED)); +static bool IsPackedType(unsigned type) { + return (type == static_cast(DXIL::ComponentType::PackedS8x32) || + type == static_cast(DXIL::ComponentType::PackedU8x32)); } static bool IsValidLinalgTypeInterpretation(uint32_t Input, bool InRegister) { switch (Input) { - case DATA_TYPE_SINT16: - case DATA_TYPE_UINT16: - case DATA_TYPE_SINT32: - case DATA_TYPE_UINT32: - case DATA_TYPE_FLOAT16: - case DATA_TYPE_FLOAT32: - case DATA_TYPE_UINT8: - case DATA_TYPE_SINT8: - case DATA_TYPE_FLOAT8_E4M3: - case DATA_TYPE_FLOAT8_E5M2: + case DXIL::ComponentType::I16: + case DXIL::ComponentType::U16: + case DXIL::ComponentType::I32: + case DXIL::ComponentType::U32: + case DXIL::ComponentType::F16: + case DXIL::ComponentType::F32: + case DXIL::ComponentType::U8: + case DXIL::ComponentType::I8: + case DXIL::ComponentType::F8_E4M3: + case DXIL::ComponentType::F8_E5M2: return true; - case DATA_TYPE_SINT8_T4_PACKED: - case DATA_TYPE_UINT8_T4_PACKED: + case DXIL::ComponentType::PackedS8x32: + case DXIL::ComponentType::PackedU8x32: return InRegister; default: return false; @@ -12038,9 +12015,9 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, diag::err_hlsl_linalg_matrix_layout_invalid) << std::to_string(MatrixLayoutValue) << std::to_string( - static_cast(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR)) + static_cast(DXIL::LinalgMatrixLayout::RowMajor)) << std::to_string(static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + DXIL::LinalgMatrixLayout::OuterProductOptimal)); return; } } else { @@ -12184,14 +12161,13 @@ static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); if (MatrixLayoutValue != - static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)) { + static_cast(DXIL::LinalgMatrixLayout::OuterProductOptimal)) { S.Diags.Report( MatrixLayoutExpr->getExprLoc(), diag:: err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal) << std::to_string(static_cast( - MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)); + DXIL::LinalgMatrixLayout::OuterProductOptimal)); return; } } else { From 3cce13133ce0966bf55e4cd14c801642c098a6df Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 7 May 2025 21:15:32 -0700 Subject: [PATCH 28/50] Fix unsafe inmplicit cast --- tools/clang/lib/Sema/SemaHLSL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index a2767d3f68..35c53b0265 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11712,7 +11712,7 @@ static bool IsPackedType(unsigned type) { static bool IsValidLinalgTypeInterpretation(uint32_t Input, bool InRegister) { - switch (Input) { + switch (static_cast(Input)) { case DXIL::ComponentType::I16: case DXIL::ComponentType::U16: case DXIL::ComponentType::I32: From c9c13890df083b60f0ee4ab436f04f614436b612 Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 8 May 2025 07:03:04 -0700 Subject: [PATCH 29/50] Add tests to mul_add_invalid for shared parameters --- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 920 +++++++++++++++++- 1 file changed, 913 insertions(+), 7 deletions(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 833c2838e7..3b5bf4f764 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -2,13 +2,6 @@ #include -enum MatLayout { - RowMajor = 0, - ColumnMajor = 1, - MulOptimal = 2, - OuterProductOptimal = 3, -}; - using namespace dx::linalg; ByteAddressBuffer input_vector_buffer; @@ -17,6 +10,919 @@ ByteAddressBuffer bias_buffer; RWByteAddressBuffer output_vector_buffer; ByteAddressBuffer constants_buffer; +// Output vector, isUnsigned mismatch +void test_invalid_output_vector_type() { + + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector output_vector_0; + const uint is_output_unsigned_0 = 0; + + // expected-error@+1 {{IsOuputUnsigned must be true for a unsigned int vector type}} + __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector output_vector_1; + const uint is_output_unsigned_1 = 1; + + // expected-error@+1 {{IsOuputUnsigned must be false for a signed int vector type}} + __builtin_MatVecMulAdd(output_vector_1, is_output_unsigned_1, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector output_vector_2; + const uint is_output_unsigned_2 = 1; + + // expected-error@+1 {{IsOuputUnsigned must be false for a float vector type}} + __builtin_MatVecMulAdd(output_vector_2, is_output_unsigned_2, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// IsOutputUnsigned is not a constant parameter +void test_invalid_is_output_unsigned_non_const() { + + vector output_vector_0; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint is_output_unsigned_0 = constants_buffer.Load(0); + + // expected-error@+1 {{IsOutputUnsigned' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned_0, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Input vector is incorrect type - 64 bit types +void test_invalid_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 0; + +// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Input vector type/isInputUnsigned mismatch +void test_invalid_input_vector_type_mismatch() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for a unsigned int vector type}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-error@+2 {{IsInputUnsigned must be false for a signed int vector type}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 1; + + // expected-error@+2 {{IsInputUnsigned must be false for a float vector type}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check is Matrix M dimension is a constant parameter +void test_invalid_matrix_M_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_dimM = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixM' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check is Matrix K dimension is a constant parameter +void test_invalid_matrix_K_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_dimK = constants_buffer.Load(0); + + // expected-error@+4 {{'MatrixK' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check is Matrix M dimension is non-zero +void test_invalid_matrix_M_dimension_non_zero() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_dimM = 0; + // expected-error@+3 {{matrix dimension must not be zero}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check is Matrix K dimension is non-zero +void test_invalid_matrix_K_dimension_non_zero() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_dimK = 0; + // expected-error@+4 {{matrix dimension must not be zero}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +//Check if InputInterpretation is a constant parameter +void test_invalid_input_interpretation_non_const() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation = constants_buffer.Load(0); + + // expected-error@+2 {{'InputInterpretation' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if InputInterpretation is a valid value +void test_invalid_input_interpretation_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = 0; + + // expected-error@+2 {{0 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_1 = 1; + + // expected-error@+2 {{1 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_2 = 6; + + // expected-error@+2 {{6 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_2, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_3 = 7; + + // expected-error@+2 {{7 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_3, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_4 = 10; + + // expected-error@+2 {{10 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_4, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_5 = 11; + + // expected-error@+2 {{11 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_5, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_6 = 12; + + // expected-error@+2 {{12 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_6, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_7 = 13; + + // expected-error@+2 {{13 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_7, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_8 = 14; + + // expected-error@+2 {{14 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_8, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_9 = 15; + + // expected-error@+2 {{15 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_9, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_10 = 16; + + // expected-error@+2 {{16 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_10, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_11 = 23; + + // expected-error@+2 {{23 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_11, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_12 = 100; + + // expected-error@+2 {{100 is an invalid Register Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation_12, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} +// Check if Input and Output vector dimensions are valid -non packed +void test_invalid_input_output_vector_dimensions_non_packed_square_matrix() { + + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 32; + const uint matrix_dimK = 32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector output_vector_0; + vector input_vector_0 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector output_vector_1; + vector input_vector_1 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_1, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if Input and Output vector dimensions are valid -non packed +void test_invalid_input_output_vector_dimensions_non_packed_rectangle_matrix() { + + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 16; + const uint matrix_dimK = 32; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + // Use dimension of Matrix K to trigger error + vector output_vector_0; + vector input_vector_0 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Check off by 1 errors + vector output_vector_1; + vector input_vector_1 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_1, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Check off by 1 errors + vector output_vector_2; + vector input_vector_2 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_2, is_output_unsigned, input_vector_2, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Use dimension of Matrix M to trigger error + vector output_vector_3; + vector input_vector_3 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_3, is_output_unsigned, input_vector_3, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Check off by 1 errors + vector output_vector_4; + vector input_vector_4 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_4, is_output_unsigned, input_vector_4, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Check off by 1 errors + vector output_vector_5; + vector input_vector_5 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_5, is_output_unsigned, input_vector_5, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + // Swap dimensions to trigger error + vector output_vector_6; + vector input_vector_6 = + input_vector_buffer.Load >(0); + + // expected-error@+1 {{output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector_6, is_output_unsigned, input_vector_6, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if matrtrix interpretation is a constant value +void test_invalid_matrix_interpretation_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_interpretation_0 = constants_buffer.Load(0); + + // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_0, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check for invalid matrix interpretation value +void test_invalid_matrix_interpretation_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_interpretation_0 = 0; + + // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_0, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_1 = 1; + + // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_1, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_2 = 6; + + // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_2, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_3 = 7; + + // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_3, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_4 = 10; + + // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_4, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_5 = 11; + + // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_5, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_6 = 12; + + // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_6, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_7 = 13; + + // expected-error@+3 {{13 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_7, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_8 = 14; + + // expected-error@+3 {{14 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_8, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_9 = 15; + + // expected-error@+3 {{15 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_9, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_10 = 16; + + // expected-error@+3 {{16 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_10, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_11 = 23; + // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_11, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_interpretation_12 = 100; + + // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation_12, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if matrix Layout is a constant value +void test_invalid_matrix_layout_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_layout = constants_buffer.Load(0); + + // expected-error@+4 {{'MatrixLayout' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check invalid matrix layout value +void test_invalid_matrix_layout_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_layout_0 = 4; + + // expected-error@+4 {{matrix layout 4 is not valid, must be in the range 0 - 3}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if matrix is transposed is a constant value +void test_invalid_matrix_transposed_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = constants_buffer.Load(0); + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + // expected-error@+4 {{'MatrixTranspose' must be a constant parameter}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if invalid matrix transpose value is used +void test_invalid_matrix_transpose_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint matrix_layout_0 = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed_0 = true; + + // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed_0, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR; + const bool matrix_is_transposed_1 = true; + + // expected-error@+4 {{RowMajor and ColumnMajor matrices are not transposable}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_1, matrix_is_transposed_1, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + + +// Check invalid matrix stride value for optimal matrix layout +void test_invalid_matrix_stride_constant_value() { + + vector output_vector; + const uint is_output_unsigned = 1; + vector input_vector = + input_vector_buffer.Load >(0); + const uint is_input_unsigned = 0; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const bool matrix_is_transposed = false; + + const uint matrix_layout_0 = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; + const uint matrix_stride_0 = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_0, matrix_is_transposed, + matrix_stride_0, bias_buffer, bias_offset, bias_interpretation); + + const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; + const uint matrix_stride_1 = 64; + + // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout_1, matrix_is_transposed, + matrix_stride_1, bias_buffer, bias_offset, bias_interpretation); +} + // Check bias interpretation is not a constant value void test_invalid_bias_interpretation() { vector output_vector; From e870b991d61eb1ceda528ed3b0546ebada3bba97 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 9 May 2025 09:52:48 -0700 Subject: [PATCH 30/50] Add validation and tests for packed input types --- .../clang/Basic/DiagnosticSemaKinds.td | 8 +- tools/clang/lib/Sema/SemaHLSL.cpp | 150 ++++++++------ .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 8 +- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 170 +++++++++++++++- .../hlsl/linalg/builtins/mul_add_valid.hlsl | 136 +++++++++++++ .../hlsl/linalg/builtins/mul_invalid.hlsl | 192 ++++++++++++++++-- .../hlsl/linalg/builtins/mul_valid.hlsl | 116 +++++++++++ 7 files changed, 700 insertions(+), 80 deletions(-) create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index d4e0ce46ef..850abd50a6 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8042,7 +8042,13 @@ def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error< def err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K : Error< "unpacked input vector length must be equal to Matrix K dimension in a linalg Mul/MulAdd operation">; def err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect : Error< - "packed input vector length must be the smallest number that can hold K values of the packed type">; + "packed input vector length must be the smallest number that can hold matrix dim K values of the " + "packed(smaller) type in linalg mul/muladd operations">; +def err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true : Error< + "IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations">; +def err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint : Error< + "packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, " + "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< "input vectors of outerproductaccumulate must have the same element type">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 35c53b0265..a91e975fb7 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11790,16 +11790,16 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, // Check if output vector is unsigned int, signed int or float // Check if the isUnsigned flag is set correctly - Expr *OutputVector = CE->getArg(kMatVecMulOutputVectorIdx); + Expr *OutputVectorExpr = CE->getArg(kMatVecMulOutputVectorIdx); unsigned OutputVectorSizeValue = 0; - if (IsHLSLVecType(OutputVector->getType())) { - OutputVectorSizeValue = GetHLSLVecSize(OutputVector->getType()); - QualType OutputVectorType = GetHLSLVecElementType(OutputVector->getType()); + if (IsHLSLVecType(OutputVectorExpr->getType())) { + OutputVectorSizeValue = GetHLSLVecSize(OutputVectorExpr->getType()); + QualType OutputVectorType = GetHLSLVecElementType(OutputVectorExpr->getType()); const Type *OutputVectorTypePtr = OutputVectorType.getTypePtr(); if (!OutputVectorTypePtr->isUnsignedIntegerType() && !OutputVectorTypePtr->isSignedIntegerType() && !OutputVectorTypePtr->isFloatingType()) { - S.Diags.Report(OutputVector->getExprLoc(), + S.Diags.Report(OutputVectorExpr->getExprLoc(), diag::err_hlsl_linalg_vector_incorrect_type) << "Output Vector"; return; @@ -11811,7 +11811,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, !OutputVectorTypePtr->isUnsignedIntegerType()) { DXASSERT_NOMSG(OutputVectorTypePtr->isSignedIntegerType() || OutputVectorTypePtr->isFloatingType()); - S.Diags.Report(OutputVector->getExprLoc(), + S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsOuputUnsigned" << false << (OutputVectorTypePtr->isSignedIntegerType() ? "signed int" @@ -11819,7 +11819,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } else if (!IsOutputUnsignedFlagValue && OutputVectorTypePtr->isUnsignedIntegerType()) { - S.Diags.Report(OutputVector->getExprLoc(), + S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsOuputUnsigned" << true << "unsigned int"; return; @@ -11840,18 +11840,45 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } + // Get InputInterpretation, check if it is constant + Expr *InputInterpretationExpr = CE->getArg(kMatVecMulInputInterpretationIdx); + llvm::APSInt InputInterpretationExprVal; + unsigned InputInterpretationValue = 0; + if (InputInterpretationExpr->isIntegerConstantExpr(InputInterpretationExprVal, + S.Context)) { + InputInterpretationValue = InputInterpretationExprVal.getLimitedValue(); + const bool InRegisterInterpretation = true; + if (!IsValidLinalgTypeInterpretation(InputInterpretationValue, + InRegisterInterpretation)) { + S.Diags.Report(InputInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_interpretation_value_incorrect) + << std::to_string(InputInterpretationValue) + << InRegisterInterpretation; + return; + } + } else { + S.Diags.Report(InputInterpretationExpr->getExprLoc(), + diag::err_hlsl_linalg_param_must_be_const) + << "InputInterpretation"; + return; + } + + bool IsInputVectorPacked = IsPackedType(InputInterpretationValue); + // Check if input vector32/16bit is unsigned int, signed int or float - Expr *InputVector = CE->getArg(kMatVecMulInputVectorIdx); + // For packed types input vector type must be uint and isUnsigned must be + // true. The signedness is determined from the InputInterpretation + Expr *InputVectorExpr = CE->getArg(kMatVecMulInputVectorIdx); unsigned InputVectorSizeValue = 0; - if (IsHLSLVecType(InputVector->getType())) { - InputVectorSizeValue = GetHLSLVecSize(InputVector->getType()); - QualType InputVectorType = GetHLSLVecElementType(InputVector->getType()); + if (IsHLSLVecType(InputVectorExpr->getType())) { + InputVectorSizeValue = GetHLSLVecSize(InputVectorExpr->getType()); + QualType InputVectorType = + GetHLSLVecElementType(InputVectorExpr->getType()); unsigned BitWidth = S.Context.getTypeSize(InputVectorType); bool Is16Bit = (BitWidth == 16); bool Is32Bit = (BitWidth == 32); - if (!Is16Bit && !Is32Bit) { - S.Diags.Report(InputVector->getExprLoc(), + S.Diags.Report(InputVectorExpr->getExprLoc(), diag::err_hlsl_linalg_vector_incorrect_type) << "Input Vector"; return; @@ -11861,29 +11888,59 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (!InputVectorTypePtr->isUnsignedIntegerType() && !InputVectorTypePtr->isSignedIntegerType() && !InputVectorTypePtr->isFloatingType()) { - S.Diags.Report(InputVector->getExprLoc(), + S.Diags.Report(InputVectorExpr->getExprLoc(), diag::err_hlsl_linalg_vector_incorrect_type) << "Input Vector"; return; } - // Check if the isUnsigned flag is set correctly - if (IsInputUnsignedFlagValue && - !InputVectorTypePtr->isUnsignedIntegerType()) { - DXASSERT_NOMSG(InputVectorTypePtr->isSignedIntegerType() || - InputVectorTypePtr->isFloatingType()); - S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), - diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) - << "IsInputUnsigned" << false - << (InputVectorTypePtr->isSignedIntegerType() ? "signed int" - : "float"); - return; - } else if (!IsInputUnsignedFlagValue && - InputVectorTypePtr->isUnsignedIntegerType()) { - S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), - diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) - << "IsInputUnsigned" << true << "unsigned int"; - return; + // Check if the isUnsigned flag setting + if (IsInputVectorPacked) { + // Check that the input vector type is always uint32_t + if (!Is32Bit) { + S.Diags.Report( + InputVectorExpr->getExprLoc(), + diag::err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint); + return; + } + + // Check that the input vector is unsigned int + if (!InputVectorTypePtr->isUnsignedIntegerType()) { + S.Diags.Report( + InputVectorExpr->getExprLoc(), + diag::err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint); + return; + } + + // Check that isInputUnsigned is always true + // Actual signedness is inferred from the InputInterpretation + if (!IsInputUnsignedFlagValue) { + S.Diags.Report( + IsInputUnsignedExpr->getExprLoc(), + diag:: + err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true); + return; + } + } else { + if (IsInputUnsignedFlagValue && + !InputVectorTypePtr->isUnsignedIntegerType()) { + DXASSERT_NOMSG(InputVectorTypePtr->isSignedIntegerType() || + InputVectorTypePtr->isFloatingType()); + S.Diags.Report( + IsInputUnsignedExpr->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsInputUnsigned" << false + << (InputVectorTypePtr->isSignedIntegerType() ? "signed int" + : "float"); + return; + } else if (!IsInputUnsignedFlagValue && + InputVectorTypePtr->isUnsignedIntegerType()) { + S.Diags.Report( + IsInputUnsignedExpr->getExprLoc(), + diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) + << "IsInputUnsigned" << true << "unsigned int"; + return; + } } } @@ -11944,38 +12001,9 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } - // Get InputInterpretation, check if it is constant - Expr *InputInterpretationExpr = CE->getArg(kMatVecMulInputInterpretationIdx); - llvm::APSInt InputInterpretationExprVal; - unsigned InputInterpretationValue = 0; - if (InputInterpretationExpr->isIntegerConstantExpr(InputInterpretationExprVal, - S.Context)) { - InputInterpretationValue = InputInterpretationExprVal.getLimitedValue(); - const bool InRegisterInterpretation = true; - if (!IsValidLinalgTypeInterpretation(InputInterpretationValue, - InRegisterInterpretation)) { - S.Diags.Report(InputInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_interpretation_value_incorrect) - << std::to_string(InputInterpretationValue) - << InRegisterInterpretation; - return; - } - } else { - S.Diags.Report(InputInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "InputInterpretation"; - return; - } - - bool isInputPacked = IsPackedType(InputInterpretationValue); - - // FIXME: Add check for if input vector is packed type then - // input interpretation has to be the corresponding pack type. - // Packed type show up as floats? - if (!IsValidVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, OutputVectorSizeValue, MatrixKValue, - MatrixMValue, isInputPacked)) { + MatrixMValue, IsInputVectorPacked)) { return; } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl index 141801c71c..e0126dd76a 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -15,26 +15,26 @@ export float4 Test1(vector Input) { Matrix, MakeInterpretedVector(Input)); } -export vector Test2(vector Input) { +export vector Test2(vector Input) { using namespace dx::linalg; MatrixRef Matrix = { Buf, 0, 0}; // note the stride argument is dropped. - // CHECK: %{{.+}} = call <8 x float> @dx.op.matVecMul.v8f32.v6f32(i32 305, <6 x float> %{{.+}}, i1 false, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 2, i1 false, i32 0, i1 false) + // CHECK: %{{.+}} = call <8 x float> @dx.op.matVecMul.v8f32.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 2, i1 false, i32 0, i1 false) return Mul(Matrix, MakeInterpretedVector(Input)); } // test that "stride" isn't ignored in non-optimal layouts -export vector Test3(vector Input) { +export vector Test3(vector Input) { using namespace dx::linalg; MatrixRef Matrix = { Buf, 0, 6 * 4 * 8}; - // CHECK: %{{.+}} = call <8 x float> @dx.op.matVecMul.v8f32.v6f32(i32 305, <6 x float> %{{.+}}, i1 false, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 false) + // CHECK: %{{.+}} = call <8 x float> @dx.op.matVecMul.v8f32.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 false) return Mul(Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 3b5bf4f764..623613493a 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -136,7 +136,175 @@ void test_invalid_input_vector_type() { matrix_stride, bias_buffer, bias_offset, bias_interpretation); } -// Input vector type/isInputUnsigned mismatch +// Input vector is incorrect type for packed InputInterpretation +void test_invalid_input_vector_type_packed_input_interpretation() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_2 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 1; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation_2, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_3 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_3 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_3 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_3, + is_input_unsigned_3, input_interpretation_3, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_4 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_4 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_4 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_4, + is_input_unsigned_4, input_interpretation_4, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// IsInputUnsigned must be true for packed input vector type +void test_invalid_is_input_unsigned_packed_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check packed input vector dimension +void test_invalid_packed_input_vector_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_UINT8; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_UINT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_0 = 4; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_1 = 7; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_2 = 7; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_2, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + +} + +// Check is Input vector type/isInputUnsigned matched void test_invalid_input_vector_type_mismatch() { vector output_vector; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl new file mode 100644 index 0000000000..d272fd334f --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl @@ -0,0 +1,136 @@ +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s + +#include + +using namespace dx::linalg; + +ByteAddressBuffer input_vector_buffer; +ByteAddressBuffer matrix_buffer; +ByteAddressBuffer bias_buffer; +RWByteAddressBuffer output_vector_buffer; +ByteAddressBuffer constants_buffer; + +// Check valid input vector packed types +void test_valid_input_vector_packed_types() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + +} + +// IsInputUnsigned must be true for packed input vector type +void test_valid_is_input_unsigned_packed_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-no-diagnostics@+2 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-no-diagnostics@+2 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check packed input vector dimension +void test_valid_packed_input_vector_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_UINT8; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_UINT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_1 = 7; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + + + diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index fc6dc9bae1..e06d5bdcac 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -15,12 +15,12 @@ void test_invalid_output_vector_type() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -62,12 +62,12 @@ void test_invalid_is_output_unsigned_non_const() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; - const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -86,12 +86,12 @@ void test_invalid_input_vector_type() { vector output_vector; const uint is_output_unsigned = 1; - const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 4; const uint matrix_dimK = 4; - const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -129,6 +129,172 @@ void test_invalid_input_vector_type() { matrix_stride); } +// Input vector is incorrect type for packed InputInterpretation +void test_invalid_input_vector_type_packed_input_interpretation() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint input_interpretation_0 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_2 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_2 = 1; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned_2, input_interpretation_2, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_3 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_3 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_3 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_3, + is_input_unsigned_3, input_interpretation_3, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_4 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_4 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_4 = 0; + + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_4, + is_input_unsigned_4, input_interpretation_4, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// IsInputUnsigned must be true for packed input vector type +void test_invalid_is_input_unsigned_packed_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 0; + + // expected-error@+2 {{IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check packed input vector dimension +void test_invalid_packed_input_vector_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_UINT8; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_UINT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_0 = 4; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_1 = 7; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_2 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_2 = 7; + + // expected-error@+1 {{packed input vector length must be the smallest number that can hold matrix dim K values of the packed(smaller) type in linalg mul/muladd operations}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_2, matrix_layout, matrix_is_transposed, + matrix_stride); + +} + // Input vector type/isInputUnsigned mismatch void test_invalid_input_vector_type_mismatch() { @@ -443,12 +609,12 @@ void test_invalid_input_output_vector_dimensions_non_packed_square_matrix() { const uint is_output_unsigned = 1; const uint is_input_unsigned = 0; - const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; - const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; // F32 + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 32; const uint matrix_dimK = 32; - const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; @@ -485,7 +651,7 @@ void test_invalid_input_output_vector_dimensions_non_packed_rectangle_matrix() { const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 16; const uint matrix_dimK = 32; - const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; // RowMajor + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; const bool matrix_is_transposed = false; const uint matrix_stride = 64; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index d05e1242b9..c0c6b4780a 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -123,3 +123,119 @@ void test_valid_input_vector_type() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); } + +// Check valid input vector packed types +void test_valid_input_vector_packed_types() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + +} + +// IsInputUnsigned must be true for packed input vector type +void test_valid_is_input_unsigned_packed_input_vector_type() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_0 = 1; + + // expected-no-diagnostics@+2 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned_0, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + const uint input_interpretation_1 = DataType::DATA_TYPE_SINT8_T4_PACKED; + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint is_input_unsigned_1 = 1; + + // expected-no-diagnostics@+2 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned_1, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check packed input vector dimension +void test_valid_packed_input_vector_dimension() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint input_interpretation = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_UINT8; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; + const bool matrix_is_transposed = false; + const uint matrix_stride = 0; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint matrix_dimK_1 = 7; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride); +} From 46c2caf3f34beeced01cbc8ae185950a4aa50c4f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 9 May 2025 16:56:53 +0000 Subject: [PATCH 31/50] chore: autopublish 2025-05-09T16:56:52Z --- tools/clang/lib/Sema/SemaHLSL.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index a91e975fb7..752c85aa44 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11794,7 +11794,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, unsigned OutputVectorSizeValue = 0; if (IsHLSLVecType(OutputVectorExpr->getType())) { OutputVectorSizeValue = GetHLSLVecSize(OutputVectorExpr->getType()); - QualType OutputVectorType = GetHLSLVecElementType(OutputVectorExpr->getType()); + QualType OutputVectorType = + GetHLSLVecElementType(OutputVectorExpr->getType()); const Type *OutputVectorTypePtr = OutputVectorType.getTypePtr(); if (!OutputVectorTypePtr->isUnsignedIntegerType() && !OutputVectorTypePtr->isSignedIntegerType() && From 99a956679e54c51dab4ac0c4a448f50f3c04828e Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 9 May 2025 10:18:55 -0700 Subject: [PATCH 32/50] review feedback --- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- tools/clang/lib/Sema/SemaHLSL.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 850abd50a6..a2e405752f 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8048,7 +8048,7 @@ def err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true : Error< "IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations">; def err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint : Error< "packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, " - "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; + "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< "input vectors of outerproductaccumulate must have the same element type">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 752c85aa44..f4404620e3 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11682,7 +11682,7 @@ static const unsigned kMatVecMulMatrixStrideIdx = 12; // MatVecAdd const unsigned kMatVecMulAddBiasInterpretation = 15; -static bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) { +static bool IsValidMatrixLayoutForMulAndMulAddOps(unsigned Layout) { return Layout <= static_cast(DXIL::LinalgMatrixLayout::OuterProductOptimal); } @@ -11897,7 +11897,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, // Check if the isUnsigned flag setting if (IsInputVectorPacked) { - // Check that the input vector type is always uint32_t + // Check that the input vector element type is "32bit" if (!Is32Bit) { S.Diags.Report( InputVectorExpr->getExprLoc(), @@ -11905,7 +11905,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } - // Check that the input vector is unsigned int + // Check that the input vector element type is an unsigned int if (!InputVectorTypePtr->isUnsignedIntegerType()) { S.Diags.Report( InputVectorExpr->getExprLoc(), @@ -12039,7 +12039,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, unsigned MatrixLayoutValue = 0; if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) { MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue(); - if (!IsValidMatrixLayoutForMulandMulAddOps(MatrixLayoutValue)) { + if (!IsValidMatrixLayoutForMulAndMulAddOps(MatrixLayoutValue)) { S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_hlsl_linalg_matrix_layout_invalid) << std::to_string(MatrixLayoutValue) From 2ab5c866e0e75c6f7089cc383d290f690471b55a Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 9 May 2025 10:22:52 -0700 Subject: [PATCH 33/50] alignment --- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index a2e405752f..788a80cf67 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8048,7 +8048,7 @@ def err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true : Error< "IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations">; def err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint : Error< "packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, " - "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; + "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< "input vectors of outerproductaccumulate must have the same element type">; From 90fac9792fe372151f1ef9f79ff176e75588f83e Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 9 May 2025 12:36:25 -0700 Subject: [PATCH 34/50] Add Max Matrix Dim checks --- .../clang/Basic/DiagnosticSemaKinds.td | 10 +- tools/clang/lib/Sema/SemaHLSL.cpp | 31 +++-- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 109 +++++++++++++++++- .../hlsl/linalg/builtins/mul_add_valid.hlsl | 108 +++++++++++++++++ .../hlsl/linalg/builtins/mul_invalid.hlsl | 102 ++++++++++++++++ .../hlsl/linalg/builtins/mul_valid.hlsl | 107 ++++++++++++++++- 6 files changed, 455 insertions(+), 12 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 788a80cf67..d12a532a94 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8028,8 +8028,6 @@ def err_hlsl_linalg_matrix_layout_is_not_transposable : Error< "RowMajor and ColumnMajor matrices are not transposable">; def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error< "for optimal matrix layout, matrix stride must be zero">; -def err_hlsl_linalg_exceeds_max_matrix_dim: Error< - "matrix dimension for linalg operations must be less than %0">; def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error< "matrix dimension must not be zero">; def err_hlsl_linalg_matrix_layout_invalid : Error< @@ -8049,6 +8047,14 @@ def err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true : Error< def err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint : Error< "packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, " "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; +def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_m: Error< + "matrix dimension M must be less than %0, in a linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_unpacked_input: Error< + "matrix dimension K when using unpacked input vectors must be less than %0, in a " + "linalg Mul/MulAdd operation">; +def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_packed_input: Error< + "matrix dimension K when using packed input vectors must be less than %0, in a " + "linalg Mul/MulAdd operation">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< "input vectors of outerproductaccumulate must have the same element type">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index f4404620e3..f8ae371d34 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11987,19 +11987,36 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, // Check MatrixM and MatrixK values are less than max // Matrix dimension cannot exceed largest vector length in a Mul/MulAdd - // operation + // operation. if (MatrixMValue > DXIL::kSM69MaxVectorLength) { S.Diags.Report(MatrixMExpr->getExprLoc(), - diag::err_hlsl_linalg_exceeds_max_matrix_dim) + diag::err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_m) << std::to_string(DXIL::kSM69MaxVectorLength); return; } - if (MatrixKValue > DXIL::kSM69MaxVectorLength) { - S.Diags.Report(MatrixKExpr->getExprLoc(), - diag::err_hlsl_linalg_exceeds_max_matrix_dim) - << std::to_string(DXIL::kSM69MaxVectorLength); - return; + // For packed input vectors 4 values are packed in a uint, so max Matrix K + // can be 4096 + if (IsInputVectorPacked) { + const unsigned PackingFactor = + 4; // Only supported packed formats: DATA_TYPE_(U)SINT8_T4_PACKED + if (MatrixKValue > DXIL::kSM69MaxVectorLength * PackingFactor) { + S.Diags.Report( + MatrixKExpr->getExprLoc(), + diag:: + err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_packed_input) + << std::to_string(DXIL::kSM69MaxVectorLength * PackingFactor); + return; + } + } else { + if (MatrixKValue > DXIL::kSM69MaxVectorLength) { + S.Diags.Report( + MatrixKExpr->getExprLoc(), + diag:: + err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_unpacked_input) + << std::to_string(DXIL::kSM69MaxVectorLength); + return; + } } if (!IsValidVectorAndMatrixDimensions(S, CE, InputVectorSizeValue, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 623613493a..144ad10b03 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -464,7 +464,114 @@ void test_invalid_matrix_K_dimension_non_zero() { matrix_stride, bias_buffer, bias_offset, bias_interpretation); } -//Check if InputInterpretation is a constant parameter +// Check if Matrix M dimension is less than Max +void test_invalid_matrix_M_dimension_less_than_Max() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = matrix_dimK * 4; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM_0 = 1025; + + // expected-error@+3 {{matrix dimension M must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_0, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimM_1 = 4097; + + // expected-error@+3 {{matrix dimension M must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_1, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if Matrix K dimension is less than Max in unpacked input vector case +void test_invalid_matrix_K_dimension_less_than_Max_unpacked_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK_0 = 1025; + + // expected-error@+4 {{matrix dimension K when using unpacked input vectors must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8; + const uint matrix_dimK_1 = 4096; + // expected-error@+4 {{matrix dimension K when using unpacked input vectors must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + +} + +// Check if Matrix M dimension is less than Max in packed input vector case +void test_invalid_matrix_M_dimension_less_than_Max_packed_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 1024; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 4096; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimK_0 = 4097; + + // expected-error@+4 {{matrix dimension K when using packed input vectors must be less than 4096, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + void test_invalid_input_interpretation_non_const() { vector output_vector; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl index d272fd334f..4b0bd6dd87 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_valid.hlsl @@ -132,5 +132,113 @@ void test_valid_packed_input_vector_dimension() { matrix_stride, bias_buffer, bias_offset, bias_interpretation); } +// Check if Matrix M dimension is less than Max +void test_valid_matrix_M_dimension_less_than_Max() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = matrix_dimK * 4; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_0, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimM_1 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_1, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + +// Check if Matrix K dimension is less than Max in unpacked input vector case +void test_valid_matrix_K_dimension_less_than_Max_unpacked_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8; + const uint matrix_dimK_1 = 4; + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); + +} + +// Check if Matrix M dimension is less than Max in packed input vector case +void test_valid_matrix_M_dimension_less_than_Max_packed_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + const uint bias_offset = 0; + const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimK_0 = 4096; + + // expected-no-diagnostics@+1 + __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride, bias_buffer, bias_offset, bias_interpretation); +} + diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index e06d5bdcac..77e39c8dc8 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -445,6 +445,108 @@ void test_invalid_matrix_K_dimension_non_zero() { matrix_stride); } +// Check if Matrix M dimension is less than Max +void test_invalid_matrix_M_dimension_less_than_Max() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = matrix_dimK * 4; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM_0 = 1025; + + // expected-error@+3 {{matrix dimension M must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_0, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimM_1 = 4097; + + // expected-error@+3 {{matrix dimension M must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_1, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check if Matrix K dimension is less than Max in unpacked input vector case +void test_invalid_matrix_K_dimension_less_than_Max_unpacked_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK_0 = 1025; + + // expected-error@+4 {{matrix dimension K when using unpacked input vectors must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8; + const uint matrix_dimK_1 = 4096; + // expected-error@+4 {{matrix dimension K when using unpacked input vectors must be less than 1024, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride); + +} + +// Check if Matrix M dimension is less than Max in packed input vector case +void test_invalid_matrix_M_dimension_less_than_Max_packed_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 1024; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 4096; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimK_0 = 4097; + + // expected-error@+4 {{matrix dimension K when using packed input vectors must be less than 4096, in a linalg Mul/MulAdd operation}} + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); +} + //Check if InputInterpretation is a constant parameter void test_invalid_input_interpretation_non_const() { diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index c0c6b4780a..dab977b7fa 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -10,7 +10,7 @@ RWByteAddressBuffer output_vector_buffer; ByteAddressBuffer const_buffer; // Output vector, isUnsigned mismatch -void test_invalid_output_vector_type() { +void test_valid_output_vector_type() { vector input_vector = input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; @@ -51,7 +51,7 @@ void test_invalid_output_vector_type() { matrix_is_transposed, matrix_stride); } -void test_invalid_is_output_unsigned_non_const() { +void test_valid_is_output_unsigned_non_const() { vector output_vector_0; vector input_vector = @@ -239,3 +239,106 @@ void test_valid_packed_input_vector_dimension() { matrix_dimK_1, matrix_layout, matrix_is_transposed, matrix_stride); } + +// Check if Matrix M dimension is less than Max +void test_valid_matrix_M_dimension_less_than_Max() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = matrix_dimK * 4; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_0, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimM_1 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM_1, + matrix_dimK, matrix_layout, matrix_is_transposed, + matrix_stride); +} + +// Check if Matrix K dimension is less than Max in unpacked input vector case +void test_valid_matrix_K_dimension_less_than_Max_unpacked_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimK_0 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); + + vector input_vector_1 = + input_vector_buffer.Load >(0); + const uint input_interpretation_1 = DataType::DATA_TYPE_UINT8; + const uint matrix_dimK_1 = 4; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, + is_input_unsigned, input_interpretation_1, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_1, matrix_layout, matrix_is_transposed, + matrix_stride); + +} + +// Check if Matrix M dimension is less than Max in packed input vector case +void test_valid_matrix_M_dimension_less_than_Max_packed_input_vector() { + + vector output_vector; + const uint is_output_unsigned = 1; + const uint is_input_unsigned = 1; + const uint matrix_offset = 0; + const uint matrix_interpretation = DataType::DATA_TYPE_FLOAT32; + const uint matrix_dimM = 4; + const uint matrix_layout = MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR; + const bool matrix_is_transposed = false; + const uint matrix_stride = 64; + + vector input_vector_0 = + input_vector_buffer.Load >(0); + const uint input_interpretation_0 = DataType::DATA_TYPE_UINT8_T4_PACKED; + const uint matrix_dimK_0 = 4096; + + // expected-no-diagnostics@+1 + __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, + is_input_unsigned, input_interpretation_0, matrix_buffer, + matrix_offset, matrix_interpretation, matrix_dimM, + matrix_dimK_0, matrix_layout, matrix_is_transposed, + matrix_stride); +} From 62c31bc5dfea922e458dfd7f89df18d21f49d0c1 Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 14 May 2025 17:19:26 -0700 Subject: [PATCH 35/50] Update diagnostics per review feedback --- .../clang/Basic/DiagnosticSemaKinds.td | 7 +- tools/clang/lib/Headers/hlsl/dx/linalg.h | 4 +- tools/clang/lib/Sema/SemaHLSL.cpp | 64 ++++++++----------- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 30 ++++----- .../hlsl/linalg/builtins/mul_invalid.hlsl | 26 ++++---- .../outer_product_accumulate_invalid.hlsl | 4 +- 6 files changed, 60 insertions(+), 75 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index d12a532a94..8769eb5e93 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8015,15 +8015,14 @@ def err_hlsl_hitobject_unsupported_stage : Error< "dx::HitObject is unavailable in shader stage '%0' (requires 'raygeneration', 'closesthit' or 'miss')">; // Linear Algebra Operations -def err_hlsl_linalg_param_must_be_const : Error< - "'%0' must be a constant parameter">; def err_hlsl_linalg_vector_incorrect_type : Error< "%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', " "'signed int' or 'float'">; def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error< - "%0 must be %select{false|true}1 for a %2 vector type">; + "%0 must be %select{false|true}1 for vector of " + "%select{floating point|signed integer|unsigned integer}2 type">; def err_hlsl_linalg_interpretation_value_incorrect : Error< - "%0 is an invalid %select{Memory|Register}1 Interpretation value">; + "%0 is an invalid %select{memory|register}1 interpretation value">; def err_hlsl_linalg_matrix_layout_is_not_transposable : Error< "RowMajor and ColumnMajor matrices are not transposable">; def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error< diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index c536deffc8..951e4cf2a2 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -53,12 +53,12 @@ template <> struct IsUnsigned { }; template <> struct IsUnsigned { - static const bool value = true; + static const bool Value = true; }; #ifdef __HLSL_ENABLE_16_BIT template <> struct IsUnsigned { - static const bool value = true; + static const bool Value = true; }; #endif //__HLSL_ENABLE_16_BIT } // namespace details diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index f8ae371d34..b5c73fe03f 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11772,7 +11772,7 @@ static bool IsValidVectorAndMatrixDimensions(Sema &S, CallExpr *CE, return true; } -static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, +static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, const hlsl::ShaderModel *SM) { // Check if IsOutputUnsigned is a const parameter bool IsOutputUnsignedFlagValue = false; @@ -11782,9 +11782,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Context)) { IsOutputUnsignedFlagValue = IsOutputUnsignedExprVal.getBoolValue(); } else { - S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "IsOutputUnsigned"; + S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_expr_not_ice) + << 0; return; } @@ -11815,14 +11814,13 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsOuputUnsigned" << false - << (OutputVectorTypePtr->isSignedIntegerType() ? "signed int" - : "float"); + << (OutputVectorTypePtr->isSignedIntegerType() ? 1 : 0); return; } else if (!IsOutputUnsignedFlagValue && OutputVectorTypePtr->isUnsignedIntegerType()) { S.Diags.Report(IsOutputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) - << "IsOuputUnsigned" << true << "unsigned int"; + << "IsOuputUnsigned" << true << 2; return; } } @@ -11835,9 +11833,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, S.Context)) { IsInputUnsignedFlagValue = IsInputUnsignedExprVal.getBoolValue(); } else { - S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "IsInputUnsigned"; + S.Diags.Report(IsInputUnsignedExpr->getExprLoc(), diag::err_expr_not_ice) + << 0; return; } @@ -11859,8 +11856,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, } } else { S.Diags.Report(InputInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "InputInterpretation"; + diag::err_expr_not_ice) + << 0; return; } @@ -11931,15 +11928,14 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, IsInputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) << "IsInputUnsigned" << false - << (InputVectorTypePtr->isSignedIntegerType() ? "signed int" - : "float"); + << (InputVectorTypePtr->isSignedIntegerType() ? 1 : 0); return; } else if (!IsInputUnsignedFlagValue && InputVectorTypePtr->isUnsignedIntegerType()) { S.Diags.Report( IsInputUnsignedExpr->getExprLoc(), diag::err_hlsl_linalg_isunsigned_incorrect_for_given_type) - << "IsInputUnsigned" << true << "unsigned int"; + << "IsInputUnsigned" << true << 2; return; } } @@ -11952,9 +11948,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (MatrixKExpr->isIntegerConstantExpr(MatrixKExprVal, S.Context)) { MatrixKValue = MatrixKExprVal.getLimitedValue(); } else { - S.Diags.Report(MatrixKExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixK"; + S.Diags.Report(MatrixKExpr->getExprLoc(), diag::err_expr_not_ice) << 0; return; } @@ -11964,9 +11958,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, if (MatrixMExpr->isIntegerConstantExpr(MatrixMExprVal, S.Context)) { MatrixMValue = MatrixMExprVal.getLimitedValue(); } else { - S.Diags.Report(MatrixMExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixM"; + S.Diags.Report(MatrixMExpr->getExprLoc(), diag::err_expr_not_ice) << 0; return; } @@ -12045,8 +12037,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, } } else { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixInterpretation"; + diag::err_expr_not_ice) + << 0; return; } @@ -12067,9 +12059,7 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } } else { - S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixLayout"; + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_expr_not_ice) << 0; return; } @@ -12088,9 +12078,8 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, return; } } else { - S.Diags.Report(MatrixTransposeExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixTranspose"; + S.Diags.Report(MatrixTransposeExpr->getExprLoc(), diag::err_expr_not_ice) + << 0; return; } @@ -12114,12 +12103,12 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE, static void CheckMulCall(Sema &S, FunctionDecl *FD, CallExpr *CE, const hlsl::ShaderModel *SM) { - CheckCommonMulandMulAddParameters(S, CE, SM); + CheckCommonMulAndMulAddParameters(S, CE, SM); } static void CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, const hlsl::ShaderModel *SM) { - CheckCommonMulandMulAddParameters(S, CE, SM); + CheckCommonMulAndMulAddParameters(S, CE, SM); // Check if BiasInterpretation is constant and a valid value Expr *BiasInterpretationExpr = CE->getArg(kMatVecMulAddBiasInterpretation); @@ -12138,9 +12127,8 @@ static void CheckMulAddCall(Sema &S, FunctionDecl *FD, CallExpr *CE, return; } } else { - S.Diags.Report(BiasInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "BiasInterpretation"; + S.Diags.Report(BiasInterpretationExpr->getExprLoc(), diag::err_expr_not_ice) + << 0; return; } } @@ -12195,8 +12183,8 @@ static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, } } else { S.Diags.Report(MatrixInterpretationExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixInterpretation"; + diag::err_expr_not_ice) + << 0; return; } @@ -12217,9 +12205,7 @@ static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD, return; } } else { - S.Diags.Report(MatrixLayoutExpr->getExprLoc(), - diag::err_hlsl_linalg_param_must_be_const) - << "MatrixLayout"; + S.Diags.Report(MatrixLayoutExpr->getExprLoc(), diag::err_expr_not_ice) << 0; return; } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 144ad10b03..215bffe40c 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -30,7 +30,7 @@ void test_invalid_output_vector_type() { vector output_vector_0; const uint is_output_unsigned_0 = 0; - // expected-error@+1 {{IsOuputUnsigned must be true for a unsigned int vector type}} + // expected-error@+1 {{IsOuputUnsigned must be true for vector of unsigned integer type}} __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned_0, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -40,7 +40,7 @@ void test_invalid_output_vector_type() { vector output_vector_1; const uint is_output_unsigned_1 = 1; - // expected-error@+1 {{IsOuputUnsigned must be false for a signed int vector type}} + // expected-error@+1 {{IsOuputUnsigned must be false for vector of signed integer type}} __builtin_MatVecMulAdd(output_vector_1, is_output_unsigned_1, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -50,7 +50,7 @@ void test_invalid_output_vector_type() { vector output_vector_2; const uint is_output_unsigned_2 = 1; - // expected-error@+1 {{IsOuputUnsigned must be false for a float vector type}} + // expected-error@+1 {{IsOuputUnsigned must be false for vector of floating point type}} __builtin_MatVecMulAdd(output_vector_2, is_output_unsigned_2, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -78,7 +78,7 @@ void test_invalid_is_output_unsigned_non_const() { const uint is_output_unsigned_0 = constants_buffer.Load(0); - // expected-error@+1 {{IsOutputUnsigned' must be a constant parameter}} + // expected-error@+1 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector_0, is_output_unsigned_0, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -324,7 +324,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 0; - // expected-error@+2 {{IsInputUnsigned must be true for a unsigned int vector type}} + // expected-error@+2 {{IsInputUnsigned must be true for vector of unsigned integer type}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -335,7 +335,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 1; - // expected-error@+2 {{IsInputUnsigned must be false for a signed int vector type}} + // expected-error@+2 {{IsInputUnsigned must be false for vector of signed integer type}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -346,7 +346,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 1; - // expected-error@+2 {{IsInputUnsigned must be false for a float vector type}} + // expected-error@+2 {{IsInputUnsigned must be false for vector of floating point type}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -374,7 +374,7 @@ void test_invalid_matrix_M_dimension() { const uint matrix_dimM = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixM' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -402,7 +402,7 @@ void test_invalid_matrix_K_dimension() { const uint matrix_dimK = constants_buffer.Load(0); - // expected-error@+4 {{'MatrixK' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -591,7 +591,7 @@ void test_invalid_input_interpretation_non_const() { const uint input_interpretation = constants_buffer.Load(0); - // expected-error@+2 {{'InputInterpretation' must be a constant parameter}} + // expected-error@+2 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -895,7 +895,7 @@ void test_invalid_matrix_interpretation_constant_value() { const uint matrix_interpretation_0 = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_0, matrix_dimM, @@ -1044,7 +1044,7 @@ void test_invalid_matrix_layout_constant_value() { vector output_vector; const uint is_output_unsigned = 1; vector input_vector = - input_vector_buffer.Load >(0); + input_vector_buffer.Load >(0); const uint is_input_unsigned = 0; const uint input_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_offset = 0; @@ -1058,7 +1058,7 @@ void test_invalid_matrix_layout_constant_value() { const uint matrix_layout = constants_buffer.Load(0); - // expected-error@+4 {{'MatrixLayout' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1113,7 +1113,7 @@ void test_invalid_matrix_transposed_constant_value() { const uint bias_offset = 0; const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; - // expected-error@+4 {{'MatrixTranspose' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1217,7 +1217,7 @@ void test_invalid_bias_interpretation() { const uint bias_interpretation_0 = constants_buffer.Load(0); - // expected-error@+6 {{'BiasInterpretation' must be a constant parameter}} + // expected-error@+6 {{expression is not an integer constant expression}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 77e39c8dc8..ccc42c4f57 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -27,7 +27,7 @@ void test_invalid_output_vector_type() { vector output_vector_0; const uint is_output_unsigned_0 = 0; - // expected-error@+1 {{IsOuputUnsigned must be true for a unsigned int vector type}} + // expected-error@+1 {{IsOuputUnsigned must be true for vector of unsigned integer type}} __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -37,7 +37,7 @@ void test_invalid_output_vector_type() { vector output_vector_1; const uint is_output_unsigned_1 = 1; - // expected-error@+1 {{IsOuputUnsigned must be false for a signed int vector type}} + // expected-error@+1 {{IsOuputUnsigned must be false for vector of signed integer type}} __builtin_MatVecMul(output_vector_1, is_output_unsigned_1, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -47,7 +47,7 @@ void test_invalid_output_vector_type() { vector output_vector_2; const uint is_output_unsigned_2 = 1; - // expected-error@+1 {{IsOuputUnsigned must be false for a float vector type}} + // expected-error@+1 {{IsOuputUnsigned must be false for vector of floating point type}} __builtin_MatVecMul(output_vector_2, is_output_unsigned_2, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -73,7 +73,7 @@ void test_invalid_is_output_unsigned_non_const() { const uint is_output_unsigned_0 = constants_buffer.Load(0); - // expected-error@+1 {{IsOutputUnsigned' must be a constant parameter}} + // expected-error@+1 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector_0, is_output_unsigned_0, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -313,7 +313,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 0; - // expected-error@+2 {{IsInputUnsigned must be true for a unsigned int vector type}} + // expected-error@+2 {{IsInputUnsigned must be true for vector of unsigned integer type}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -324,7 +324,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 1; - // expected-error@+2 {{IsInputUnsigned must be false for a signed int vector type}} + // expected-error@+2 {{IsInputUnsigned must be false for vector of signed integer type}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -335,7 +335,7 @@ void test_invalid_input_vector_type_mismatch() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 1; - // expected-error@+2 {{IsInputUnsigned must be false for a float vector type}} + // expected-error@+2 {{IsInputUnsigned must be false for vector of floating point type}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -361,7 +361,7 @@ void test_invalid_matrix_M_dimension() { const uint matrix_dimM = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixM' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -387,7 +387,7 @@ void test_invalid_matrix_K_dimension() { const uint matrix_dimK = constants_buffer.Load(0); - // expected-error@+4 {{'MatrixK' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -565,7 +565,7 @@ void test_invalid_input_interpretation_non_const() { const uint input_interpretation = constants_buffer.Load(0); - // expected-error@+2 {{'InputInterpretation' must be a constant parameter}} + // expected-error@+2 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -861,7 +861,7 @@ void test_invalid_matrix_interpretation_constant_value() { const uint matrix_interpretation_0 = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_0, matrix_dimM, @@ -1020,7 +1020,7 @@ void test_invalid_matrix_layout_constant_value() { const uint matrix_layout = constants_buffer.Load(0); - // expected-error@+4 {{'MatrixLayout' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1071,7 +1071,7 @@ void test_invalid_matrix_transposed_constant_value() { const bool matrix_is_transposed = constants_buffer.Load(0); const uint matrix_stride = 64; - // expected-error@+4 {{'MatrixTranspose' must be a constant parameter}} + // expected-error@+4 {{expression is not an integer constant expression}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl index 7ffc15a225..13ecd104de 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -46,7 +46,7 @@ void test_non_constant_matrix_interpretation() { const uint matrix_interpretation = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixInterpretation' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation, matrix_layout, @@ -195,7 +195,7 @@ void test_non_constant_matrix_layout() { const uint matrix_layout = constants_buffer.Load(0); - // expected-error@+3 {{'MatrixLayout' must be a constant parameter}} + // expected-error@+3 {{expression is not an integer constant expression}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation, matrix_layout, From a8676ea0db927d9dcf765a020de9b77ddde7880e Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 14 May 2025 17:26:14 -0700 Subject: [PATCH 36/50] Per review feedback, change upper to lower case register/memory interpretation --- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 82 +++++++++---------- .../hlsl/linalg/builtins/mul_invalid.hlsl | 52 ++++++------ .../outer_product_accumulate_invalid.hlsl | 30 +++---- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 215bffe40c..820d206337 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -619,7 +619,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_0 = 0; - // expected-error@+2 {{0 is an invalid Register Interpretation value}} + // expected-error@+2 {{0 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_0, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -628,7 +628,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_1 = 1; - // expected-error@+2 {{1 is an invalid Register Interpretation value}} + // expected-error@+2 {{1 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_1, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -637,7 +637,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_2 = 6; - // expected-error@+2 {{6 is an invalid Register Interpretation value}} + // expected-error@+2 {{6 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_2, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -646,7 +646,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_3 = 7; - // expected-error@+2 {{7 is an invalid Register Interpretation value}} + // expected-error@+2 {{7 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_3, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -655,7 +655,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_4 = 10; - // expected-error@+2 {{10 is an invalid Register Interpretation value}} + // expected-error@+2 {{10 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_4, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -664,7 +664,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_5 = 11; - // expected-error@+2 {{11 is an invalid Register Interpretation value}} + // expected-error@+2 {{11 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_5, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -673,7 +673,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_6 = 12; - // expected-error@+2 {{12 is an invalid Register Interpretation value}} + // expected-error@+2 {{12 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_6, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -682,7 +682,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_7 = 13; - // expected-error@+2 {{13 is an invalid Register Interpretation value}} + // expected-error@+2 {{13 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_7, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -691,7 +691,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_8 = 14; - // expected-error@+2 {{14 is an invalid Register Interpretation value}} + // expected-error@+2 {{14 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_8, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -700,7 +700,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_9 = 15; - // expected-error@+2 {{15 is an invalid Register Interpretation value}} + // expected-error@+2 {{15 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_9, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -709,7 +709,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_10 = 16; - // expected-error@+2 {{16 is an invalid Register Interpretation value}} + // expected-error@+2 {{16 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_10, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -718,7 +718,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_11 = 23; - // expected-error@+2 {{23 is an invalid Register Interpretation value}} + // expected-error@+2 {{23 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_11, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -727,7 +727,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_12 = 100; - // expected-error@+2 {{100 is an invalid Register Interpretation value}} + // expected-error@+2 {{100 is an invalid register interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_12, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -923,7 +923,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_0 = 0; - // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + // expected-error@+3 {{0 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_0, matrix_dimM, @@ -932,7 +932,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_1 = 1; - // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + // expected-error@+3 {{1 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_1, matrix_dimM, @@ -941,7 +941,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_2 = 6; - // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + // expected-error@+3 {{6 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_2, matrix_dimM, @@ -950,7 +950,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_3 = 7; - // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + // expected-error@+3 {{7 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_3, matrix_dimM, @@ -959,7 +959,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_4 = 10; - // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + // expected-error@+3 {{10 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_4, matrix_dimM, @@ -968,7 +968,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_5 = 11; - // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + // expected-error@+3 {{11 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_5, matrix_dimM, @@ -977,7 +977,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_6 = 12; - // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + // expected-error@+3 {{12 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_6, matrix_dimM, @@ -986,7 +986,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_7 = 13; - // expected-error@+3 {{13 is an invalid Memory Interpretation value}} + // expected-error@+3 {{13 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_7, matrix_dimM, @@ -995,7 +995,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_8 = 14; - // expected-error@+3 {{14 is an invalid Memory Interpretation value}} + // expected-error@+3 {{14 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_8, matrix_dimM, @@ -1004,7 +1004,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_9 = 15; - // expected-error@+3 {{15 is an invalid Memory Interpretation value}} + // expected-error@+3 {{15 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_9, matrix_dimM, @@ -1013,7 +1013,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_10 = 16; - // expected-error@+3 {{16 is an invalid Memory Interpretation value}} + // expected-error@+3 {{16 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_10, matrix_dimM, @@ -1021,7 +1021,7 @@ void test_invalid_matrix_interpretation_value() { matrix_stride, bias_buffer, bias_offset, bias_interpretation); const uint matrix_interpretation_11 = 23; - // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + // expected-error@+3 {{23 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_11, matrix_dimM, @@ -1030,7 +1030,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_12 = 100; - // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + // expected-error@+3 {{100 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_12, matrix_dimM, @@ -1245,7 +1245,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_0 = 0; - // expected-error@+6 {{0 is an invalid Memory Interpretation value}} + // expected-error@+6 {{0 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1255,7 +1255,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_1 = 1; - // expected-error@+6 {{1 is an invalid Memory Interpretation value}} + // expected-error@+6 {{1 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1265,7 +1265,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_2 = 6; - // expected-error@+6 {{6 is an invalid Memory Interpretation value}} + // expected-error@+6 {{6 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1275,7 +1275,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_3 = 7; - // expected-error@+6 {{7 is an invalid Memory Interpretation value}} + // expected-error@+6 {{7 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1285,7 +1285,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_4 = 10; - // expected-error@+6 {{10 is an invalid Memory Interpretation value}} + // expected-error@+6 {{10 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1295,7 +1295,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_5 = 11; - // expected-error@+6 {{11 is an invalid Memory Interpretation value}} + // expected-error@+6 {{11 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1305,7 +1305,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_6 = 12; - // expected-error@+6 {{12 is an invalid Memory Interpretation value}} + // expected-error@+6 {{12 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1315,7 +1315,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_7 = 13; - // expected-error@+6 {{13 is an invalid Memory Interpretation value}} + // expected-error@+6 {{13 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1325,7 +1325,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_8 = 14; - // expected-error@+6 {{14 is an invalid Memory Interpretation value}} + // expected-error@+6 {{14 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1335,7 +1335,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_9 = 15; - // expected-error@+6 {{15 is an invalid Memory Interpretation value}} + // expected-error@+6 {{15 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1345,7 +1345,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_10 = 16; - // expected-error@+6 {{16 is an invalid Memory Interpretation value}} + // expected-error@+6 {{16 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1355,7 +1355,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_11 = DataType::DATA_TYPE_SINT8_T4_PACKED; - // expected-error@+6 {{17 is an invalid Memory Interpretation value}} + // expected-error@+6 {{17 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1365,7 +1365,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_12 = DataType::DATA_TYPE_UINT8_T4_PACKED; - // expected-error@+6 {{18 is an invalid Memory Interpretation value}} + // expected-error@+6 {{18 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1375,7 +1375,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_13 = 23; - // expected-error@+6 {{23 is an invalid Memory Interpretation value}} + // expected-error@+6 {{23 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1385,7 +1385,7 @@ void test_invalid_bias_interpretation_value() { const uint bias_interpretation_14 = 100; - // expected-error@+6 {{100 is an invalid Memory Interpretation value}} + // expected-error@+6 {{100 is an invalid memory interpretation value}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index ccc42c4f57..8cd0f7b08b 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -591,7 +591,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_0 = 0; - // expected-error@+2 {{0 is an invalid Register Interpretation value}} + // expected-error@+2 {{0 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_0, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -600,7 +600,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_1 = 1; - // expected-error@+2 {{1 is an invalid Register Interpretation value}} + // expected-error@+2 {{1 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_1, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -609,7 +609,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_2 = 6; - // expected-error@+2 {{6 is an invalid Register Interpretation value}} + // expected-error@+2 {{6 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_2, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -618,7 +618,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_3 = 7; - // expected-error@+2 {{7 is an invalid Register Interpretation value}} + // expected-error@+2 {{7 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_3, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -627,7 +627,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_4 = 10; - // expected-error@+2 {{10 is an invalid Register Interpretation value}} + // expected-error@+2 {{10 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_4, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -636,7 +636,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_5 = 11; - // expected-error@+2 {{11 is an invalid Register Interpretation value}} + // expected-error@+2 {{11 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_5, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -645,7 +645,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_6 = 12; - // expected-error@+2 {{12 is an invalid Register Interpretation value}} + // expected-error@+2 {{12 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_6, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -654,7 +654,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_7 = 13; - // expected-error@+2 {{13 is an invalid Register Interpretation value}} + // expected-error@+2 {{13 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_7, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -663,7 +663,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_8 = 14; - // expected-error@+2 {{14 is an invalid Register Interpretation value}} + // expected-error@+2 {{14 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_8, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -672,7 +672,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_9 = 15; - // expected-error@+2 {{15 is an invalid Register Interpretation value}} + // expected-error@+2 {{15 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_9, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -681,7 +681,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_10 = 16; - // expected-error@+2 {{16 is an invalid Register Interpretation value}} + // expected-error@+2 {{16 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_10, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -690,7 +690,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_11 = 23; - // expected-error@+2 {{23 is an invalid Register Interpretation value}} + // expected-error@+2 {{23 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_11, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -699,7 +699,7 @@ void test_invalid_input_interpretation_value() { const uint input_interpretation_12 = 100; - // expected-error@+2 {{100 is an invalid Register Interpretation value}} + // expected-error@+2 {{100 is an invalid register interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation_12, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -887,7 +887,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_0 = 0; - // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + // expected-error@+3 {{0 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_0, matrix_dimM, @@ -896,7 +896,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_1 = 1; - // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + // expected-error@+3 {{1 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_1, matrix_dimM, @@ -905,7 +905,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_2 = 6; - // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + // expected-error@+3 {{6 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_2, matrix_dimM, @@ -914,7 +914,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_3 = 7; - // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + // expected-error@+3 {{7 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_3, matrix_dimM, @@ -923,7 +923,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_4 = 10; - // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + // expected-error@+3 {{10 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_4, matrix_dimM, @@ -932,7 +932,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_5 = 11; - // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + // expected-error@+3 {{11 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_5, matrix_dimM, @@ -941,7 +941,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_6 = 12; - // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + // expected-error@+3 {{12 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_6, matrix_dimM, @@ -950,7 +950,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_7 = 13; - // expected-error@+3 {{13 is an invalid Memory Interpretation value}} + // expected-error@+3 {{13 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_7, matrix_dimM, @@ -959,7 +959,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_8 = 14; - // expected-error@+3 {{14 is an invalid Memory Interpretation value}} + // expected-error@+3 {{14 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_8, matrix_dimM, @@ -968,7 +968,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_9 = 15; - // expected-error@+3 {{15 is an invalid Memory Interpretation value}} + // expected-error@+3 {{15 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_9, matrix_dimM, @@ -977,7 +977,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_10 = 16; - // expected-error@+3 {{16 is an invalid Memory Interpretation value}} + // expected-error@+3 {{16 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_10, matrix_dimM, @@ -985,7 +985,7 @@ void test_invalid_matrix_interpretation_value() { matrix_stride); const uint matrix_interpretation_11 = 23; - // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + // expected-error@+3 {{23 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_11, matrix_dimM, @@ -994,7 +994,7 @@ void test_invalid_matrix_interpretation_value() { const uint matrix_interpretation_12 = 100; - // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + // expected-error@+3 {{100 is an invalid memory interpretation value}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation_12, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl index 13ecd104de..42facc70d6 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -64,7 +64,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation = 0; - // expected-error@+3 {{0 is an invalid Memory Interpretation value}} + // expected-error@+3 {{0 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation, matrix_layout, @@ -72,7 +72,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_2 = 1; - // expected-error@+3 {{1 is an invalid Memory Interpretation value}} + // expected-error@+3 {{1 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_2, matrix_layout, @@ -80,7 +80,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_3 = 6; - // expected-error@+3 {{6 is an invalid Memory Interpretation value}} + // expected-error@+3 {{6 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_3, matrix_layout, @@ -88,7 +88,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_4 = 7; - // expected-error@+3 {{7 is an invalid Memory Interpretation value}} + // expected-error@+3 {{7 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_4, matrix_layout, @@ -96,7 +96,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_5 = 10; - // expected-error@+3 {{10 is an invalid Memory Interpretation value}} + // expected-error@+3 {{10 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_5, matrix_layout, @@ -104,7 +104,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_6 = 11; - // expected-error@+3 {{11 is an invalid Memory Interpretation value}} + // expected-error@+3 {{11 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_6, matrix_layout, @@ -112,7 +112,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_7 = 12; - // expected-error@+3 {{12 is an invalid Memory Interpretation value}} + // expected-error@+3 {{12 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_7, matrix_layout, @@ -120,7 +120,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_8 = 13; - // expected-error@+3 {{13 is an invalid Memory Interpretation value}} + // expected-error@+3 {{13 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_8, matrix_layout, @@ -128,7 +128,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_9 = 14; - // expected-error@+3 {{14 is an invalid Memory Interpretation value}} + // expected-error@+3 {{14 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_9, matrix_layout, @@ -136,7 +136,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_10 = 15; - // expected-error@+3 {{15 is an invalid Memory Interpretation value}} + // expected-error@+3 {{15 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_10, matrix_layout, @@ -144,7 +144,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_11 = 16; - // expected-error@+3 {{16 is an invalid Memory Interpretation value}} + // expected-error@+3 {{16 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_11, matrix_layout, @@ -152,7 +152,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_12 = DataType::DATA_TYPE_SINT8_T4_PACKED; - // expected-error@+3 {{17 is an invalid Memory Interpretation value}} + // expected-error@+3 {{17 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_12, matrix_layout, @@ -160,7 +160,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_13 = DataType::DATA_TYPE_UINT8_T4_PACKED; - // expected-error@+3 {{18 is an invalid Memory Interpretation value}} + // expected-error@+3 {{18 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_13, matrix_layout, @@ -168,7 +168,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_14 = 23; - // expected-error@+3 {{23 is an invalid Memory Interpretation value}} + // expected-error@+3 {{23 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_14, matrix_layout, @@ -176,7 +176,7 @@ void test_invalid_matrix_interpretation() { const uint matrix_interpretation_15 = 100; - // expected-error@+3 {{100 is an invalid Memory Interpretation value}} + // expected-error@+3 {{100 is an invalid memory interpretation value}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation_15, matrix_layout, From 9045c8266161205efd75ecdb5dc456e0e35bb9dd Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 14 May 2025 17:47:49 -0700 Subject: [PATCH 37/50] Review feedback: Prefer 0 over zero in diagnostic messages to avoid localization issues --- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++--- tools/clang/lib/Sema/SemaHLSL.cpp | 4 ++-- .../SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl | 8 ++++---- .../test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl | 8 ++++---- .../linalg/builtins/outer_product_accumulate_invalid.hlsl | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8769eb5e93..116f2172db 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8026,9 +8026,9 @@ def err_hlsl_linalg_interpretation_value_incorrect : Error< def err_hlsl_linalg_matrix_layout_is_not_transposable : Error< "RowMajor and ColumnMajor matrices are not transposable">; def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error< - "for optimal matrix layout, matrix stride must be zero">; -def err_hlsl_linalg_matrix_dim_must_not_be_zero: Error< - "matrix dimension must not be zero">; + "for optimal matrix layout, matrix stride must be 0">; +def err_hlsl_linalg_matrix_dim_must_be_greater_than_zero: Error< + "matrix dimension must be greater than 0">; def err_hlsl_linalg_matrix_layout_invalid : Error< "matrix layout %0 is not valid, must be in the range %1 - %2">; def err_hlsl_linalg_function_requires_shader_model_6_9_or_above : Error< diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index b5c73fe03f..8363518445 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11965,14 +11965,14 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, // Check MatrixM and MatrixK values are non-zero if (MatrixMValue == 0) { S.Diags.Report(MatrixMExpr->getExprLoc(), - diag::err_hlsl_linalg_matrix_dim_must_not_be_zero) + diag::err_hlsl_linalg_matrix_dim_must_be_greater_than_zero) << std::to_string(DXIL::kSM69MaxVectorLength); return; } if (MatrixKValue == 0) { S.Diags.Report(MatrixKExpr->getExprLoc(), - diag::err_hlsl_linalg_matrix_dim_must_not_be_zero) + diag::err_hlsl_linalg_matrix_dim_must_be_greater_than_zero) << std::to_string(DXIL::kSM69MaxVectorLength); return; } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 820d206337..b5a9e4f75f 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -429,7 +429,7 @@ void test_invalid_matrix_M_dimension_non_zero() { const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimM = 0; - // expected-error@+3 {{matrix dimension must not be zero}} + // expected-error@+3 {{matrix dimension must be greater than 0}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -456,7 +456,7 @@ void test_invalid_matrix_K_dimension_non_zero() { const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; const uint matrix_dimK = 0; - // expected-error@+4 {{matrix dimension must not be zero}} + // expected-error@+4 {{matrix dimension must be greater than 0}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1180,7 +1180,7 @@ void test_invalid_matrix_stride_constant_value() { const uint bias_offset = 0; const uint bias_interpretation = DataType::DATA_TYPE_FLOAT32; - // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + // expected-error@+5 {{for optimal matrix layout, matrix stride must be 0}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1190,7 +1190,7 @@ void test_invalid_matrix_stride_constant_value() { const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride_1 = 64; - // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + // expected-error@+5 {{for optimal matrix layout, matrix stride must be 0}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 8cd0f7b08b..52593c0dc9 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -412,7 +412,7 @@ void test_invalid_matrix_M_dimension_non_zero() { const uint matrix_stride = 64; const uint matrix_dimM = 0; - // expected-error@+3 {{matrix dimension must not be zero}} + // expected-error@+3 {{matrix dimension must be greater than 0}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -437,7 +437,7 @@ void test_invalid_matrix_K_dimension_non_zero() { const uint matrix_stride = 64; const uint matrix_dimK = 0; - // expected-error@+4 {{matrix dimension must not be zero}} + // expected-error@+4 {{matrix dimension must be greater than 0}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1134,7 +1134,7 @@ void test_invalid_matrix_stride_constant_value() { const uint matrix_layout_0 = MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL; const uint matrix_stride_0 = 64; - // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + // expected-error@+5 {{for optimal matrix layout, matrix stride must be 0}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -1144,7 +1144,7 @@ void test_invalid_matrix_stride_constant_value() { const uint matrix_layout_1 = MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL; const uint matrix_stride_1 = 64; - // expected-error@+5 {{for optimal matrix layout, matrix stride must be zero}} + // expected-error@+5 {{for optimal matrix layout, matrix stride must be 0}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl index 42facc70d6..cad32eff59 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -248,7 +248,7 @@ void test_zero_matrix_stride() { const uint matrix_stride = 16; - // expected-error@+4 {{for optimal matrix layout, matrix stride must be zero}} + // expected-error@+4 {{for optimal matrix layout, matrix stride must be 0}} __builtin_OuterProductAccumulate(input_vector_0, input_vector_1, accumulate_buffer, matrix_offset, matrix_interpretation, matrix_layout, From 4fc747e95c216691b32a981386316e80567a158c Mon Sep 17 00:00:00 2001 From: anupamac Date: Wed, 14 May 2025 17:54:31 -0700 Subject: [PATCH 38/50] Updates based on review feedback: fix range specification --- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- .../test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl | 2 +- tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 116f2172db..675ad7df75 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8030,7 +8030,7 @@ def err_hlsl_linalg_optimal_matrix_layout_matrix_stride_must_be_zero : Error< def err_hlsl_linalg_matrix_dim_must_be_greater_than_zero: Error< "matrix dimension must be greater than 0">; def err_hlsl_linalg_matrix_layout_invalid : Error< - "matrix layout %0 is not valid, must be in the range %1 - %2">; + "matrix layout %0 is not valid, must be in the range [%1, %2]">; def err_hlsl_linalg_function_requires_shader_model_6_9_or_above : Error< "intrinsic function %0 requires shader model 6.9 or greater">; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index b5a9e4f75f..6e4416361a 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -1086,7 +1086,7 @@ void test_invalid_matrix_layout_value() { const uint matrix_layout_0 = 4; - // expected-error@+4 {{matrix layout 4 is not valid, must be in the range 0 - 3}} + // expected-error@+4 {{matrix layout 4 is not valid, must be in the range [0, 3]}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 52593c0dc9..0db7920dff 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -1046,7 +1046,7 @@ void test_invalid_matrix_layout_value() { const uint matrix_layout_0 = 4; - // expected-error@+4 {{matrix layout 4 is not valid, must be in the range 0 - 3}} + // expected-error@+4 {{matrix layout 4 is not valid, must be in the range [0, 3]}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, From 5650cf149e00dab9ef74c195bbec3c28e1908cdd Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 00:07:04 -0700 Subject: [PATCH 39/50] Change input/output vector allowed types from numeric to custom linalg component class and update tests --- include/dxc/dxcapi.internal.h | 10 +++++++--- tools/clang/lib/Sema/SemaHLSL.cpp | 9 +++++++++ .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 11 +++++++---- .../SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl | 11 +++++++---- .../test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl | 2 +- utils/hct/gen_intrin_main.txt | 8 ++++---- utils/hct/hctdb.py | 1 + 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/dxc/dxcapi.internal.h b/include/dxc/dxcapi.internal.h index 28bd3e7066..41891338e6 100644 --- a/include/dxc/dxcapi.internal.h +++ b/include/dxc/dxcapi.internal.h @@ -133,11 +133,15 @@ enum LEGAL_INTRINSIC_COMPTYPES { LICOMPTYPE_HIT_OBJECT = 51, LICOMPTYPE_RAY_QUERY = 52, + LICOMPTYPE_LINALG = 53, // f32, partial-precision-f32, f16, + // i32, i16, u32, u16, + // int8_4packed, uint8_4packed + #ifdef ENABLE_SPIRV_CODEGEN - LICOMPTYPE_VK_BUFFER_POINTER = 53, - LICOMPTYPE_COUNT = 54 + LICOMPTYPE_VK_BUFFER_POINTER = 54, + LICOMPTYPE_COUNT = 55 #else - LICOMPTYPE_COUNT = 53 + LICOMPTYPE_COUNT = 54 #endif }; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 8363518445..20fb9d3452 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -1139,6 +1139,14 @@ static const ArBasicKind g_RayDescCT[] = {AR_OBJECT_RAY_DESC, AR_BASIC_UNKNOWN}; static const ArBasicKind g_RayQueryCT[] = {AR_OBJECT_RAY_QUERY, AR_BASIC_UNKNOWN}; +static const ArBasicKind g_LinAlgCT[] = { + AR_BASIC_FLOAT32, AR_BASIC_FLOAT32_PARTIAL_PRECISION, + AR_BASIC_FLOAT16, AR_BASIC_INT32, + AR_BASIC_INT16, AR_BASIC_UINT32, + AR_BASIC_UINT16, AR_BASIC_INT8_4PACKED, + AR_BASIC_UINT8_4PACKED, AR_BASIC_NOCAST, + AR_BASIC_UNKNOWN}; + static const ArBasicKind g_AccelerationStructCT[] = { AR_OBJECT_ACCELERATION_STRUCT, AR_BASIC_UNKNOWN}; @@ -1302,6 +1310,7 @@ const ArBasicKind *g_LegalIntrinsicCompTypes[] = { g_ThreadNodeOutputRecordsCT, // LICOMPTYPE_THREAD_NODE_OUTPUT_RECORDS g_DxHitObjectCT, // LICOMPTYPE_HIT_OBJECT g_RayQueryCT, // LICOMPTYPE_RAY_QUERY + g_LinAlgCT, // LICOMPTYPE_LINALG #ifdef ENABLE_SPIRV_CODEGEN g_VKBufferPointerCT, // LICOMPTYPE_VK_BUFFER_POINTER #endif diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index 6e4416361a..bcc8653c81 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -37,7 +37,7 @@ void test_invalid_output_vector_type() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride, bias_buffer, bias_offset, bias_interpretation); - vector output_vector_1; + vector output_vector_1; const uint is_output_unsigned_1 = 1; // expected-error@+1 {{IsOuputUnsigned must be false for vector of signed integer type}} @@ -106,7 +106,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMulAdd'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -117,7 +118,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 1; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMulAdd'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -128,7 +130,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMulAdd'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 0db7920dff..4c63384f42 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -34,7 +34,7 @@ void test_invalid_output_vector_type() { matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - vector output_vector_1; + vector output_vector_1; const uint is_output_unsigned_1 = 1; // expected-error@+1 {{IsOuputUnsigned must be false for vector of signed integer type}} @@ -99,7 +99,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMul'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -110,7 +111,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 1; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMul'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -121,7 +123,8 @@ void test_invalid_input_vector_type() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 0; -// expected-error@+1 {{Input Vector is incorrect type, must be 16-bit or 32-bit 'unsigned int', 'signed int' or 'float'}} +// expected-error@+2 {{no matching function for call to '__builtin_MatVecMul'}} +// expected-note@+1 {{candidate function not viable: no known conversion from 'vector' to 'vector' for 3rd argument}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl index dab977b7fa..5972b22b95 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_valid.hlsl @@ -32,7 +32,7 @@ void test_valid_output_vector_type() { matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, matrix_is_transposed, matrix_stride); - vector output_vector_1; + vector output_vector_1; const uint is_output_unsigned_1 = 0; // expected-no-diagnostics@+1 diff --git a/utils/hct/gen_intrin_main.txt b/utils/hct/gen_intrin_main.txt index c394611302..91ba487c94 100644 --- a/utils/hct/gen_intrin_main.txt +++ b/utils/hct/gen_intrin_main.txt @@ -383,13 +383,13 @@ void [[]] Barrier(in NodeRecordOrUAV o, in uint SemanticFlags); uint [[]] GetRemainingRecursionLevels(); -void [[]] __builtin_MatVecMul(out numeric OutputVector, in bool OutputIsUnsigned, in numeric InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride); +void [[]] __builtin_MatVecMul(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride); -void [[]] __builtin_MatVecMulAdd(out numeric OutputVector, in bool OutputIsUnsigned, in numeric InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride, in ByteAddressBuffer BiasVector, in uint BiasOffset, in uint BiasInterpretation); +void [[]] __builtin_MatVecMulAdd(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride, in ByteAddressBuffer BiasVector, in uint BiasOffset, in uint BiasInterpretation); -void [[]] __builtin_OuterProductAccumulate(in numeric InputVector1, in numeric InputVector2, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint MatrixLayout, in uint MatrixStride); +void [[]] __builtin_OuterProductAccumulate(in LinAlg InputVector1, in LinAlg InputVector2, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint MatrixLayout, in uint MatrixStride); -void [[]] __builtin_VectorAccumulate(in numeric InputVector, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset); +void [[]] __builtin_VectorAccumulate(in LinAlg InputVector, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset); } namespace diff --git a/utils/hct/hctdb.py b/utils/hct/hctdb.py index e8cd186628..615c9064a3 100644 --- a/utils/hct/hctdb.py +++ b/utils/hct/hctdb.py @@ -9340,6 +9340,7 @@ def __init__(self, intrinsic_defs, opcode_data): "DxHitObject": "LICOMPTYPE_HIT_OBJECT", "VkBufferPointer": "LICOMPTYPE_VK_BUFFER_POINTER", "RayQuery": "LICOMPTYPE_RAY_QUERY", + "LinAlg": "LICOMPTYPE_LINALG" } self.trans_rowcol = {"r": "IA_R", "c": "IA_C", "r2": "IA_R2", "c2": "IA_C2"} From b845582b3817b8f8b11617702ae15d7c0bf3ff3a Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 07:11:18 -0700 Subject: [PATCH 40/50] Update per feeback: refactor Matrix dimension check diagnostics --- .../clang/Basic/DiagnosticSemaKinds.td | 18 ++----- tools/clang/lib/Sema/SemaHLSL.cpp | 48 +++++-------------- .../hlsl/linalg/builtins/mul_add_invalid.hlsl | 10 ++-- .../hlsl/linalg/builtins/mul_invalid.hlsl | 10 ++-- 4 files changed, 26 insertions(+), 60 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index 675ad7df75..f724bdedc4 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8015,9 +8015,6 @@ def err_hlsl_hitobject_unsupported_stage : Error< "dx::HitObject is unavailable in shader stage '%0' (requires 'raygeneration', 'closesthit' or 'miss')">; // Linear Algebra Operations -def err_hlsl_linalg_vector_incorrect_type : Error< - "%0 is incorrect type, must be 16-bit or 32-bit 'unsigned int', " - "'signed int' or 'float'">; def err_hlsl_linalg_isunsigned_incorrect_for_given_type : Error< "%0 must be %select{false|true}1 for vector of " "%select{floating point|signed integer|unsigned integer}2 type">; @@ -8044,16 +8041,11 @@ def err_hlsl_linalg_mul_muladd_packed_input_vector_size_incorrect : Error< def err_hlsl_linalg_mul_muladd_isUnsigned_for_packed_input_must_be_true : Error< "IsInputUnsigned must be true for packed input interpretations in linalg mul/muladd operations">; def err_hlsl_linalg_mul_muladd_packed_input_vector_must_be_uint : Error< - "packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, " - "packed formats uint8_t4_packed and sint8_t4_packed are not supported currently">; -def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_m: Error< - "matrix dimension M must be less than %0, in a linalg Mul/MulAdd operation">; -def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_unpacked_input: Error< - "matrix dimension K when using unpacked input vectors must be less than %0, in a " - "linalg Mul/MulAdd operation">; -def err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_packed_input: Error< - "matrix dimension K when using packed input vectors must be less than %0, in a " - "linalg Mul/MulAdd operation">; + "packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations">; +def err_hlsl_linalg_mul_muladd_invalid_dim: Error< + "matrix dimension %select{M|K when using unpacked input vectors|K " + "when using packed input vectors}0 must be less than %1, in a linalg " + "Mul/MulAdd operation">; def err_hlsl_linalg_outer_prod_acc_vector_type_mismatch : Error< "input vectors of outerproductaccumulate must have the same element type">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 20fb9d3452..0b76059ed1 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11796,8 +11796,6 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, return; } - // Check if output vector is unsigned int, signed int or float - // Check if the isUnsigned flag is set correctly Expr *OutputVectorExpr = CE->getArg(kMatVecMulOutputVectorIdx); unsigned OutputVectorSizeValue = 0; if (IsHLSLVecType(OutputVectorExpr->getType())) { @@ -11805,14 +11803,7 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, QualType OutputVectorType = GetHLSLVecElementType(OutputVectorExpr->getType()); const Type *OutputVectorTypePtr = OutputVectorType.getTypePtr(); - if (!OutputVectorTypePtr->isUnsignedIntegerType() && - !OutputVectorTypePtr->isSignedIntegerType() && - !OutputVectorTypePtr->isFloatingType()) { - S.Diags.Report(OutputVectorExpr->getExprLoc(), - diag::err_hlsl_linalg_vector_incorrect_type) - << "Output Vector"; - return; - } + // Check if IsOutputUnsigned flag matches output vector type. // Must be true for unsigned int outputs, false for signed int/float // outputs. @@ -11872,7 +11863,6 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, bool IsInputVectorPacked = IsPackedType(InputInterpretationValue); - // Check if input vector32/16bit is unsigned int, signed int or float // For packed types input vector type must be uint and isUnsigned must be // true. The signedness is determined from the InputInterpretation Expr *InputVectorExpr = CE->getArg(kMatVecMulInputVectorIdx); @@ -11884,22 +11874,10 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, unsigned BitWidth = S.Context.getTypeSize(InputVectorType); bool Is16Bit = (BitWidth == 16); bool Is32Bit = (BitWidth == 32); - if (!Is16Bit && !Is32Bit) { - S.Diags.Report(InputVectorExpr->getExprLoc(), - diag::err_hlsl_linalg_vector_incorrect_type) - << "Input Vector"; - return; - } + DXASSERT(Is16Bit || Is32Bit, + "Linalg Input vectors must be 32 or 16 bit element types"); const Type *InputVectorTypePtr = InputVectorType.getTypePtr(); - if (!InputVectorTypePtr->isUnsignedIntegerType() && - !InputVectorTypePtr->isSignedIntegerType() && - !InputVectorTypePtr->isFloatingType()) { - S.Diags.Report(InputVectorExpr->getExprLoc(), - diag::err_hlsl_linalg_vector_incorrect_type) - << "Input Vector"; - return; - } // Check if the isUnsigned flag setting if (IsInputVectorPacked) { @@ -11991,8 +11969,8 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, // operation. if (MatrixMValue > DXIL::kSM69MaxVectorLength) { S.Diags.Report(MatrixMExpr->getExprLoc(), - diag::err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_m) - << std::to_string(DXIL::kSM69MaxVectorLength); + diag::err_hlsl_linalg_mul_muladd_invalid_dim) + << 0 << std::to_string(DXIL::kSM69MaxVectorLength); return; } @@ -12002,20 +11980,16 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, const unsigned PackingFactor = 4; // Only supported packed formats: DATA_TYPE_(U)SINT8_T4_PACKED if (MatrixKValue > DXIL::kSM69MaxVectorLength * PackingFactor) { - S.Diags.Report( - MatrixKExpr->getExprLoc(), - diag:: - err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_packed_input) - << std::to_string(DXIL::kSM69MaxVectorLength * PackingFactor); + S.Diags.Report(MatrixKExpr->getExprLoc(), + diag::err_hlsl_linalg_mul_muladd_invalid_dim) + << 2 << std::to_string(DXIL::kSM69MaxVectorLength * PackingFactor); return; } } else { if (MatrixKValue > DXIL::kSM69MaxVectorLength) { - S.Diags.Report( - MatrixKExpr->getExprLoc(), - diag:: - err_hlsl_linalg_mul_muladd_exceeds_max_matrix_dim_k_unpacked_input) - << std::to_string(DXIL::kSM69MaxVectorLength); + S.Diags.Report(MatrixKExpr->getExprLoc(), + diag::err_hlsl_linalg_mul_muladd_invalid_dim) + << 1 << std::to_string(DXIL::kSM69MaxVectorLength); return; } } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl index bcc8653c81..866fad8225 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_add_invalid.hlsl @@ -159,7 +159,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 1; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation_0, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -171,7 +171,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation_1, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -183,7 +183,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 1; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation_2, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -195,7 +195,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_3 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_3, is_input_unsigned_3, input_interpretation_3, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -207,7 +207,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_4 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector_4, is_input_unsigned_4, input_interpretation_4, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl index 4c63384f42..14f34d62c4 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/mul_invalid.hlsl @@ -150,7 +150,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_0 = 1; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_0, is_input_unsigned_0, input_interpretation_0, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -162,7 +162,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_1 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_1, is_input_unsigned_1, input_interpretation_1, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -174,7 +174,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_2 = 1; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_2, is_input_unsigned_2, input_interpretation_2, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -186,7 +186,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_3 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_3, is_input_unsigned_3, input_interpretation_3, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, @@ -198,7 +198,7 @@ void test_invalid_input_vector_type_packed_input_interpretation() { input_vector_buffer.Load >(0); const uint is_input_unsigned_4 = 0; - // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int in linalg mul/muladd operations, packed formats uint8_t4_packed and sint8_t4_packed are not supported currently}} + // expected-error@+1 {{packed input vector type must be a 32-bit unsigned int type in linalg mul/muladd operations}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector_4, is_input_unsigned_4, input_interpretation_4, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, From baa4bbc3417977d697d343f0ee8713a91413212b Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 07:28:32 -0700 Subject: [PATCH 41/50] Fix darker error --- utils/hct/hctdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hct/hctdb.py b/utils/hct/hctdb.py index 615c9064a3..a3366d73d8 100644 --- a/utils/hct/hctdb.py +++ b/utils/hct/hctdb.py @@ -9340,7 +9340,7 @@ def __init__(self, intrinsic_defs, opcode_data): "DxHitObject": "LICOMPTYPE_HIT_OBJECT", "VkBufferPointer": "LICOMPTYPE_VK_BUFFER_POINTER", "RayQuery": "LICOMPTYPE_RAY_QUERY", - "LinAlg": "LICOMPTYPE_LINALG" + "LinAlg": "LICOMPTYPE_LINALG", } self.trans_rowcol = {"r": "IA_R", "c": "IA_C", "r2": "IA_R2", "c2": "IA_C2"} From 5751f2b3dfdc1cd8e5bfb6b2aeed80f3a9044548 Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 10:08:49 -0700 Subject: [PATCH 42/50] Fix typo --- .../hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl index cad32eff59..4e15c92a5d 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/builtins/outer_product_accumulate_invalid.hlsl @@ -8,7 +8,7 @@ ByteAddressBuffer input_vector_buffer; RWByteAddressBuffer accumulate_buffer; ByteAddressBuffer constants_buffer; -// Check ofr input vectors aren't the same component type +// Check if input vectors aren't the same component type void test_invalid_input_vector_component_type() { const uint matrix_offset = 0; From c60bcba10757a2670f3e11aa35253f9a38aa9148 Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 10:59:14 -0700 Subject: [PATCH 43/50] Remove unused variable --- tools/clang/lib/Sema/SemaHLSL.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index cdbed59043..7376bc9da7 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -11872,11 +11872,7 @@ static void CheckCommonMulAndMulAddParameters(Sema &S, CallExpr *CE, QualType InputVectorType = GetHLSLVecElementType(InputVectorExpr->getType()); unsigned BitWidth = S.Context.getTypeSize(InputVectorType); - bool Is16Bit = (BitWidth == 16); bool Is32Bit = (BitWidth == 32); - DXASSERT(Is16Bit || Is32Bit, - "Linalg Input vectors must be 32 or 16 bit element types"); - const Type *InputVectorTypePtr = InputVectorType.getTypePtr(); // Check if the isUnsigned flag setting From 1bbaa40611a3ef95027a32210b7dd817f4bc790e Mon Sep 17 00:00:00 2001 From: anupamac Date: Thu, 15 May 2025 15:03:42 -0700 Subject: [PATCH 44/50] Add tests for IsUnsigned::value, remove uint64 case --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 4 --- .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 26 +++++++++++++++++++ .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 +-- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../linalg/outerproductaccumulate-errors.hlsl | 6 ++--- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 951e4cf2a2..b06ad65497 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -52,10 +52,6 @@ template <> struct IsUnsigned { static const bool Value = true; }; -template <> struct IsUnsigned { - static const bool Value = true; -}; - #ifdef __HLSL_ENABLE_16_BIT template <> struct IsUnsigned { static const bool Value = true; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl index e0126dd76a..3dcd89c866 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -38,3 +38,29 @@ export vector Test3(vector Input) { return Mul(Matrix, MakeInterpretedVector(Input)); } + +// test that isUnsigned is set correctly for uint16_t +export vector Test4(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 6 * 4 * 8}; + + // CHECK: %{{.+}} = call <8 x i16> @dx.op.matVecMul.v8i16.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 true) + return Mul(Matrix, + MakeInterpretedVector(Input)); + +} + +// test that isUnsigned is set correctly for uint32_t +export vector Test5(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 6 * 4 * 8}; + + // CHECK: %{{.+}} = call <8 x i32> @dx.op.matVecMul.v8i32.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 true) + return Mul(Matrix, + MakeInterpretedVector(Input)); + +} \ No newline at end of file diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index b647478e4a..88ac605652 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:107{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:103{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:107{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:103{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index bf4f52304c..a99b27a10b 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:121{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:117{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index ca4113b1c6..580e3d35b7 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:147{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:143{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index f0e34522f0..ef24c6fa8a 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:167{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:167{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:171{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:167{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From de5d0eaf76af52eb4cef616fd7b07c1dc89e8233 Mon Sep 17 00:00:00 2001 From: Tex Riddell Date: Fri, 16 May 2025 10:13:52 -0700 Subject: [PATCH 45/50] Replace explicit SM6.9 checks with intrinsic attribute --- .../clang/Basic/DiagnosticSemaKinds.td | 2 - tools/clang/lib/Sema/SemaHLSL.cpp | 42 ------------------- .../hlsl/linalg/unavailable-pre-sm69.hlsl | 14 +++---- utils/hct/gen_intrin_main.txt | 8 ++-- 4 files changed, 11 insertions(+), 55 deletions(-) diff --git a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td index f724bdedc4..6209726773 100644 --- a/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8028,8 +8028,6 @@ def err_hlsl_linalg_matrix_dim_must_be_greater_than_zero: Error< "matrix dimension must be greater than 0">; def err_hlsl_linalg_matrix_layout_invalid : Error< "matrix layout %0 is not valid, must be in the range [%1, %2]">; -def err_hlsl_linalg_function_requires_shader_model_6_9_or_above : Error< - "intrinsic function %0 requires shader model 6.9 or greater">; def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error< "output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 7376bc9da7..fe5dfa222b 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -12252,44 +12252,14 @@ void Sema::CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, CheckBarrierCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_MatVecMul: - if (!SM->IsSM69Plus()) { - Diags.Report( - TheCall->getExprLoc(), - diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) - << FDecl->getNameAsString(); - return; - } CheckMulCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_MatVecMulAdd: - if (!SM->IsSM69Plus()) { - Diags.Report( - TheCall->getExprLoc(), - diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) - << FDecl->getNameAsString(); - return; - } CheckMulAddCall(*this, FDecl, TheCall, SM); break; case hlsl::IntrinsicOp::IOP___builtin_OuterProductAccumulate: - if (!SM->IsSM69Plus()) { - Diags.Report( - TheCall->getExprLoc(), - diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) - << FDecl->getNameAsString(); - return; - } CheckOuterProductAccumulateCall(*this, FDecl, TheCall); break; - case hlsl::IntrinsicOp::IOP___builtin_VectorAccumulate: - if (!SM->IsSM69Plus()) { - Diags.Report( - TheCall->getExprLoc(), - diag::err_hlsl_linalg_function_requires_shader_model_6_9_or_above) - << FDecl->getNameAsString(); - return; - } - break; #ifdef ENABLE_SPIRV_CODEGEN case hlsl::IntrinsicOp::IOP_Vkreinterpret_pointer_cast: CheckVKBufferPointerCast(*this, FDecl, TheCall, false); @@ -12688,18 +12658,6 @@ void Sema::DiagnoseReachableHLSLCall(CallExpr *CE, const hlsl::ShaderModel *SM, break; case hlsl::IntrinsicOp::IOP_DxMaybeReorderThread: DiagnoseReachableSERCall(*this, CE, EntrySK, EntryDecl, true); - break; - case hlsl::IntrinsicOp::IOP___builtin_MatVecMul: - case hlsl::IntrinsicOp::IOP___builtin_MatVecMulAdd: - case hlsl::IntrinsicOp::IOP___builtin_OuterProductAccumulate: - case hlsl::IntrinsicOp::IOP___builtin_VectorAccumulate: - if (!SM->IsSM69Plus()) { - Diags.Report(CE->getExprLoc(), - diag::warn_hlsl_intrinsic_in_wrong_shader_model) - << FD->getNameAsString() << EntryDecl->getNameAsString() << "6.9"; - return; - } - break; default: break; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl index 66e9da4b99..57683b9a59 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/unavailable-pre-sm69.hlsl @@ -23,7 +23,7 @@ void cs_main() const bool matrix_is_transposed = false; const uint matrix_stride = 64; - //expected-error@+1{{intrinsic function __builtin_MatVecMul requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic hlsl::__builtin_MatVecMul potentially used by ''cs_main'' requires shader model 6.9 or greater}} __builtin_MatVecMul(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, @@ -32,7 +32,7 @@ void cs_main() const uint bias_offset = 0; const uint bias_interpretation = 9; /*F32*/ - //expected-error@+1{{intrinsic function __builtin_MatVecMulAdd requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic hlsl::__builtin_MatVecMulAdd potentially used by ''cs_main'' requires shader model 6.9 or greater}} __builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector, is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset, matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout, @@ -44,16 +44,16 @@ void cs_main() const uint opa_matrix_offset = 0; const uint opa_matrix_interpretation = 5; /*U32*/ const uint opa_matrix_layout = 3; /*OuterProductOptimal*/ - const uint opa_matrix_stride = 64; + const uint opa_matrix_stride = 0; - //expected-error@+1{{intrinsic function __builtin_OuterProductAccumulate requires shader model 6.9 or greater}} + //expected-error@+1{{intrinsic hlsl::__builtin_OuterProductAccumulate potentially used by ''cs_main'' requires shader model 6.9 or greater}} __builtin_OuterProductAccumulate(input_vector1, input_vector2, rw_matrix_buffer, opa_matrix_offset, opa_matrix_interpretation, opa_matrix_layout, opa_matrix_stride); const uint va_matrix_offset = 0; - //expected-error@+1{{intrinsic function __builtin_VectorAccumulate requires shader model 6.9 or greater}} - __builtin_VectorAccumulate(input_vector1, rw_matrix_buffer, - va_matrix_offset); + //expected-error@+1{{intrinsic hlsl::__builtin_VectorAccumulate potentially used by ''cs_main'' requires shader model 6.9 or greater}} + __builtin_VectorAccumulate(input_vector1, rw_matrix_buffer, + va_matrix_offset); } \ No newline at end of file diff --git a/utils/hct/gen_intrin_main.txt b/utils/hct/gen_intrin_main.txt index 64bbc70a4e..60bef02f18 100644 --- a/utils/hct/gen_intrin_main.txt +++ b/utils/hct/gen_intrin_main.txt @@ -383,13 +383,13 @@ void [[]] Barrier(in NodeRecordOrUAV o, in uint SemanticFlags); uint [[]] GetRemainingRecursionLevels(); -void [[]] __builtin_MatVecMul(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride); +void [[min_sm=6.9]] __builtin_MatVecMul(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride); -void [[]] __builtin_MatVecMulAdd(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride, in ByteAddressBuffer BiasVector, in uint BiasOffset, in uint BiasInterpretation); +void [[min_sm=6.9]] __builtin_MatVecMulAdd(out LinAlg OutputVector, in bool OutputIsUnsigned, in LinAlg InputVector, in bool InputIsUnsigned, in uint InputInterpretation, in ByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint M, in uint K, in uint MatrixLayout, in bool MatrixIsTransposed, in uint MatrixStride, in ByteAddressBuffer BiasVector, in uint BiasOffset, in uint BiasInterpretation); -void [[]] __builtin_OuterProductAccumulate(in LinAlg InputVector1, in LinAlg InputVector2, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint MatrixLayout, in uint MatrixStride); +void [[min_sm=6.9]] __builtin_OuterProductAccumulate(in LinAlg InputVector1, in LinAlg InputVector2, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset, in uint MatrixInterpretation, in uint MatrixLayout, in uint MatrixStride); -void [[]] __builtin_VectorAccumulate(in LinAlg InputVector, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset); +void [[min_sm=6.9]] __builtin_VectorAccumulate(in LinAlg InputVector, in RWByteAddressBuffer MatrixBuffer, in uint MatrixOffset); } namespace From ffdb3d4fe1186da13a3bf039128e5d46ec5cb483 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 16 May 2025 10:53:23 -0700 Subject: [PATCH 46/50] Add IsUnsigned template specializations for all allowed types --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 30 ++++++++++++++++++- .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 28 ++++++++++++++++- .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 +-- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../linalg/outerproductaccumulate-errors.hlsl | 6 ++-- 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index b06ad65497..6673b94341 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -45,18 +45,46 @@ enum MatrixLayout { namespace details { template struct IsUnsigned { - static const bool Value = false; +}; + +template <> struct IsUnsigned { + static const bool Value = true; +}; + +template <> struct IsUnsigned { + static const bool Value = true; }; template <> struct IsUnsigned { static const bool Value = true; }; +template <> struct IsUnsigned { + static const bool Value = false; +}; + +template <> struct IsUnsigned { + static const bool Value = false; +}; + #ifdef __HLSL_ENABLE_16_BIT template <> struct IsUnsigned { static const bool Value = true; }; + +template <> struct IsUnsigned { + static const bool Value = false; +}; + +template <> struct IsUnsigned { + static const bool Value = false; +}; +#else // //__HLSL_ENABLE_16_BIT +template <> struct IsUnsigned { + static const bool Value = false; +}; #endif //__HLSL_ENABLE_16_BIT + } // namespace details // diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl index 3dcd89c866..15eb6a592d 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -28,7 +28,7 @@ export vector Test2(vector Input) { } // test that "stride" isn't ignored in non-optimal layouts -export vector Test3(vector Input) { +export vector Test3(vector Input) { using namespace dx::linalg; MatrixRef Matrix = { @@ -63,4 +63,30 @@ export vector Test5(vector Input) { return Mul(Matrix, MakeInterpretedVector(Input)); +} + +// test that isUnsigned is set correctly for uint32_t +export vector Test5(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 6 * 4 * 8}; + + // CHECK: %{{.+}} = call <8 x i32> @dx.op.matVecMul.v8i32.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 18, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 true) + return Mul(Matrix, + MakeInterpretedVector(Input)); + +} + +// test that isUnsigned is set correctly for uint32_t +export vector Test5(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 6 * 4 * 8}; + + // CHECK: %{{.+}} = call <8 x i32> @dx.op.matVecMul.v8i32.v6i32(i32 305, <6 x i32> %{{.+}}, i1 true, i32 17, %dx.types.Handle %{{.+}}, i32 0, i32 19, i32 8, i32 24, i32 0, i1 false, i32 192, i1 true) + return Mul(Matrix, + MakeInterpretedVector(Input)); + } \ No newline at end of file diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index 88ac605652..a522dee7e9 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:103{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:131{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:103{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:131{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index a99b27a10b..53f77e8e82 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:117{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:145{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 580e3d35b7..086f25d363 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:143{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index ef24c6fa8a..ca663e16c7 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:167{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:195{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:167{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:195{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:167{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:195{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From 78e52689ecdd3ece43a8c82b0757e70857a52360 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 16 May 2025 10:59:39 -0700 Subject: [PATCH 47/50] Minor fixes --- tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl index 15eb6a592d..26bcc75da2 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -28,7 +28,7 @@ export vector Test2(vector Input) { } // test that "stride" isn't ignored in non-optimal layouts -export vector Test3(vector Input) { +export vector Test3(vector Input) { using namespace dx::linalg; MatrixRef Matrix = { @@ -65,7 +65,7 @@ export vector Test5(vector Input) { } -// test that isUnsigned is set correctly for uint32_t +// test that isUnsigned is set correctly for uint8_t4_packed export vector Test5(vector Input) { using namespace dx::linalg; @@ -78,7 +78,7 @@ export vector Test5(vector Input) { } -// test that isUnsigned is set correctly for uint32_t +// test that isUnsigned is set correctly for int8_t4_packed export vector Test5(vector Input) { using namespace dx::linalg; From 15d9177c29916e29e48fb4a16d42bb77f4cf0907 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 16 May 2025 12:14:01 -0700 Subject: [PATCH 48/50] Clang format plus test updates with linenum --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 28 +++++-------------- .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 +-- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../linalg/outerproductaccumulate-errors.hlsl | 6 ++-- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 6673b94341..1598afc13a 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -55,34 +55,20 @@ template <> struct IsUnsigned { static const bool Value = true; }; -template <> struct IsUnsigned { - static const bool Value = true; -}; +template <> struct IsUnsigned { static const bool Value = true; }; -template <> struct IsUnsigned { - static const bool Value = false; -}; +template <> struct IsUnsigned { static const bool Value = false; }; -template <> struct IsUnsigned { - static const bool Value = false; -}; +template <> struct IsUnsigned { static const bool Value = false; }; #ifdef __HLSL_ENABLE_16_BIT -template <> struct IsUnsigned { - static const bool Value = true; -}; +template <> struct IsUnsigned { static const bool Value = true; }; -template <> struct IsUnsigned { - static const bool Value = false; -}; +template <> struct IsUnsigned { static const bool Value = false; }; -template <> struct IsUnsigned { - static const bool Value = false; -}; +template <> struct IsUnsigned { static const bool Value = false; }; #else // //__HLSL_ENABLE_16_BIT -template <> struct IsUnsigned { - static const bool Value = false; -}; +template <> struct IsUnsigned { static const bool Value = false; }; #endif //__HLSL_ENABLE_16_BIT } // namespace details diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index a522dee7e9..86caee0ef0 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:131{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:117{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:131{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:117{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index 53f77e8e82..48dc0250a7 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:145{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:131{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 086f25d363..0c6f5420af 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:171{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index ca663e16c7..fb8273c6cc 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:195{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:181{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:195{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:181{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:195{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:181{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From 1e4dfbc2f9299a6c9a250b50c08f361501a58cf0 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 16 May 2025 12:22:56 -0700 Subject: [PATCH 49/50] Clang format fixes --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 3 +-- .../test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl | 4 ++-- .../clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl | 6 +++--- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 1598afc13a..e71fbabfa4 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -44,8 +44,7 @@ enum MatrixLayout { // namespace details { -template struct IsUnsigned { -}; +template struct IsUnsigned {}; template <> struct IsUnsigned { static const bool Value = true; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index 86caee0ef0..89649306a8 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:117{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:116{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:117{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:116{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index 48dc0250a7..4db3f2a608 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:131{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:130{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 0c6f5420af..40aba72e15 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:156{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index fb8273c6cc..81478d3446 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:181{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:180{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:181{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:180{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:181{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:180{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } From a8fe58fd4dbf121964e58fd2457c18da91100f37 Mon Sep 17 00:00:00 2001 From: anupamac Date: Fri, 16 May 2025 13:19:42 -0700 Subject: [PATCH 50/50] Update IsUnsigned specializations to use macros: better readability --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 35 +++++++++---------- .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 +-- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 2 +- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 +- .../linalg/outerproductaccumulate-errors.hlsl | 6 ++-- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index e71fbabfa4..4f5e62070d 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -46,30 +46,27 @@ namespace details { template struct IsUnsigned {}; -template <> struct IsUnsigned { - static const bool Value = true; -}; - -template <> struct IsUnsigned { - static const bool Value = true; -}; - -template <> struct IsUnsigned { static const bool Value = true; }; +#define _SPECIALIZE_ISUNSIGNED(type, value) \ + template <> struct IsUnsigned { \ + static const bool Value = value; \ + } -template <> struct IsUnsigned { static const bool Value = false; }; - -template <> struct IsUnsigned { static const bool Value = false; }; +_SPECIALIZE_ISUNSIGNED(uint8_t4_packed, true); +_SPECIALIZE_ISUNSIGNED(int8_t4_packed, true); +_SPECIALIZE_ISUNSIGNED(uint32_t, true); +_SPECIALIZE_ISUNSIGNED(int32_t, false); +_SPECIALIZE_ISUNSIGNED(float32_t, false); #ifdef __HLSL_ENABLE_16_BIT -template <> struct IsUnsigned { static const bool Value = true; }; - -template <> struct IsUnsigned { static const bool Value = false; }; - -template <> struct IsUnsigned { static const bool Value = false; }; -#else // //__HLSL_ENABLE_16_BIT -template <> struct IsUnsigned { static const bool Value = false; }; +_SPECIALIZE_ISUNSIGNED(uint16_t, true); +_SPECIALIZE_ISUNSIGNED(int16_t, false); +_SPECIALIZE_ISUNSIGNED(float16_t, false); +#else // //__HLSL_ENABLE_16_BIT +_SPECIALIZE_ISUNSIGNED(half, false); #endif //__HLSL_ENABLE_16_BIT +#undef _SPECIALIZE_ISUNSIGNED + } // namespace details // diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl index 89649306a8..be67d92546 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -10,7 +10,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:116{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:113{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); } @@ -26,7 +26,7 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} - // expected-note@dx/linalg.h:116{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:113{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl index 4db3f2a608..b911de648e 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'Mul'}} - // expected-note@dx/linalg.h:130{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:127{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 40aba72e15..24ad3ef46c 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -11,6 +11,6 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // expected-error@+2{{no matching function for call to 'MulAdd'}} - // expected-note@dx/linalg.h:156{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:153{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl index 81478d3446..5759631bcb 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -12,7 +12,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:180{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:177{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -25,7 +25,7 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:180{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:177{{candidate template ignored: could not match 0 against 1}} OuterProductAccumulate(Input1, Input2, matrix); } @@ -38,7 +38,7 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} - // expected-note@dx/linalg.h:180{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:177{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); }