1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
export const description = `
Execution Tests for non-matrix f16 division expression
`;
import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { TypeF16, TypeVec } from '../../../../util/conversion.js';
import { FP, FPVector } from '../../../../util/floating_point.js';
import { sparseF16Range, sparseVectorF16Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';
import { allInputSources, run } from '../expression.js';
import { binary, compoundBinary } from './binary.js';
const divisionVectorScalarInterval = (v: readonly number[], s: number): FPVector => {
return FP.f16.toVector(v.map(e => FP.f16.divisionInterval(e, s)));
};
const divisionScalarVectorInterval = (s: number, v: readonly number[]): FPVector => {
return FP.f16.toVector(v.map(e => FP.f16.divisionInterval(s, e)));
};
export const g = makeTestGroup(GPUTest);
const scalar_cases = ([true, false] as const)
.map(nonConst => ({
[`scalar_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f16.generateScalarPairToIntervalCases(
sparseF16Range(),
sparseF16Range(),
nonConst ? 'unfiltered' : 'finite',
FP.f16.divisionInterval
);
},
}))
.reduce((a, b) => ({ ...a, ...b }), {});
const vector_scalar_cases = ([2, 3, 4] as const)
.flatMap(dim =>
([true, false] as const).map(nonConst => ({
[`vec${dim}_scalar_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f16.generateVectorScalarToVectorCases(
sparseVectorF16Range(dim),
sparseF16Range(),
nonConst ? 'unfiltered' : 'finite',
divisionVectorScalarInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});
const scalar_vector_cases = ([2, 3, 4] as const)
.flatMap(dim =>
([true, false] as const).map(nonConst => ({
[`scalar_vec${dim}_${nonConst ? 'non_const' : 'const'}`]: () => {
return FP.f16.generateScalarVectorToVectorCases(
sparseF16Range(),
sparseVectorF16Range(dim),
nonConst ? 'unfiltered' : 'finite',
divisionScalarVectorInterval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});
export const d = makeCaseCache('binary/f16_division', {
...scalar_cases,
...vector_scalar_cases,
...scalar_vector_cases,
});
g.test('scalar')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x / y, where x and y are scalars
Accuracy: 2.5 ULP for |y| in the range [2^-126, 2^126]
`
)
.params(u => u.combine('inputSource', allInputSources))
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const cases = await d.get(
t.params.inputSource === 'const' ? 'scalar_const' : 'scalar_non_const'
);
await run(t, binary('/'), [TypeF16, TypeF16], TypeF16, t.params, cases);
});
g.test('vector')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x / y, where x and y are vectors
Accuracy: 2.5 ULP for |y| in the range [2^-126, 2^126]
`
)
.params(u => u.combine('inputSource', allInputSources).combine('vectorize', [2, 3, 4] as const))
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const cases = await d.get(
t.params.inputSource === 'const' ? 'scalar_const' : 'scalar_non_const' // Using vectorize to generate vector cases based on scalar cases
);
await run(t, binary('/'), [TypeF16, TypeF16], TypeF16, t.params, cases);
});
g.test('scalar_compound')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x /= y
Accuracy: 2.5 ULP for |y| in the range [2^-126, 2^126]
`
)
.params(u =>
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
)
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const cases = await d.get(
t.params.inputSource === 'const' ? 'scalar_const' : 'scalar_non_const'
);
await run(t, compoundBinary('/='), [TypeF16, TypeF16], TypeF16, t.params, cases);
});
g.test('vector_scalar')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x / y, where x is a vector and y is a scalar
Accuracy: Correctly rounded
`
)
.params(u => u.combine('inputSource', allInputSources).combine('dim', [2, 3, 4] as const))
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const dim = t.params.dim;
const cases = await d.get(
t.params.inputSource === 'const' ? `vec${dim}_scalar_const` : `vec${dim}_scalar_non_const`
);
await run(
t,
binary('/'),
[TypeVec(dim, TypeF16), TypeF16],
TypeVec(dim, TypeF16),
t.params,
cases
);
});
g.test('vector_scalar_compound')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x /= y, where x is a vector and y is a scalar
Accuracy: Correctly rounded
`
)
.params(u => u.combine('inputSource', allInputSources).combine('dim', [2, 3, 4] as const))
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const dim = t.params.dim;
const cases = await d.get(
t.params.inputSource === 'const' ? `vec${dim}_scalar_const` : `vec${dim}_scalar_non_const`
);
await run(
t,
compoundBinary('/='),
[TypeVec(dim, TypeF16), TypeF16],
TypeVec(dim, TypeF16),
t.params,
cases
);
});
g.test('scalar_vector')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.desc(
`
Expression: x / y, where x is a scalar and y is a vector
Accuracy: Correctly rounded
`
)
.params(u => u.combine('inputSource', allInputSources).combine('dim', [2, 3, 4] as const))
.beforeAllSubcases(t => {
t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
})
.fn(async t => {
const dim = t.params.dim;
const cases = await d.get(
t.params.inputSource === 'const' ? `scalar_vec${dim}_const` : `scalar_vec${dim}_non_const`
);
await run(
t,
binary('/'),
[TypeF16, TypeVec(dim, TypeF16)],
TypeVec(dim, TypeF16),
t.params,
cases
);
});
|