Skip to content

Conversation

@luciechoi
Copy link
Collaborator

@luciechoi luciechoi commented Oct 31, 2025

Fixes #7695 (part of offload test suite)

HLSL spec indicates that the elements are mutilplied with half-precision but the summation results in a float. OpDot requires the ResultType to be the same as the vector's ComponentType, so this opcode cannot be used.

The fix is to untangle OpDot -- multiply half2 vectors and convert them to float before summing the elements.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is the correct interpretation of the description of dot2add.

A 2-dimensional floating point dot-product of half2 vectors with add. Multiplies the elements of the two half-precision float input vectors together and sums the results into the 32-bit float accumulator. This instructions operates within a single 32-bit wide SIMD lane. The inputs are 16-bit quantities packed into the same lane.

This instructions operates within a single 32-bit wide SIMD lane. The inputs are 16-bit quantities packed into the same lane.

This suggest that the multiplications should be done as 16-bit operations.

sums the results into the 32-bit float accumulator.

This suggests that the sum is done as a 32-bit operation.

The correct code might be:

%2 = OpMul %vhalf_n %input %input
%3 = OpFConvert %vfloat_n %2
// for i = 0 to n-1
%ex_i = OpCompositeExtract %float %3 <i>

%sum_1 = OpFAdd %float %ex_0 %ex_1
// for i = 2 to n-1
%sum_i = OpFAdd %sum_<i-1> %ex_i

Repeat the instructions, do not put a loop in the spir-v.

@luciechoi luciechoi requested a review from s-perron November 1, 2025 00:58
@luciechoi
Copy link
Collaborator Author

This suggest that the multiplications should be done as 16-bit operations.

You are right, thanks for the detailed explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

[SPIR-V] dot2add constant folding tests producing wrong output for Vulkan target

2 participants