Skip to content

Commit ec968ab

Browse files
authored
[SM6.10][Bugfix] Make sure DstN::Value calculation is rounded up (#8359)
Fixes #8356
1 parent e9d74b2 commit ec968ab

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tools/clang/lib/Headers/hlsl/dx/linalg.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ __MATRIX_SCALAR_COMPONENT_MAPPING(ComponentType::U64, uint64_t)
186186
__MATRIX_SCALAR_COMPONENT_MAPPING(ComponentType::F64, double)
187187

188188
template <ComponentEnum DstTy, ComponentEnum SrcTy, int SrcN> struct DstN {
189+
// Make sure to round up in case SrcN isn't an even multiple of the number of
190+
// elements per scalar
189191
static const int Value =
190-
(SrcN * ComponentTypeTraits<SrcTy>::ElementsPerScalar) /
192+
(SrcN * ComponentTypeTraits<SrcTy>::ElementsPerScalar +
193+
ComponentTypeTraits<DstTy>::ElementsPerScalar - 1) /
191194
ComponentTypeTraits<DstTy>::ElementsPerScalar;
192195
};
193196

tools/clang/test/CodeGenDXIL/hlsl/linalg/api/vectors.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ void main(uint ID : SV_GroupID) {
8282
half16 srcF16 = BAB.Load<half16>(128);
8383
InterpretedVector<uint, 4, ComponentEnum::F8_E4M3FN> convertedPacked = Convert<ComponentEnum::F8_E4M3FN, ComponentEnum::F16>(srcF16);
8484

85+
// CHECK: call <1 x i32> @dx.op.linAlgConvert.v1i32.v3f16(i32 -2147483618, <3 x half> %25, i32 8, i32 21)
86+
// CHECK-SAME: ; LinAlgConvert(inputVector,inputInterpretation,outputInterpretation)
87+
half3 ThreeF16 = BAB.Load<half3>(256);
88+
InterpretedVector<uint, 1, ComponentEnum::F8_E4M3FN> convertedPacked2 =
89+
Convert<ComponentEnum::F8_E4M3FN, ComponentEnum::F16>(ThreeF16);
8590
}

0 commit comments

Comments
 (0)