Skip to content

Commit

Permalink
wgsl: Add AbstractFloat floor execution tests (#3084)
Browse files Browse the repository at this point in the history
Issue #1297
  • Loading branch information
zoddicus authored Oct 24, 2023
1 parent 3fe36f2 commit d491499
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
12 changes: 10 additions & 2 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarToIntervalCase>(p => {
const constants = FP[p.trait].constants();
Expand All @@ -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] },
Expand Down
60 changes: 28 additions & 32 deletions src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
27 changes: 21 additions & 6 deletions src/webgpu/shader/execution/expression/call/builtin/round.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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')
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 @@ -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(
Expand Down

0 comments on commit d491499

Please sign in to comment.