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

Builtin function precision is backend specific #511

Merged

Conversation

gmlueck
Copy link
Contributor

@gmlueck gmlueck commented Nov 30, 2023

Resolve conflicting wording about the precision requirements of the builtin math functions. The introductory paragraph of section 4.17 "SYCL built-in functions for SYCL host and device" says that the precision is defined by the backend. However, the descriptions in section 4.17.4 "Math functions" and 4.17.6 "Half precision math functions" specified a required precision for all backends. Resolve this by removing the the wording in 4.17.4 and 4.17.6. (See issue #507 for more on this.)

Also add a new section to the OpenCL backend specification stating that the precision of these builtin math functions for the OpenCL backend matches the precision of the corresponding functions in the OpenCL specification.

There are a few other related changes in this PR:

Closes #507
Closes #509

Resolve conflicting wording about the precision requirements of the
builtin math functions.  The introductory paragraph of section 4.17
"SYCL built-in functions for SYCL host and device" says that the
precision is defined by the backend.  However, the descriptions in
section 4.17.4 "Math functions" and 4.17.6 "Half precision math
functions" specified a required precision for all backends.  Resolve
this by removing the the wording in 4.17.4 and 4.17.6.  (See issue KhronosGroup#507
for more on this.)

Also add a new section to the OpenCL backend specification stating that
the precision of these builtin math functions for the OpenCL backend
matches the precision of the corresponding functions in the OpenCL
specification.

There are a few other related changes in this PR:

* Clarify that the native precision and half precision functions are
  available in both host and device code (see issue KhronosGroup#509).

* Remove a statement that the geometric functions use round to nearest
  even rounding mode.  This also seems backend specific, and it doesn't
  even make sense for the OpenCL backend.  See OpenCL issue
  KhronosGroup/OpenCL-Docs#1024 for more details on this.

* Editorial changes to remove gratuitous references to OpenCL in the
  introductory paragraphs.

* Editorial changes to make the introductions of sections 4.17.4 -
  4.17.10 read consistently.

Closes KhronosGroup#507
Closes KhronosGroup#509
@gmlueck
Copy link
Contributor Author

gmlueck commented Dec 14, 2023

Call for reviewers here ...

Copy link
Collaborator

@AerialMantis AerialMantis 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, just one comment about the meaning of the native vs regular math functions, now that we don't specify any precision requirements in the core specification.

namespace [code]#sycl::native#.
The functions that are available within this namespace are specified in
<<table.native.math.functions>>.
<<table.native.math.functions>> describes the native precision math functions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we describe the functions in the native namespace as native precision math functions, but if we are removing the precision requirement of the regular math functions, this term becomes less meaningful. Maybe we should introduce some wording which states that the regular math functions are intended to be precise, whereas the native math functions are intended to be faster at the cost of precision, even as a non-normative note?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that makes sense. I can add a paragraph similar to the one I added below for the half-precision functions. I'll have to think how to differentiate the half-precision functions from the native-precision ones, though. They are both defined by the backend and both trade off precision for performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I addressed this in 56196d2.

@gmlueck
Copy link
Contributor Author

gmlueck commented Dec 14, 2023

  • Do native and half-precision functions guarantee the same range of input values as the normal functions? E.g. infinity and NaN.

gmlueck and others added 2 commits December 21, 2023 16:13
Better clarify the intent of the `sycl::native` and
`sycl::half_precision` math functions.
@gmlueck
Copy link
Contributor Author

gmlueck commented Dec 21, 2023

Do native and half-precision functions guarantee the same range of input values as the normal functions? E.g. infinity and NaN.

I looked at the OpenCL C specification to see how they define the half-precision functions. The only limitation I saw on input values was for cos, sin, and tan. These functions all say that the input must be in the range [-216, +216], and that same limitation is in the SYCL specification. According to OpenCL C, the half-precision functions must support NaN and INF, which is the same for the regular math functions.

I don't think we need to say anything more about legal input values in the SYCL spec.

Copy link
Member

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Thanks.

@tomdeakin
Copy link
Contributor

WG approved to merge.

@gmlueck gmlueck merged commit e0486e5 into KhronosGroup:SYCL-2020/master Jan 11, 2024
1 check passed
@gmlueck gmlueck deleted the gmlueck/builtin-precision branch January 11, 2024 21:28
AlexeySachkov added a commit to AlexeySachkov/SYCL-CTS that referenced this pull request Feb 1, 2024
KhronosGroup/SYCL-Docs#511 essentially removed any precision guarantees for
math built-ins invoked on host and this PR aligns CTS with that
direction.
keryell pushed a commit that referenced this pull request Sep 10, 2024
Builtin function precision is backend specific
gmlueck added a commit that referenced this pull request Nov 7, 2024
Builtin function precision is backend specific

(cherry picked from commit e0486e5)
gmlueck added a commit that referenced this pull request Nov 7, 2024
Builtin function precision is backend specific

(cherry picked from commit e0486e5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants