Skip to content

Commit

Permalink
wgsl: Implement AbstractFloat matrix multiplcation tests
Browse files Browse the repository at this point in the history
Issue #1626
  • Loading branch information
zoddicus committed Mar 6, 2024
1 parent 3dcdba7 commit 2f24495
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 117 deletions.
185 changes: 94 additions & 91 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,107 +1,110 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "38b261fa",
"webgpu/shader/execution/binary/af_addition.bin": "3537bbf",
"webgpu/shader/execution/binary/af_logical.bin": "a483b968",
"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/af_division.bin": "8759f887",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "3eb7b746",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "a1173db6",
"webgpu/shader/execution/binary/af_multiplication.bin": "b77f680a",
"webgpu/shader/execution/binary/af_remainder.bin": "c4697dfb",
"webgpu/shader/execution/binary/af_subtraction.bin": "17624e58",
"webgpu/shader/execution/binary/f16_addition.bin": "32b920a0",
"webgpu/shader/execution/binary/f16_logical.bin": "b89ca9b9",
"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/f16_division.bin": "e1e74564",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "37418ae2",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "f9e16ada",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "739ecb65",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "c20eaf83",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "1e0127c0",
"webgpu/shader/execution/binary/f16_multiplication.bin": "e89c81f8",
"webgpu/shader/execution/binary/f16_remainder.bin": "85339fca",
"webgpu/shader/execution/binary/f16_subtraction.bin": "cd4bf3d3",
"webgpu/shader/execution/binary/f32_addition.bin": "9eaa0e04",
"webgpu/shader/execution/binary/f32_logical.bin": "c7370c09",
"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/f32_division.bin": "a81fa2e1",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "e3a3f2a2",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "51146714",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "99d99f13",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "dfab64d5",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "f7de887d",
"webgpu/shader/execution/binary/f32_multiplication.bin": "ec380a2f",
"webgpu/shader/execution/binary/f32_remainder.bin": "8113a345",
"webgpu/shader/execution/binary/f32_subtraction.bin": "c65c7882",
"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": "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/abs.bin": "e7d0db43",
"webgpu/shader/execution/acos.bin": "5c26b875",
"webgpu/shader/execution/acosh.bin": "6006745a",
"webgpu/shader/execution/asin.bin": "bd0a6605",
"webgpu/shader/execution/asinh.bin": "871eabc6",
"webgpu/shader/execution/atan.bin": "87e5508e",
"webgpu/shader/execution/atan2.bin": "587e430f",
"webgpu/shader/execution/atanh.bin": "24973287",
"webgpu/shader/execution/bitcast.bin": "d3767f75",
"webgpu/shader/execution/ceil.bin": "3597359f",
"webgpu/shader/execution/clamp.bin": "db80e3d4",
"webgpu/shader/execution/cos.bin": "be6a43df",
"webgpu/shader/execution/cosh.bin": "6b1522b4",
"webgpu/shader/execution/cross.bin": "6e12c696",
"webgpu/shader/execution/degrees.bin": "272d85f9",
"webgpu/shader/execution/determinant.bin": "e8c0910f",
"webgpu/shader/execution/distance.bin": "fcd1a459",
"webgpu/shader/execution/dot.bin": "6cb8305e",
"webgpu/shader/execution/exp.bin": "340a4471",
"webgpu/shader/execution/exp2.bin": "c3483a4f",
"webgpu/shader/execution/faceForward.bin": "2d7047cb",
"webgpu/shader/execution/floor.bin": "64eb44f3",
"webgpu/shader/execution/fma.bin": "af8fc9a1",
"webgpu/shader/execution/fract.bin": "546bfc4b",
"webgpu/shader/execution/frexp.bin": "73131e48",
"webgpu/shader/execution/inverseSqrt.bin": "af8b8480",
"webgpu/shader/execution/ldexp.bin": "b5d05356",
"webgpu/shader/execution/length.bin": "87a7a79e",
"webgpu/shader/execution/log.bin": "d7929d6d",
"webgpu/shader/execution/log2.bin": "4ba66d33",
"webgpu/shader/execution/max.bin": "ebc85f1f",
"webgpu/shader/execution/min.bin": "5b60cb58",
"webgpu/shader/execution/mix.bin": "c8ec2505",
"webgpu/shader/execution/modf.bin": "de35d27c",
"webgpu/shader/execution/normalize.bin": "1824edd9",
"webgpu/shader/execution/pack2x16float.bin": "e6859c1a",
"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/pow.bin": "6b8532ae",
"webgpu/shader/execution/quantizeToF16.bin": "4956513f",
"webgpu/shader/execution/radians.bin": "199010e",
"webgpu/shader/execution/reflect.bin": "995fae9e",
"webgpu/shader/execution/refract.bin": "181fbbc8",
"webgpu/shader/execution/round.bin": "98dce70b",
"webgpu/shader/execution/saturate.bin": "3060e843",
"webgpu/shader/execution/sign.bin": "7879f29c",
"webgpu/shader/execution/sin.bin": "1f3d20e3",
"webgpu/shader/execution/sinh.bin": "749425d6",
"webgpu/shader/execution/smoothstep.bin": "3b82bce3",
"webgpu/shader/execution/sqrt.bin": "b2e5210a",
"webgpu/shader/execution/step.bin": "7d27ada6",
"webgpu/shader/execution/tan.bin": "a9edf243",
"webgpu/shader/execution/tanh.bin": "a733eb02",
"webgpu/shader/execution/transpose.bin": "f1a8852b",
"webgpu/shader/execution/trunc.bin": "3a3cf31f",
"webgpu/shader/execution/unpack2x16float.bin": "e3450db3",
"webgpu/shader/execution/unpack2x16snorm.bin": "beb21243",
"webgpu/shader/execution/unpack2x16unorm.bin": "37aab928",
"webgpu/shader/execution/unpack4x8snorm.bin": "1b57ee27",
"webgpu/shader/execution/unpack4x8unorm.bin": "19b3ac32",
"webgpu/shader/execution/unary/af_arithmetic.bin": "113dbf1a",
"webgpu/shader/execution/unary/af_assignment.bin": "47945f59",
"webgpu/shader/execution/unary/bool_conversion.bin": "dd71f171",
"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/f16_arithmetic.bin": "1d6b84ef",
"webgpu/shader/execution/unary/f16_conversion.bin": "406aff92",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "6d2c7f7b",
"webgpu/shader/execution/unary/f32_conversion.bin": "d7f9967f",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "c69716e2",
"webgpu/shader/execution/unary/i32_conversion.bin": "83218e69",
"webgpu/shader/execution/unary/u32_conversion.bin": "8f5bad00",
"webgpu/shader/execution/unary/ai_assignment.bin": "c7e6ac33",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "81c11ec2",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "3d27dc97"
"webgpu/shader/execution/unary/ai_arithmetic.bin": "3d27dc97",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "17ffa31c",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "718ef50",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "495e66cf"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 20 additions & 6 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7193,7 +7193,7 @@ g.test('subtractionMatrixMatrixInterval')
g.test('multiplicationMatrixMatrixInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.combineWithParams<MatrixPairToMatrixCase>([
// Only testing that different shapes of matrices are handled correctly
Expand Down Expand Up @@ -7768,12 +7768,26 @@ const kMultiplicationMatrixScalarIntervalCases = {
],
},
] as MatrixScalarToMatrixCase[],
abstract: [
// From https://github.com/gpuweb/cts/issues/3044
{
matrix: [
[kValue.f64.negative.min, 0],
[0, 0],
],
scalar: kValue.f64.negative.subnormal.min,
expected: [
[[0, reinterpretU64AsF64(0x400ffffffffffffdn)], 0], // [[0, 3.9999995...], 0],
[0, 0],
],
},
] as MatrixScalarToMatrixCase[],
} as const;

g.test('multiplicationMatrixScalarInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.expandWithParams<MatrixScalarToMatrixCase>(p => {
const trait = FP[p.trait];
Expand Down Expand Up @@ -7945,7 +7959,7 @@ interface MatrixVectorToVectorCase {
g.test('multiplicationMatrixVectorInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.combineWithParams<MatrixVectorToVectorCase>([
// Only testing that different shapes of matrices are handled correctly
Expand Down Expand Up @@ -8062,16 +8076,16 @@ interface VectorMatrixToVectorCase {
g.test('multiplicationVectorMatrixInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.combineWithParams<VectorMatrixToVectorCase>([
// Only testing that different shapes of matrices are handled correctly
// here, to reduce test duplication.
// multiplicationVectorMatrixInterval uses DotIntervalOp for calculating
// intervals, so the testing for dotInterval covers the actual interval
// calculations.
// Keep all expected result integer no larger than 2047 to ensure that all result is exactly
// represeantable in both f32 and f16.
// Keep all expected result integer no larger than 2047 to ensure that
// all result is exactly representable in both f32 and f16.
{
vector: [1, 2],
matrix: [
Expand Down
5 changes: 5 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,12 @@
"webgpu:shader,execution,expression,binary,af_division:vector:*": { "subcaseMS": 237.134 },
"webgpu:shader,execution,expression,binary,af_division:vector_scalar:*": { "subcaseMS": 580.000 },
"webgpu:shader,execution,expression,binary,af_matrix_addition:matrix:*": { "subcaseMS": 11169.534 },
"webgpu:shader,execution,expression,binary,af_matrix_matrix_multiplication:matrix_matrix:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,binary,af_matrix_scalar_multiplication:matrix_scalar:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,binary,af_matrix_scalar_multiplication:scalar_matrix:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,binary,af_matrix_subtraction:matrix:*": { "subcaseMS": 14060.956 },
"webgpu:shader,execution,expression,binary,af_matrix_vector_multiplication:matrix_vector:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,binary,af_matrix_vector_multiplication:vector_matrix:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,binary,af_multiplication:scalar:*": { "subcaseMS": 777.901 },
"webgpu:shader,execution,expression,binary,af_multiplication:scalar_vector:*": { "subcaseMS": 2025.534 },
"webgpu:shader,execution,expression,binary,af_multiplication:vector:*": { "subcaseMS": 710.667 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FP } from '../../../../util/floating_point.js';
import { sparseMatrixF64Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';

// Cases: matKxR_matCxK
const mat_mat_cases = ([2, 3, 4] as const)
.flatMap(k =>
([2, 3, 4] as const).flatMap(cols =>
([2, 3, 4] as const).map(rows => ({
[`mat${k}x${rows}_mat${cols}x${k}`]: () => {
return FP.abstract.generateMatrixPairToMatrixCases(
sparseMatrixF64Range(k, rows),
sparseMatrixF64Range(cols, k),
'finite',
FP.abstract.multiplicationMatrixMatrixInterval
);
},
}))
)
)
.reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('binary/af_matrix_matrix_multiplication', mat_mat_cases);
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const description = `
Execution Tests for matrix-matrix AbstractFloat multiplication expression
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { TypeAbstractFloat, TypeMat } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './af_matrix_matrix_multiplication.cache.js';
import { abstractFloatBinary } from './binary.js';

export const g = makeTestGroup(GPUTest);

g.test('matrix_matrix')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x * y, where x is a matrix and y is a matrix
Accuracy: Correctly rounded
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('common_dim', [2, 3, 4] as const)
.combine('x_rows', [2, 3, 4] as const)
.combine('y_cols', [2, 3, 4] as const)
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const x_cols = t.params.common_dim;
const x_rows = t.params.x_rows;
const y_cols = t.params.y_cols;
const y_rows = t.params.common_dim;

const cases = await d.get(`mat${x_cols}x${x_rows}_mat${y_cols}x${y_rows}`);
await run(
t,
abstractFloatBinary('*'),
[TypeMat(x_cols, x_rows, TypeAbstractFloat), TypeMat(y_cols, y_rows, TypeAbstractFloat)],
TypeMat(y_cols, x_rows, TypeAbstractFloat),
t.params,
cases
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { FP } from '../../../../util/floating_point.js';
import { sparseMatrixF64Range, sparseScalarF64Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';

// Cases: matCxR_scalar
const mat_scalar_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).map(rows => ({
[`mat${cols}x${rows}_scalar`]: () => {
return FP.abstract.generateMatrixScalarToMatrixCases(
sparseMatrixF64Range(cols, rows),
sparseScalarF64Range(),
'finite',
FP.abstract.multiplicationMatrixScalarInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

// Cases: scalar_matCxR
const scalar_mat_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).map(rows => ({
[`scalar_mat${cols}x${rows}`]: () => {
return FP.abstract.generateScalarMatrixToMatrixCases(
sparseScalarF64Range(),
sparseMatrixF64Range(cols, rows),
'finite',
FP.abstract.multiplicationScalarMatrixInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('binary/af_matrix_scalar_multiplication', {
...mat_scalar_cases,
...scalar_mat_cases,
});
Loading

0 comments on commit 2f24495

Please sign in to comment.