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

Add AbstractFloat bitcast execution tests. #3299

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Changes from 1 commit
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
Next Next commit
Add AbstractFloat bitcast execution tests.
This CL adds tests for the bitcasting of abstract float values. This
includes:
 * abstract float to f32
 * abstract float to vec2<f16>
 * vec2<abstract-float> to vec4<f16>

Stubs are added for the equivalent AbstractInt tests.
dj2 committed Jan 22, 2024
commit b63726ed54edaad085e98c5cffcb16706def5a0a
2 changes: 1 addition & 1 deletion src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
"webgpu/shader/execution/atan.bin": "30e5cdba",
"webgpu/shader/execution/atan2.bin": "2cb9c01c",
"webgpu/shader/execution/atanh.bin": "cf945e3e",
"webgpu/shader/execution/bitcast.bin": "3a3d8e53",
"webgpu/shader/execution/bitcast.bin": "b905ac02",
"webgpu/shader/execution/ceil.bin": "c89008e0",
"webgpu/shader/execution/clamp.bin": "cf06c601",
"webgpu/shader/execution/cos.bin": "2bbc33",
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { assert } from '../../../../../../common/util/util.js';
import { Comparator, alwaysPass, anyOf } from '../../../../../util/compare.js';
import { kBit, kValue } from '../../../../../util/constants.js';
import { Scalar, Vector, f16, f32, i32, toVector, u32 } from '../../../../../util/conversion.js';
import {
Scalar,
Vector,
f16,
f32,
i32,
toVector,
u32,
abstractFloat,
} from '../../../../../util/conversion.js';
import { FP, FPInterval } from '../../../../../util/floating_point.js';
import {
cartesianProduct,
@@ -690,6 +699,11 @@ export const d = makeCaseCache('bitcast', {
input: f32(e),
expected: bitcastF32ToVec2F16Comparator(e),
})),
af_to_vec2_f16: () =>
f32FiniteRangeForF16Vec2Finite.map(e => ({
input: abstractFloat(e),
expected: bitcastF32ToVec2F16Comparator(e),
})),

// vec2<i32>, vec2<u32>, vec2<f32> to vec4<f16>
vec2_i32_to_vec4_f16_inf_nan: () =>
@@ -722,6 +736,11 @@ export const d = makeCaseCache('bitcast', {
input: toVector(e, f32),
expected: bitcastVec2F32ToVec4F16Comparator(e),
})),
vec2_af_to_vec4_f16: () =>
slidingSlice(f32FiniteRangeForF16Vec2Finite, 2).map(e => ({
input: toVector(e, abstractFloat),
expected: bitcastVec2F32ToVec4F16Comparator(e),
})),

// vec2<f16> to i32, u32, f32
vec2_f16_to_u32: () =>
136 changes: 134 additions & 2 deletions src/webgpu/shader/execution/expression/call/builtin/bitcast.spec.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@ S is i32, u32, f32
T is i32, u32, f32, and T is not S
Reinterpretation of bits. Beware non-normal f32 values.

@const @must_use fn bitcast<u32>(e : AbstractInt) -> T
@const @must_use fn bitcast<vecN<u32>>(e : vecN<AbstractInt>) -> T

@const @must_use fn bitcast<T>(e: vec2<f16> ) -> T
@const @must_use fn bitcast<vec2<T>>(e: vec4<f16> ) -> vec2<T>
@const @must_use fn bitcast<vec2<f16>>(e: T ) -> vec2<f16>
@@ -21,8 +24,18 @@ T is i32, u32, f32
import { TestParams } from '../../../../../../common/framework/fixture.js';
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { TypeF16, TypeF32, TypeI32, TypeU32, TypeVec } from '../../../../../util/conversion.js';
import { ShaderBuilder, allInputSources, run } from '../../expression.js';
import {
TypeF16,
TypeF32,
TypeI32,
TypeU32,
TypeVec,
TypeAbstractFloat,
f32,
abstractFloat,
} from '../../../../../util/conversion.js';
import { scalarF32Range } from '../../../../../util/math.js';
import { ShaderBuilder, allInputSources, onlyConstInputSource, run } from '../../expression.js';

import { d } from './bitcast.cache.js';
import { builtinWithPredeclaration } from './builtin.js';
@@ -465,3 +478,122 @@ g.test('vec4h_to_vec2f')
cases
);
});

// Abstract Float
g.test('af_to_f32')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract float to f32 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = scalarF32Range().map(u => {
return { input: abstractFloat(u), expected: f32(u) };
});

await run(t, bitcastBuilder('f32', t.params), [TypeAbstractFloat], TypeF32, t.params, cases);
});

g.test('af_to_vec2f16')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract float to f16 tests`)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase('shader-f16');
})
.params(u => u.combine('inputSource', onlyConstInputSource))
.fn(async t => {
const cases = await d.get('af_to_vec2_f16');

await run(
t,
bitcastBuilder('vec2<f16>', t.params),
[TypeAbstractFloat],
TypeVec(2, TypeF16),
t.params,
cases
);
});

g.test('vec2af_to_vec4f16')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract float to f16 tests`)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase('shader-f16');
})
.params(u => u.combine('inputSource', onlyConstInputSource))
.fn(async t => {
const cases = await d.get('vec2_af_to_vec4_f16');

await run(
t,
bitcastBuilder('vec4<f16>', t.params),
[TypeVec(2, TypeAbstractFloat)],
TypeVec(4, TypeF16),
t.params,
cases
);
});

// Abstract Int

// bitcast<i32>(12)
// - cases: scalarI32Range
g.test('ai_to_i32')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract int to i32 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();

// bitcast<u32>(12)
// - cases: scalarU32Range
g.test('ai_to_u32')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract int to u32 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();

// bitcast<f32>(12)
// - cases: scalarF32Range
g.test('ai_to_f32')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract flointat to f32 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();

// bitcast<vec2<f16>>(12)
// - cases: scalarF16Range
g.test('ai_to_vec2f16')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast abstract int to vec2f16 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();

// bitcast<vec4<f16>>(vec2(12, 12))
// - cases: sparseVectorF16Range
g.test('vec2ai_to_vec4f16')
.specURL('https://www.w3.org/TR/WGSL/#bitcast-builtin')
.desc(`bitcast vec2ai to vec4f16 tests`)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.unimplemented();