Skip to content

Commit

Permalink
wgsl: Enable Absolute Error intervals for AbstractFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
zoddicus committed Mar 7, 2024
1 parent 561ab2a commit da3af98
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 110 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": "de575056",
"webgpu/shader/execution/binary/af_addition.bin": "ca81925e",
"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/af_division.bin": "99a5b647",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "552af47",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "709a233c",
"webgpu/shader/execution/binary/af_multiplication.bin": "b7e4f64",
"webgpu/shader/execution/binary/af_remainder.bin": "640eaf2b",
"webgpu/shader/execution/binary/af_subtraction.bin": "fa3085bf",
"webgpu/shader/execution/binary/f16_addition.bin": "508338b7",
"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/f16_division.bin": "82099c2e",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "eb15ddd1",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "2606d754",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "3c7a2639",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "8a4ba38a",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "a24739ae",
"webgpu/shader/execution/binary/f16_multiplication.bin": "2617c9a3",
"webgpu/shader/execution/binary/f16_remainder.bin": "2d441f34",
"webgpu/shader/execution/binary/f16_subtraction.bin": "207ccfd4",
"webgpu/shader/execution/binary/f32_addition.bin": "e15eed22",
"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/f32_division.bin": "36cf3067",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "78e16304",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "920f7140",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "abe2ea49",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "6a365a1c",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "b1337cf",
"webgpu/shader/execution/binary/f32_multiplication.bin": "5f75fed7",
"webgpu/shader/execution/binary/f32_remainder.bin": "fc1ea5a3",
"webgpu/shader/execution/binary/f32_subtraction.bin": "2ffbfbbf",
"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/abs.bin": "7101f77c",
"webgpu/shader/execution/acos.bin": "128c278e",
"webgpu/shader/execution/acosh.bin": "97d9fc9b",
"webgpu/shader/execution/asin.bin": "396b0634",
"webgpu/shader/execution/asinh.bin": "8a37a6b5",
"webgpu/shader/execution/atan.bin": "280df3b0",
"webgpu/shader/execution/atan2.bin": "7daa018e",
"webgpu/shader/execution/atanh.bin": "f87dc7a3",
"webgpu/shader/execution/bitcast.bin": "a48e46de",
"webgpu/shader/execution/ceil.bin": "98fdd766",
"webgpu/shader/execution/clamp.bin": "9e241dab",
"webgpu/shader/execution/cos.bin": "815c1b80",
"webgpu/shader/execution/cosh.bin": "b7b7a45a",
"webgpu/shader/execution/cross.bin": "dfd5704c",
"webgpu/shader/execution/degrees.bin": "a2701367",
"webgpu/shader/execution/determinant.bin": "6303759d",
"webgpu/shader/execution/distance.bin": "a14d7826",
"webgpu/shader/execution/dot.bin": "e8909211",
"webgpu/shader/execution/exp.bin": "76a7ae08",
"webgpu/shader/execution/exp2.bin": "1499f1bd",
"webgpu/shader/execution/faceForward.bin": "a1be9329",
"webgpu/shader/execution/floor.bin": "18a036b7",
"webgpu/shader/execution/fma.bin": "bc05ba74",
"webgpu/shader/execution/fract.bin": "476c1377",
"webgpu/shader/execution/frexp.bin": "292a260f",
"webgpu/shader/execution/inverseSqrt.bin": "f98304f0",
"webgpu/shader/execution/ldexp.bin": "b7025040",
"webgpu/shader/execution/length.bin": "ef2b2d08",
"webgpu/shader/execution/log.bin": "76986d52",
"webgpu/shader/execution/log2.bin": "eb7d9499",
"webgpu/shader/execution/max.bin": "37212ba0",
"webgpu/shader/execution/min.bin": "281e5429",
"webgpu/shader/execution/mix.bin": "8b799da4",
"webgpu/shader/execution/modf.bin": "dafda32a",
"webgpu/shader/execution/normalize.bin": "bcbba6c7",
"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/pow.bin": "1337bba0",
"webgpu/shader/execution/quantizeToF16.bin": "d820c3c1",
"webgpu/shader/execution/radians.bin": "a9d65c64",
"webgpu/shader/execution/reflect.bin": "c5c9a9ed",
"webgpu/shader/execution/refract.bin": "b3a8db7b",
"webgpu/shader/execution/round.bin": "84dcc0a6",
"webgpu/shader/execution/saturate.bin": "200315c2",
"webgpu/shader/execution/sign.bin": "b7225718",
"webgpu/shader/execution/sin.bin": "5d27ba39",
"webgpu/shader/execution/sinh.bin": "7c311d85",
"webgpu/shader/execution/smoothstep.bin": "90c8a6f1",
"webgpu/shader/execution/sqrt.bin": "e17b9342",
"webgpu/shader/execution/step.bin": "a65d84f8",
"webgpu/shader/execution/tan.bin": "14fac19a",
"webgpu/shader/execution/tanh.bin": "dbed2d84",
"webgpu/shader/execution/transpose.bin": "d37f8f6a",
"webgpu/shader/execution/trunc.bin": "8cc815f0",
"webgpu/shader/execution/unpack2x16float.bin": "d7d67e73",
"webgpu/shader/execution/unpack2x16snorm.bin": "67eb8ff3",
"webgpu/shader/execution/unpack2x16unorm.bin": "70fbef8f",
"webgpu/shader/execution/unpack4x8snorm.bin": "cd19c9b6",
"webgpu/shader/execution/unpack4x8unorm.bin": "ebe9a1b7",
"webgpu/shader/execution/unary/af_arithmetic.bin": "724bf5a2",
"webgpu/shader/execution/unary/af_assignment.bin": "ebd483c5",
"webgpu/shader/execution/unary/bool_conversion.bin": "dd71f171",
"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/f16_arithmetic.bin": "df91bb64",
"webgpu/shader/execution/unary/f16_conversion.bin": "1d6b7f2a",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "c6652001",
"webgpu/shader/execution/unary/f32_conversion.bin": "ec4a54d6",
"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": "dfcd593a",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "3d27dc97",
"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"
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "5bf6ec62",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "da8e7f",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "7b504218"
}
43 changes: 27 additions & 16 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1836,31 +1836,55 @@ interface AbsoluteErrorCase {
const kSmallAbsoluteErrorValue = {
f32: 2 ** -11, // Builtin cos and sin has a absolute error 2**-11 for f32
f16: 2 ** -7, // Builtin cos and sin has a absolute error 2**-7 for f16
abstract: 2 ** -11, // Builtin cos and sin has a absolute error 2**-11 for AbstractFloat
} as const;
// A large absolute error value is a representable value x that much smaller than maximum
// positive, but positive.max - x is still exactly representable.
const kLargeAbsoluteErrorValue = {
f32: 2 ** 110, // f32.positive.max - 2**110 = 3.4028104e+38 = 0x7f7fffbf in f32
f16: 2 ** 10, // f16.positive.max - 2**10 = 64480 = 0x7bdf in f16
abstract: 2 ** 977, // f64.positive.man - 2**977 = 1.79769e+308 = 0x7fefffffffffffbf in f64
} as const;
// A subnormal absolute error value is a subnormal representable value x of kind, which ensures
// that positive.subnormal.min +/- x is still exactly representable.
const kSubnormalAbsoluteErrorValue = {
f32: 2 ** -140, // f32 0x00000200
f16: 2 ** -20, // f16 0x0010
abstract: 2 ** -1065, // f64 0x0000_0000_0000_0200
} as const;

g.test('absoluteErrorInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.expandWithParams<AbsoluteErrorCase>(p => {
const trait = FP[p.trait];
const constants = trait.constants();
const smallErr = kSmallAbsoluteErrorValue[p.trait];
const largeErr = kLargeAbsoluteErrorValue[p.trait];
const subnormalErr = kSubnormalAbsoluteErrorValue[p.trait];

// Additional testing for non-f64 values, since JS number is f64 internally
// prettier-ignore
const additionalSubnormal64bit = p.trait !== 'abstract' ?
[
// 64-bit subnormals, expected to be treated as 0.0 or smallest subnormal of kind.
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: 0, expected: [0, constants.positive.subnormal.min] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: subnormalErr, expected: [-subnormalErr, constants.positive.subnormal.min + subnormalErr] },
// Note that f32 minimum subnormal is so smaller than 1.0, adding them together may result in the f64 results 1.0.
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: 1, expected: [-1, constants.positive.subnormal.min + 1] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: 0, expected: [0, constants.positive.subnormal.min] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: subnormalErr, expected: [-subnormalErr, constants.positive.subnormal.min + subnormalErr] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: 1, expected: [-1, constants.positive.subnormal.min + 1] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: 0, expected: [constants.negative.subnormal.max, 0] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: subnormalErr, expected: [constants.negative.subnormal.max - subnormalErr, subnormalErr] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: 1, expected: [constants.negative.subnormal.max - 1, 1] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: 0, expected: [constants.negative.subnormal.max, 0] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: subnormalErr, expected: [constants.negative.subnormal.max - subnormalErr, subnormalErr] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: 1, expected: [constants.negative.subnormal.max - 1, 1] },
] as const : [] as const;

