Skip to content

Commit

Permalink
Use hash based filtering instead of stochastic
Browse files Browse the repository at this point in the history
  • Loading branch information
zoddicus committed Mar 6, 2024
1 parent a2b2b9f commit efa7b4f
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 198 deletions.
204 changes: 102 additions & 102 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": "3537bbf",
"webgpu/shader/execution/binary/af_logical.bin": "a483b968",
"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": "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": "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": "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": "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/binary/af_addition.bin": "de575056",
"webgpu/shader/execution/binary/af_logical.bin": "dc2105f8",
"webgpu/shader/execution/binary/af_division.bin": "d7e6d98f",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "c215cf6d",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "57892276",
"webgpu/shader/execution/binary/af_multiplication.bin": "4c282ac2",
"webgpu/shader/execution/binary/af_remainder.bin": "9fdddf97",
"webgpu/shader/execution/binary/af_subtraction.bin": "a27de3c1",
"webgpu/shader/execution/binary/f16_addition.bin": "ecc2aa17",
"webgpu/shader/execution/binary/f16_logical.bin": "1851f647",
"webgpu/shader/execution/binary/f16_division.bin": "2cfec6de",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "f5b6ef4f",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "c47070a0",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "30b9d67c",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "46b631ba",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "19e6a937",
"webgpu/shader/execution/binary/f16_multiplication.bin": "8fbfc97c",
"webgpu/shader/execution/binary/f16_remainder.bin": "66cd384c",
"webgpu/shader/execution/binary/f16_subtraction.bin": "8b5fed3d",
"webgpu/shader/execution/binary/f32_addition.bin": "2ef1211a",
"webgpu/shader/execution/binary/f32_logical.bin": "3c97c69d",
"webgpu/shader/execution/binary/f32_division.bin": "2867ef0a",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "da9390d1",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "2d67296e",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "c79709f5",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "38b7c05f",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "f9b675d7",
"webgpu/shader/execution/binary/f32_multiplication.bin": "bb7ee512",
"webgpu/shader/execution/binary/f32_remainder.bin": "e0d16b8f",
"webgpu/shader/execution/binary/f32_subtraction.bin": "755fc63",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "3c1d6f0f",
"webgpu/shader/execution/binary/i32_comparison.bin": "4759dfea",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "6bf6989d",
"webgpu/shader/execution/binary/u32_comparison.bin": "ca8b140b",
"webgpu/shader/execution/abs.bin": "a79b85f3",
"webgpu/shader/execution/acos.bin": "eed1c72",
"webgpu/shader/execution/acosh.bin": "a1b7dc12",
"webgpu/shader/execution/asin.bin": "fbf69cb0",
"webgpu/shader/execution/asinh.bin": "7b8f7a8",
"webgpu/shader/execution/atan.bin": "250334d8",
"webgpu/shader/execution/atan2.bin": "9df3f787",
"webgpu/shader/execution/atanh.bin": "5c79c30d",
"webgpu/shader/execution/bitcast.bin": "964fdecd",
"webgpu/shader/execution/ceil.bin": "246bf087",
"webgpu/shader/execution/clamp.bin": "3a299eaf",
"webgpu/shader/execution/cos.bin": "d3efc52b",
"webgpu/shader/execution/cosh.bin": "867cbf85",
"webgpu/shader/execution/cross.bin": "a1089567",
"webgpu/shader/execution/degrees.bin": "d1cfaeac",
"webgpu/shader/execution/determinant.bin": "44faf0f8",
"webgpu/shader/execution/distance.bin": "e1191c92",
"webgpu/shader/execution/dot.bin": "242201b",
"webgpu/shader/execution/exp.bin": "e5f97f39",
"webgpu/shader/execution/exp2.bin": "65bd37ec",
"webgpu/shader/execution/faceForward.bin": "ebb6017a",
"webgpu/shader/execution/floor.bin": "a24e0ff8",
"webgpu/shader/execution/fma.bin": "87615a5f",
"webgpu/shader/execution/fract.bin": "eab1b9fa",
"webgpu/shader/execution/frexp.bin": "7dd8033",
"webgpu/shader/execution/inverseSqrt.bin": "356b47c5",
"webgpu/shader/execution/ldexp.bin": "788fdf3e",
"webgpu/shader/execution/length.bin": "69f13c20",
"webgpu/shader/execution/log.bin": "dc9c311c",
"webgpu/shader/execution/log2.bin": "d1a49443",
"webgpu/shader/execution/max.bin": "6750f2eb",
"webgpu/shader/execution/min.bin": "c8200395",
"webgpu/shader/execution/mix.bin": "86c40712",
"webgpu/shader/execution/modf.bin": "50483a83",
"webgpu/shader/execution/normalize.bin": "244a8e05",
"webgpu/shader/execution/pack2x16float.bin": "dcd8656d",
"webgpu/shader/execution/pow.bin": "633c917a",
"webgpu/shader/execution/quantizeToF16.bin": "f6044bd2",
"webgpu/shader/execution/radians.bin": "a90b21ea",
"webgpu/shader/execution/reflect.bin": "670fbba2",
"webgpu/shader/execution/refract.bin": "63b06feb",
"webgpu/shader/execution/round.bin": "d4c09bde",
"webgpu/shader/execution/saturate.bin": "d4f8a4d0",
"webgpu/shader/execution/sign.bin": "57c988b9",
"webgpu/shader/execution/sin.bin": "59aab9f5",
"webgpu/shader/execution/sinh.bin": "3890a90c",
"webgpu/shader/execution/smoothstep.bin": "b695fd45",
"webgpu/shader/execution/sqrt.bin": "9524c93",
"webgpu/shader/execution/step.bin": "b9cc90a4",
"webgpu/shader/execution/tan.bin": "e5792957",
"webgpu/shader/execution/tanh.bin": "ba99c688",
"webgpu/shader/execution/transpose.bin": "83588805",
"webgpu/shader/execution/trunc.bin": "aad5d037",
"webgpu/shader/execution/unpack2x16float.bin": "493cbe7b",
"webgpu/shader/execution/unpack2x16snorm.bin": "fd0b5eb9",
"webgpu/shader/execution/unpack2x16unorm.bin": "f7436a6c",
"webgpu/shader/execution/unpack4x8snorm.bin": "eca842d9",
"webgpu/shader/execution/unpack4x8unorm.bin": "8654f67e",
"webgpu/shader/execution/unary/af_arithmetic.bin": "e05d3c45",
"webgpu/shader/execution/unary/af_assignment.bin": "45da8cfe",
"webgpu/shader/execution/unary/bool_conversion.bin": "dd71f171",
"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/f16_arithmetic.bin": "9c17fdca",
"webgpu/shader/execution/unary/f16_conversion.bin": "c02b6c8",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "feff26f7",
"webgpu/shader/execution/unary/f32_conversion.bin": "f2639f4c",
"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/binary/ai_arithmetic.bin": "dfcd593a",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "3d27dc97",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "df23d63a",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "718ef50",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "495e66cf"
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "7e551ea1",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "fe7ea65b",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "2a98deaa"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { FP } from '../../../../util/floating_point.js';
import { sparseMatrixF64Range } from '../../../../util/math.js';
import { StochasticFilter } from '../../../../util/stochastic_filter.js';
import { selectNCases } from '../case.js';
import { makeCaseCache } from '../case_cache.js';

