Skip to content

Floating point accuracy for sin and cos with range constraint #914

@philloooo

Description

@philloooo

It looks like currently we don't define the accuracy of floating point operations.

I am running into an issue with the cos and sin web platform tests:

  • WGSL spec defines floating point accuracy for some built-in functions.
  • For cos, and sin , the allowed error is at most 2**-11 for fp32 and 2**-7 for fp16. However it's only for values within [-π, π]
  • Our WPTs contains inputs outside of the range.

So currently some fp16 tests are failing in some bots for tflite gpu backend with output diff greater than 2**-7.

I think we can either:
a. align with the WGSL spec, so no guarantee for inputs outside of [-π, π]. And update the WPTs.
b. using the periodicity of the cos/sin function, perform range reduction by emulation before calling cos.

@fdwr @huningxin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions