Skip to content

Commit

Permalink
wgsl: Add AbstractFloat sign execution tests (#3081)
Browse files Browse the repository at this point in the history
Fixes #2582
  • Loading branch information
zoddicus authored Oct 23, 2023
1 parent 3148e15 commit 2499ea9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3647,7 +3647,7 @@ g.test('saturateInterval')
g.test('signInterval')
.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 Down
2 changes: 1 addition & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@
"webgpu:shader,execution,expression,call,builtin,saturate:f32:*": { "subcaseMS": 116.275 },
"webgpu:shader,execution,expression,call,builtin,select:scalar:*": { "subcaseMS": 6.882 },
"webgpu:shader,execution,expression,call,builtin,select:vector:*": { "subcaseMS": 7.096 },
"webgpu:shader,execution,expression,call,builtin,sign:abstract_float:*": { "subcaseMS": 31.708 },
"webgpu:shader,execution,expression,call,builtin,sign:abstract_float:*": { "subcaseMS": 412.925 },
"webgpu:shader,execution,expression,call,builtin,sign:abstract_int:*": { "subcaseMS": 25.806 },
"webgpu:shader,execution,expression,call,builtin,sign:f16:*": { "subcaseMS": 25.103 },
"webgpu:shader,execution,expression,call,builtin,sign:f32:*": { "subcaseMS": 8.188 },
Expand Down
37 changes: 30 additions & 7 deletions src/webgpu/shader/execution/expression/call/builtin/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ Returns the sign of e. Component-wise when T is a vector.

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { i32, TypeF32, TypeF16, TypeI32 } from '../../../../../util/conversion.js';
import {
i32,
TypeF32,
TypeF16,
TypeI32,
TypeAbstractFloat,
} from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { fullF32Range, fullF16Range, fullI32Range } from '../../../../../util/math.js';
import {
fullF32Range,
fullF16Range,
fullI32Range,
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 @@ -26,6 +37,13 @@ export const d = makeCaseCache('sign', {
f16: () => {
return FP.f16.generateScalarToIntervalCases(fullF16Range(), 'unfiltered', FP.f16.signInterval);
},
abstract_float: () => {
return FP.abstract.generateScalarToIntervalCases(
fullF64Range(),
'unfiltered',
FP.abstract.signInterval
);
},
i32: () =>
fullI32Range().map(i => {
const signFunc = (i: number): number => (i < 0 ? -1 : i > 0 ? 1 : 0);
Expand All @@ -37,13 +55,18 @@ g.test('abstract_float')
.specURL('https://www.w3.org/TR/WGSL/#sign-builtin')
.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_float');
await run(t, abstractBuiltin('sign'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases);
});

g.test('abstract_int')
.specURL('https://www.w3.org/TR/WGSL/#sign-builtin')
.desc(`abstract float tests`)
.desc(`abstract int tests`)
.params(u =>
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
)
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 @@ -5070,7 +5070,7 @@ class FPAbstractTraits extends FPTraits {
};
public readonly roundInterval = this.unimplementedScalarToInterval.bind(this, 'roundInterval');
public readonly saturateInterval = this.saturateIntervalImpl.bind(this);
public readonly signInterval = this.unimplementedScalarToInterval.bind(this, 'signInterval');
public readonly signInterval = this.signIntervalImpl.bind(this);
public readonly sinInterval = this.unimplementedScalarToInterval.bind(this, 'sinInterval');
public readonly sinhInterval = this.unimplementedScalarToInterval.bind(this, 'sinhInterval');
public readonly smoothStepInterval = this.unimplementedScalarTripleToInterval.bind(
Expand Down

0 comments on commit 2499ea9

Please sign in to comment.