Skip to content

Commit

Permalink
wgsl: Implement AbstractInt comparison execution tests
Browse files Browse the repository at this point in the history
Fixes #1627
  • Loading branch information
zoddicus committed Feb 28, 2024
1 parent 0a3a99b commit ecac2f9
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"webgpu/shader/execution/unary/u32_conversion.bin": "579a043f",
"webgpu/shader/execution/unary/ai_assignment.bin": "954223ff",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "6c440be0",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "e89e9e9"
"webgpu/shader/execution/unary/ai_arithmetic.bin": "e89e9e9",
"webgpu/shader/execution/binary/ai_comparison.bin": "6d1aa87b"
}
Binary file not shown.
21 changes: 21 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,27 @@
"webgpu:idl,constructable:gpu_errors:*": { "subcaseMS": 0.101 },
"webgpu:idl,constructable:pipeline_errors:*": { "subcaseMS": 0.101 },
"webgpu:idl,constructable:uncaptured_error_event:*": { "subcaseMS": 0.101 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:remainder:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:remainder_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:remainder_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:equals:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:greater_equals:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:greater_than:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:less_equals:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:less_than:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_comparison:not_equals:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,af_addition:scalar:*": { "subcaseMS": 815.300 },
"webgpu:shader,execution,expression,binary,af_addition:scalar_vector:*": { "subcaseMS": 1803.434 },
"webgpu:shader,execution,expression,binary,af_addition:vector:*": { "subcaseMS": 719.600 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { abstractInt, bool } from '../../../../util/conversion.js';
import { vectorI64Range } from '../../../../util/math.js';
import { Case } from '../case.js';
import { makeCaseCache } from '../case_cache.js';

/**
* @returns a test case for the provided left hand & right hand values and
* expected boolean result.
*/
function makeCase(lhs: bigint, rhs: bigint, expected_answer: boolean): Case {
return { input: [abstractInt(lhs), abstractInt(rhs)], expected: bool(expected_answer) };
}

export const d = makeCaseCache('binary/ai_comparison', {
equals: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] === v[1])),
not_equals: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] !== v[1])),
less_than: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] < v[1])),
less_equal: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] <= v[1])),
greater_than: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] > v[1])),
greater_equal: () => vectorI64Range(2).map(v => makeCase(v[0], v[1], v[0] >= v[1])),
});
115 changes: 115 additions & 0 deletions src/webgpu/shader/execution/expression/binary/ai_comparison.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
export const description = `
Execution Tests for the abstract int comparison expressions
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { TypeBool, TypeAbstractInt } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './ai_comparison.cache.js';
import { binary } from './binary.js';

export const g = makeTestGroup(GPUTest);

g.test('equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x == y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('equals');
await run(t, binary('=='), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

g.test('not_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x != y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('not_equals');
await run(t, binary('!='), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

g.test('less_than')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x < y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('less_than');
await run(t, binary('<'), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

g.test('less_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x <= y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('less_equal');
await run(t, binary('<='), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

g.test('greater_than')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x > y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('greater_than');
await run(t, binary('>'), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

g.test('greater_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x >= y
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('greater_equal');
await run(t, binary('>='), [TypeAbstractInt, TypeAbstractInt], TypeBool, t.params, cases);
});

0 comments on commit ecac2f9

Please sign in to comment.