// prettier-ignore
return [
// Edge Cases
Expand Down Expand Up @@ -1903,21 +1927,6 @@ g.test('absoluteErrorInterval')
{ value: constants.negative.subnormal.max, error: smallErr, expected: [constants.negative.subnormal.max - smallErr, smallErr] },
{ value: constants.negative.subnormal.max, error: 1, expected: [constants.negative.subnormal.max - 1, 1] },

// 64-bit subnormals, expected to be treated as 0.0 or smallest subnormal of kind.
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: 0, expected: [0, constants.positive.subnormal.min] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: subnormalErr, expected: [-subnormalErr, constants.positive.subnormal.min + subnormalErr] },
// Note that f32 minimum subnormal is so smaller than 1.0, adding them together may result in the f64 results 1.0.
{ value: reinterpretU64AsF64(0x0000_0000_0000_0001n), error: 1, expected: [-1, constants.positive.subnormal.min + 1] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: 0, expected: [0, constants.positive.subnormal.min] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: subnormalErr, expected: [-subnormalErr, constants.positive.subnormal.min + subnormalErr] },
{ value: reinterpretU64AsF64(0x0000_0000_0000_0002n), error: 1, expected: [-1, constants.positive.subnormal.min + 1] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: 0, expected: [constants.negative.subnormal.max, 0] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: subnormalErr, expected: [constants.negative.subnormal.max - subnormalErr, subnormalErr] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_ffffn), error: 1, expected: [constants.negative.subnormal.max - 1, 1] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: 0, expected: [constants.negative.subnormal.max, 0] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: subnormalErr, expected: [constants.negative.subnormal.max - subnormalErr, subnormalErr] },
{ value: reinterpretU64AsF64(0x800f_ffff_ffff_fffen), error: 1, expected: [constants.negative.subnormal.max - 1, 1] },

// Zero
{ value: 0, error: 0, expected: 0 },
{ value: 0, error: smallErr, expected: [-smallErr, smallErr] },
Expand All @@ -1930,6 +1939,8 @@ g.test('absoluteErrorInterval')
{ value: -2, error: 0, expected: -2 },
{ value: -2, error: smallErr, expected: [-2 - smallErr, -2 + smallErr] },
{ value: -2, error: 1, expected: [-3, -1] },

...additionalSubnormal64bit,
];
})
)
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 @@ -5091,7 +5091,7 @@ class FPAbstractTraits extends FPTraits {
public readonly sparseMatrixRange = sparseMatrixF64Range;

// Framework - Fundamental Error Intervals - Overrides
public readonly absoluteErrorInterval = this.unboundedAbsoluteErrorInterval.bind(this);
public readonly absoluteErrorInterval = this.absoluteErrorIntervalImpl.bind(this);
public readonly correctlyRoundedInterval = this.correctlyRoundedIntervalImpl.bind(this);
public readonly correctlyRoundedMatrix = this.correctlyRoundedMatrixImpl.bind(this);
public readonly ulpInterval = (n: number, numULP: number): FPInterval => {
Expand Down

0 comments on commit da3af98

Please sign in to comment.