Skip to content

Commit

Permalink
wgsl: Implement AbstractFloat step execution tests (#3525)
Browse files Browse the repository at this point in the history
Also switching to using sparse ranges since there are N^2 cases being
run.

Fixes #2530
  • Loading branch information
zoddicus authored Mar 21, 2024
1 parent e21de10 commit c8ec26a
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 107 deletions.
186 changes: 93 additions & 93 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "4e1c9823",
"webgpu/shader/execution/binary/af_addition.bin": "8295e1ff",
"webgpu/shader/execution/binary/af_logical.bin": "1b9df6b8",
"webgpu/shader/execution/binary/af_division.bin": "ab272a1a",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "62e4115b",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "25582ea8",
"webgpu/shader/execution/binary/af_multiplication.bin": "5bb8440c",
"webgpu/shader/execution/binary/af_remainder.bin": "b595a1af",
"webgpu/shader/execution/binary/af_subtraction.bin": "a677a089",
"webgpu/shader/execution/binary/f16_addition.bin": "99e5ccb3",
"webgpu/shader/execution/binary/af_division.bin": "5d795028",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "853758e4",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "ef3de2db",
"webgpu/shader/execution/binary/af_multiplication.bin": "3c615c8b",
"webgpu/shader/execution/binary/af_remainder.bin": "2bc2bbc3",
"webgpu/shader/execution/binary/af_subtraction.bin": "c0abd1d",
"webgpu/shader/execution/binary/f16_addition.bin": "4dd18ff",
"webgpu/shader/execution/binary/f16_logical.bin": "56f5fb0a",
"webgpu/shader/execution/binary/f16_division.bin": "db23ed18",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "4411d8a4",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "ce9c0328",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "6e893577",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "98385b2",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "2bd07a62",
"webgpu/shader/execution/binary/f16_multiplication.bin": "deb2895d",
"webgpu/shader/execution/binary/f16_remainder.bin": "d0d9c028",
"webgpu/shader/execution/binary/f16_subtraction.bin": "669b1af2",
"webgpu/shader/execution/binary/f32_addition.bin": "7d863c40",
"webgpu/shader/execution/binary/f16_division.bin": "f89baa3a",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "f1975960",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "22e337e2",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "baf0c21",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "187cf217",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "e6b99cca",
"webgpu/shader/execution/binary/f16_multiplication.bin": "7616a3c5",
"webgpu/shader/execution/binary/f16_remainder.bin": "d8a04999",
"webgpu/shader/execution/binary/f16_subtraction.bin": "edbed2d4",
"webgpu/shader/execution/binary/f32_addition.bin": "c7ba1d32",
"webgpu/shader/execution/binary/f32_logical.bin": "d64f0f75",
"webgpu/shader/execution/binary/f32_division.bin": "dc70ef4e",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "2af55a35",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "a36e65c6",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "31c0ee4",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "f6c6e3e1",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "d1f901d2",
"webgpu/shader/execution/binary/f32_multiplication.bin": "463ea28c",
"webgpu/shader/execution/binary/f32_remainder.bin": "9122273a",
"webgpu/shader/execution/binary/f32_subtraction.bin": "ed4a5504",
"webgpu/shader/execution/binary/f32_division.bin": "245361cb",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "182f7c3d",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "344933a3",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "d6815f41",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "a0566cc6",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "506bddf5",
"webgpu/shader/execution/binary/f32_multiplication.bin": "8f0ffb40",
"webgpu/shader/execution/binary/f32_remainder.bin": "a07e3b6e",
"webgpu/shader/execution/binary/f32_subtraction.bin": "5250713f",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "b5e7533e",
"webgpu/shader/execution/binary/i32_comparison.bin": "9e3294e2",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "ba4907a2",
"webgpu/shader/execution/binary/u32_comparison.bin": "51b6a5e0",
"webgpu/shader/execution/abs.bin": "25d7c8e4",
"webgpu/shader/execution/acos.bin": "ce76bb6a",
"webgpu/shader/execution/acosh.bin": "7ddff1a3",
"webgpu/shader/execution/asin.bin": "c85ac1b2",
"webgpu/shader/execution/asinh.bin": "5f02ab0",
"webgpu/shader/execution/atan.bin": "46a0df1a",
"webgpu/shader/execution/atan2.bin": "5f2ef117",
"webgpu/shader/execution/atanh.bin": "9a5bbc",
"webgpu/shader/execution/bitcast.bin": "93bfd36d",
"webgpu/shader/execution/ceil.bin": "86e3feb0",
"webgpu/shader/execution/clamp.bin": "91032199",
"webgpu/shader/execution/cos.bin": "30bfeb39",
"webgpu/shader/execution/cosh.bin": "5a7d4056",
"webgpu/shader/execution/cross.bin": "25a9648c",
"webgpu/shader/execution/degrees.bin": "68bb4b6a",
"webgpu/shader/execution/determinant.bin": "fe06388d",
"webgpu/shader/execution/distance.bin": "ae9f6920",
"webgpu/shader/execution/dot.bin": "89b96104",
"webgpu/shader/execution/exp.bin": "2335b71d",
"webgpu/shader/execution/exp2.bin": "f697e1ab",
"webgpu/shader/execution/faceForward.bin": "862617e3",
"webgpu/shader/execution/floor.bin": "dc7eecc0",
"webgpu/shader/execution/fma.bin": "f24fea8b",
"webgpu/shader/execution/fract.bin": "89f59577",
"webgpu/shader/execution/frexp.bin": "677d8f0",
"webgpu/shader/execution/inverseSqrt.bin": "928111d3",
"webgpu/shader/execution/ldexp.bin": "87816579",
"webgpu/shader/execution/length.bin": "2a08219b",
"webgpu/shader/execution/log.bin": "ed71fd58",
"webgpu/shader/execution/log2.bin": "e652dd8f",
"webgpu/shader/execution/max.bin": "91624408",
"webgpu/shader/execution/min.bin": "362714c5",
"webgpu/shader/execution/mix.bin": "dc8a4d96",
"webgpu/shader/execution/modf.bin": "aeaee5f0",
"webgpu/shader/execution/normalize.bin": "28819b59",
"webgpu/shader/execution/abs.bin": "37c9ff92",
"webgpu/shader/execution/acos.bin": "9fe49787",
"webgpu/shader/execution/acosh.bin": "f0cab83b",
"webgpu/shader/execution/asin.bin": "60a6f81b",
"webgpu/shader/execution/asinh.bin": "54b743",
"webgpu/shader/execution/atan.bin": "a4c06d28",
"webgpu/shader/execution/atan2.bin": "23378b78",
"webgpu/shader/execution/atanh.bin": "7a9e01b7",
"webgpu/shader/execution/bitcast.bin": "919a54af",
"webgpu/shader/execution/ceil.bin": "bd652de3",
"webgpu/shader/execution/clamp.bin": "f4a07fd9",
"webgpu/shader/execution/cos.bin": "a25213d8",
"webgpu/shader/execution/cosh.bin": "50a62a9c",
"webgpu/shader/execution/cross.bin": "9a90cd4d",
"webgpu/shader/execution/degrees.bin": "a5e2277b",
"webgpu/shader/execution/determinant.bin": "f3219ff",
"webgpu/shader/execution/distance.bin": "2f1ba649",
"webgpu/shader/execution/dot.bin": "d76ca862",
"webgpu/shader/execution/exp.bin": "bace8733",
"webgpu/shader/execution/exp2.bin": "83187dc2",
"webgpu/shader/execution/faceForward.bin": "d6a8c672",
"webgpu/shader/execution/floor.bin": "141fa1cb",
"webgpu/shader/execution/fma.bin": "eef58d71",
"webgpu/shader/execution/fract.bin": "e0ed5a47",
"webgpu/shader/execution/frexp.bin": "53c880c2",
"webgpu/shader/execution/inverseSqrt.bin": "7b0bea55",
"webgpu/shader/execution/ldexp.bin": "1d95d50",
"webgpu/shader/execution/length.bin": "714dc281",
"webgpu/shader/execution/log.bin": "4f49547e",
"webgpu/shader/execution/log2.bin": "98c354ce",
"webgpu/shader/execution/max.bin": "7d1077ce",
"webgpu/shader/execution/min.bin": "38f100e5",
"webgpu/shader/execution/mix.bin": "3fd0b0e4",
"webgpu/shader/execution/modf.bin": "843cf9cf",
"webgpu/shader/execution/normalize.bin": "3f90b427",
"webgpu/shader/execution/pack2x16float.bin": "1a61f373",
"webgpu/shader/execution/pow.bin": "49f81801",
"webgpu/shader/execution/quantizeToF16.bin": "cf4851f",
"webgpu/shader/execution/radians.bin": "59ec7c38",
"webgpu/shader/execution/reflect.bin": "5a1486d6",
"webgpu/shader/execution/refract.bin": "fc630c7c",
"webgpu/shader/execution/round.bin": "a2d271c3",
"webgpu/shader/execution/saturate.bin": "11bff5ef",
"webgpu/shader/execution/sign.bin": "ddc6cb6",
"webgpu/shader/execution/sin.bin": "b6cbcb92",
"webgpu/shader/execution/sinh.bin": "4897ac31",
"webgpu/shader/execution/smoothstep.bin": "5c96f965",
"webgpu/shader/execution/sqrt.bin": "10333cdd",
"webgpu/shader/execution/step.bin": "cd25f421",
"webgpu/shader/execution/tan.bin": "11181dcc",
"webgpu/shader/execution/tanh.bin": "4c353c33",
"webgpu/shader/execution/transpose.bin": "abf74887",
"webgpu/shader/execution/trunc.bin": "9434b1f4",
"webgpu/shader/execution/unpack2x16float.bin": "ed8a2014",
"webgpu/shader/execution/unpack2x16snorm.bin": "23e5686b",
"webgpu/shader/execution/unpack2x16unorm.bin": "2bebee9f",
"webgpu/shader/execution/unpack4x8snorm.bin": "e4a875b7",
"webgpu/shader/execution/unpack4x8unorm.bin": "e98ec4c5",
"webgpu/shader/execution/unary/af_arithmetic.bin": "ea18da7",
"webgpu/shader/execution/unary/af_assignment.bin": "473797e8",
"webgpu/shader/execution/pow.bin": "2b754e9d",
"webgpu/shader/execution/quantizeToF16.bin": "d5569d0b",
"webgpu/shader/execution/radians.bin": "804c845a",
"webgpu/shader/execution/reflect.bin": "6d7d89be",
"webgpu/shader/execution/refract.bin": "85cb8a6f",
"webgpu/shader/execution/round.bin": "83a9f09f",
"webgpu/shader/execution/saturate.bin": "4b0444bc",
"webgpu/shader/execution/sign.bin": "6e88b42f",
"webgpu/shader/execution/sin.bin": "44cc0d7b",
"webgpu/shader/execution/sinh.bin": "f698cb93",
"webgpu/shader/execution/smoothstep.bin": "f2acff50",
"webgpu/shader/execution/sqrt.bin": "c5b2e68a",
"webgpu/shader/execution/step.bin": "950499ce",
"webgpu/shader/execution/tan.bin": "69e7b99e",
"webgpu/shader/execution/tanh.bin": "13a69f4e",
"webgpu/shader/execution/transpose.bin": "97cca475",
"webgpu/shader/execution/trunc.bin": "8a03c63e",
"webgpu/shader/execution/unpack2x16float.bin": "d3346aee",
"webgpu/shader/execution/unpack2x16snorm.bin": "b141ba89",
"webgpu/shader/execution/unpack2x16unorm.bin": "1574f0e0",
"webgpu/shader/execution/unpack4x8snorm.bin": "359c9b67",
"webgpu/shader/execution/unpack4x8unorm.bin": "463f3622",
"webgpu/shader/execution/unary/af_arithmetic.bin": "387cffde",
"webgpu/shader/execution/unary/af_assignment.bin": "7b6fea86",
"webgpu/shader/execution/unary/bool_conversion.bin": "d42a9e83",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "ddb90b55",
"webgpu/shader/execution/unary/f16_conversion.bin": "63738ee3",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "3bc7154b",
"webgpu/shader/execution/unary/f32_conversion.bin": "abbf3539",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "6ccfa9b9",
"webgpu/shader/execution/unary/f16_conversion.bin": "cf0b38be",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "6725561f",
"webgpu/shader/execution/unary/f32_conversion.bin": "c331aec1",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "22f94632",
"webgpu/shader/execution/unary/i32_conversion.bin": "3f89d871",
"webgpu/shader/execution/unary/u32_conversion.bin": "4751045f",
"webgpu/shader/execution/unary/ai_assignment.bin": "19653bbf",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "a41d22e",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "69403380",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "a0802765",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "58e81f82",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "78f4496b"
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "813b0c99",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "d4a350eb",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "e5fd3330"
}
Binary file modified src/resources/cache/webgpu/shader/execution/step.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 @@ -4938,7 +4938,7 @@ g.test('remainderInterval')
g.test('stepInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.expandWithParams<ScalarPairToIntervalCase>(p => {
const constants = FP[p.trait].constants();
Expand All @@ -4956,12 +4956,17 @@ g.test('stepInterval')
{ input: [1, -1], expected: 0 },

// 64-bit normals
{ input: [0.1, 0.1], expected: [0, 1] },
// number is f64 internally, so the value representing the literal
// 0.1/-0.1 will always be exactly representable in AbstractFloat,
// since AF is also f64 internally.
// It is impossible with normals to cause the rounding ambiguity that
// causes the 0 or 1 result.
{ input: [0.1, 0.1], expected: p.trait === 'abstract' ? 1 : [0, 1] },
{ input: [0, 0.1], expected: 1 },
{ input: [0.1, 0], expected: 0 },
{ input: [0.1, 1], expected: 1 },
{ input: [1, 0.1], expected: 0 },
{ input: [-0.1, -0.1], expected: [0, 1] },
{ input: [-0.1, -0.1], expected: p.trait === 'abstract' ? 1 : [0, 1] },
{ input: [0, -0.1], expected: 0 },
{ input: [-0.1, 0], expected: 1 },
{ input: [-0.1, -1], expected: 0 },
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@
"webgpu:shader,execution,expression,call,builtin,sqrt:abstract_float:*": { "subcaseMS": 1545.649 },
"webgpu:shader,execution,expression,call,builtin,sqrt:f16:*": { "subcaseMS": 22.908 },
"webgpu:shader,execution,expression,call,builtin,sqrt:f32:*": { "subcaseMS": 10.813 },
"webgpu:shader,execution,expression,call,builtin,step:abstract_float:*": { "subcaseMS": 73.533 },
"webgpu:shader,execution,expression,call,builtin,step:abstract_float:*": { "subcaseMS": 92.310 },
"webgpu:shader,execution,expression,call,builtin,step:f16:*": { "subcaseMS": 32.508 },
"webgpu:shader,execution,expression,call,builtin,step:f32:*": { "subcaseMS": 291.363 },
"webgpu:shader,execution,expression,call,builtin,storageBarrier:barrier:*": { "subcaseMS": 0.801 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { makeCaseCache } from '../../case_cache.js';
// interval, valid result may be 0.0 or 1.0 or both of them, but will never be a
// value in interval (0.0, 1.0).
// See the comment block on stepInterval for more details
const makeCase = (trait: 'f32' | 'f16', edge: number, x: number): Case => {
const makeCase = (trait: 'f32' | 'f16' | 'abstract', edge: number, x: number): Case => {
const FPTrait = FP[trait];
edge = FPTrait.quantize(edge);
x = FPTrait.quantize(x);
Expand All @@ -27,13 +27,13 @@ const makeCase = (trait: 'f32' | 'f16', edge: number, x: number): Case => {
};
};

// Cases: [f32|f16]
const cases = (['f32', 'f16'] as const)
// Cases: [f32|f16|abstract]
const cases = (['f32', 'f16', 'abstract'] as const)
.map(trait => ({
[`${trait}`]: () => {
return FP[trait]
.scalarRange()
.flatMap(edge => FP[trait].scalarRange().map(x => makeCase(trait, edge, x)));
.sparseScalarRange()
.flatMap(edge => FP[trait].sparseScalarRange().map(x => makeCase(trait, edge, x)));
},
}))
.reduce((a, b) => ({ ...a, ...b }), {});
Expand Down
20 changes: 16 additions & 4 deletions src/webgpu/shader/execution/expression/call/builtin/step.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Returns 1.0 if edge ≤ x, and 0.0 otherwise. Component-wise when T is a vector.
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { Type } from '../../../../../util/conversion.js';
import { allInputSources, run } from '../../expression.js';
import { allInputSources, onlyConstInputSource, run } from '../../expression.js';

import { builtin } from './builtin.js';
import { abstractFloatBuiltin, builtin } from './builtin.js';
import { d } from './step.cache.js';

export const g = makeTestGroup(GPUTest);
Expand All @@ -21,9 +21,21 @@ g.test('abstract_float')
.specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions')
.desc(`abstract float tests`)
.params(u =>
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();
.fn(async t => {
const cases = await d.get('abstract');
await run(
t,
abstractFloatBuiltin('step'),
[Type.abstractFloat, Type.abstractFloat],
Type.abstractFloat,
t.params,
cases
);
});

g.test('f32')
.specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions')
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 @@ -5212,7 +5212,7 @@ class FPAbstractTraits extends FPTraits {
'smoothStepInterval'
);
public readonly sqrtInterval = this.unimplementedScalarToInterval.bind(this, 'sqrtInterval');
public readonly stepInterval = this.unimplementedScalarPairToInterval.bind(this, 'stepInterval');
public readonly stepInterval = this.stepIntervalImpl.bind(this);
public readonly subtractionInterval = this.subtractionIntervalImpl.bind(this);
public readonly subtractionMatrixMatrixInterval =
this.subtractionMatrixMatrixIntervalImpl.bind(this);
Expand Down

0 comments on commit c8ec26a

Please sign in to comment.