From d4914999a0cb5cb9877f5037aa051582dd74a78e Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 24 Oct 2023 11:03:58 -0400 Subject: [PATCH] wgsl: Add AbstractFloat `floor` execution tests (#3084) Issue #1297 --- src/unittests/floating_point.spec.ts | 12 +++- .../expression/call/builtin/floor.spec.ts | 60 +++++++++---------- .../expression/call/builtin/round.spec.ts | 27 +++++++-- src/webgpu/util/floating_point.ts | 2 +- 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/unittests/floating_point.spec.ts b/src/unittests/floating_point.spec.ts index 052ee84bc6d4..3d73d4254577 100644 --- a/src/unittests/floating_point.spec.ts +++ b/src/unittests/floating_point.spec.ts @@ -3026,12 +3026,20 @@ const kFloorIntervalCases = { { input: -(2 ** 14), expected: -(2 ** 14) }, { input: 0x8000, expected: 0x8000 }, // https://github.com/gpuweb/cts/issues/2766 ], + abstract: [ + { input: 2 ** 62, expected: 2 ** 62 }, + { input: -(2 ** 62), expected: -(2 ** 62) }, + { + input: 0x8000_0000_0000_0000, + expected: 0x8000_0000_0000_0000, + }, // https://github.com/gpuweb/cts/issues/2766 + ], } as const; g.test('floorInterval') .params(u => u - .combine('trait', ['f32', 'f16'] as const) + .combine('trait', ['f32', 'f16', 'abstract'] as const) .beginSubcases() .expandWithParams(p => { const constants = FP[p.trait].constants(); @@ -3058,7 +3066,7 @@ g.test('floorInterval') { input: constants.negative.max, expected: -1 }, ...kFloorIntervalCases[p.trait], - // 32-bit subnormals + // Subnormals { input: constants.positive.subnormal.max, expected: 0 }, { input: constants.positive.subnormal.min, expected: 0 }, { input: constants.negative.subnormal.min, expected: [-1, 0] }, diff --git a/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts index 9dd7f3f9a8cf..873a6772c360 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts @@ -9,34 +9,25 @@ Returns the floor of e. Component-wise when T is a vector. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../../gpu_test.js'; -import { TypeF32, TypeF16 } from '../../../../../util/conversion.js'; +import { TypeF32, TypeF16, TypeAbstractFloat } from '../../../../../util/conversion.js'; import { FP } from '../../../../../util/floating_point.js'; -import { fullF32Range, fullF16Range } from '../../../../../util/math.js'; +import { fullF32Range, fullF16Range, fullF64Range } from '../../../../../util/math.js'; import { makeCaseCache } from '../../case_cache.js'; -import { allInputSources, run } from '../../expression.js'; +import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { builtin } from './builtin.js'; +import { abstractBuiltin, builtin } from './builtin.js'; export const g = makeTestGroup(GPUTest); +const kSmallMagnitudeTestValues = [0.1, 0.9, 1.0, 1.1, 1.9, -0.1, -0.9, -1.0, -1.1, -1.9]; + export const d = makeCaseCache('floor', { f32: () => { return FP.f32.generateScalarToIntervalCases( [ - // Small positive numbers - 0.1, - 0.9, - 1.0, - 1.1, - 1.9, - // Small negative numbers - -0.1, - -0.9, - -1.0, - -1.1, - -1.9, - 0x80000000, // https://github.com/gpuweb/cts/issues/2766 + ...kSmallMagnitudeTestValues, ...fullF32Range(), + 0x8000_0000, // https://github.com/gpuweb/cts/issues/2766 ], 'unfiltered', FP.f32.floorInterval @@ -45,34 +36,39 @@ export const d = makeCaseCache('floor', { f16: () => { return FP.f16.generateScalarToIntervalCases( [ - // Small positive numbers - 0.1, - 0.9, - 1.0, - 1.1, - 1.9, - // Small negative numbers - -0.1, - -0.9, - -1.0, - -1.1, - -1.9, - 0x8000, // https://github.com/gpuweb/cts/issues/2766 + ...kSmallMagnitudeTestValues, ...fullF16Range(), + 0x8000, // https://github.com/gpuweb/cts/issues/2766 ], 'unfiltered', FP.f16.floorInterval ); }, + abstract: () => { + return FP.abstract.generateScalarToIntervalCases( + [ + ...kSmallMagnitudeTestValues, + ...fullF64Range(), + 0x8000_0000_0000_0000, // https://github.com/gpuweb/cts/issues/2766 + ], + 'unfiltered', + FP.abstract.floorInterval + ); + }, }); g.test('abstract_float') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') .desc(`abstract float tests`) .params(u => - u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const) + u + .combine('inputSource', onlyConstInputSource) + .combine('vectorize', [undefined, 2, 3, 4] as const) ) - .unimplemented(); + .fn(async t => { + const cases = await d.get('abstract'); + await run(t, abstractBuiltin('floor'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + }); g.test('f32') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') diff --git a/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts index bd40ed4b2a3e..fe81af632660 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts @@ -12,13 +12,13 @@ Component-wise when T is a vector. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../../gpu_test.js'; -import { TypeF32, TypeF16 } from '../../../../../util/conversion.js'; +import { TypeF32, TypeF16, TypeAbstractFloat } from '../../../../../util/conversion.js'; import { FP } from '../../../../../util/floating_point.js'; -import { fullF32Range, fullF16Range } from '../../../../../util/math.js'; +import { fullF32Range, fullF16Range, fullF64Range } from '../../../../../util/math.js'; import { makeCaseCache } from '../../case_cache.js'; -import { allInputSources, run } from '../../expression.js'; +import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { builtin } from './builtin.js'; +import { abstractBuiltin, builtin } from './builtin.js'; export const g = makeTestGroup(GPUTest); @@ -43,15 +43,30 @@ export const d = makeCaseCache('round', { FP.f16.roundInterval ); }, + abstract: () => { + return FP.abstract.generateScalarToIntervalCases( + [ + 0x8000_0000_0000_0000, // https://github.com/gpuweb/cts/issues/2766 + ...fullF64Range(), + ], + 'unfiltered', + FP.abstract.roundInterval + ); + }, }); g.test('abstract_float') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') .desc(`abstract float tests`) .params(u => - u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const) + u + .combine('inputSource', onlyConstInputSource) + .combine('vectorize', [undefined, 2, 3, 4] as const) ) - .unimplemented(); + .fn(async t => { + const cases = await d.get('abstract'); + await run(t, abstractBuiltin('round'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + }); g.test('f32') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') diff --git a/src/webgpu/util/floating_point.ts b/src/webgpu/util/floating_point.ts index 4d2f9a324cb5..20f74483df31 100644 --- a/src/webgpu/util/floating_point.ts +++ b/src/webgpu/util/floating_point.ts @@ -5002,7 +5002,7 @@ class FPAbstractTraits extends FPTraits { public readonly expInterval = this.unimplementedScalarToInterval.bind(this, 'expInterval'); public readonly exp2Interval = this.unimplementedScalarToInterval.bind(this, 'exp2Interval'); public readonly faceForwardIntervals = this.unimplementedFaceForward.bind(this); - public readonly floorInterval = this.unimplementedScalarToInterval.bind(this, 'floorInterval'); + public readonly floorInterval = this.floorIntervalImpl.bind(this); public readonly fmaInterval = this.fmaIntervalImpl.bind(this); public readonly fractInterval = this.unimplementedScalarToInterval.bind(this, 'fractInterval'); public readonly inverseSqrtInterval = this.unimplementedScalarToInterval.bind(