Skip to content

Commit

Permalink
wgsl: Add sparseMatrixRange to FPTraits API (#3183)
Browse files Browse the repository at this point in the history
Fixes #3174
  • Loading branch information
zoddicus authored Nov 23, 2023
1 parent 591c655 commit b37df1c
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 171 deletions.
208 changes: 104 additions & 104 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,106 +1,106 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "ca9569aa",
"webgpu/shader/execution/binary/af_logical.bin": "79fb9de7",
"webgpu/shader/execution/binary/af_division.bin": "87cef40b",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "8afe5300",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "bd433833",
"webgpu/shader/execution/binary/af_multiplication.bin": "7803251d",
"webgpu/shader/execution/binary/af_remainder.bin": "f5feb53",
"webgpu/shader/execution/binary/af_subtraction.bin": "7cc42f3a",
"webgpu/shader/execution/binary/f16_addition.bin": "e56d4073",
"webgpu/shader/execution/binary/f16_logical.bin": "6dfc24ba",
"webgpu/shader/execution/binary/f16_division.bin": "933c3c35",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "934c3596",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "f2a1e8",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "b1ca61be",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "e054a92b",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "4706075e",
"webgpu/shader/execution/binary/f16_multiplication.bin": "28dbd8b6",
"webgpu/shader/execution/binary/f16_remainder.bin": "986de10c",
"webgpu/shader/execution/binary/f16_subtraction.bin": "d3e7f74f",
"webgpu/shader/execution/binary/f32_addition.bin": "fc66b530",
"webgpu/shader/execution/binary/f32_logical.bin": "6aecdb17",
"webgpu/shader/execution/binary/f32_division.bin": "b0b2294c",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "4f84f9a4",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "cf99f3b9",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "ac8e0983",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "76301b8",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "db0f8c38",
"webgpu/shader/execution/binary/f32_multiplication.bin": "ecbcde06",
"webgpu/shader/execution/binary/f32_remainder.bin": "9d11467e",
"webgpu/shader/execution/binary/f32_subtraction.bin": "7dbddc79",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "43c80b5e",
"webgpu/shader/execution/binary/i32_comparison.bin": "1b9d7888",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "c031871c",
"webgpu/shader/execution/binary/u32_comparison.bin": "9b05600",
"webgpu/shader/execution/abs.bin": "acfe9bb2",
"webgpu/shader/execution/acos.bin": "8ed18869",
"webgpu/shader/execution/acosh.bin": "1cf98804",
"webgpu/shader/execution/asin.bin": "71698297",
"webgpu/shader/execution/asinh.bin": "7256451c",
"webgpu/shader/execution/atan.bin": "96e29c5d",
"webgpu/shader/execution/atan2.bin": "2dd9139",
"webgpu/shader/execution/atanh.bin": "fafe4e6c",
"webgpu/shader/execution/bitcast.bin": "b9fb1fbd",
"webgpu/shader/execution/ceil.bin": "ff230775",
"webgpu/shader/execution/clamp.bin": "ae2f4ac",
"webgpu/shader/execution/cos.bin": "ff432f2b",
"webgpu/shader/execution/cosh.bin": "d7af2ee9",
"webgpu/shader/execution/cross.bin": "11bf35a8",
"webgpu/shader/execution/degrees.bin": "c53959da",
"webgpu/shader/execution/determinant.bin": "da997a93",
"webgpu/shader/execution/distance.bin": "817d1cb",
"webgpu/shader/execution/dot.bin": "96070df0",
"webgpu/shader/execution/exp.bin": "e9728b8a",
"webgpu/shader/execution/exp2.bin": "66d0d5c5",
"webgpu/shader/execution/faceForward.bin": "cac5c81",
"webgpu/shader/execution/floor.bin": "18f58cc",
"webgpu/shader/execution/fma.bin": "6372916b",
"webgpu/shader/execution/fract.bin": "6335e79f",
"webgpu/shader/execution/frexp.bin": "54d2bdb0",
"webgpu/shader/execution/inverseSqrt.bin": "10ba17af",
"webgpu/shader/execution/ldexp.bin": "dba21b3e",
"webgpu/shader/execution/length.bin": "aad9991",
"webgpu/shader/execution/log.bin": "ff19d8a0",
"webgpu/shader/execution/log2.bin": "b3ebf3dd",
"webgpu/shader/execution/max.bin": "61a11c89",
"webgpu/shader/execution/min.bin": "5de15c84",
"webgpu/shader/execution/mix.bin": "a07ec401",
"webgpu/shader/execution/modf.bin": "91cac6b2",
"webgpu/shader/execution/normalize.bin": "6da0731",
"webgpu/shader/execution/pack2x16float.bin": "119a9ab1",
"webgpu/shader/execution/pow.bin": "986f5d89",
"webgpu/shader/execution/quantizeToF16.bin": "77efff6b",
"webgpu/shader/execution/radians.bin": "a035b517",
"webgpu/shader/execution/reflect.bin": "c2763f1a",
"webgpu/shader/execution/refract.bin": "e71dd5de",
"webgpu/shader/execution/round.bin": "36f3ecde",
"webgpu/shader/execution/saturate.bin": "392167ed",
"webgpu/shader/execution/sign.bin": "766ace88",
"webgpu/shader/execution/sin.bin": "c1fd0733",
"webgpu/shader/execution/sinh.bin": "3f78d331",
"webgpu/shader/execution/smoothstep.bin": "9f72a10",
"webgpu/shader/execution/sqrt.bin": "17fe3757",
"webgpu/shader/execution/step.bin": "e20fb42",
"webgpu/shader/execution/tan.bin": "c3c67187",
"webgpu/shader/execution/tanh.bin": "9d06e776",
"webgpu/shader/execution/transpose.bin": "f739a482",
"webgpu/shader/execution/trunc.bin": "16600f63",
"webgpu/shader/execution/unpack2x16float.bin": "4d6c065c",
"webgpu/shader/execution/unpack2x16snorm.bin": "8d8fc5df",
"webgpu/shader/execution/unpack2x16unorm.bin": "1824a555",
"webgpu/shader/execution/unpack4x8snorm.bin": "bad79c86",
"webgpu/shader/execution/unpack4x8unorm.bin": "8a744dfa",
"webgpu/shader/execution/unary/af_arithmetic.bin": "63f22c73",
"webgpu/shader/execution/unary/af_assignment.bin": "fb65d5ff",
"webgpu/shader/execution/unary/bool_conversion.bin": "cae3c1bd",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "f6937f3e",
"webgpu/shader/execution/unary/f16_conversion.bin": "786501ec",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "eef2bb81",
"webgpu/shader/execution/unary/f32_conversion.bin": "983e48bb",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "c93e4e68",
"webgpu/shader/execution/unary/i32_complement.bin": "2505e4e6",
"webgpu/shader/execution/unary/i32_conversion.bin": "8cceff52",
"webgpu/shader/execution/unary/u32_complement.bin": "dada6764",
"webgpu/shader/execution/unary/u32_conversion.bin": "9b89fb5"
"webgpu/shader/execution/binary/af_addition.bin": "a5da1df9",
"webgpu/shader/execution/binary/af_logical.bin": "27d915bd",
"webgpu/shader/execution/binary/af_division.bin": "a5270697",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "62f800a8",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "9183d57f",
"webgpu/shader/execution/binary/af_multiplication.bin": "865258e7",
"webgpu/shader/execution/binary/af_remainder.bin": "4c61df7e",
"webgpu/shader/execution/binary/af_subtraction.bin": "43dd47ae",
"webgpu/shader/execution/binary/f16_addition.bin": "513d71c8",
"webgpu/shader/execution/binary/f16_logical.bin": "443f9a98",
"webgpu/shader/execution/binary/f16_division.bin": "f54e29cb",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "f910cec6",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "b70ddbb2",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "62afef7a",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "29e3722d",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "f4a29ad1",
"webgpu/shader/execution/binary/f16_multiplication.bin": "9baf80a1",
"webgpu/shader/execution/binary/f16_remainder.bin": "85c74732",
"webgpu/shader/execution/binary/f16_subtraction.bin": "b06f0345",
"webgpu/shader/execution/binary/f32_addition.bin": "e0f9ce70",
"webgpu/shader/execution/binary/f32_logical.bin": "47cadba6",
"webgpu/shader/execution/binary/f32_division.bin": "7005e989",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "98e53a9",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "b5c60cda",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "522a3569",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "c19e488c",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "9af1d0c3",
"webgpu/shader/execution/binary/f32_multiplication.bin": "e59c1749",
"webgpu/shader/execution/binary/f32_remainder.bin": "f0aa263b",
"webgpu/shader/execution/binary/f32_subtraction.bin": "f4bc3081",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "e92caa13",
"webgpu/shader/execution/binary/i32_comparison.bin": "21f566be",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "4190d758",
"webgpu/shader/execution/binary/u32_comparison.bin": "91fe8844",
"webgpu/shader/execution/abs.bin": "40c39d52",
"webgpu/shader/execution/acos.bin": "9998e303",
"webgpu/shader/execution/acosh.bin": "7636c6b9",
"webgpu/shader/execution/asin.bin": "fd7059cd",
"webgpu/shader/execution/asinh.bin": "58959a2",
"webgpu/shader/execution/atan.bin": "ed0a5fe5",
"webgpu/shader/execution/atan2.bin": "bcfaa17a",
"webgpu/shader/execution/atanh.bin": "fe79d05d",
"webgpu/shader/execution/bitcast.bin": "ab8f3a85",
"webgpu/shader/execution/ceil.bin": "82690ce1",
"webgpu/shader/execution/clamp.bin": "a30a2b8e",
"webgpu/shader/execution/cos.bin": "bf80f288",
"webgpu/shader/execution/cosh.bin": "2add503b",
"webgpu/shader/execution/cross.bin": "ce546995",
"webgpu/shader/execution/degrees.bin": "af783136",
"webgpu/shader/execution/determinant.bin": "16d6108",
"webgpu/shader/execution/distance.bin": "34788cf8",
"webgpu/shader/execution/dot.bin": "5d8d3fff",
"webgpu/shader/execution/exp.bin": "e890f3d",
"webgpu/shader/execution/exp2.bin": "80f0c788",
"webgpu/shader/execution/faceForward.bin": "4cf3e04d",
"webgpu/shader/execution/floor.bin": "4d91b147",
"webgpu/shader/execution/fma.bin": "9579e337",
"webgpu/shader/execution/fract.bin": "a1372b54",
"webgpu/shader/execution/frexp.bin": "7d140601",
"webgpu/shader/execution/inverseSqrt.bin": "515fb6e3",
"webgpu/shader/execution/ldexp.bin": "826a29a8",
"webgpu/shader/execution/length.bin": "124ac33b",
"webgpu/shader/execution/log.bin": "aad3a1a8",
"webgpu/shader/execution/log2.bin": "7ef34360",
"webgpu/shader/execution/max.bin": "69a1807",
"webgpu/shader/execution/min.bin": "8dfa353d",
"webgpu/shader/execution/mix.bin": "96c9d02d",
"webgpu/shader/execution/modf.bin": "26670f53",
"webgpu/shader/execution/normalize.bin": "60571bc4",
"webgpu/shader/execution/pack2x16float.bin": "31601129",
"webgpu/shader/execution/pow.bin": "8f5de92",
"webgpu/shader/execution/quantizeToF16.bin": "9936c450",
"webgpu/shader/execution/radians.bin": "56c3610d",
"webgpu/shader/execution/reflect.bin": "61beb0cf",
"webgpu/shader/execution/refract.bin": "d0180f9b",
"webgpu/shader/execution/round.bin": "3bc78d47",
"webgpu/shader/execution/saturate.bin": "8478071d",
"webgpu/shader/execution/sign.bin": "58d75a88",
"webgpu/shader/execution/sin.bin": "b14cf00a",
"webgpu/shader/execution/sinh.bin": "a8d76c62",
"webgpu/shader/execution/smoothstep.bin": "246c76eb",
"webgpu/shader/execution/sqrt.bin": "f6c4f4c1",
"webgpu/shader/execution/step.bin": "8268c823",
"webgpu/shader/execution/tan.bin": "af3ecb02",
"webgpu/shader/execution/tanh.bin": "c22b8364",
"webgpu/shader/execution/transpose.bin": "f8663cd3",
"webgpu/shader/execution/trunc.bin": "b532e654",
"webgpu/shader/execution/unpack2x16float.bin": "67d0b480",
"webgpu/shader/execution/unpack2x16snorm.bin": "be8c0687",
"webgpu/shader/execution/unpack2x16unorm.bin": "8ef57a36",
"webgpu/shader/execution/unpack4x8snorm.bin": "a807e0f6",
"webgpu/shader/execution/unpack4x8unorm.bin": "b8ed39e8",
"webgpu/shader/execution/unary/af_arithmetic.bin": "f6181e3d",
"webgpu/shader/execution/unary/af_assignment.bin": "1da130e3",
"webgpu/shader/execution/unary/bool_conversion.bin": "166e7b55",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "576d8432",
"webgpu/shader/execution/unary/f16_conversion.bin": "187365c9",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "abfce14d",
"webgpu/shader/execution/unary/f32_conversion.bin": "69c41336",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "cca83969",
"webgpu/shader/execution/unary/i32_complement.bin": "2a173277",
"webgpu/shader/execution/unary/i32_conversion.bin": "11d03e95",
"webgpu/shader/execution/unary/u32_complement.bin": "6fce0665",
"webgpu/shader/execution/unary/u32_conversion.bin": "53c94e7b"
}
Binary file modified src/resources/cache/webgpu/shader/execution/transpose.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,37 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js'
import { GPUTest } from '../../../../../gpu_test.js';
import { TypeAbstractFloat, TypeF16, TypeF32, TypeMat } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import {
sparseMatrixF16Range,
sparseMatrixF32Range,
sparseMatrixF64Range,
} 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);

