From d3c4249dc3f932021a93785d8b29af9c1bbe2164 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Apr 2025 16:21:29 -0700 Subject: [PATCH 01/18] a start --- tools/clang/lib/Headers/hlsl/linalg.h | 176 ++++++++++++++++++ .../CodeGenDXIL/hlsl/linalg/.clang-format | 2 + .../hlsl/linalg/make-interp-vec-errors.hlsl | 38 ++++ .../hlsl/linalg/mat-vec-mul-errors.hlsl | 18 ++ .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 31 +++ .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 18 ++ .../hlsl/linalg/mat-vec-muladd.hlsl | 96 ++++++++++ .../linalg/outerproductaccumulate-errors.hlsl | 20 ++ .../hlsl/linalg/outerproductaccumulate.hlsl | 17 ++ .../hlsl/linalg/vector-matrix-proposal.hlsl | 143 ++++++++++++++ .../hlsl/linalg/vectoraccumulate.hlsl | 16 ++ 11 files changed, 575 insertions(+) create mode 100644 tools/clang/lib/Headers/hlsl/linalg.h create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl diff --git a/tools/clang/lib/Headers/hlsl/linalg.h b/tools/clang/lib/Headers/hlsl/linalg.h new file mode 100644 index 0000000000..f2e6e7bfc6 --- /dev/null +++ b/tools/clang/lib/Headers/hlsl/linalg.h @@ -0,0 +1,176 @@ + +// Header for linear algebra APIs. +// +// This needs to find a proper home! +// + +namespace dx { +namespace linalg { + +// NOTE: can't be an enum class because we get this error: +// error: non-type template argument of type 'dx::linalg::DataType' is not +// an integral constant expression +// +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) +}; + +enum MatrixLayout { + MATRIX_LAYOUT_ROW_MAJOR = 0, + MATRIX_LAYOUT_COLUMN_MAJOR = 1, + MATRIX_LAYOUT_MUL_OPTIMAL = 2, + MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 +}; + +// +// Helper for signedness +// +namespace details { +template bool IsUnsigned() { return false; } + +#ifdef __HLSL_ENABLE_16_BIT +template <> bool IsUnsigned() { return true; } +#endif + +template <> bool IsUnsigned() { return true; } +template <> bool IsUnsigned() { return true; } +} // namespace details + +// +// (RW)MatrixRef +// + +template +struct MatrixRefImpl { + BufferTy Buffer; + uint StartOffset; + uint Stride; +}; + +template +using MatrixRef = MatrixRefImpl; + +template +using RWMatrixRef = MatrixRefImpl; + +// +// (RW)VectorRef +// + +template struct VectorRefImpl { + BufferTy Buffer; + uint StartOffset; +}; + +template using VectorRef = VectorRefImpl; + +template +using RWVectorRef = VectorRefImpl; + +// +// Vector +// + +template struct InterpretedVector { + vector Data; +}; + +template +InterpretedVector MakeInterpretedVector(vector Vec) { + InterpretedVector IV = {Vec}; + return IV; +} + +// +// Mul +// + +template +vector +Mul(MatrixRefImpl + Matrix, + InterpretedVector InputVector) { + + vector OutputVector; + + __builtin_MatVecMul( + /*out*/ OutputVector, details::IsUnsigned(), InputVector.Data, + details::IsUnsigned(), InputDT, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, + MatrixTranspose, Matrix.Stride); + + return OutputVector; +} + +// +// MulAdd +// + +template +vector +MulAdd(MatrixRefImpl + Matrix, + InterpretedVector InputVector, + VectorRefImpl BiasVector) { + + vector OutputVector; + + __builtin_MatVecMulAdd( + /*out*/ OutputVector, details::IsUnsigned(), InputVector.Data, + details::IsUnsigned(), InputDT, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, + MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, + BiasVectorDT); + + return OutputVector; +} + +// +// OuterProductAccumulate +// + +template +void OuterProductAccumulate( + vector InputVector1, vector InputVector2, + RWMatrixRef Matrix) { + __builtin_OuterProductAccumulate(InputVector1, InputVector2, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixLayout, + Matrix.Stride); +} + +// +// VectorAccumulate +// + +template +void VectorAccumulate(vector InputVector, + RWByteAddressBuffer Buffer, uint Offset) { + __builtin_VectorAccumulate(InputVector, Buffer, Offset); +} + +} // namespace linalg +} // namespace dx diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format b/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format new file mode 100644 index 0000000000..70797e559f --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +ColumnLimit: 80 diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl new file mode 100644 index 0000000000..a7e40cb374 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -0,0 +1,38 @@ +// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +export float4 Test1(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'MakeInterpretedVector' + // CHECK: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'DT' + return Mul( + Matrix, MakeInterpretedVector<2>(Input)); + // clang-format on +} + +enum DataType { + DATA_TYPE_InvalidType = 40 +}; + +export float4 Test2(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'MakeInterpretedVector' + // CHECK: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'DT' + return Mul( + Matrix, MakeInterpretedVector(Input)); + // clang-format on +} + diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl new file mode 100644 index 0000000000..f60eb70e0f --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -0,0 +1,18 @@ +// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +vector MixUpVectorAndMatrixArguments(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'Mul' + // CHECK: note: candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector' + // clang-format on + return Mul(MakeInterpretedVector(Input), Matrix); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl new file mode 100644 index 0000000000..4dbee65eaf --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -0,0 +1,31 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +export float4 Test1(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMul.v4f32.v4f32(i32 305, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle %{{.+}}, i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, i1 false) + return Mul( + Matrix, MakeInterpretedVector(Input)); + // clang-format on +} + +export vector Test2(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // 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) + // clang-format on + return Mul(Matrix, + MakeInterpretedVector(Input)); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl new file mode 100644 index 0000000000..89a895accb --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -0,0 +1,18 @@ +// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +vector MixUpVectorAndMatrixArguments(vector Input) { + using namespace dx::linalg; + + MatrixRef<1, 128, 128, MATRIX_LAYOUT_MUL_OPTIMAL> Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'MulAdd' + // CHECK: note: candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector' + // clang-format on + return MulAdd(MakeInterpretedVector<1>(Input), Matrix, MakeInterpretedVector<1>(Input)); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl new file mode 100644 index 0000000000..e1efa3f929 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl @@ -0,0 +1,96 @@ +// RUN: %dxc -T lib_6_9 %s | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +export float4 Test1(float4 input) { + using namespace dx::linalg; + + MatrixRef matrix = {Buf, + 0, 0}; + VectorRef biasVector = {Buf, 256}; + + InterpretedVector theVector = {input}; + + // clang-format off + // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 false, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) + return MulAdd( + matrix, theVector, + biasVector); + // clang-format on +} + +export float4 Test2(float4 input) { + using namespace dx::linalg; + + MatrixRef matrix = { + Buf, 0, 0}; + VectorRef biasVector = {Buf, 256}; + + InterpretedVector theVector = {input}; + + // clang-format off + // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) + return MulAdd( + matrix, theVector, + biasVector); + // clang-format on +} + +export float4 Test3(float4 input) { + using namespace dx::linalg; + + MatrixRef matrix = { + Buf, 0, 0}; + VectorRef biasVector = {Buf, 256}; + + // clang-format off + // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) + return MulAdd( + matrix, MakeInterpretedVector(input), + biasVector); + // clang-format on +} + +namespace ProposalExample { + +ByteAddressBuffer model; + +vector ApplyNeuralMaterial(vector inputVector) { + using namespace dx::linalg; + + MatrixRef matrix0 = { + model, 0, 0}; + + VectorRef biasVector0 = {model, 1024}; + + MatrixRef matrix1 = + {model, 2048, 0}; + + VectorRef biasVector1 = {model, 3072}; + + MatrixRef matrix2 = { + model, 4096, 0}; + + VectorRef biasVector2 = {model, 5120}; + + vector layer0 = MulAdd( + matrix0, MakeInterpretedVector(inputVector), + biasVector0); + layer0 = max(layer0, 0); + + vector layer1 = MulAdd( + matrix1, MakeInterpretedVector(layer0), + biasVector1); + layer1 = max(layer1, 0); + + vector output = MulAdd( + matrix2, MakeInterpretedVector(layer1), + biasVector2); + output = exp(output); + + return output; +} + +} // namespace ProposalExample diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl new file mode 100644 index 0000000000..2729538720 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -0,0 +1,20 @@ +// RUN: not %dxc -T lib_6_9 -enable-16bit-types %s 2>&1 | FileCheck %s + +#include "linalg.h" + +RWByteAddressBuffer RWBuf; + +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'OuterProductAccumulate' + // CHECK: note: candidate template ignored: could not match 0 against 1 + // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); + // clang-format on + + OuterProductAccumulate(Input1, Input2, matrix); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl new file mode 100644 index 0000000000..c9b0d7410e --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl @@ -0,0 +1,17 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s + +RWByteAddressBuffer RWBuf; + +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + // clang-format off + // CHECK: call void @dx.op.outerProductAccumulate.v128f16.v64f16(i32 307, <128 x half> %{{.+}}, <64 x half> %{{.+}}, %dx.types.Handle %{{.+}}, i32 0, i32 8, i32 3, i32 0) + // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); + // clang-format on + + OuterProductAccumulate(Input1, Input2, matrix); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl new file mode 100644 index 0000000000..21119cf90c --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl @@ -0,0 +1,143 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s + +#include "linalg.h" + +namespace code_example { +ByteAddressBuffer Model; + +vector ApplyNeuralMaterial(vector InputVector) { + using namespace dx::linalg; + + MatrixRef Matrix0 = { + Model, 0, 0}; + + VectorRef BiasVector0 = {Model, 1024}; + + MatrixRef Matrix1 = + {Model, 2048, 0}; + + VectorRef BiasVector1 = {Model, 3072}; + + MatrixRef Matrix2 = { + Model, 4096, 0}; + + VectorRef BiasVector2 = {Model, 5120}; + + vector Layer0 = MulAdd( + Matrix0, MakeInterpretedVector(InputVector), + BiasVector0); + Layer0 = max(Layer0, 0); + + vector Layer1 = MulAdd( + Matrix1, MakeInterpretedVector(Layer0), + BiasVector1); + Layer1 = max(Layer1, 0); + + vector Output = MulAdd( + Matrix2, MakeInterpretedVector(Layer1), + BiasVector2); + Output = exp(Output); + + return Output; +} +} // namespace code_example + +namespace matrixref_example { +ByteAddressBuffer ROBuffer; +RWByteAddressBuffer RWBuffer; + +void Example() { + using namespace dx::linalg; + + MatrixRef MatrixA = + {ROBuffer, /*offset=*/128, /*stride=*/0}; + + MatrixRef MatrixB = { + ROBuffer, /*offset=*/128, /*stride=*/16}; + + RWMatrixRef + MatrixC = {RWBuffer, /*offset=*/64, /*stride=*/0}; +} +} // namespace matrixref_example + +namespace vectorref_example { +ByteAddressBuffer ROBuffer; +RWByteAddressBuffer RWBuffer; + +void Example() { + using namespace dx::linalg; + + VectorRef VectorA = {ROBuffer, /*offset=*/128}; + VectorRef VectorB = {ROBuffer, /*offset=*/128}; + RWVectorRef VectorC = {RWBuffer, /*offset=*/64}; +} +} // namespace vectorref_example + +namespace vector_example { +ByteAddressBuffer Buffer; +void Example() { + using namespace dx::linalg; + + MatrixRef + Matrix = {Buffer, 0, 0}; + + vector V = 0; + vector Result = + Mul(Matrix, MakeInterpretedVector(V)); + + // alternative: + InterpretedVector IV = {V}; + vector Result2 = Mul(Matrix, IV); +} +} // namespace vector_example + +namespace mul_example { +ByteAddressBuffer Buffer; +float4 Example(float4 Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buffer, 0, 0}; + + return Mul(Matrix, MakeInterpretedVector(Input)); +} +} // namespace mul_example + +namespace muladd_example { +ByteAddressBuffer Buffer; + +void Example() { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buffer, 0, 0}; + + VectorRef BiasVector = {Buffer, 1024}; + + vector V = 0; + vector Result = MulAdd( + Matrix, MakeInterpretedVector(V), BiasVector); +} +} // namespace muladd_example + +namespace outerproductaccumulate_example { +RWByteAddressBuffer RWBuf; + +void Example(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + Matrix = {RWBuf, 0, 0}; + + OuterProductAccumulate(Input1, Input2, Matrix); +} +} // namespace outerproductaccumulate_example + +namespace vector_accumulate { +RWByteAddressBuffer RWBuf; + +void Test(vector Input) { + using namespace dx::linalg; + VectorAccumulate(Input, RWBuf, 0); +} +} // namespace vector_accumulate diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl new file mode 100644 index 0000000000..e6fcca1433 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl @@ -0,0 +1,16 @@ +// RUN: %dxc -T lib_6_9 %s | FileCheck %s + +#include "linalg.h" + +RWByteAddressBuffer RWBuf; + +export void Test5(vector Input) { + using namespace dx::linalg; + + RWBuf.Store >(0, Input); + + // clang-format off + // CHECK: call void @dx.op.vectorAccumulate.v128f32(i32 308, <128 x float> %{{.*}}, %dx.types.Handle %{{.*}}, i32 0) + VectorAccumulate(Input, RWBuf, 0); + // clang-format on +} From de0f2ceac99de41c3355d856bdc38bdf01b32c47 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 14 Apr 2025 11:37:37 -0700 Subject: [PATCH 02/18] add missing tests --- .../linalg/mat-vec-mul-transpose-errors.hlsl | 31 ++++++++++++++++++ .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 15 +++++++++ .../linalg/outerproductaccumulate-errors.hlsl | 32 +++++++++++++++++++ .../hlsl/linalg/vectoraccumulate-errors.hlsl | 16 ++++++++++ 4 files changed, 94 insertions(+) create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl create mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl new file mode 100644 index 0000000000..6cb2afa7e5 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl @@ -0,0 +1,31 @@ +// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s + +#include "linalg.h" + +ByteAddressBuffer Buf; + +export float4 Test1(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts + return Mul( + Matrix, MakeInterpretedVector(Input)); + // clang-format on +} + +export vector Test2(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 0}; + + // clang-format off + // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts + // clang-format on + return Mul(Matrix, + MakeInterpretedVector(Input)); +} 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 4dbee65eaf..0475dd7377 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -24,8 +24,23 @@ export vector Test2(vector Input) { Buf, 0, 0}; // clang-format off + // 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) // clang-format on return Mul(Matrix, MakeInterpretedVector(Input)); } + +// test that "stride" isn't ignored in non-optimal layouts +export vector Test2(vector Input) { + using namespace dx::linalg; + + MatrixRef Matrix = { + Buf, 0, 6 * 4 * 8}; + + // clang-format off + // 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, i32 192) + // clang-format on + return Mul(Matrix, + MakeInterpretedVector(Input)); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl index 2729538720..e593f86c02 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -18,3 +18,35 @@ export void Test4(vector Input1, vector Input2) { OuterProductAccumulate(Input1, Input2, matrix); } + +// now test for an error when element types differ +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'OuterProductAccumulate' + // CHECK: note: candidate template ignored: could not match 0 against 1 + // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); + // clang-format on + + OuterProductAccumulate(Input1, Input2, matrix); +} + +// now test for an error when matrix transpose parameter is false +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + // clang-format off + // CHECK: error: no matching function for call to 'OuterProductAccumulate' + // CHECK: note: candidate template ignored: could not match 0 against 1 + // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); + // clang-format on + + OuterProductAccumulate(Input1, Input2, matrix); +} diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl new file mode 100644 index 0000000000..0ceb47df28 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -0,0 +1,16 @@ +// RUN: %dxc -T lib_6_9 %s | FileCheck %s + +#include "linalg.h" + +RWByteAddressBuffer RWBuf; + +export void Test5(vector Input) { + using namespace dx::linalg; + + RWBuf.Store >(0, Input); + + // clang-format off + // CHECK: Perhaps this is an error? + VectorAccumulate(Input, RWBuf, 0); + // clang-format on +} From 4858fc29b3a3d7bb723d086c1ba55e66a0b82c7a Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 15 Apr 2025 10:25:24 -0700 Subject: [PATCH 03/18] update comment --- tools/clang/lib/Headers/hlsl/linalg.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/linalg.h b/tools/clang/lib/Headers/hlsl/linalg.h index f2e6e7bfc6..1e69763e4c 100644 --- a/tools/clang/lib/Headers/hlsl/linalg.h +++ b/tools/clang/lib/Headers/hlsl/linalg.h @@ -1,8 +1,4 @@ - // Header for linear algebra APIs. -// -// This needs to find a proper home! -// namespace dx { namespace linalg { From 4422d803ee03952d5ec591dcd8b5479c0e1d1ef4 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 15 Apr 2025 10:41:47 -0700 Subject: [PATCH 04/18] clarify comment --- .../test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 0ceb47df28..77e144f5c5 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -10,7 +10,7 @@ export void Test5(vector Input) { RWBuf.Store >(0, Input); // clang-format off - // CHECK: Perhaps this is an error? + // CHECK: Something about an error due to illegal conversions VectorAccumulate(Input, RWBuf, 0); // clang-format on } From 34302d69128d18774f29f196cf541ba18fb88624 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 15 Apr 2025 10:48:31 -0700 Subject: [PATCH 05/18] fix up this test --- .../hlsl/linalg/outerproductaccumulate-errors.hlsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl index e593f86c02..da0c0fe042 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -4,6 +4,7 @@ RWByteAddressBuffer RWBuf; +// test for inputs of different size export void Test4(vector Input1, vector Input2) { using namespace dx::linalg; @@ -20,7 +21,7 @@ export void Test4(vector Input1, vector Input2) { } // now test for an error when element types differ -export void Test4(vector Input1, vector Input2) { +export void Test5(vector Input1, vector Input2) { using namespace dx::linalg; RWMatrixRef @@ -35,11 +36,11 @@ export void Test4(vector Input1, vector Input2) { OuterProductAccumulate(Input1, Input2, matrix); } -// now test for an error when matrix transpose parameter is false -export void Test4(vector Input1, vector Input2) { +// now test for an error when matrix transpose parameter is true +export void Test4(vector Input1, vector Input2) { using namespace dx::linalg; - RWMatrixRef + RWMatrixRef matrix = {RWBuf, 0, 0}; // clang-format off From 6747741da3d647d23fec9540397fe372278c197a Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 15 Apr 2025 10:50:58 -0700 Subject: [PATCH 06/18] move header to dx dir, remove all unneeded include directives --- tools/clang/lib/Headers/hlsl/{ => dx}/linalg.h | 0 .../test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl | 2 -- .../clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl | 2 -- .../CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl | 2 -- tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 2 -- .../test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl | 2 -- tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl | 2 -- .../CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl | 2 -- .../test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl | 2 -- .../test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl | 2 -- tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl | 2 -- 11 files changed, 20 deletions(-) rename tools/clang/lib/Headers/hlsl/{ => dx}/linalg.h (100%) diff --git a/tools/clang/lib/Headers/hlsl/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h similarity index 100% rename from tools/clang/lib/Headers/hlsl/linalg.h rename to tools/clang/lib/Headers/hlsl/dx/linalg.h diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl index a7e40cb374..ca85a9be18 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -1,7 +1,5 @@ // RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; export float4 Test1(vector Input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl index f60eb70e0f..01eb2e66c1 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -1,7 +1,5 @@ // RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; vector MixUpVectorAndMatrixArguments(vector Input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl index 6cb2afa7e5..473dc312ae 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; export float4 Test1(vector Input) { 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 0475dd7377..81060b29da 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; export float4 Test1(vector Input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl index 89a895accb..a4b4ad71a5 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -1,7 +1,5 @@ // RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; vector MixUpVectorAndMatrixArguments(vector Input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl index e1efa3f929..b06848f77b 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 %s | FileCheck %s -#include "linalg.h" - ByteAddressBuffer Buf; export float4 Test1(float4 input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl index da0c0fe042..5f4f58c387 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -1,7 +1,5 @@ // RUN: not %dxc -T lib_6_9 -enable-16bit-types %s 2>&1 | FileCheck %s -#include "linalg.h" - RWByteAddressBuffer RWBuf; // test for inputs of different size diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl index 21119cf90c..feee88cc98 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 -enable-16bit-types %s -#include "linalg.h" - namespace code_example { ByteAddressBuffer Model; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 77e144f5c5..99d7902d29 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 %s | FileCheck %s -#include "linalg.h" - RWByteAddressBuffer RWBuf; export void Test5(vector Input) { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl index e6fcca1433..26ebe43dc5 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl @@ -1,7 +1,5 @@ // RUN: %dxc -T lib_6_9 %s | FileCheck %s -#include "linalg.h" - RWByteAddressBuffer RWBuf; export void Test5(vector Input) { From ab78c627321ddd614829ef7218cacc2ec0dc0050 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 17 Apr 2025 14:05:36 -0700 Subject: [PATCH 07/18] ifdef header, add back includes in test files, with -i option, make verifier tests, and mark preview todos --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 6 ++++++ .../hlsl/linalg/make-interp-vec-errors.hlsl | 11 ++++++----- .../hlsl/linalg/mat-vec-mul-errors.hlsl | 8 +++++--- .../linalg/mat-vec-mul-transpose-errors.hlsl | 6 +++++- .../CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 6 ++++-- .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 12 +++++++----- .../CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl | 4 +++- .../linalg/outerproductaccumulate-errors.hlsl | 16 +++++++++------- .../hlsl/linalg/outerproductaccumulate.hlsl | 4 +++- .../hlsl/linalg/vector-matrix-proposal.hlsl | 4 +++- .../hlsl/linalg/vectoraccumulate-errors.hlsl | 5 ++++- .../hlsl/linalg/vectoraccumulate.hlsl | 4 +++- 12 files changed, 58 insertions(+), 28 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 1e69763e4c..63a4a63963 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -1,5 +1,9 @@ // Header for linear algebra APIs. +#if ((__SHADER_TARGET_MAJOR > 6) || \ + (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ + (__HLSL_VERSION >= 2021) + namespace dx { namespace linalg { @@ -170,3 +174,5 @@ void VectorAccumulate(vector InputVector, } // namespace linalg } // namespace dx + +#endif diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl index ca85a9be18..47110c099a 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl @@ -1,5 +1,6 @@ -// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s -verify +#include ByteAddressBuffer Buf; export float4 Test1(vector Input) { @@ -9,8 +10,8 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'MakeInterpretedVector' - // CHECK: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'DT' + // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} + // expected-note@dx/linalg.h:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); // clang-format on @@ -27,8 +28,8 @@ export float4 Test2(vector Input) { Buf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'MakeInterpretedVector' - // CHECK: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'DT' + // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} + // expected-note@dx/linalg.h:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); // clang-format on diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl index 01eb2e66c1..a4ad213968 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl @@ -1,4 +1,6 @@ -// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s -verify + +#include ByteAddressBuffer Buf; @@ -9,8 +11,8 @@ vector MixUpVectorAndMatrixArguments(vector Input) { Buf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'Mul' - // CHECK: note: candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector' + // expected-error@+3{{no matching function for call to 'Mul'}} + // expected-note@dx/linalg.h:107{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} // clang-format on return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl index 473dc312ae..2e17cb3aef 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include ByteAddressBuffer Buf; @@ -9,6 +11,7 @@ export float4 Test1(vector Input) { Buf, 0, 0}; // clang-format off + // PREVIEW CHECK TODO: // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts return Mul( Matrix, MakeInterpretedVector(Input)); @@ -22,6 +25,7 @@ export vector Test2(vector Input) { Buf, 0, 0}; // clang-format off + // PREVIEW CHECK TODO: // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts // clang-format on return Mul(Matrix, 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 81060b29da..3c2cf9b0b6 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s | FileCheck %s + +#include ByteAddressBuffer Buf; @@ -30,7 +32,7 @@ export vector Test2(vector Input) { } // test that "stride" isn't ignored in non-optimal layouts -export vector Test2(vector Input) { +export vector Test3(vector Input) { using namespace dx::linalg; MatrixRef Matrix = { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl index a4b4ad71a5..cfe66f9c4b 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl @@ -1,16 +1,18 @@ -// RUN: not %dxc -T lib_6_9 %s 2>&1 | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s -verify + +#include ByteAddressBuffer Buf; vector MixUpVectorAndMatrixArguments(vector Input) { using namespace dx::linalg; - MatrixRef<1, 128, 128, MATRIX_LAYOUT_MUL_OPTIMAL> Matrix = { + MatrixRef Matrix = { Buf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'MulAdd' - // CHECK: note: candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector' + // expected-error@+3{{no matching function for call to 'MulAdd'}} + // expected-note@dx/linalg.h:133{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} // clang-format on - return MulAdd(MakeInterpretedVector<1>(Input), Matrix, MakeInterpretedVector<1>(Input)); + return MulAdd(MakeInterpretedVector(Input), Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl index b06848f77b..32032fe71b 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s | FileCheck %s + +#include ByteAddressBuffer Buf; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl index 5f4f58c387..b08ee0b6bc 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -1,4 +1,6 @@ -// RUN: not %dxc -T lib_6_9 -enable-16bit-types %s 2>&1 | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify + +#include RWByteAddressBuffer RWBuf; @@ -10,8 +12,8 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'OuterProductAccumulate' - // CHECK: note: candidate template ignored: could not match 0 against 1 + // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 0 against 1}} // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); // clang-format on @@ -26,8 +28,8 @@ export void Test5(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'OuterProductAccumulate' - // CHECK: note: candidate template ignored: could not match 0 against 1 + // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 0 against 1}} // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); // clang-format on @@ -42,8 +44,8 @@ export void Test4(vector Input1, vector Input2) { matrix = {RWBuf, 0, 0}; // clang-format off - // CHECK: error: no matching function for call to 'OuterProductAccumulate' - // CHECK: note: candidate template ignored: could not match 0 against 1 + // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-note@dx/linalg.h:157{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); // clang-format on diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl index c9b0d7410e..cc7f8778fb 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s | FileCheck %s + +#include RWByteAddressBuffer RWBuf; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl index feee88cc98..90afad247f 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 -enable-16bit-types %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s + +#include "dx/linalg.h" namespace code_example { ByteAddressBuffer Model; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 99d7902d29..3de9615b4d 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s | FileCheck %s + +#include "dx/linalg.h" RWByteAddressBuffer RWBuf; @@ -8,6 +10,7 @@ export void Test5(vector Input) { RWBuf.Store >(0, Input); // clang-format off + // PREVIEW CHECK TODO: // CHECK: Something about an error due to illegal conversions VectorAccumulate(Input, RWBuf, 0); // clang-format on diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl index 26ebe43dc5..46523a9883 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl @@ -1,4 +1,6 @@ -// RUN: %dxc -T lib_6_9 %s | FileCheck %s +// RUN: %dxc -I %hlsl_headers -T lib_6_9 %s | FileCheck %s + +#include RWByteAddressBuffer RWBuf; From 9e79c492889c6b0868e154540b67216c7d14eb46 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 17 Apr 2025 14:08:13 -0700 Subject: [PATCH 08/18] add back xfails --- .../CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl | 1 + .../test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl index 2e17cb3aef..8218c64431 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl @@ -1,3 +1,4 @@ +// XFAIL: * // RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -verify #include diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 3de9615b4d..337c3db237 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -1,3 +1,4 @@ +// XFAIL: * // RUN: %dxc -I %hlsl_headers -T lib_6_9 %s | FileCheck %s #include "dx/linalg.h" From a2b371d074cfb4fdc3ff4d03c7d3e3b0d0487c53 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 17 Apr 2025 14:11:17 -0700 Subject: [PATCH 09/18] use angle brackets --- .../test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl | 2 +- .../test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl index 90afad247f..94c414c8ba 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl @@ -1,6 +1,6 @@ // RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s -#include "dx/linalg.h" +#include namespace code_example { ByteAddressBuffer Model; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 337c3db237..6c12146773 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -1,7 +1,7 @@ // XFAIL: * // RUN: %dxc -I %hlsl_headers -T lib_6_9 %s | FileCheck %s -#include "dx/linalg.h" +#include RWByteAddressBuffer RWBuf; From a791ede156023f98532aaa92127ad1149382a164 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 17 Apr 2025 16:52:30 -0700 Subject: [PATCH 10/18] move sema diag verifier tests over to semahlsl dir --- .../hlsl/linalg/make-interp-vec-errors.hlsl | 0 .../{CodeGenDXIL => SemaHLSL}/hlsl/linalg/mat-vec-mul-errors.hlsl | 0 .../hlsl/linalg/mat-vec-mul-transpose-errors.hlsl | 0 .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 0 .../hlsl/linalg/outerproductaccumulate-errors.hlsl | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/make-interp-vec-errors.hlsl (100%) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/mat-vec-mul-errors.hlsl (100%) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl (100%) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/mat-vec-muladd-errors.hlsl (100%) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/outerproductaccumulate-errors.hlsl (100%) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/make-interp-vec-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/make-interp-vec-errors.hlsl diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-muladd-errors.hlsl diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl From 8f950ced8a146d95b5311dbc612c3cdcbc4d9118 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Apr 2025 21:25:10 +0000 Subject: [PATCH 11/18] chore: autopublish 2025-04-17T21:25:10Z --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 63a4a63963..8241bc2d72 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -1,7 +1,7 @@ // Header for linear algebra APIs. -#if ((__SHADER_TARGET_MAJOR > 6) || \ - (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ +#if ((__SHADER_TARGET_MAJOR > 6) || \ + (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ (__HLSL_VERSION >= 2021) namespace dx { From d987a590ac1454cf06461e00db9ceac9a4d6a4bb Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 18 Apr 2025 15:25:28 -0700 Subject: [PATCH 12/18] update check line --- tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3c2cf9b0b6..49541d9306 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -39,7 +39,7 @@ export vector Test3(vector Input) { Buf, 0, 6 * 4 * 8}; // clang-format off - // 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, i32 192) + // 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) // clang-format on return Mul(Matrix, MakeInterpretedVector(Input)); From 0cf39438e9c1474ed42ed6542f725d82647a1785 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 21 Apr 2025 14:01:18 -0700 Subject: [PATCH 13/18] address Damyan --- .../test/CodeGenDXIL/hlsl/linalg/.clang-format | 2 -- .../test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl | 6 ------ .../CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl | 6 ------ .../hlsl/linalg/outerproductaccumulate.hlsl | 3 --- .../hlsl/linalg/vectoraccumulate-errors.hlsl | 2 -- .../CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl | 2 -- .../hlsl/linalg/make-interp-vec-errors.hlsl | 4 ---- .../SemaHLSL/hlsl/linalg/mat-vec-mul-errors.hlsl | 4 +--- .../hlsl/linalg/mat-vec-mul-transpose-errors.hlsl | 8 ++------ .../hlsl/linalg/mat-vec-muladd-errors.hlsl | 4 +--- .../linalg/outerproductaccumulate-errors.hlsl | 15 +++------------ 11 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format b/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format deleted file mode 100644 index 70797e559f..0000000000 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -BasedOnStyle: LLVM -ColumnLimit: 80 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 49541d9306..141801c71c 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-mul.hlsl @@ -10,11 +10,9 @@ export float4 Test1(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMul.v4f32.v4f32(i32 305, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle %{{.+}}, i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, i1 false) return Mul( Matrix, MakeInterpretedVector(Input)); - // clang-format on } export vector Test2(vector Input) { @@ -23,10 +21,8 @@ export vector Test2(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // 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) - // clang-format on return Mul(Matrix, MakeInterpretedVector(Input)); } @@ -38,9 +34,7 @@ export vector Test3(vector Input) { MatrixRef Matrix = { Buf, 0, 6 * 4 * 8}; - // clang-format off // 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) - // clang-format on return Mul(Matrix, MakeInterpretedVector(Input)); } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl index 32032fe71b..c19e601904 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/mat-vec-muladd.hlsl @@ -13,12 +13,10 @@ export float4 Test1(float4 input) { InterpretedVector theVector = {input}; - // clang-format off // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 false, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) return MulAdd( matrix, theVector, biasVector); - // clang-format on } export float4 Test2(float4 input) { @@ -30,12 +28,10 @@ export float4 Test2(float4 input) { InterpretedVector theVector = {input}; - // clang-format off // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) return MulAdd( matrix, theVector, biasVector); - // clang-format on } export float4 Test3(float4 input) { @@ -45,12 +41,10 @@ export float4 Test3(float4 input) { Buf, 0, 0}; VectorRef biasVector = {Buf, 256}; - // clang-format off // CHECK: %{{.+}} = call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> %{{.+}}, i1 false, i32 8, %dx.types.Handle [[RES:%.+]], i32 0, i32 8, i32 4, i32 4, i32 2, i1 true, i32 0, %dx.types.Handle [[RES]], i32 256, i32 8, i1 false) return MulAdd( matrix, MakeInterpretedVector(input), biasVector); - // clang-format on } namespace ProposalExample { diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl index cc7f8778fb..eda15c66f6 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/outerproductaccumulate.hlsl @@ -10,10 +10,7 @@ export void Test4(vector Input1, vector Input2) { RWMatrixRef matrix = {RWBuf, 0, 0}; - // clang-format off // CHECK: call void @dx.op.outerProductAccumulate.v128f16.v64f16(i32 307, <128 x half> %{{.+}}, <64 x half> %{{.+}}, %dx.types.Handle %{{.+}}, i32 0, i32 8, i32 3, i32 0) - // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); - // clang-format on OuterProductAccumulate(Input1, Input2, matrix); } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl index 6c12146773..4c8ae6f049 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl @@ -10,9 +10,7 @@ export void Test5(vector Input) { RWBuf.Store >(0, Input); - // clang-format off // PREVIEW CHECK TODO: // CHECK: Something about an error due to illegal conversions VectorAccumulate(Input, RWBuf, 0); - // clang-format on } diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl index 46523a9883..9157156f10 100644 --- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl +++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate.hlsl @@ -9,8 +9,6 @@ export void Test5(vector Input) { RWBuf.Store >(0, Input); - // clang-format off // CHECK: call void @dx.op.vectorAccumulate.v128f32(i32 308, <128 x float> %{{.*}}, %dx.types.Handle %{{.*}}, i32 0) VectorAccumulate(Input, RWBuf, 0); - // clang-format on } 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 47110c099a..cbcd8147e8 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 @@ -9,12 +9,10 @@ export float4 Test1(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} // expected-note@dx/linalg.h:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector<2>(Input)); - // clang-format on } enum DataType { @@ -27,11 +25,9 @@ export float4 Test2(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // expected-error@+3{{no matching function for call to 'MakeInterpretedVector'}} // expected-note@dx/linalg.h:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} return Mul( Matrix, MakeInterpretedVector(Input)); - // clang-format on } 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 a4ad213968..cdc3ed020f 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 @@ -10,9 +10,7 @@ vector MixUpVectorAndMatrixArguments(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off - // expected-error@+3{{no matching function for call to 'Mul'}} + // expected-error@+2{{no matching function for call to 'Mul'}} // expected-note@dx/linalg.h:107{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} - // clang-format on return Mul(MakeInterpretedVector(Input), Matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl index 8218c64431..2018acafab 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/mat-vec-mul-transpose-errors.hlsl @@ -11,12 +11,10 @@ export float4 Test1(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // PREVIEW CHECK TODO: - // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts + // expected-error@+1{{something about transposing not supported for rowmajor / colmajor layouts}} return Mul( Matrix, MakeInterpretedVector(Input)); - // clang-format on } export vector Test2(vector Input) { @@ -25,10 +23,8 @@ export vector Test2(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off // PREVIEW CHECK TODO: - // CHECK: error: something about transposing not supported for rowmajor / colmajor layouts - // clang-format on + // expected-error@+1{{something about transposing not supported for rowmajor / colmajor layouts}} return Mul(Matrix, MakeInterpretedVector(Input)); } 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 cfe66f9c4b..03cdacb8f6 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 @@ -10,9 +10,7 @@ vector MixUpVectorAndMatrixArguments(vector Input) { MatrixRef Matrix = { Buf, 0, 0}; - // clang-format off - // expected-error@+3{{no matching function for call to 'MulAdd'}} + // expected-error@+2{{no matching function for call to 'MulAdd'}} // expected-note@dx/linalg.h:133{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} - // clang-format on 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 b08ee0b6bc..9c707d5c3e 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-errors.hlsl @@ -11,11 +11,8 @@ export void Test4(vector Input1, vector Input2) { RWMatrixRef matrix = {RWBuf, 0, 0}; - // clang-format off - // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 0 against 1}} - // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); - // clang-format on OuterProductAccumulate(Input1, Input2, matrix); } @@ -27,11 +24,8 @@ export void Test5(vector Input1, vector Input2) { RWMatrixRef matrix = {RWBuf, 0, 0}; - // clang-format off - // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} // expected-note@dx/linalg.h:157{{candidate template ignored: could not match 0 against 1}} - // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); - // clang-format on OuterProductAccumulate(Input1, Input2, matrix); } @@ -43,11 +37,8 @@ export void Test4(vector Input1, vector Input2) { RWMatrixRef matrix = {RWBuf, 0, 0}; - // clang-format off - // expected-error@+5{{no matching function for call to 'OuterProductAccumulate'}} + // expected-error@+3{{no matching function for call to 'OuterProductAccumulate'}} // expected-note@dx/linalg.h:157{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} - // __builtin_OuterProductAccumulate(Input1, Input2, RWBuf, 0, DATA_TYPE_FLOAT16, MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL, 0); - // clang-format on OuterProductAccumulate(Input1, Input2, matrix); } From acec5c8d3d2b8c97392f562bb5c1ffee9826c27b Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 21 Apr 2025 15:47:21 -0700 Subject: [PATCH 14/18] move proposal file --- .../hlsl/linalg => examples/LinAlg}/vector-matrix-proposal.hlsl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tools/clang/test/CodeGenDXIL/hlsl/linalg => examples/LinAlg}/vector-matrix-proposal.hlsl (100%) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl b/examples/LinAlg/vector-matrix-proposal.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/vector-matrix-proposal.hlsl rename to examples/LinAlg/vector-matrix-proposal.hlsl From 31629b111fdef1b66601d443acfaac2480e0c445 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 21 Apr 2025 16:56:44 -0700 Subject: [PATCH 15/18] remove proposal file --- examples/LinAlg/vector-matrix-proposal.hlsl | 143 -------------------- 1 file changed, 143 deletions(-) delete mode 100644 examples/LinAlg/vector-matrix-proposal.hlsl diff --git a/examples/LinAlg/vector-matrix-proposal.hlsl b/examples/LinAlg/vector-matrix-proposal.hlsl deleted file mode 100644 index 94c414c8ba..0000000000 --- a/examples/LinAlg/vector-matrix-proposal.hlsl +++ /dev/null @@ -1,143 +0,0 @@ -// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types %s - -#include - -namespace code_example { -ByteAddressBuffer Model; - -vector ApplyNeuralMaterial(vector InputVector) { - using namespace dx::linalg; - - MatrixRef Matrix0 = { - Model, 0, 0}; - - VectorRef BiasVector0 = {Model, 1024}; - - MatrixRef Matrix1 = - {Model, 2048, 0}; - - VectorRef BiasVector1 = {Model, 3072}; - - MatrixRef Matrix2 = { - Model, 4096, 0}; - - VectorRef BiasVector2 = {Model, 5120}; - - vector Layer0 = MulAdd( - Matrix0, MakeInterpretedVector(InputVector), - BiasVector0); - Layer0 = max(Layer0, 0); - - vector Layer1 = MulAdd( - Matrix1, MakeInterpretedVector(Layer0), - BiasVector1); - Layer1 = max(Layer1, 0); - - vector Output = MulAdd( - Matrix2, MakeInterpretedVector(Layer1), - BiasVector2); - Output = exp(Output); - - return Output; -} -} // namespace code_example - -namespace matrixref_example { -ByteAddressBuffer ROBuffer; -RWByteAddressBuffer RWBuffer; - -void Example() { - using namespace dx::linalg; - - MatrixRef MatrixA = - {ROBuffer, /*offset=*/128, /*stride=*/0}; - - MatrixRef MatrixB = { - ROBuffer, /*offset=*/128, /*stride=*/16}; - - RWMatrixRef - MatrixC = {RWBuffer, /*offset=*/64, /*stride=*/0}; -} -} // namespace matrixref_example - -namespace vectorref_example { -ByteAddressBuffer ROBuffer; -RWByteAddressBuffer RWBuffer; - -void Example() { - using namespace dx::linalg; - - VectorRef VectorA = {ROBuffer, /*offset=*/128}; - VectorRef VectorB = {ROBuffer, /*offset=*/128}; - RWVectorRef VectorC = {RWBuffer, /*offset=*/64}; -} -} // namespace vectorref_example - -namespace vector_example { -ByteAddressBuffer Buffer; -void Example() { - using namespace dx::linalg; - - MatrixRef - Matrix = {Buffer, 0, 0}; - - vector V = 0; - vector Result = - Mul(Matrix, MakeInterpretedVector(V)); - - // alternative: - InterpretedVector IV = {V}; - vector Result2 = Mul(Matrix, IV); -} -} // namespace vector_example - -namespace mul_example { -ByteAddressBuffer Buffer; -float4 Example(float4 Input) { - using namespace dx::linalg; - - MatrixRef Matrix = { - Buffer, 0, 0}; - - return Mul(Matrix, MakeInterpretedVector(Input)); -} -} // namespace mul_example - -namespace muladd_example { -ByteAddressBuffer Buffer; - -void Example() { - using namespace dx::linalg; - - MatrixRef Matrix = { - Buffer, 0, 0}; - - VectorRef BiasVector = {Buffer, 1024}; - - vector V = 0; - vector Result = MulAdd( - Matrix, MakeInterpretedVector(V), BiasVector); -} -} // namespace muladd_example - -namespace outerproductaccumulate_example { -RWByteAddressBuffer RWBuf; - -void Example(vector Input1, vector Input2) { - using namespace dx::linalg; - - RWMatrixRef - Matrix = {RWBuf, 0, 0}; - - OuterProductAccumulate(Input1, Input2, Matrix); -} -} // namespace outerproductaccumulate_example - -namespace vector_accumulate { -RWByteAddressBuffer RWBuf; - -void Test(vector Input) { - using namespace dx::linalg; - VectorAccumulate(Input, RWBuf, 0); -} -} // namespace vector_accumulate From 6dd02480e59ab2104ebd4f4621073c342f46ba20 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 22 Apr 2025 11:00:15 -0700 Subject: [PATCH 16/18] move sema test --- .../hlsl/linalg/vectoraccumulate-errors.hlsl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/clang/test/{CodeGenDXIL => SemaHLSL}/hlsl/linalg/vectoraccumulate-errors.hlsl (100%) diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/vectoraccumulate-errors.hlsl similarity index 100% rename from tools/clang/test/CodeGenDXIL/hlsl/linalg/vectoraccumulate-errors.hlsl rename to tools/clang/test/SemaHLSL/hlsl/linalg/vectoraccumulate-errors.hlsl From 7fcd4ff3fd392f63c6e00fe9825215202884f6e1 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 22 Apr 2025 13:58:13 -0700 Subject: [PATCH 17/18] add spirv check --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 6 +- .../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 +- .../outerproductaccumulate-spirv-errors.hlsl | 19 ++ .../outerproductaccumulate-spirv-errors.i | 193 ++++++++++++++++++ 7 files changed, 224 insertions(+), 8 deletions(-) create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl create mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 8241bc2d72..ed3d0a0184 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -1,5 +1,9 @@ // Header for linear algebra APIs. +#if __spirv__ +#error "Cooperative matrix/vectors not (yet) supported for SPIRV" +#endif + #if ((__SHADER_TARGET_MAJOR > 6) || \ (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ (__HLSL_VERSION >= 2021) @@ -175,4 +179,4 @@ void VectorAccumulate(vector InputVector, } // namespace linalg } // namespace dx -#endif +#endif // SM 6.9 check and HV version check 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 cbcd8147e8..9f2793d417 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:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:97{{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:93{{candidate template ignored: invalid explicitly-specified argument for template parameter 'DT'}} + // expected-note@dx/linalg.h:97{{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 cdc3ed020f..2d5a11e83e 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:107{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:111{{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 03cdacb8f6..f444f81c3a 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:133{{candidate template ignored: could not match 'MatrixRefImpl' against 'InterpretedVector'}} + // expected-note@dx/linalg.h:137{{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 9c707d5c3e..6f503b367b 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:157{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:161{{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:157{{candidate template ignored: could not match 0 against 1}} + // expected-note@dx/linalg.h:161{{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:157{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} + // expected-note@dx/linalg.h:161{{candidate template ignored: deduced conflicting types for parameter 'ElTy' ('int' vs. 'unsigned int')}} OuterProductAccumulate(Input1, Input2, matrix); } diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl new file mode 100644 index 0000000000..3ec5998f75 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl @@ -0,0 +1,19 @@ +// RUN: %dxc -I %hlsl_headers -T lib_6_9 -enable-16bit-types -spirv %s -verify + +// Tests that the header file cannot be included for spirv compilations +// This is a copy of \tools\clang\test\CodeGenDXIL\hlsl\linalg\outerproductaccumulate.hlsl +// except that spirv is targeted + +// expected-error@dx/linalg.h:4{{Cooperative matrix/vectors not (yet) supported for SPIRV}} +#include + +RWByteAddressBuffer RWBuf; + +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + OuterProductAccumulate(Input1, Input2, matrix); +} diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i new file mode 100644 index 0000000000..44ac09f9e8 --- /dev/null +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i @@ -0,0 +1,193 @@ +#line 1 "D:\\DXC\\tools\\clang\\test\\SemaHLSL\\hlsl\\linalg\\outerproductaccumulate-spirv-errors.hlsl" + + + + + + +#line 1 "D:/DXC/tools/clang/lib/Headers/hlsl\\dx/linalg.h" +#line 11 "D:/DXC/tools/clang/lib/Headers/hlsl\\dx/linalg.h" +namespace dx { +namespace linalg { + + + + + +enum DataType { + DATA_TYPE_SINT16 = 2, + DATA_TYPE_UINT16 = 3, + DATA_TYPE_SINT32 = 4, + DATA_TYPE_UINT32 = 5, + DATA_TYPE_FLOAT16 = 8, + DATA_TYPE_FLOAT32 = 9, + DATA_TYPE_SINT8_T4_PACKED = 17, + DATA_TYPE_UINT8_T4_PACKED = 18, + DATA_TYPE_UINT8 = 19, + DATA_TYPE_SINT8 = 20, + DATA_TYPE_FLOAT8_E4M3 = 21, + + DATA_TYPE_FLOAT8_E5M2 = 22, + +}; + +enum MatrixLayout { + MATRIX_LAYOUT_ROW_MAJOR = 0, + MATRIX_LAYOUT_COLUMN_MAJOR = 1, + MATRIX_LAYOUT_MUL_OPTIMAL = 2, + MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 +}; + + + + +namespace details { +template bool IsUnsigned() { return false; } + + +template <> bool IsUnsigned() { return true; } + + +template <> bool IsUnsigned() { return true; } +template <> bool IsUnsigned() { return true; } +} + + + + + +template +struct MatrixRefImpl { + BufferTy Buffer; + uint StartOffset; + uint Stride; +}; + +template +using MatrixRef = MatrixRefImpl; + +template +using RWMatrixRef = MatrixRefImpl; + + + + + +template struct VectorRefImpl { + BufferTy Buffer; + uint StartOffset; +}; + +template using VectorRef = VectorRefImpl; + +template +using RWVectorRef = VectorRefImpl; + + + + + +template struct InterpretedVector { + vector Data; +}; + +template +InterpretedVector MakeInterpretedVector(vector Vec) { + InterpretedVector IV = {Vec}; + return IV; +} + + + + + +template +vector +Mul(MatrixRefImpl + Matrix, + InterpretedVector InputVector) { + + vector OutputVector; + + __builtin_MatVecMul( + OutputVector, details::IsUnsigned(), InputVector.Data, + details::IsUnsigned(), InputDT, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, + MatrixTranspose, Matrix.Stride); + + return OutputVector; +} + + + + + +template +vector +MulAdd(MatrixRefImpl + Matrix, + InterpretedVector InputVector, + VectorRefImpl BiasVector) { + + vector OutputVector; + + __builtin_MatVecMulAdd( + OutputVector, details::IsUnsigned(), InputVector.Data, + details::IsUnsigned(), InputDT, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, + MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, + BiasVectorDT); + + return OutputVector; +} + + + + + +template +void OuterProductAccumulate( + vector InputVector1, vector InputVector2, + RWMatrixRef Matrix) { + __builtin_OuterProductAccumulate(InputVector1, InputVector2, Matrix.Buffer, + Matrix.StartOffset, MatrixDT, MatrixLayout, + Matrix.Stride); +} + + + + + +template +void VectorAccumulate(vector InputVector, + RWByteAddressBuffer Buffer, uint Offset) { + __builtin_VectorAccumulate(InputVector, Buffer, Offset); +} + +} +} +#line 7 "D:\\DXC\\tools\\clang\\test\\SemaHLSL\\hlsl\\linalg\\outerproductaccumulate-spirv-errors.hlsl" + + +RWByteAddressBuffer RWBuf; + +export void Test4(vector Input1, vector Input2) { + using namespace dx::linalg; + + RWMatrixRef + matrix = {RWBuf, 0, 0}; + + + OuterProductAccumulate(Input1, Input2, matrix); +} From d81fd22622e5f34f991964f3e77852ab7e310c37 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 22 Apr 2025 16:47:56 -0700 Subject: [PATCH 18/18] adjust error msg --- tools/clang/lib/Headers/hlsl/dx/linalg.h | 2 +- .../outerproductaccumulate-spirv-errors.hlsl | 2 +- .../outerproductaccumulate-spirv-errors.i | 193 ------------------ 3 files changed, 2 insertions(+), 195 deletions(-) delete mode 100644 tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index ed3d0a0184..51e662bbc9 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -1,7 +1,7 @@ // Header for linear algebra APIs. #if __spirv__ -#error "Cooperative matrix/vectors not (yet) supported for SPIRV" +#error "Cooperative vectors not (yet) supported for SPIRV" #endif #if ((__SHADER_TARGET_MAJOR > 6) || \ diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl index 3ec5998f75..0213103926 100644 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.hlsl @@ -4,7 +4,7 @@ // This is a copy of \tools\clang\test\CodeGenDXIL\hlsl\linalg\outerproductaccumulate.hlsl // except that spirv is targeted -// expected-error@dx/linalg.h:4{{Cooperative matrix/vectors not (yet) supported for SPIRV}} +// expected-error@dx/linalg.h:4{{Cooperative vectors not (yet) supported for SPIRV}} #include RWByteAddressBuffer RWBuf; diff --git a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i b/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i deleted file mode 100644 index 44ac09f9e8..0000000000 --- a/tools/clang/test/SemaHLSL/hlsl/linalg/outerproductaccumulate-spirv-errors.i +++ /dev/null @@ -1,193 +0,0 @@ -#line 1 "D:\\DXC\\tools\\clang\\test\\SemaHLSL\\hlsl\\linalg\\outerproductaccumulate-spirv-errors.hlsl" - - - - - - -#line 1 "D:/DXC/tools/clang/lib/Headers/hlsl\\dx/linalg.h" -#line 11 "D:/DXC/tools/clang/lib/Headers/hlsl\\dx/linalg.h" -namespace dx { -namespace linalg { - - - - - -enum DataType { - DATA_TYPE_SINT16 = 2, - DATA_TYPE_UINT16 = 3, - DATA_TYPE_SINT32 = 4, - DATA_TYPE_UINT32 = 5, - DATA_TYPE_FLOAT16 = 8, - DATA_TYPE_FLOAT32 = 9, - DATA_TYPE_SINT8_T4_PACKED = 17, - DATA_TYPE_UINT8_T4_PACKED = 18, - DATA_TYPE_UINT8 = 19, - DATA_TYPE_SINT8 = 20, - DATA_TYPE_FLOAT8_E4M3 = 21, - - DATA_TYPE_FLOAT8_E5M2 = 22, - -}; - -enum MatrixLayout { - MATRIX_LAYOUT_ROW_MAJOR = 0, - MATRIX_LAYOUT_COLUMN_MAJOR = 1, - MATRIX_LAYOUT_MUL_OPTIMAL = 2, - MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3 -}; - - - - -namespace details { -template bool IsUnsigned() { return false; } - - -template <> bool IsUnsigned() { return true; } - - -template <> bool IsUnsigned() { return true; } -template <> bool IsUnsigned() { return true; } -} - - - - - -template -struct MatrixRefImpl { - BufferTy Buffer; - uint StartOffset; - uint Stride; -}; - -template -using MatrixRef = MatrixRefImpl; - -template -using RWMatrixRef = MatrixRefImpl; - - - - - -template struct VectorRefImpl { - BufferTy Buffer; - uint StartOffset; -}; - -template using VectorRef = VectorRefImpl; - -template -using RWVectorRef = VectorRefImpl; - - - - - -template struct InterpretedVector { - vector Data; -}; - -template -InterpretedVector MakeInterpretedVector(vector Vec) { - InterpretedVector IV = {Vec}; - return IV; -} - - - - - -template -vector -Mul(MatrixRefImpl - Matrix, - InterpretedVector InputVector) { - - vector OutputVector; - - __builtin_MatVecMul( - OutputVector, details::IsUnsigned(), InputVector.Data, - details::IsUnsigned(), InputDT, Matrix.Buffer, - Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, - MatrixTranspose, Matrix.Stride); - - return OutputVector; -} - - - - - -template -vector -MulAdd(MatrixRefImpl - Matrix, - InterpretedVector InputVector, - VectorRefImpl BiasVector) { - - vector OutputVector; - - __builtin_MatVecMulAdd( - OutputVector, details::IsUnsigned(), InputVector.Data, - details::IsUnsigned(), InputDT, Matrix.Buffer, - Matrix.StartOffset, MatrixDT, MatrixM, MatrixK, MatrixLayout, - MatrixTranspose, Matrix.Stride, BiasVector.Buffer, BiasVector.StartOffset, - BiasVectorDT); - - return OutputVector; -} - - - - - -template -void OuterProductAccumulate( - vector InputVector1, vector InputVector2, - RWMatrixRef Matrix) { - __builtin_OuterProductAccumulate(InputVector1, InputVector2, Matrix.Buffer, - Matrix.StartOffset, MatrixDT, MatrixLayout, - Matrix.Stride); -} - - - - - -template -void VectorAccumulate(vector InputVector, - RWByteAddressBuffer Buffer, uint Offset) { - __builtin_VectorAccumulate(InputVector, Buffer, Offset); -} - -} -} -#line 7 "D:\\DXC\\tools\\clang\\test\\SemaHLSL\\hlsl\\linalg\\outerproductaccumulate-spirv-errors.hlsl" - - -RWByteAddressBuffer RWBuf; - -export void Test4(vector Input1, vector Input2) { - using namespace dx::linalg; - - RWMatrixRef - matrix = {RWBuf, 0, 0}; - - - OuterProductAccumulate(Input1, Input2, matrix); -}