const sf = new StochasticFilter(0);
// 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 sf.filter(
return selectNCases(
'binary/af_matrix_matrix_multiplication',
50,
FP.abstract.generateMatrixPairToMatrixCases(
sparseMatrixF64Range(k, rows),
sparseMatrixF64Range(cols, k),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { FP } from '../../../../util/floating_point.js';
import { sparseMatrixF64Range, sparseScalarF64Range } from '../../../../util/math.js';
import { selectNCases } from '../case.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
return selectNCases(
'binary/af_matrix_scalar_multiplication_mat_scalar',
50,
FP.abstract.generateMatrixScalarToMatrixCases(
sparseMatrixF64Range(cols, rows),
sparseScalarF64Range(),
'finite',
FP.abstract.multiplicationMatrixScalarInterval
)
);
},
}))
Expand All @@ -23,11 +28,15 @@ 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
return selectNCases(
'binary/af_matrix_scalar_multiplication_scalar_mat',
50,
FP.abstract.generateScalarMatrixToMatrixCases(
sparseScalarF64Range(),
sparseMatrixF64Range(cols, rows),
'finite',
FP.abstract.multiplicationScalarMatrixInterval
)
);
},
}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { FP } from '../../../../util/floating_point.js';
import { sparseMatrixF64Range, sparseVectorF64Range } from '../../../../util/math.js';
import { selectNCases } from '../case.js';
import { makeCaseCache } from '../case_cache.js';

