Skip to content

Commit

Permalink
Remove ULP & Absolute Error support for AF (#3487)
Browse files Browse the repository at this point in the history
For AbstractFloat, builtins that have absolute or ULP errors, (or
inherit their error) should defer to the intervals for f32, so
replacing the underlying intervals with stubs that assert instead.
  • Loading branch information
zoddicus authored Mar 13, 2024
1 parent 392da47 commit 022bbf5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 129 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": "91af48f0",
"webgpu/shader/execution/binary/af_addition.bin": "24160909",
"webgpu/shader/execution/binary/af_logical.bin": "ffb5a83f",
"webgpu/shader/execution/binary/af_division.bin": "73039eea",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "e13e9e6e",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "5dc56318",
"webgpu/shader/execution/binary/af_multiplication.bin": "33cb4a90",
"webgpu/shader/execution/binary/af_remainder.bin": "b06c2cd5",
"webgpu/shader/execution/binary/af_subtraction.bin": "d5c5a9de",
"webgpu/shader/execution/binary/f16_addition.bin": "41c253b",
"webgpu/shader/execution/binary/af_division.bin": "c230ac78",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "9079a042",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "6b55102f",
"webgpu/shader/execution/binary/af_multiplication.bin": "4fc3b0d6",
"webgpu/shader/execution/binary/af_remainder.bin": "366caec6",
"webgpu/shader/execution/binary/af_subtraction.bin": "49a16db4",
"webgpu/shader/execution/binary/f16_addition.bin": "3fb1ee09",
"webgpu/shader/execution/binary/f16_logical.bin": "65cdc6f",
"webgpu/shader/execution/binary/f16_division.bin": "4e0dd3f3",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "7131d2e",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "27105bab",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "e4edd8d1",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "3f8f0d6",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "4379fdb1",
"webgpu/shader/execution/binary/f16_multiplication.bin": "f1ce631d",
"webgpu/shader/execution/binary/f16_remainder.bin": "c3400825",
"webgpu/shader/execution/binary/f16_subtraction.bin": "c84c09b4",
"webgpu/shader/execution/binary/f32_addition.bin": "d1ce98cf",
"webgpu/shader/execution/binary/f16_division.bin": "1b5bd44a",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "fdea291a",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "e727482e",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "24d70bdd",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "7acd3c3b",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "9e01e0cf",
"webgpu/shader/execution/binary/f16_multiplication.bin": "c24b705c",
"webgpu/shader/execution/binary/f16_remainder.bin": "2764c7e1",
"webgpu/shader/execution/binary/f16_subtraction.bin": "d4014a38",
"webgpu/shader/execution/binary/f32_addition.bin": "b6707259",
"webgpu/shader/execution/binary/f32_logical.bin": "d40c1c0",
"webgpu/shader/execution/binary/f32_division.bin": "27a33c63",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "84296a9c",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "a601448a",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "f025741a",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "db1d203c",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a7456950",
"webgpu/shader/execution/binary/f32_multiplication.bin": "e6a47586",
"webgpu/shader/execution/binary/f32_remainder.bin": "31d588d",
"webgpu/shader/execution/binary/f32_subtraction.bin": "4b79931f",
"webgpu/shader/execution/binary/f32_division.bin": "e19e30a6",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "6a13d6d6",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "4c5cb0a2",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "6b00d17f",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "319d3ae1",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "1c4893ca",
"webgpu/shader/execution/binary/f32_multiplication.bin": "f7dbbc8",
"webgpu/shader/execution/binary/f32_remainder.bin": "fb5dd3fe",
"webgpu/shader/execution/binary/f32_subtraction.bin": "aeaca568",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "90a3514a",
"webgpu/shader/execution/binary/i32_comparison.bin": "840b09e6",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "e3f04e97",
"webgpu/shader/execution/binary/u32_comparison.bin": "dc1398d3",
"webgpu/shader/execution/abs.bin": "1ff1f454",
"webgpu/shader/execution/acos.bin": "539c5984",
"webgpu/shader/execution/acosh.bin": "e1155c5f",
"webgpu/shader/execution/asin.bin": "a17f7afb",
"webgpu/shader/execution/asinh.bin": "dbb0f8a",
"webgpu/shader/execution/atan.bin": "80b2e232",
"webgpu/shader/execution/atan2.bin": "19853e04",
"webgpu/shader/execution/atanh.bin": "1dd56fe0",
"webgpu/shader/execution/bitcast.bin": "83ba0a2d",
"webgpu/shader/execution/ceil.bin": "51abcdee",
"webgpu/shader/execution/clamp.bin": "8b77f1be",
"webgpu/shader/execution/cos.bin": "486fa019",
"webgpu/shader/execution/cosh.bin": "b796f446",
"webgpu/shader/execution/cross.bin": "934a9528",
"webgpu/shader/execution/degrees.bin": "e767ec2b",
"webgpu/shader/execution/determinant.bin": "a82df7ed",
"webgpu/shader/execution/distance.bin": "189f7e7",
"webgpu/shader/execution/dot.bin": "48b08425",
"webgpu/shader/execution/exp.bin": "7a9b65c9",
"webgpu/shader/execution/exp2.bin": "40857179",
"webgpu/shader/execution/faceForward.bin": "a4d3d7fd",
"webgpu/shader/execution/floor.bin": "78ddd3e0",
"webgpu/shader/execution/fma.bin": "8fe936c7",
"webgpu/shader/execution/fract.bin": "c9527ef2",
"webgpu/shader/execution/frexp.bin": "66d03941",
"webgpu/shader/execution/inverseSqrt.bin": "b6242d36",
"webgpu/shader/execution/ldexp.bin": "a0827b94",
"webgpu/shader/execution/length.bin": "23579568",
"webgpu/shader/execution/log.bin": "43822075",
"webgpu/shader/execution/log2.bin": "18e01bd3",
"webgpu/shader/execution/max.bin": "3754c33c",
"webgpu/shader/execution/min.bin": "33935035",
"webgpu/shader/execution/mix.bin": "f67ad46a",
"webgpu/shader/execution/modf.bin": "edb80b8c",
"webgpu/shader/execution/normalize.bin": "167d7c79",
"webgpu/shader/execution/abs.bin": "2b663377",
"webgpu/shader/execution/acos.bin": "a888c67f",
"webgpu/shader/execution/acosh.bin": "5383658b",
"webgpu/shader/execution/asin.bin": "a580a322",
"webgpu/shader/execution/asinh.bin": "31388535",
"webgpu/shader/execution/atan.bin": "c6f4c771",
"webgpu/shader/execution/atan2.bin": "3b9a37a1",
"webgpu/shader/execution/atanh.bin": "7295a313",
"webgpu/shader/execution/bitcast.bin": "73e0bea6",
"webgpu/shader/execution/ceil.bin": "24bd6be9",
"webgpu/shader/execution/clamp.bin": "8ed55492",
"webgpu/shader/execution/cos.bin": "4d36fa0",
"webgpu/shader/execution/cosh.bin": "a7da3a3",
"webgpu/shader/execution/cross.bin": "6ce2660b",
"webgpu/shader/execution/degrees.bin": "53a0849",
"webgpu/shader/execution/determinant.bin": "873e78af",
"webgpu/shader/execution/distance.bin": "bfce09a0",
"webgpu/shader/execution/dot.bin": "566b6e55",
"webgpu/shader/execution/exp.bin": "d8142d49",
"webgpu/shader/execution/exp2.bin": "52a403d1",
"webgpu/shader/execution/faceForward.bin": "f90dacbe",
"webgpu/shader/execution/floor.bin": "c7465b11",
"webgpu/shader/execution/fma.bin": "db3497d4",
"webgpu/shader/execution/fract.bin": "e65c5bd1",
"webgpu/shader/execution/frexp.bin": "5ce112f4",
"webgpu/shader/execution/inverseSqrt.bin": "84ea0a57",
"webgpu/shader/execution/ldexp.bin": "9d11f120",
"webgpu/shader/execution/length.bin": "dd759736",
"webgpu/shader/execution/log.bin": "5f77a59d",
"webgpu/shader/execution/log2.bin": "57fff45e",
"webgpu/shader/execution/max.bin": "c7cdd54f",
"webgpu/shader/execution/min.bin": "422be325",
"webgpu/shader/execution/mix.bin": "957e7d92",
"webgpu/shader/execution/modf.bin": "946d1f4f",
"webgpu/shader/execution/normalize.bin": "2ac02e80",
"webgpu/shader/execution/pack2x16float.bin": "d7ef3cf5",
"webgpu/shader/execution/pow.bin": "b3f33461",
"webgpu/shader/execution/quantizeToF16.bin": "c41ec650",
"webgpu/shader/execution/radians.bin": "74748445",
"webgpu/shader/execution/reflect.bin": "e2b029bd",
"webgpu/shader/execution/refract.bin": "7916ffc2",
"webgpu/shader/execution/round.bin": "8d428840",
"webgpu/shader/execution/saturate.bin": "6de2e522",
"webgpu/shader/execution/sign.bin": "7ae6222a",
"webgpu/shader/execution/sin.bin": "4178e4ca",
"webgpu/shader/execution/sinh.bin": "7c104d99",
"webgpu/shader/execution/smoothstep.bin": "c461cdc6",
"webgpu/shader/execution/sqrt.bin": "bf85c8fb",
"webgpu/shader/execution/step.bin": "adb873a1",
"webgpu/shader/execution/tan.bin": "a1777146",
"webgpu/shader/execution/tanh.bin": "ceeebb22",
"webgpu/shader/execution/transpose.bin": "f41b25c8",
"webgpu/shader/execution/trunc.bin": "c71488f3",
"webgpu/shader/execution/unpack2x16float.bin": "a763e4a1",
"webgpu/shader/execution/unpack2x16snorm.bin": "e414f14b",
"webgpu/shader/execution/unpack2x16unorm.bin": "488b474a",
"webgpu/shader/execution/unpack4x8snorm.bin": "d4fd9078",
"webgpu/shader/execution/unpack4x8unorm.bin": "7aa3c88e",
"webgpu/shader/execution/unary/af_arithmetic.bin": "14207fe0",
"webgpu/shader/execution/unary/af_assignment.bin": "ddb98d17",
"webgpu/shader/execution/pow.bin": "cd492166",
"webgpu/shader/execution/quantizeToF16.bin": "58bac06c",
"webgpu/shader/execution/radians.bin": "6ac08f50",
"webgpu/shader/execution/reflect.bin": "3c260554",
"webgpu/shader/execution/refract.bin": "7e952d7c",
"webgpu/shader/execution/round.bin": "f6b9bda1",
"webgpu/shader/execution/saturate.bin": "1c22f301",
"webgpu/shader/execution/sign.bin": "3ce55105",
"webgpu/shader/execution/sin.bin": "d48e7f2a",
"webgpu/shader/execution/sinh.bin": "f227c1d1",
"webgpu/shader/execution/smoothstep.bin": "6bdb4309",
"webgpu/shader/execution/sqrt.bin": "cd576d27",
"webgpu/shader/execution/step.bin": "dd584686",
"webgpu/shader/execution/tan.bin": "5ae50f61",
"webgpu/shader/execution/tanh.bin": "fe7a619d",
"webgpu/shader/execution/transpose.bin": "469edd7e",
"webgpu/shader/execution/trunc.bin": "8d3a05de",
"webgpu/shader/execution/unpack2x16float.bin": "e897c5ac",
"webgpu/shader/execution/unpack2x16snorm.bin": "450d5402",
"webgpu/shader/execution/unpack2x16unorm.bin": "306b3bf9",
"webgpu/shader/execution/unpack4x8snorm.bin": "fc1bd4c3",
"webgpu/shader/execution/unpack4x8unorm.bin": "763288cc",
"webgpu/shader/execution/unary/af_arithmetic.bin": "a39d4121",
"webgpu/shader/execution/unary/af_assignment.bin": "6ed540e8",
"webgpu/shader/execution/unary/bool_conversion.bin": "f37ea003",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "26b20f68",
"webgpu/shader/execution/unary/f16_conversion.bin": "5e3a4bce",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "c30910",
"webgpu/shader/execution/unary/f32_conversion.bin": "7e716fd3",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "9cadc739",
"webgpu/shader/execution/unary/f16_conversion.bin": "49c7b38e",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "28da577a",
"webgpu/shader/execution/unary/f32_conversion.bin": "fcdfdd08",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "25cf27d1",
"webgpu/shader/execution/unary/i32_conversion.bin": "276dcf69",
"webgpu/shader/execution/unary/u32_conversion.bin": "acac2172",
"webgpu/shader/execution/unary/ai_assignment.bin": "c876d431",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "36a1d65b",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "89e34dcf",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "4116ac44",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "b2738fb2",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "4d3df8a8"
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "3fd8797b",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "bf99158a",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "8bcc7c30"
}
Binary file modified src/resources/cache/webgpu/shader/execution/bitcast.bin
Binary file not shown.
42 changes: 16 additions & 26 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1836,27 +1836,24 @@ 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', 'abstract'] as const)
.combine('trait', ['f32', 'f16'] as const)
.beginSubcases()
.expandWithParams<AbsoluteErrorCase>(p => {
const trait = FP[p.trait];
Expand All @@ -1865,26 +1862,6 @@ g.test('absoluteErrorInterval')
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 @@ -1940,7 +1917,20 @@ g.test('absoluteErrorInterval')
{ value: -2, error: smallErr, expected: [-2 - smallErr, -2 + smallErr] },
{ value: -2, error: 1, expected: [-3, -1] },

...additionalSubnormal64bit,
// 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] },
];
})
)
Expand Down Expand Up @@ -2102,7 +2092,7 @@ const kULPErrorValue = {
g.test('ulpInterval')
.params(u =>
u
.combine('trait', ['abstract', 'f32', 'f16'] as const)
.combine('trait', ['f32', 'f16'] as const)
.beginSubcases()
.expandWithParams<ULPCase>(p => {
const trait = kFPTraitForULP[p.trait];
Expand Down
Loading

0 comments on commit 022bbf5

Please sign in to comment.