-
Notifications
You must be signed in to change notification settings - Fork 15k
[libclc] Refine __clc_fp*_subnormals_supported and __clc_flush_denormal_if_not_supported #157633
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
7e2d210
96ec9dc
d52fcdb
4608f77
3f665ce
7b290a2
3da9705
7d21a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,6 @@ | |
|
|
||
| #include <clc/clc_as_type.h> | ||
| #include <clc/clcfunc.h> | ||
| #include <clc/math/clc_subnormal_config.h> | ||
|
|
||
| #define SNAN 0x001 | ||
| #define QNAN 0x002 | ||
|
|
@@ -66,13 +65,11 @@ bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void); | |
| #define LOG_MAGIC_NUM_SP32 (1 + NUMEXPBITS_SP32 - EXPBIAS_SP32) | ||
|
|
||
| _CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) { | ||
| int ix = __clc_as_int(x); | ||
| if (!__clc_fp32_subnormals_supported() && ((ix & EXPBITS_SP32) == 0) && | ||
| ((ix & MANTBITS_SP32) != 0)) { | ||
| ix &= SIGNBIT_SP32; | ||
| x = __clc_as_float(ix); | ||
| } | ||
| return x; | ||
| // Avoid calling __clc_fp32_subnormals_supported here: it uses | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might have less trouble just using canonicalize for now and trying to relax it later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
do you mean reverting __clc_soft_flush_denormal to use __clc_fp32_subnormals_supported which uses llvm.canonicalize, or just replacing use of __clc_fp32_subnormals_supported with __builtin_elementwise_canonicalize? |
||
| // llvm.canonicalize, which quiets sNaN. | ||
| return __builtin_fabsf(x) < 0x1p-149f | ||
| ? __builtin_elementwise_copysign(0.0f, x) | ||
| : x; | ||
|
Comment on lines
59
to
63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function no longer matches the name or behavior. This is an unconditional flush to zero There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If denormal is not supported
If denormal is supported
So this function only flushes to zero if denormal is not supported, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no support check here. Also you can use __builtin_elementwise_abs to be consistently using elementwise builtins There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
thanks @arsenm. Now I see what you mean. Renamed __clc_flush_denormal_if_not_supported to __clc_soft_flush_denormal in 3f665ce and use __builtin_elementwise_abs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is now right, but the usage is not. You do not want to unconditionally force a denormal flush, pretty much anywhere. I also believe most of the explicit flushes / canonicalizes in the math function implementations can be deleted with some shuffling around. I removed most of these in the rocm-device-libs implementations a few years ago. A few more remain but I believe they can also be avoided |
||
| } | ||
|
|
||
| #ifdef cl_khr_fp64 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <clc/internal/clc.h> | ||
| #include <clc/math/clc_subnormal_config.h> | ||
|
|
||
| #ifdef cl_khr_fp16 | ||
| #pragma OPENCL EXTENSION cl_khr_fp16 : enable | ||
| _CLC_DEF bool __clc_fp16_subnormals_supported() { | ||
| #ifdef CLC_SPIRV | ||
| // SPIR-V doesn't support llvm.canonicalize for now. | ||
| return false; | ||
| #else | ||
| return !__builtin_isfpclass(__builtin_elementwise_canonicalize(0x1p-24h), | ||
| __FPCLASS_POSZERO); | ||
| #endif | ||
| } | ||
| #endif // cl_khr_fp16 | ||
|
|
||
| _CLC_DEF bool __clc_fp32_subnormals_supported() { | ||
| #ifdef CLC_SPIRV | ||
| // SPIR-V doesn't support llvm.canonicalize for now. | ||
| return false; | ||
| #else | ||
| return !__builtin_isfpclass(__builtin_elementwise_canonicalize(0x1p-149f), | ||
| __FPCLASS_POSZERO); | ||
| #endif | ||
| } | ||
|
|
||
| #ifdef cl_khr_fp64 | ||
| #pragma OPENCL EXTENSION cl_khr_fp64 : enable | ||
| _CLC_DEF bool __clc_fp64_subnormals_supported() { | ||
| #ifdef CLC_SPIRV | ||
| // SPIR-V doesn't support llvm.canonicalize for now. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you just fix that instead of special casing it here? It's not difficult to implement |
||
| return false; | ||
| #else | ||
| return !__builtin_isfpclass(__builtin_elementwise_canonicalize(0x1p-1074), | ||
| __FPCLASS_POSZERO); | ||
| #endif | ||
| } | ||
| #endif // cl_khr_fp64 | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.