Skip to content

Commit

Permalink
wgsl: Add vectorRange and sparseVectorRange to FPTraits API (#3176)
Browse files Browse the repository at this point in the history
This allows for selection of these generators based on the floating
point type, which in-turn allows folding a bunch of case builders
together.

Issue #3174
  • Loading branch information
zoddicus authored Nov 22, 2023
1 parent 7dda75f commit 1390017
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 466 deletions.
180 changes: 90 additions & 90 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "a56b8e5b",
"webgpu/shader/execution/binary/af_addition.bin": "9ad2b249",
"webgpu/shader/execution/binary/af_logical.bin": "ae4d0245",
"webgpu/shader/execution/binary/af_division.bin": "272d8801",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "808bf815",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "1d2c3ef5",
"webgpu/shader/execution/binary/af_multiplication.bin": "51bcd4fa",
"webgpu/shader/execution/binary/af_remainder.bin": "4cf24b9a",
"webgpu/shader/execution/binary/af_subtraction.bin": "320f8bec",
"webgpu/shader/execution/binary/f16_addition.bin": "2158527",
"webgpu/shader/execution/binary/af_division.bin": "d3376690",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "e3bc27b",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "9cc3291c",
"webgpu/shader/execution/binary/af_multiplication.bin": "17f2a567",
"webgpu/shader/execution/binary/af_remainder.bin": "5582cf38",
"webgpu/shader/execution/binary/af_subtraction.bin": "de31266e",
"webgpu/shader/execution/binary/f16_addition.bin": "6cd9e104",
"webgpu/shader/execution/binary/f16_logical.bin": "8b97670c",
"webgpu/shader/execution/binary/f16_division.bin": "ab5a1978",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "281dfb13",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "afb1ba5",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "9f0b30b8",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "a0d7171c",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "99abdf10",
"webgpu/shader/execution/binary/f16_multiplication.bin": "c9b3a1f7",
"webgpu/shader/execution/binary/f16_remainder.bin": "37d766fb",
"webgpu/shader/execution/binary/f16_subtraction.bin": "569714bb",
"webgpu/shader/execution/binary/f32_addition.bin": "4036bb6c",
"webgpu/shader/execution/binary/f16_division.bin": "10202143",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "63f361ba",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "47fb7bc",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "89b49d2f",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "1c7c2571",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "551ba6cc",
"webgpu/shader/execution/binary/f16_multiplication.bin": "e5c32f73",
"webgpu/shader/execution/binary/f16_remainder.bin": "404927e7",
"webgpu/shader/execution/binary/f16_subtraction.bin": "64188676",
"webgpu/shader/execution/binary/f32_addition.bin": "741c7a51",
"webgpu/shader/execution/binary/f32_logical.bin": "c761067f",
"webgpu/shader/execution/binary/f32_division.bin": "cd7ff99f",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "9dca27e2",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "6f1a3cee",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "faa9f9b6",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "2d8bce4f",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "16935a68",
"webgpu/shader/execution/binary/f32_multiplication.bin": "3b4bd117",
"webgpu/shader/execution/binary/f32_remainder.bin": "323866c9",
"webgpu/shader/execution/binary/f32_subtraction.bin": "e7850558",
"webgpu/shader/execution/binary/f32_division.bin": "69aeed3a",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "10082f79",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "e82ac781",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "2bd684f",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "48da0bda",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "8776a032",
"webgpu/shader/execution/binary/f32_multiplication.bin": "565152c2",
"webgpu/shader/execution/binary/f32_remainder.bin": "87e5fe4e",
"webgpu/shader/execution/binary/f32_subtraction.bin": "fd539f36",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "d385729b",
"webgpu/shader/execution/binary/i32_comparison.bin": "a212a9e5",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "d9387c9a",
"webgpu/shader/execution/binary/u32_comparison.bin": "cb609171",
"webgpu/shader/execution/abs.bin": "49f7faf5",
"webgpu/shader/execution/acos.bin": "866f09e1",
"webgpu/shader/execution/acosh.bin": "4560e02a",
"webgpu/shader/execution/asin.bin": "cc81b07b",
"webgpu/shader/execution/asinh.bin": "9725f077",
"webgpu/shader/execution/atan.bin": "609df34a",
"webgpu/shader/execution/atan2.bin": "fe507972",
"webgpu/shader/execution/atanh.bin": "57f6b8a3",
"webgpu/shader/execution/bitcast.bin": "1f24ff3a",
"webgpu/shader/execution/ceil.bin": "4ed0c45b",
"webgpu/shader/execution/clamp.bin": "ad417174",
"webgpu/shader/execution/cos.bin": "96beac42",
"webgpu/shader/execution/cosh.bin": "f804dcd",
"webgpu/shader/execution/cross.bin": "afc0eb76",
"webgpu/shader/execution/degrees.bin": "91f06824",
"webgpu/shader/execution/determinant.bin": "eceba086",
"webgpu/shader/execution/distance.bin": "35e14924",
"webgpu/shader/execution/dot.bin": "57b17ace",
"webgpu/shader/execution/exp.bin": "1df2ddb6",
"webgpu/shader/execution/exp2.bin": "1bd38dd",
"webgpu/shader/execution/faceForward.bin": "6f4b9a73",
"webgpu/shader/execution/floor.bin": "f8c9993f",
"webgpu/shader/execution/fma.bin": "8f076f30",
"webgpu/shader/execution/fract.bin": "2b18f48f",
"webgpu/shader/execution/frexp.bin": "93592d00",
"webgpu/shader/execution/inverseSqrt.bin": "5cef7c26",
"webgpu/shader/execution/ldexp.bin": "71954769",
"webgpu/shader/execution/length.bin": "f0871818",
"webgpu/shader/execution/log.bin": "365b395d",
"webgpu/shader/execution/log2.bin": "6d844fc7",
"webgpu/shader/execution/max.bin": "850c61e6",
"webgpu/shader/execution/min.bin": "dd9dedde",
"webgpu/shader/execution/mix.bin": "25b0bc44",
"webgpu/shader/execution/modf.bin": "3995f421",
"webgpu/shader/execution/normalize.bin": "40d115ec",
"webgpu/shader/execution/abs.bin": "3161e44d",
"webgpu/shader/execution/acos.bin": "dc04c013",
"webgpu/shader/execution/acosh.bin": "5f2d5d46",
"webgpu/shader/execution/asin.bin": "7dcbb4e4",
"webgpu/shader/execution/asinh.bin": "a7826495",
"webgpu/shader/execution/atan.bin": "c38ef29f",
"webgpu/shader/execution/atan2.bin": "e3fe2caf",
"webgpu/shader/execution/atanh.bin": "7bbb6084",
"webgpu/shader/execution/bitcast.bin": "87bfa9e8",
"webgpu/shader/execution/ceil.bin": "e43ad5bb",
"webgpu/shader/execution/clamp.bin": "f59d5615",
"webgpu/shader/execution/cos.bin": "84722156",
"webgpu/shader/execution/cosh.bin": "cf071209",
"webgpu/shader/execution/cross.bin": "bf2f7adf",
"webgpu/shader/execution/degrees.bin": "c4254ee0",
"webgpu/shader/execution/determinant.bin": "e5fe08db",
"webgpu/shader/execution/distance.bin": "89368db",
"webgpu/shader/execution/dot.bin": "5902ed6a",
"webgpu/shader/execution/exp.bin": "fdbe406e",
"webgpu/shader/execution/exp2.bin": "69983959",
"webgpu/shader/execution/faceForward.bin": "56141bff",
"webgpu/shader/execution/floor.bin": "cc77695",
"webgpu/shader/execution/fma.bin": "63b076cc",
"webgpu/shader/execution/fract.bin": "46113f72",
"webgpu/shader/execution/frexp.bin": "7a578d2d",
"webgpu/shader/execution/inverseSqrt.bin": "b89e412c",
"webgpu/shader/execution/ldexp.bin": "2e387a8b",
"webgpu/shader/execution/length.bin": "1cf5a3d0",
"webgpu/shader/execution/log.bin": "d29e19c4",
"webgpu/shader/execution/log2.bin": "8493434a",
"webgpu/shader/execution/max.bin": "b3ac49b0",
"webgpu/shader/execution/min.bin": "7e92bdf4",
"webgpu/shader/execution/mix.bin": "a242b580",
"webgpu/shader/execution/modf.bin": "60c1b4c2",
"webgpu/shader/execution/normalize.bin": "d1c8e8ce",
"webgpu/shader/execution/pack2x16float.bin": "acd2d4cc",
"webgpu/shader/execution/pow.bin": "ba4aa9d5",
"webgpu/shader/execution/quantizeToF16.bin": "5eaa050",
"webgpu/shader/execution/radians.bin": "ad3b9408",
"webgpu/shader/execution/reflect.bin": "371ab49a",
"webgpu/shader/execution/refract.bin": "127389a3",
"webgpu/shader/execution/round.bin": "cb947f1d",
"webgpu/shader/execution/saturate.bin": "84a77008",
"webgpu/shader/execution/sign.bin": "694483cb",
"webgpu/shader/execution/sin.bin": "588f5708",
"webgpu/shader/execution/sinh.bin": "55e2f80a",
"webgpu/shader/execution/smoothstep.bin": "f532f7ee",
"webgpu/shader/execution/sqrt.bin": "a12f423b",
"webgpu/shader/execution/step.bin": "56327d5",
"webgpu/shader/execution/tan.bin": "8d9ea9af",
"webgpu/shader/execution/tanh.bin": "96d01d58",
"webgpu/shader/execution/transpose.bin": "22e1a807",
"webgpu/shader/execution/trunc.bin": "eb14c04d",
"webgpu/shader/execution/unpack2x16float.bin": "cc1e0067",
"webgpu/shader/execution/unpack2x16snorm.bin": "85f1c3c5",
"webgpu/shader/execution/unpack2x16unorm.bin": "2f956a85",
"webgpu/shader/execution/unpack4x8snorm.bin": "404052b4",
"webgpu/shader/execution/unpack4x8unorm.bin": "b7bdf499",
"webgpu/shader/execution/unary/af_arithmetic.bin": "24315037",
"webgpu/shader/execution/unary/af_assignment.bin": "405dcc78",
"webgpu/shader/execution/pow.bin": "bd5ad2f1",
"webgpu/shader/execution/quantizeToF16.bin": "e1d5b687",
"webgpu/shader/execution/radians.bin": "ab8ffce",
"webgpu/shader/execution/reflect.bin": "21b95d6c",
"webgpu/shader/execution/refract.bin": "673f11a5",
"webgpu/shader/execution/round.bin": "e258877c",
"webgpu/shader/execution/saturate.bin": "ea81a5bb",
"webgpu/shader/execution/sign.bin": "506ea55a",
"webgpu/shader/execution/sin.bin": "a7343188",
"webgpu/shader/execution/sinh.bin": "958eb14d",
"webgpu/shader/execution/smoothstep.bin": "53d2d03f",
"webgpu/shader/execution/sqrt.bin": "bee99723",
"webgpu/shader/execution/step.bin": "5fd9e33e",
"webgpu/shader/execution/tan.bin": "7f4bdf13",
"webgpu/shader/execution/tanh.bin": "db866ad7",
"webgpu/shader/execution/transpose.bin": "5841777f",
"webgpu/shader/execution/trunc.bin": "7e39b544",
"webgpu/shader/execution/unpack2x16float.bin": "836d1dff",
"webgpu/shader/execution/unpack2x16snorm.bin": "c29710",
"webgpu/shader/execution/unpack2x16unorm.bin": "fee2226a",
"webgpu/shader/execution/unpack4x8snorm.bin": "fc72f2ee",
"webgpu/shader/execution/unpack4x8unorm.bin": "2e335e83",
"webgpu/shader/execution/unary/af_arithmetic.bin": "b332ab15",
"webgpu/shader/execution/unary/af_assignment.bin": "9cd4b66",
"webgpu/shader/execution/unary/bool_conversion.bin": "8916fbb",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "d59a9bec",
"webgpu/shader/execution/unary/f16_conversion.bin": "70096394",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "b9430cfe",
"webgpu/shader/execution/unary/f32_conversion.bin": "c03cad58",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "5448a82c",
"webgpu/shader/execution/unary/f16_conversion.bin": "1ad05153",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "a2e45ea0",
"webgpu/shader/execution/unary/f32_conversion.bin": "fa062da3",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "2bba8fe4",
"webgpu/shader/execution/unary/i32_complement.bin": "caa954b2",
"webgpu/shader/execution/unary/i32_conversion.bin": "22a36f9e",
Expand Down
Binary file modified src/resources/cache/webgpu/shader/execution/cross.bin
Binary file not shown.
Binary file modified src/resources/cache/webgpu/shader/execution/distance.bin
Binary file not shown.
Binary file modified src/resources/cache/webgpu/shader/execution/dot.bin
Binary file not shown.
Binary file modified src/resources/cache/webgpu/shader/execution/frexp.bin
Binary file not shown.
Binary file modified src/resources/cache/webgpu/shader/execution/length.bin
Binary file not shown.
Binary file modified src/resources/cache/webgpu/shader/execution/mix.bin
Binary file not shown.
66 changes: 22 additions & 44 deletions src/webgpu/shader/execution/expression/call/builtin/cross.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,41 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js'
import { GPUTest } from '../../../../../gpu_test.js';
import { TypeAbstractFloat, TypeF16, TypeF32, TypeVec } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { sparseVectorF64Range, vectorF16Range, vectorF32Range } from '../../../../../util/math.js';
import { makeCaseCache } from '../../case_cache.js';
import { allInputSources, onlyConstInputSource, run } from '../../expression.js';

import { abstractBuiltin, builtin } from './builtin.js';

export const g = makeTestGroup(GPUTest);

export const d = makeCaseCache('cross', {
f32_const: () => {
return FP.f32.generateVectorPairToVectorCases(
vectorF32Range(3),
vectorF32Range(3),
'finite',
FP.f32.crossInterval
);
},
f32_non_const: () => {
return FP.f32.generateVectorPairToVectorCases(
vectorF32Range(3),
vectorF32Range(3),
'unfiltered',
FP.f32.crossInterval
);
},
f16_const: () => {
return FP.f16.generateVectorPairToVectorCases(
vectorF16Range(3),
vectorF16Range(3),
'finite',
FP.f16.crossInterval
);
},
f16_non_const: () => {
return FP.f16.generateVectorPairToVectorCases(
vectorF16Range(3),
vectorF16Range(3),
'unfiltered',
FP.f16.crossInterval
);
},
abstract: () => {
return FP.abstract.generateVectorPairToVectorCases(
sparseVectorF64Range(3),
sparseVectorF64Range(3),
'finite',
FP.abstract.crossInterval
);
},
});
// Cases: [f32|f16|abstract]_[non_]const
// abstract_non_const is empty and not used
const cases = (['f32', 'f16', 'abstract'] as const)
.flatMap(trait =>
([true, false] as const).map(nonConst => ({
[`${trait}_${nonConst ? 'non_const' : 'const'}`]: () => {
if (trait === 'abstract' && nonConst) {
return [];
}
return FP[trait].generateVectorPairToVectorCases(
FP[trait].vectorRange(3),
FP[trait].vectorRange(3),
nonConst ? 'unfiltered' : 'finite',
FP[trait].crossInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('cross', cases);

g.test('abstract_float')
.specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions')
.desc(`abstract float tests`)
.params(u => u.combine('inputSource', onlyConstInputSource))
.fn(async t => {
const cases = await d.get('abstract');
const cases = await d.get('abstract_const');
await run(
t,
abstractBuiltin('cross'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,29 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js'
import { GPUTest } from '../../../../../gpu_test.js';
import { TypeF32, TypeF16, TypeVec } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import {
fullF32Range,
fullF16Range,
sparseVectorF32Range,
sparseVectorF16Range,
} from '../../../../../util/math.js';
import { fullF32Range, fullF16Range } from '../../../../../util/math.js';
import { makeCaseCache } from '../../case_cache.js';
import { allInputSources, run } from '../../expression.js';

import { builtin } from './builtin.js';

export const g = makeTestGroup(GPUTest);

// Cases: f32_vecN_[non_]const
const f32_vec_cases = ([2, 3, 4] as const)
.flatMap(n =>
([true, false] as const).map(nonConst => ({
[`f32_vec${n}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f32.generateVectorPairToIntervalCases(
sparseVectorF32Range(n),
sparseVectorF32Range(n),
nonConst ? 'unfiltered' : 'finite',
FP.f32.distanceInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

// Cases: f16_vecN_[non_]const
const f16_vec_cases = ([2, 3, 4] as const)
.flatMap(n =>
([true, false] as const).map(nonConst => ({
[`f16_vec${n}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f16.generateVectorPairToIntervalCases(
sparseVectorF16Range(n),
sparseVectorF16Range(n),
nonConst ? 'unfiltered' : 'finite',
FP.f16.distanceInterval
);
},
}))
// Cases: [f32|f16]_vecN_[non_]const
const vec_cases = (['f32', 'f16'] as const)
.flatMap(trait =>
([2, 3, 4] as const).flatMap(dim =>
([true, false] as const).map(nonConst => ({
[`${trait}_vec${dim}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP[trait].generateVectorPairToIntervalCases(
FP[trait].sparseVectorRange(dim),
FP[trait].sparseVectorRange(dim),
nonConst ? 'unfiltered' : 'finite',
FP[trait].distanceInterval
);
},
}))
)
)
.reduce((a, b) => ({ ...a, ...b }), {});

Expand All @@ -74,7 +55,6 @@ export const d = makeCaseCache('distance', {
FP.f32.distanceInterval
);
},
...f32_vec_cases,
f16_const: () => {
return FP.f16.generateScalarPairToIntervalCases(
fullF16Range(),
Expand All @@ -91,7 +71,7 @@ export const d = makeCaseCache('distance', {
FP.f16.distanceInterval
);
},
...f16_vec_cases,
...vec_cases,
});

g.test('abstract_float')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js'
import { GPUTest } from '../../../../../gpu_test.js';
import { TypeF32, TypeF16, TypeVec } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { sparseVectorF32Range, vectorF32Range } from '../../../../../util/math.js';
import { makeCaseCache } from '../../case_cache.js';
import { allInputSources, run } from '../../expression.js';

Expand All @@ -27,8 +26,8 @@ const cases = (['f32', 'f16'] as const)
// 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(
N === 2 ? vectorF32Range(2) : sparseVectorF32Range(N),
N === 2 ? vectorF32Range(2) : sparseVectorF32Range(N),
N === 2 ? FP[trait].vectorRange(2) : FP[trait].sparseVectorRange(N),
N === 2 ? FP[trait].vectorRange(2) : FP[trait].sparseVectorRange(N),
nonConst ? 'unfiltered' : 'finite',
FP[trait].dotInterval
);
Expand Down
Loading

0 comments on commit 1390017

Please sign in to comment.