// Cases: f32_matCxR_[non_]const
const f32_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).flatMap(rows =>
([true, false] as const).map(nonConst => ({
[`f32_mat${cols}x${rows}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f32.generateMatrixToMatrixCases(
sparseMatrixF32Range(cols, rows),
nonConst ? 'unfiltered' : 'finite',
FP.f32.transposeInterval
);
},
}))
// Cases: [f32|f16|abstract]_matCxR_[non_]const
// abstract_matCxR_non_const is empty and not used
const cases = (['f32', 'f16', 'abstract'] as const)
.flatMap(trait =>
([2, 3, 4] as const).flatMap(cols =>
([2, 3, 4] as const).flatMap(rows =>
([true, false] as const).map(nonConst => ({
[`${trait}_mat${cols}x${rows}_${nonConst ? 'non_const' : 'const'}`]: () => {
if (trait === 'abstract' && nonConst) {
return [];
}
return FP[trait].generateMatrixToMatrixCases(
FP[trait].sparseMatrixRange(cols, rows),
nonConst ? 'unfiltered' : 'finite',
FP[trait].transposeInterval
);
},
}))
)
)
)
.reduce((a, b) => ({ ...a, ...b }), {});

// Cases: f16_matCxR_[non_]const
const f16_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).flatMap(rows =>
([true, false] as const).map(nonConst => ({
[`f16_mat${cols}x${rows}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f16.generateMatrixToMatrixCases(
sparseMatrixF16Range(cols, rows),
nonConst ? 'unfiltered' : 'finite',
FP.f16.transposeInterval
);
},
}))
)
)
.reduce((a, b) => ({ ...a, ...b }), {});

