Skip to content

Commit

Permalink
wgsl: Implement AbstractFloat dot execution tests (#3443)
Browse files Browse the repository at this point in the history
Fixes #2512
  • Loading branch information
zoddicus authored Feb 29, 2024
1 parent 57bd1b0 commit 69f8a9b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 99 deletions.
182 changes: 90 additions & 92 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,107 +1,105 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "bbc5103c",
"webgpu/shader/execution/binary/af_addition.bin": "38b261fa",
"webgpu/shader/execution/binary/af_logical.bin": "a483b968",
"webgpu/shader/execution/binary/af_division.bin": "7c221c28",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "ebab2b30",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "6078475c",
"webgpu/shader/execution/binary/af_multiplication.bin": "66ad501",
"webgpu/shader/execution/binary/af_remainder.bin": "5a87ed27",
"webgpu/shader/execution/binary/af_subtraction.bin": "66bad739",
"webgpu/shader/execution/binary/f16_addition.bin": "3ff7fed3",
"webgpu/shader/execution/binary/af_division.bin": "ec39b0da",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "ca1373a8",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "406d99af",
"webgpu/shader/execution/binary/af_multiplication.bin": "2eb6d50d",
"webgpu/shader/execution/binary/af_remainder.bin": "e2b6b21",
"webgpu/shader/execution/binary/af_subtraction.bin": "84794350",
"webgpu/shader/execution/binary/f16_addition.bin": "19e8823d",
"webgpu/shader/execution/binary/f16_logical.bin": "b89ca9b9",
"webgpu/shader/execution/binary/f16_division.bin": "a01c2499",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "cb64b0b6",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "edbbdd7b",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "f5ded61d",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "11ad421b",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "5ef65699",
"webgpu/shader/execution/binary/f16_multiplication.bin": "24c6a56f",
"webgpu/shader/execution/binary/f16_remainder.bin": "d47a8347",
"webgpu/shader/execution/binary/f16_subtraction.bin": "755f4b0b",
"webgpu/shader/execution/binary/f32_addition.bin": "6db93d07",
"webgpu/shader/execution/binary/f16_division.bin": "6dc4b748",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "7533842",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "2d799920",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "44e3b295",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "412f0911",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "a231201b",
"webgpu/shader/execution/binary/f16_multiplication.bin": "94b11030",
"webgpu/shader/execution/binary/f16_remainder.bin": "de68a200",
"webgpu/shader/execution/binary/f16_subtraction.bin": "f308327a",
"webgpu/shader/execution/binary/f32_addition.bin": "c87c8c08",
"webgpu/shader/execution/binary/f32_logical.bin": "c7370c09",
"webgpu/shader/execution/binary/f32_division.bin": "c28058b5",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "3f49bac9",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "592cc2c4",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "e3750b3c",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "b16d21e2",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "c982cd63",
"webgpu/shader/execution/binary/f32_multiplication.bin": "835ec6ee",
"webgpu/shader/execution/binary/f32_remainder.bin": "daf70203",
"webgpu/shader/execution/binary/f32_subtraction.bin": "2fc781f8",
"webgpu/shader/execution/binary/f32_division.bin": "34ce65ae",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "f3808d0c",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "e33e7fe5",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "41091ebf",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "37ccb101",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "4d67866",
"webgpu/shader/execution/binary/f32_multiplication.bin": "5d85a36c",
"webgpu/shader/execution/binary/f32_remainder.bin": "62f591b2",
"webgpu/shader/execution/binary/f32_subtraction.bin": "60fc275a",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "a0b0a016",
"webgpu/shader/execution/binary/i32_comparison.bin": "f3d9b3f9",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "16e32fd",
"webgpu/shader/execution/binary/u32_comparison.bin": "da33cc5d",
"webgpu/shader/execution/abs.bin": "e8dce87a",
"webgpu/shader/execution/acos.bin": "2762bad",
"webgpu/shader/execution/acosh.bin": "a3b96c53",
"webgpu/shader/execution/asin.bin": "1d9d590",
"webgpu/shader/execution/asinh.bin": "c2cc05",
"webgpu/shader/execution/atan.bin": "3f701bba",
"webgpu/shader/execution/atan2.bin": "559fb65a",
"webgpu/shader/execution/atanh.bin": "6d352d21",
"webgpu/shader/execution/bitcast.bin": "ec72fa7",
"webgpu/shader/execution/ceil.bin": "42f80be0",
"webgpu/shader/execution/clamp.bin": "1440b818",
"webgpu/shader/execution/cos.bin": "c5da20d",
"webgpu/shader/execution/cosh.bin": "a01e8091",
"webgpu/shader/execution/cross.bin": "c756d650",
"webgpu/shader/execution/degrees.bin": "2c481603",
"webgpu/shader/execution/determinant.bin": "1e67d0f3",
"webgpu/shader/execution/distance.bin": "9a305a9d",
"webgpu/shader/execution/dot.bin": "1a3853b8",
"webgpu/shader/execution/exp.bin": "11112dba",
"webgpu/shader/execution/exp2.bin": "583e9c6a",
"webgpu/shader/execution/faceForward.bin": "7528aff7",
"webgpu/shader/execution/floor.bin": "96044530",
"webgpu/shader/execution/fma.bin": "8e795844",
"webgpu/shader/execution/fract.bin": "997d1bb5",
"webgpu/shader/execution/frexp.bin": "4a1efc69",
"webgpu/shader/execution/inverseSqrt.bin": "3e7d725",
"webgpu/shader/execution/ldexp.bin": "79646a61",
"webgpu/shader/execution/length.bin": "177f62e6",
"webgpu/shader/execution/log.bin": "4e0f535c",
"webgpu/shader/execution/log2.bin": "a961449",
"webgpu/shader/execution/max.bin": "3d764667",
"webgpu/shader/execution/min.bin": "c02f865",
"webgpu/shader/execution/mix.bin": "9431b1b0",
"webgpu/shader/execution/modf.bin": "1fdcef82",
"webgpu/shader/execution/normalize.bin": "78dd7ec5",
"webgpu/shader/execution/abs.bin": "1ead834c",
"webgpu/shader/execution/acos.bin": "e25802ba",
"webgpu/shader/execution/acosh.bin": "2321726f",
"webgpu/shader/execution/asin.bin": "d554a73b",
"webgpu/shader/execution/asinh.bin": "d2bdb21b",
"webgpu/shader/execution/atan.bin": "eb6476f3",
"webgpu/shader/execution/atan2.bin": "cf15e7fa",
"webgpu/shader/execution/atanh.bin": "6c57cc3",
"webgpu/shader/execution/bitcast.bin": "a25e9714",
"webgpu/shader/execution/ceil.bin": "8d120ea3",
"webgpu/shader/execution/clamp.bin": "a762ef58",
"webgpu/shader/execution/cos.bin": "a859da89",
"webgpu/shader/execution/cosh.bin": "86abdd85",
"webgpu/shader/execution/cross.bin": "e4556729",
"webgpu/shader/execution/degrees.bin": "1fa19a41",
"webgpu/shader/execution/determinant.bin": "108c3d65",
"webgpu/shader/execution/distance.bin": "77a1baa6",
"webgpu/shader/execution/dot.bin": "d4ac2e8a",
"webgpu/shader/execution/exp.bin": "15539afd",
"webgpu/shader/execution/exp2.bin": "7f6a8523",
"webgpu/shader/execution/faceForward.bin": "e7b35f43",
"webgpu/shader/execution/floor.bin": "b26656ca",
"webgpu/shader/execution/fma.bin": "5a70c683",
"webgpu/shader/execution/fract.bin": "23c0d5ec",
"webgpu/shader/execution/frexp.bin": "d28e66be",
"webgpu/shader/execution/inverseSqrt.bin": "9f297854",
"webgpu/shader/execution/ldexp.bin": "638db0c7",
"webgpu/shader/execution/length.bin": "7d237c62",
"webgpu/shader/execution/log.bin": "70720bf0",
"webgpu/shader/execution/log2.bin": "93a309be",
"webgpu/shader/execution/max.bin": "36eb4779",
"webgpu/shader/execution/min.bin": "ca772bf1",
"webgpu/shader/execution/mix.bin": "ecbf61ae",
"webgpu/shader/execution/modf.bin": "6ddea900",
"webgpu/shader/execution/normalize.bin": "d3e47c61",
"webgpu/shader/execution/pack2x16float.bin": "e6859c1a",
"webgpu/shader/execution/pow.bin": "4877dcfb",
"webgpu/shader/execution/quantizeToF16.bin": "c80d80ea",
"webgpu/shader/execution/radians.bin": "ac062ec8",
"webgpu/shader/execution/reflect.bin": "a4e70e5a",
"webgpu/shader/execution/refract.bin": "2ca0bc97",
"webgpu/shader/execution/round.bin": "3471eaad",
"webgpu/shader/execution/saturate.bin": "5bb3dced",
"webgpu/shader/execution/sign.bin": "5b54134",
"webgpu/shader/execution/sin.bin": "c5bb923c",
"webgpu/shader/execution/sinh.bin": "122dba1b",
"webgpu/shader/execution/smoothstep.bin": "91223043",
"webgpu/shader/execution/sqrt.bin": "e630cb4e",
"webgpu/shader/execution/step.bin": "a3349b96",
"webgpu/shader/execution/tan.bin": "ecc23f5e",
"webgpu/shader/execution/tanh.bin": "96c30607",
"webgpu/shader/execution/transpose.bin": "8968d6f9",
"webgpu/shader/execution/trunc.bin": "6c17efc2",
"webgpu/shader/execution/unpack2x16float.bin": "f035f149",
"webgpu/shader/execution/unpack2x16snorm.bin": "e92a1762",
"webgpu/shader/execution/unpack2x16unorm.bin": "abe4e594",
"webgpu/shader/execution/unpack4x8snorm.bin": "9bb9c594",
"webgpu/shader/execution/unpack4x8unorm.bin": "53ceebc",
"webgpu/shader/execution/unary/af_arithmetic.bin": "cd5b7fa3",
"webgpu/shader/execution/unary/af_assignment.bin": "86b66309",
"webgpu/shader/execution/pow.bin": "a58be71c",
"webgpu/shader/execution/quantizeToF16.bin": "eca85bca",
"webgpu/shader/execution/radians.bin": "a216c9aa",
"webgpu/shader/execution/reflect.bin": "ebce9830",
"webgpu/shader/execution/refract.bin": "59d1e5d6",
"webgpu/shader/execution/round.bin": "9389a090",
"webgpu/shader/execution/saturate.bin": "7ca4b681",
"webgpu/shader/execution/sign.bin": "1f4eeb34",
"webgpu/shader/execution/sin.bin": "a1e234b4",
"webgpu/shader/execution/sinh.bin": "1a62054b",
"webgpu/shader/execution/smoothstep.bin": "d5824fd6",
"webgpu/shader/execution/sqrt.bin": "66f21d02",
"webgpu/shader/execution/step.bin": "310cb6c7",
"webgpu/shader/execution/tan.bin": "1e26f533",
"webgpu/shader/execution/tanh.bin": "4c546d1c",
"webgpu/shader/execution/transpose.bin": "7bef2494",
"webgpu/shader/execution/trunc.bin": "e72535eb",
"webgpu/shader/execution/unpack2x16float.bin": "593d88c6",
"webgpu/shader/execution/unpack2x16snorm.bin": "9ebd3e40",
"webgpu/shader/execution/unpack2x16unorm.bin": "83a36fa9",
"webgpu/shader/execution/unpack4x8snorm.bin": "41b12606",
"webgpu/shader/execution/unpack4x8unorm.bin": "96f1850b",
"webgpu/shader/execution/unary/af_arithmetic.bin": "6fa1d84a",
"webgpu/shader/execution/unary/af_assignment.bin": "98c8f82a",
"webgpu/shader/execution/unary/bool_conversion.bin": "dd71f171",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "9537b14",
"webgpu/shader/execution/unary/f16_conversion.bin": "3948e7eb",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "f8aa7493",
"webgpu/shader/execution/unary/f32_conversion.bin": "7ee18c9e",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "2f2d38fc",
"webgpu/shader/execution/unary/f16_conversion.bin": "70c94538",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "db90c01c",
"webgpu/shader/execution/unary/f32_conversion.bin": "81912140",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "c69716e2",
"webgpu/shader/execution/unary/i32_complement.bin": "70c49c98",
"webgpu/shader/execution/unary/i32_conversion.bin": "83218e69",
"webgpu/shader/execution/unary/u32_complement.bin": "84f3d299",
"webgpu/shader/execution/unary/u32_conversion.bin": "8f5bad00",
"webgpu/shader/execution/unary/ai_assignment.bin": "c7e6ac33",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "81c11ec2",
Expand Down
Binary file modified src/resources/cache/webgpu/shader/execution/dot.bin
Binary file not shown.
11 changes: 8 additions & 3 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6127,12 +6127,17 @@ const kDotIntervalCases = {
{ input: [[kValue.f16.positive.max, 1.0, 2.0, 3.0], [-1.0, kValue.f16.positive.max, -2.0, -3.0]], expected: kUnboundedEndpoints },
{ input: [[kValue.f16.positive.max, 1.0, 2.0, 3.0], [1.0, kValue.f16.negative.min, 2.0, 3.0]], expected: kUnboundedEndpoints },
] as VectorPairToIntervalCase[],
abstract: [
// See f32 for details
{ input: [[kValue.f64.positive.max, 1.0, 2.0, 3.0], [-1.0, kValue.f64.positive.max, -2.0, -3.0]], expected: [-13, 0] },
{ input: [[kValue.f64.positive.max, 1.0, 2.0, 3.0], [1.0, kValue.f64.negative.min, 2.0, 3.0]], expected: [0, 13] },
] as VectorPairToIntervalCase[],
} as const;

