Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wgsl: Implement AbstractFloat ldexp execution tests #3534

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "cc46f375",
"webgpu/shader/execution/binary/af_addition.bin": "120b0299",
"webgpu/shader/execution/binary/af_logical.bin": "a96d0397",
"webgpu/shader/execution/binary/af_division.bin": "9947b11a",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "56d9ea9e",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "e3431b91",
"webgpu/shader/execution/binary/af_multiplication.bin": "d87b2f1b",
"webgpu/shader/execution/binary/af_remainder.bin": "71d8432f",
"webgpu/shader/execution/binary/af_subtraction.bin": "8c3e4a0a",
"webgpu/shader/execution/binary/f16_addition.bin": "dd5dd072",
"webgpu/shader/execution/binary/af_division.bin": "ac59aa23",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "9804c75c",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "7761d693",
"webgpu/shader/execution/binary/af_multiplication.bin": "b89bfd3f",
"webgpu/shader/execution/binary/af_remainder.bin": "85aeeae",
"webgpu/shader/execution/binary/af_subtraction.bin": "5c5210a6",
"webgpu/shader/execution/binary/f16_addition.bin": "fe267615",
"webgpu/shader/execution/binary/f16_logical.bin": "d1f632dd",
"webgpu/shader/execution/binary/f16_division.bin": "166dbe68",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "47c71854",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "fe436936",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "e192e191",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "8b8ea740",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "8f85bf5f",
"webgpu/shader/execution/binary/f16_multiplication.bin": "1f9bd007",
"webgpu/shader/execution/binary/f16_remainder.bin": "75cebe2e",
"webgpu/shader/execution/binary/f16_subtraction.bin": "665cb599",
"webgpu/shader/execution/binary/f32_addition.bin": "d66775eb",
"webgpu/shader/execution/binary/f16_division.bin": "df668b0a",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "ccc54edf",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "f2f641b1",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "b92bbc1e",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "3cdc6048",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "eb5774bf",
"webgpu/shader/execution/binary/f16_multiplication.bin": "4dd28c86",
"webgpu/shader/execution/binary/f16_remainder.bin": "6b85ab32",
"webgpu/shader/execution/binary/f16_subtraction.bin": "db794da4",
"webgpu/shader/execution/binary/f32_addition.bin": "616611b9",
"webgpu/shader/execution/binary/f32_logical.bin": "8759f532",
"webgpu/shader/execution/binary/f32_division.bin": "4cf768ee",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "29c7484c",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "d2ecc107",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "cccb9209",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "3cc4c9b8",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "d2e2029e",
"webgpu/shader/execution/binary/f32_multiplication.bin": "13d34f2",
"webgpu/shader/execution/binary/f32_remainder.bin": "17d30b22",
"webgpu/shader/execution/binary/f32_subtraction.bin": "49a59e26",
"webgpu/shader/execution/binary/f32_division.bin": "c8d5eaea",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "c20b3029",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "58051f59",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "9af1c79e",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "7509079d",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a2a9df30",
"webgpu/shader/execution/binary/f32_multiplication.bin": "e730f6ce",
"webgpu/shader/execution/binary/f32_remainder.bin": "bf328256",
"webgpu/shader/execution/binary/f32_subtraction.bin": "ad95d2f8",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "119fe0bd",
"webgpu/shader/execution/binary/i32_comparison.bin": "9749440b",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "902e89b8",
"webgpu/shader/execution/binary/u32_comparison.bin": "a5f8da57",
"webgpu/shader/execution/abs.bin": "805797bf",
"webgpu/shader/execution/acos.bin": "93089d9e",
"webgpu/shader/execution/acosh.bin": "b35dc462",
"webgpu/shader/execution/asin.bin": "d5bda311",
"webgpu/shader/execution/asinh.bin": "ae10d9a0",
"webgpu/shader/execution/atan.bin": "99c1e67f",
"webgpu/shader/execution/atan2.bin": "462e7e6a",
"webgpu/shader/execution/atanh.bin": "e70e1792",
"webgpu/shader/execution/bitcast.bin": "bd0bc184",
"webgpu/shader/execution/ceil.bin": "b56ea84a",
"webgpu/shader/execution/clamp.bin": "ff5a401f",
"webgpu/shader/execution/cos.bin": "bfad82a2",
"webgpu/shader/execution/cosh.bin": "e71a9b5",
"webgpu/shader/execution/cross.bin": "27700ac",
"webgpu/shader/execution/degrees.bin": "690bf0ac",
"webgpu/shader/execution/determinant.bin": "b9597fbc",
"webgpu/shader/execution/distance.bin": "55181230",
"webgpu/shader/execution/dot.bin": "7f477f0d",
"webgpu/shader/execution/exp.bin": "8b9f445d",
"webgpu/shader/execution/exp2.bin": "84e22d81",
"webgpu/shader/execution/faceForward.bin": "7dad0a6f",
"webgpu/shader/execution/floor.bin": "87184f81",
"webgpu/shader/execution/fma.bin": "c020820d",
"webgpu/shader/execution/fract.bin": "d0bb2f7a",
"webgpu/shader/execution/frexp.bin": "d18a686e",
"webgpu/shader/execution/inverseSqrt.bin": "47aca3d3",
"webgpu/shader/execution/ldexp.bin": "55575b9e",
"webgpu/shader/execution/length.bin": "48c6ff24",
"webgpu/shader/execution/log.bin": "ea97557c",
"webgpu/shader/execution/log2.bin": "5f800fe1",
"webgpu/shader/execution/max.bin": "582080bc",
"webgpu/shader/execution/min.bin": "aa7c99c6",
"webgpu/shader/execution/mix.bin": "29595ab0",
"webgpu/shader/execution/modf.bin": "6556fce6",
"webgpu/shader/execution/normalize.bin": "53441d1e",
"webgpu/shader/execution/abs.bin": "99ce1599",
"webgpu/shader/execution/acos.bin": "306e8319",
"webgpu/shader/execution/acosh.bin": "36660581",
"webgpu/shader/execution/asin.bin": "2c7e6a39",
"webgpu/shader/execution/asinh.bin": "1a876442",
"webgpu/shader/execution/atan.bin": "658d73cf",
"webgpu/shader/execution/atan2.bin": "3682bf6f",
"webgpu/shader/execution/atanh.bin": "8cefd75d",
"webgpu/shader/execution/bitcast.bin": "8aac75fe",
"webgpu/shader/execution/ceil.bin": "9aed57a4",
"webgpu/shader/execution/clamp.bin": "b21a1f68",
"webgpu/shader/execution/cos.bin": "e0124922",
"webgpu/shader/execution/cosh.bin": "38a0e519",
"webgpu/shader/execution/cross.bin": "2519efdd",
"webgpu/shader/execution/degrees.bin": "b7ecc453",
"webgpu/shader/execution/determinant.bin": "934b3491",
"webgpu/shader/execution/distance.bin": "6cd619f",
"webgpu/shader/execution/dot.bin": "ca1d811f",
"webgpu/shader/execution/exp.bin": "f79f7f73",
"webgpu/shader/execution/exp2.bin": "3612290f",
"webgpu/shader/execution/faceForward.bin": "f1edf98b",
"webgpu/shader/execution/floor.bin": "eee7b3a8",
"webgpu/shader/execution/fma.bin": "2b45444e",
"webgpu/shader/execution/fract.bin": "18ccdfe3",
"webgpu/shader/execution/frexp.bin": "c24193b0",
"webgpu/shader/execution/inverseSqrt.bin": "a9308598",
"webgpu/shader/execution/ldexp.bin": "e8ccd454",
"webgpu/shader/execution/length.bin": "a7831d48",
"webgpu/shader/execution/log.bin": "3a05ac55",
"webgpu/shader/execution/log2.bin": "e9effb5c",
"webgpu/shader/execution/max.bin": "a9683a83",
"webgpu/shader/execution/min.bin": "58c7c058",
"webgpu/shader/execution/mix.bin": "b9562a60",
"webgpu/shader/execution/modf.bin": "5c9be9f2",
"webgpu/shader/execution/normalize.bin": "c8deea41",
"webgpu/shader/execution/pack2x16float.bin": "83b4b256",
"webgpu/shader/execution/pow.bin": "90403cbe",
"webgpu/shader/execution/quantizeToF16.bin": "2fce486e",
"webgpu/shader/execution/radians.bin": "540e8c18",
"webgpu/shader/execution/reflect.bin": "2d7a6f8f",
"webgpu/shader/execution/refract.bin": "f180e0bb",
"webgpu/shader/execution/round.bin": "65f0fae6",
"webgpu/shader/execution/saturate.bin": "7e0a1def",
"webgpu/shader/execution/sign.bin": "c628a9b3",
"webgpu/shader/execution/sin.bin": "447991fb",
"webgpu/shader/execution/sinh.bin": "1e833f83",
"webgpu/shader/execution/smoothstep.bin": "e7adffa5",
"webgpu/shader/execution/sqrt.bin": "b3cb5e5",
"webgpu/shader/execution/step.bin": "c26e3a34",
"webgpu/shader/execution/tan.bin": "8eebcaac",
"webgpu/shader/execution/tanh.bin": "46e7a9d1",
"webgpu/shader/execution/transpose.bin": "e7ae0d43",
"webgpu/shader/execution/trunc.bin": "47c27ad9",
"webgpu/shader/execution/unpack2x16float.bin": "870b90d",
"webgpu/shader/execution/unpack2x16snorm.bin": "b5ee7356",
"webgpu/shader/execution/unpack2x16unorm.bin": "310beef6",
"webgpu/shader/execution/unpack4x8snorm.bin": "5c9e94f5",
"webgpu/shader/execution/unpack4x8unorm.bin": "290950c8",
"webgpu/shader/execution/unary/af_arithmetic.bin": "87085660",
"webgpu/shader/execution/unary/af_assignment.bin": "cce1a82b",
"webgpu/shader/execution/pow.bin": "ac862364",
"webgpu/shader/execution/quantizeToF16.bin": "2d2282b2",
"webgpu/shader/execution/radians.bin": "22d792c3",
"webgpu/shader/execution/reflect.bin": "fe9d7b45",
"webgpu/shader/execution/refract.bin": "eaee4a84",
"webgpu/shader/execution/round.bin": "779ee489",
"webgpu/shader/execution/saturate.bin": "c98ab10b",
"webgpu/shader/execution/sign.bin": "c2469a86",
"webgpu/shader/execution/sin.bin": "f06016d9",
"webgpu/shader/execution/sinh.bin": "eb4314b0",
"webgpu/shader/execution/smoothstep.bin": "c91ccf23",
"webgpu/shader/execution/sqrt.bin": "17899c50",
"webgpu/shader/execution/step.bin": "565d461b",
"webgpu/shader/execution/tan.bin": "1a4ae6d",
"webgpu/shader/execution/tanh.bin": "ff124cd3",
"webgpu/shader/execution/transpose.bin": "fafbc42",
"webgpu/shader/execution/trunc.bin": "be374270",
"webgpu/shader/execution/unpack2x16float.bin": "6032e028",
"webgpu/shader/execution/unpack2x16snorm.bin": "d2e11b25",
"webgpu/shader/execution/unpack2x16unorm.bin": "84156a6a",
"webgpu/shader/execution/unpack4x8snorm.bin": "887311df",
"webgpu/shader/execution/unpack4x8unorm.bin": "b2442020",
"webgpu/shader/execution/unary/af_arithmetic.bin": "19d001ef",
"webgpu/shader/execution/unary/af_assignment.bin": "565e26d1",
"webgpu/shader/execution/unary/bool_conversion.bin": "247f2b83",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "3345fdcb",
"webgpu/shader/execution/unary/f16_conversion.bin": "dc75125b",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "a1ed9b8",
"webgpu/shader/execution/unary/f32_conversion.bin": "886fa15d",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "3d9f043e",
"webgpu/shader/execution/unary/f16_conversion.bin": "b2ceb97a",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "d4b0b87b",
"webgpu/shader/execution/unary/f32_conversion.bin": "9ac02a7d",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "d51bbffb",
"webgpu/shader/execution/unary/i32_conversion.bin": "76c9d481",
"webgpu/shader/execution/unary/u32_conversion.bin": "f6b0e41",
"webgpu/shader/execution/unary/ai_assignment.bin": "79ae98e8",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "c59804c3",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "9e23d866",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "b951f27f",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "6756e689",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "60714ed1"
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "ab9d1adc",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "85218049",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "3d30361b"
}
Binary file modified src/resources/cache/webgpu/shader/execution/ldexp.bin
Binary file not shown.
45 changes: 43 additions & 2 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4465,19 +4465,60 @@ const kLdexpIntervalCases = {
{ input: [-100, 14], expected: kUnboundedEndpoints },
{ input: [2 ** 10, 10], expected: kUnboundedEndpoints },
] as ScalarPairToIntervalCase[],
abstract: [
// Edge Cases
// 1.9999999999999997779553950749686919152736663818359375 * 2 ** 1023 = f64.positive.max
{
input: [1.9999999999999997779553950749686919152736663818359375, 1023],
expected: kValue.f64.positive.max,
},
// f64.positive.min = 1 * 2 ** -1022
{ input: [1, -1022], expected: kValue.f64.positive.min },
// f64.positive.subnormal.max = 1.9999999999999997779553950749686919152736663818359375 * 2 ** -1022
{
input: [0.9999999999999997779553950749686919152736663818359375, -1022],
expected: [0, kValue.f64.positive.subnormal.max],
},
// f64.positive.subnormal.min = 0.0000000000000002220446049250313080847263336181640625 * 2 ** -1022
{
input: [0.0000000000000002220446049250313080847263336181640625, -1022],
expected: [0, kValue.f64.positive.subnormal.min],
},
{
input: [-0.0000000000000002220446049250313080847263336181640625, -1022],
expected: [kValue.f64.negative.subnormal.max, 0],
},
{
input: [-0.9999999999999997779553950749686919152736663818359375, -1022],
expected: [kValue.f64.negative.subnormal.min, 0],
},
{ input: [-1, -1022], expected: kValue.f64.negative.max },
{
input: [-1.9999999999999997779553950749686919152736663818359375, 1023],
expected: kValue.f64.negative.min,
},
// e2 + bias <= 0, expect correctly rounded intervals.
{ input: [2 ** 120, -130], expected: 2 ** -10 },
// Out of Bounds
{ input: [1, 1024], expected: kUnboundedEndpoints },
{ input: [-1, 1024], expected: kUnboundedEndpoints },
{ input: [100, 1024], expected: kUnboundedEndpoints },
{ input: [-100, 1024], expected: kUnboundedEndpoints },
{ input: [2 ** 100, 1000], expected: kUnboundedEndpoints },
] as ScalarPairToIntervalCase[],
} as const;