// Cases: matCxR_vecC
const mat_vec_cases = ([2, 3, 4] as const)
.flatMap(cols =>
([2, 3, 4] as const).map(rows => ({
[`mat${cols}x${rows}_vec${cols}`]: () => {
return FP.abstract.generateMatrixVectorToVectorCases(
sparseMatrixF64Range(cols, rows),
sparseVectorF64Range(cols),
'finite',
FP.abstract.multiplicationMatrixVectorInterval
return selectNCases(
'binary/af_matrix_vector_multiplication_mat_vec',
50,
FP.abstract.generateMatrixVectorToVectorCases(
sparseMatrixF64Range(cols, rows),
sparseVectorF64Range(cols),
'finite',
FP.abstract.multiplicationMatrixVectorInterval
)
);
},
}))
Expand All @@ -23,11 +28,15 @@ const vec_mat_cases = ([2, 3, 4] as const)
.flatMap(rows =>
([2, 3, 4] as const).map(cols => ({
[`vec${rows}_mat${cols}x${rows}`]: () => {
return FP.abstract.generateVectorMatrixToVectorCases(
sparseVectorF64Range(rows),
sparseMatrixF64Range(cols, rows),
'finite',
FP.abstract.multiplicationVectorMatrixInterval
return selectNCases(
'binary/af_matrix_vector_multiplication_vec_mat',
50,
FP.abstract.generateVectorMatrixToVectorCases(
sparseVectorF64Range(rows),
sparseMatrixF64Range(cols, rows),
'finite',
FP.abstract.multiplicationVectorMatrixInterval
)
);
},
}))
Expand Down
49 changes: 46 additions & 3 deletions src/webgpu/shader/execution/expression/case.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { crc32 } from '../../../../common/util/crc32.js';
import { ROArrayArray } from '../../../../common/util/types.js';
import { ScalarBuilder, Value, Vector, i32, u32, abstractInt } from '../../../util/conversion.js';
import { assert } from '../../../../common/util/util.js';
import { abstractInt, i32, ScalarBuilder, u32, Value, Vector } from '../../../util/conversion.js';
import {
QuantizeFunc,
cartesianProduct,
QuantizeFunc,
quantizeToI32,
quantizeToU32,
quantizeToI64,
quantizeToU32,
} from '../../../util/math.js';

import { Expectation } from './expectation.js';
Expand All @@ -25,6 +27,47 @@ export type Case = {
/** CaseList is a list of Cases */
export type CaseList = Array<Case>;

/**
* Filters a given set of Cases down to a target number of cases by
* randomly selecting which Cases to return.
*
* The selection algorithm is deterministic and stable for a case's
* inputs.
*
* This means that if a specific case is selected is not affected by the
* presence of other cases in the list, so in theory it is possible to create a
* pathological set of cases such that all or not of the cases are selected
* in spite of the target number.
*
* This is a trade-off from guaranteeing stability of the selected cases over
* small changes, so the target number of cases is more of a suggestion. It is
* still guaranteed that if you set n0 < n1, then the invocation with n0 will
* return at most the number of cases that n1 does, it just isn't guaranteed to
* be less.
*
* @param dis is a string provided for additional hashing information to avoid
* systemic bias in the selection process across different test
* suites. Specifically every Case with the same input values being
* included or skipped regardless of the operation that they are
* testing. This string should be something like the name of the case
* cache the values are for or the operation under test.
* @param n number of cases targeted be returned. Expected to be a positive
* integer. If equal or greater than the number of cases, then all the
* cases are returned. 0 is not allowed, since it is likely a
* programming error, because if the caller intentionally wants 0
* items, they can just use [].
* @param cases list of Cases to be selected from.
*/
export function selectNCases(dis: string, n: number, cases: CaseList): CaseList {
assert(n > 0 && Math.round(n) === n, `n ${n} is expected to be a positive integer`);
const count = cases.length;
if (n >= count) {
return cases;
}
const dis_crc32 = crc32(dis);
return cases.filter(c => n * (0xffff_ffff / count) > (crc32(c.input.toString()) ^ dis_crc32));
}

/**
* A function that performs a binary operation on x and y, and returns the
* expected result.
Expand Down
Loading

0 comments on commit efa7b4f

Please sign in to comment.