// Cases: abstract_matCxR
const abstract_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).map(rows => ({
[`abstract_mat${cols}x${rows}`]: () => {
return FP.abstract.generateMatrixToMatrixCases(
sparseMatrixF64Range(cols, rows),
'finite',
FP.abstract.transposeInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('transpose', {
...f32_cases,
...f16_cases,
...abstract_cases,
});
export const d = makeCaseCache('transpose', cases);

g.test('abstract_float')
.specURL('https://www.w3.org/TR/WGSL/#matrix-builtin-functions')
Expand All @@ -89,7 +54,7 @@ g.test('abstract_float')
.fn(async t => {
const cols = t.params.cols;
const rows = t.params.rows;
const cases = await d.get(`abstract_mat${cols}x${rows}`);
const cases = await d.get(`abstract_mat${cols}x${rows}_const`);
await run(
t,
abstractBuiltin('transpose'),
Expand Down
26 changes: 19 additions & 7 deletions src/webgpu/util/floating_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ import {
map2DArray,
oneULPF16,
oneULPF32,
quantizeToF32,
quantizeToF16,
quantizeToF32,
scalarF16Range,
scalarF32Range,
scalarF64Range,
sparseMatrixF16Range,
sparseMatrixF32Range,
sparseMatrixF64Range,
sparseScalarF16Range,
sparseScalarF32Range,
sparseScalarF64Range,
sparseVectorF16Range,
sparseVectorF32Range,
sparseVectorF64Range,
unflatten2DArray,
vectorF16Range,
vectorF32Range,
vectorF64Range,
scalarF32Range,
sparseScalarF32Range,
scalarF64Range,
sparseScalarF64Range,
scalarF16Range,
sparseScalarF16Range,
} from './math.js';

/** Indicate the kind of WGSL floating point numbers being operated on */
Expand Down Expand Up @@ -1101,6 +1104,12 @@ export abstract class FPTraits {
public abstract vectorRange(dim: number): ROArrayArray<number>;
/** @returns a reduced range of dim element vectors for testing */
public abstract sparseVectorRange(dim: number): ROArrayArray<number>;
/** @returns a reduced range of cols x rows matrices for testing
*
* A non-sparse version of this generator is intentionally not provided due to
* runtime issues with more dense ranges.
*/
public abstract sparseMatrixRange(cols: number, rows: number): ROArrayArrayArray<number>;

// Framework - Cases

Expand Down Expand Up @@ -4544,6 +4553,7 @@ class F32Traits extends FPTraits {
public readonly sparseScalarRange = sparseScalarF32Range;
public readonly vectorRange = vectorF32Range;
public readonly sparseVectorRange = sparseVectorF32Range;
public readonly sparseMatrixRange = sparseMatrixF32Range;

// Framework - Fundamental Error Intervals - Overrides
public readonly absoluteErrorInterval = this.absoluteErrorIntervalImpl.bind(this);
Expand Down Expand Up @@ -5020,6 +5030,7 @@ class FPAbstractTraits extends FPTraits {
public readonly sparseScalarRange = sparseScalarF64Range;
public readonly vectorRange = vectorF64Range;
public readonly sparseVectorRange = sparseVectorF64Range;
public readonly sparseMatrixRange = sparseMatrixF64Range;

// Framework - Fundamental Error Intervals - Overrides
public readonly absoluteErrorInterval = this.unboundedAbsoluteErrorInterval.bind(this);
Expand Down Expand Up @@ -5356,6 +5367,7 @@ class F16Traits extends FPTraits {
public readonly sparseScalarRange = sparseScalarF16Range;
public readonly vectorRange = vectorF16Range;
public readonly sparseVectorRange = sparseVectorF16Range;
public readonly sparseMatrixRange = sparseMatrixF16Range;

// Framework - Fundamental Error Intervals - Overrides
public readonly absoluteErrorInterval = this.absoluteErrorIntervalImpl.bind(this);
Expand Down
Loading

0 comments on commit b37df1c

Please sign in to comment.