g.test('dotInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.expandWithParams<VectorPairToIntervalCase>(p => {
const trait = FP[p.trait];
Expand All @@ -6145,7 +6150,7 @@ g.test('dotInterval')
{ input: [[1.0, 1.0], [1.0, 1.0]], expected: 2.0 },
{ input: [[-1.0, -1.0], [-1.0, -1.0]], expected: 2.0 },
{ input: [[-1.0, 1.0], [1.0, -1.0]], expected: -2.0 },
{ input: [[0.1, 0.0], [1.0, 0.0]], expected: kConstantCorrectlyRoundedExpectation[p.trait]['0.1']}, // correclt rounded of 0.1
{ input: [[0.1, 0.0], [1.0, 0.0]], expected: kConstantCorrectlyRoundedExpectation[p.trait]['0.1']}, // correctly rounded of 0.1

// vec3
{ input: [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], expected: 1.0 },
Expand All @@ -6154,7 +6159,7 @@ g.test('dotInterval')
{ input: [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], expected: 3.0 },
{ input: [[-1.0, -1.0, -1.0], [-1.0, -1.0, -1.0]], expected: 3.0 },
{ input: [[1.0, -1.0, -1.0], [-1.0, 1.0, -1.0]], expected: -1.0 },
{ input: [[0.1, 0.0, 0.0], [1.0, 0.0, 0.0]], expected: kConstantCorrectlyRoundedExpectation[p.trait]['0.1']}, // correclt rounded of 0.1
{ input: [[0.1, 0.0, 0.0], [1.0, 0.0, 0.0]], expected: kConstantCorrectlyRoundedExpectation[p.trait]['0.1']}, // correctly rounded of 0.1

// vec4
{ input: [[1.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0]], expected: 1.0 },
Expand Down
12 changes: 9 additions & 3 deletions src/webgpu/shader/execution/expression/call/builtin/dot.cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ function ci_dot(x: number[], y: number[]): number | undefined {
return x.reduce((prev, _, idx) => prev + Math.imul(x[idx], y[idx]), 0);
}

// Cases: [f32|f16]_vecN_[non_]const
const float_cases = (['f32', 'f16'] as const)
// Cases: [f32|f16|abstract]_vecN_[non_]const
const float_cases = (['f32', 'f16', 'abstract'] as const)
.flatMap(trait =>
([2, 3, 4] as const).flatMap(N =>
([true, false] as const).map(nonConst => ({
[`${trait}_vec${N}_${nonConst ? 'non_const' : 'const'}`]: () => {
[`${trait === 'abstract' ? 'abstract_float' : trait}_vec${N}_${
nonConst ? 'non_const' : 'const'
}`]: () => {
// Emit an empty array for not const abstract float, since they will never be run
if (trait === 'abstract' && nonConst) {
return [];
}
// vec3 and vec4 require calculating all possible permutations, so their runtime is much
// longer per test, so only using sparse vectors for them.
return FP[trait].generateVectorPairToIntervalCases(
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/util/floating_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,7 @@ class FPAbstractTraits extends FPTraits {
): FPInterval => {
return this.toInterval(kF32Traits.divisionInterval(x, y));
};
public readonly dotInterval = this.unimplementedVectorPairToInterval.bind(this, 'dotInterval');
public readonly dotInterval = this.dotIntervalImpl.bind(this);
public readonly expInterval = this.unimplementedScalarToInterval.bind(this, 'expInterval');
public readonly exp2Interval = this.unimplementedScalarToInterval.bind(this, 'exp2Interval');
public readonly faceForwardIntervals = this.unimplementedFaceForward.bind(this);
Expand Down

0 comments on commit 69f8a9b

Please sign in to comment.