g.test('ldexpInterval')
.params(u =>
u
.combine('trait', ['f32', 'f16'] as const)
.combine('trait', ['f32', 'f16', 'abstract'] as const)
.beginSubcases()
.expandWithParams<ScalarPairToIntervalCase>(p => {
const trait = FP[p.trait];
const constants = trait.constants();
// prettier-ignore
return [
// always exactly represeantable cases
// always exactly representable cases
{ input: [0, 0], expected: 0 },
{ input: [0, 1], expected: 0 },
{ input: [0, -1], expected: 0 },
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@
"webgpu:shader,execution,expression,call,builtin,inversesqrt:abstract_float:*": { "subcaseMS": 19408.045 },
"webgpu:shader,execution,expression,call,builtin,inversesqrt:f16:*": { "subcaseMS": 21.411 },
"webgpu:shader,execution,expression,call,builtin,inversesqrt:f32:*": { "subcaseMS": 50.125 },
"webgpu:shader,execution,expression,call,builtin,ldexp:abstract_float:*": { "subcaseMS": 106.196 },
"webgpu:shader,execution,expression,call,builtin,ldexp:abstract_float:*": { "subcaseMS": 87.640 },
"webgpu:shader,execution,expression,call,builtin,ldexp:f16:*": { "subcaseMS": 271.038 },
"webgpu:shader,execution,expression,call,builtin,ldexp:f32:*": { "subcaseMS": 161.250 },
"webgpu:shader,execution,expression,call,builtin,length:abstract_float:*": { "subcaseMS": 377.202 },
Expand Down
28 changes: 14 additions & 14 deletions src/webgpu/shader/execution/expression/call/builtin/ldexp.cache.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import { assert } from '../../../../../../common/util/util.js';
import { anyOf } from '../../../../../util/compare.js';
import { i32 } from '../../../../../util/conversion.js';
import { abstractInt, i32 } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { biasedRange, quantizeToI32, sparseI32Range } from '../../../../../util/math.js';
import { Case } from '../../case.js';
import { makeCaseCache } from '../../case_cache.js';

const bias = {
f32: 127,
f16: 15,
} as const;

// ldexpInterval's return interval doesn't cover the flush-to-zero cases when e2 + bias <= 0, thus
// special examination is required.
// See the comment block on ldexpInterval for more details
// e2 is an integer (i32) while e1 is float.
const makeCase = (trait: 'f32' | 'f16', e1: number, e2: number): Case => {
const makeCase = (trait: 'f32' | 'f16' | 'abstract', e1: number, e2: number): Case => {
const FPTrait = FP[trait];
e1 = FPTrait.quantize(e1);
// e2 should be in i32 range for the convinience.
// e2 should be in i32 range for the convenience.
assert(-2147483648 <= e2 && e2 <= 2147483647, 'e2 should be in i32 range');
e2 = quantizeToI32(e2);

const expected = FPTrait.ldexpInterval(e1, e2);

const e2_scalar = trait === 'abstract' ? abstractInt(BigInt(e2)) : i32(e2);
// Result may be zero if e2 + bias <= 0
if (e2 + bias[trait] <= 0) {
if (e2 + FPTrait.constants().bias <= 0) {
return {
input: [FPTrait.scalarBuilder(e1), i32(e2)],
input: [FPTrait.scalarBuilder(e1), e2_scalar],
expected: anyOf(expected, FPTrait.constants().zeroInterval),
};
}

return { input: [FPTrait.scalarBuilder(e1), i32(e2)], expected };
return { input: [FPTrait.scalarBuilder(e1), e2_scalar], expected };
};

// Cases: [f32|f16]_[non_]const
const cases = (['f32', 'f16'] as const)
// Cases: [f32|f16|abstract]_[non_]const
const cases = (['f32', 'f16', 'abstract'] as const)
.flatMap(trait =>
([true, false] as const).map(nonConst => ({
[`${trait}_${nonConst ? 'non_const' : 'const'}`]: () => {
if (nonConst) {
if (trait === 'abstract') {
return [];
}
return FP[trait]
.sparseScalarRange()
.flatMap(e1 => sparseI32Range().map(e2 => makeCase(trait, e1, e2)));
}
const bias = FP[trait].constants().bias;
// const
return FP[trait]
.sparseScalarRange()
.flatMap(e1 =>
biasedRange(-bias[trait] - 10, bias[trait] + 1, 10).flatMap(e2 =>
biasedRange(-bias - 10, bias + 1, 10).flatMap(e2 =>
FP[trait].isFinite(e1 * 2 ** quantizeToI32(e2)) ? makeCase(trait, e1, e2) : []
)
);
Expand Down
Loading
Loading