8000 Fix nan check on 16bit precision in triangular solve. by yhmtsai · Pull Request #1860 · ginkgo-project/ginkgo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix nan check on 16bit precision in triangular solve. #1860

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

Merged
merged 2 commits into from
Jun 9, 2025

Conversation

yhmtsai
Copy link
Member
@yhmtsai yhmtsai commented Jun 8, 2025

We use the nan to check the status of dependence by checking the same bit representation as gko::nan (quiet_NaN) in #1665

This PR contains two parts:

  1. device half, bfloat16 are checked by gko::nan<gko::half> and gko::nan<gko::bfloat16>, which is the value we initialize in the x vector.
  2. is_nan_exact check on the orignial type because the casting can give not the same kind of quiet NaN or different precision can use different kind of NaN.

There is no specification for quiet NaN in IEEE more than exponent field is filled by 1 and the significant field != 0

Note. the first one can also be done by add quiet_NaN into device_numeric_limit and add test ensuring they are identical between device and host. However, the current value of quiet NaN of gko::half might be conflict with one of sycl::half. Or different compiler might also give different quiet_NaN. It needs more t 8000 ime to check the consistence, so I put the fix only under is_nan_exact now

@yhmtsai yhmtsai added this to the Ginkgo 1.10.0 milestone Jun 8, 2025
@yhmtsai yhmtsai requested review from upsj and MarcelKoch June 8, 2025 20:14
@yhmtsai yhmtsai self-assigned this Jun 8, 2025
@yhmtsai yhmtsai added the is:bugfix This fixes a bug label Jun 8, 2025
@ginkgo-bot ginkgo-bot added mod:cuda This is related to the CUDA module. type:solver This is related to the solvers labels Jun 8, 2025
@yhmtsai yhmtsai force-pushed the fix_trs_nan_check branch from c38d506 to 0d97768 Compare June 8, 2025 20:26
@yhmtsai yhmtsai added 1:ST:ready-for-review This PR is ready for review 1:ST:run-full-test labels Jun 8, 2025
Copy link
Member
@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

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

I would suggest a slightly different approach. However, I would also be fine with the current one, if there are issues with my suggestion.

while (is_nan_exact(
val = load_relaxed(x + dependency * x_stride + rhs))) {
output_val = load_relaxed(x + dependency * x_stride + rhs))) {
Copy link
Member

Choose a reason for hiding this comment

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

Since the conversions are the issue here, I would propose a slightly different approach:

  1. Make sure that x stores the bit-wise exact nan value of SharedValueType, via memcpy.
  2. Use a function bitwise_equal(a, b), where a is the loaded value and b the expected nan value.

I think this could make it a bit clearer what is happening, and not use the gko<half|bfloat> types internally.

Copy link
Member Author
@yhmtsai yhmtsai Jun 8, 2025

Choose a reason for hiding this comment

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

Maybe I get the first point wrong. x is stored exact nan value because we fill it by gko::nan<ValueType> and x_shared is stored by gko::nan<SharedValueType>. We do not have the casting during assignment.

I think bitwise_equal(a, b) indeed makes the comparison value more clear. (or we can make it more clear/consistent what the exact nan among different backend/compiler)
Unfortunately, we do not have the host_type map currently to do bitwise_eqaul(a, nan<host_type<T>>) and I would not like to introduce another type mapping in short time of notice.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, I guess it was getting a bit late for me. Could an alternative be to fill the x with gko::nan<device_type<ValueType>> already? I will still approve this, just curious.

Copy link
Member Author

Choose a reason for hiding this comment

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

no, at least not a small change. Postponing it to later such that we do not rush with a mistake.
gko::nan will call std::numeric_limits<>::quiet_NaN, which is only a default value on device type (usually 0).
Thus, it needs to specialize that on the device type or specialize gko::nan on device/math.
I think ensuring that quiet_NaN in device_numeric_limits on device type can give the same value as std::numeric_limits on host type might be more consistent.
Filling some value with device_type value is a bit weird to me unless we use another kernel to fill the value in the kernel directly not set the value from host.

@yhmtsai yhmtsai requested a review from MarcelKoch June 9, 2025 07:19
@yhmtsai yhmtsai added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Jun 9, 2025
@yhmtsai yhmtsai force-pushed the fix_trs_nan_check branch from 0d97768 to ed2fac8 Compare June 9, 2025 09:11
@yhmtsai yhmtsai merged commit 3993421 into develop Jun 9, 2025
12 of 15 checks passed
@yhmtsai yhmtsai deleted the fix_trs_nan_check branch June 9, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-to-merge This PR is ready to merge. 1:ST:run-full-test is:bugfix This fixes a bug mod:cuda This is related to the CUDA module. type:solver This is related to the solvers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0