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

wgsl: Add AF Division execution tests #3074

Merged
merged 4 commits into from
Oct 23, 2023
Merged

Conversation

zoddicus
Copy link
Contributor

Adds in forwarding of ULP and division interval calls to f32 for abstract

Issue #1626


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

Adds in forwarding of ULP and division interval calls to f32 for
abstract

Issue gpuweb#1626
@zoddicus zoddicus added the wgsl label Oct 19, 2023
@zoddicus zoddicus self-assigned this Oct 19, 2023
@github-actions
Copy link

Previews, as seen when this build job started (f58eab5):
Run tests | View tsdoc

This allows for removing wrapper utilities and directly use arrow
functions instead.
@github-actions
Copy link

Previews, as seen when this build job started (bf48a54):
Run tests | View tsdoc

zoddicus added a commit to zoddicus/cts that referenced this pull request Oct 19, 2023
Copy link
Contributor

@jiangzhaoming jiangzhaoming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks

const constants = this.constants();
const domain_x = [this.toInterval([constants.negative.min, constants.positive.max])];
const domain_y =
this.kind === 'f32'
this.kind === 'f32' || this.kind === 'abstract'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By using the same domain_y for af and f32, the division interval op will return unbounded interval for af in the wide range of normal af number that out of f32 range.

But since the spec didn't mention what to expect in that range for af, this would be OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thank you for reading this very closely.

The thinking is that we don't want WGSL to specify anything more strict than ECMAScript, and ECMAScript does not specify much in terms of ULP. On the other hand, we also don't want AbstractFloat to be worse than f32.

['scalar']: () => {
return FP.abstract.generateScalarPairToIntervalCases(
sparseF64Range(),
sparseF64Range(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some data point in this range may be out of domain_y of division interval operation, and result in unbounded expectation. Good thing is that this won't cause false error.

m.every(c => c.length === r),
`Unexpectedly received jagged array to map`
);
for (let i = 0; i < c; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the following be better?

  return m.every(col => col.every(el => op(el)));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const minusOneULP = kMinusOneULPFunctions[p.trait];
const minusNULP = kMinusNULPFunctions[p.trait];
// For ULP purposes, abstract float behaves like f32, so swizzling it in.
const trait = p.trait === 'abstract' ? 'f32' : p.trait;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about introducing some kind of FP mapping dictionary for ULP propose, instead of using ?: in multiple places?

Something in the file scope like

// For ULP purposes, abstract float behaves like f32, so swizzling it in.
const kFPTraitForULP = {
  abstract: 'f32',
  f32: 'f32',
  f16: 'f16',
} as const;

and then use e.g.

        const constants = FP[kFPTraitForULP[p.trait]].constants();
        const ULPValue = kULPErrorValue[kFPTraitForULP[p.trait]];
        const plusOneULP = kPlusOneULPFunctions[kFPTraitForULP[p.trait]];
        const plusNULP = kPlusNULPFunctions[kFPTraitForULP[p.trait]];
        const minusOneULP = kMinusOneULPFunctions[kFPTraitForULP[p.trait]];
        const minusNULP = kMinusNULPFunctions[kFPTraitForULP[p.trait]];

or

        const trait = kFPTraitForULP[p.trait];
        const constants = FP[trait].constants();
        const ULPValue = kULPErrorValue[trait];
        const plusOneULP = kPlusOneULPFunctions[trait];
        const plusNULP = kPlusNULPFunctions[trait];
        const minusOneULP = kMinusOneULPFunctions[trait];
        const minusNULP = kMinusNULPFunctions[trait];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const constants = this.constants();
const domain_x = [this.toInterval([constants.negative.min, constants.positive.max])];
const domain_y =
this.kind === 'f32'
this.kind === 'f32' || this.kind === 'abstract'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thank you for reading this very closely.

The thinking is that we don't want WGSL to specify anything more strict than ECMAScript, and ECMAScript does not specify much in terms of ULP. On the other hand, we also don't want AbstractFloat to be worse than f32.

m.every(c => c.length === r),
`Unexpectedly received jagged array to map`
);
for (let i = 0; i < c; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. :-)

@github-actions
Copy link

Previews, as seen when this build job started (13b3ec7):
Run tests | View tsdoc

@zoddicus zoddicus merged commit c2d5b05 into gpuweb:main Oct 23, 2023
2 checks passed
@zoddicus zoddicus deleted the addAFDivisonTests branch October 23, 2023 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants