-
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 5 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 | ||
|
|
@@ -65,14 +64,12 @@ 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; | ||
| _CLC_OVERLOAD _CLC_INLINE float __clc_soft_flush_denormal(float 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_elementwise_abs(x) < 0x1p-149f | ||
| ? __builtin_elementwise_copysign(0.0f, x) | ||
| : x; | ||
| } | ||
|
|
||
| #ifdef cl_khr_fp64 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,9 +127,9 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) { | |
| return c; | ||
| } | ||
|
|
||
| a = __clc_flush_denormal_if_not_supported(a); | ||
| b = __clc_flush_denormal_if_not_supported(b); | ||
| c = __clc_flush_denormal_if_not_supported(c); | ||
| a = __clc_soft_flush_denormal(a); | ||
| b = __clc_soft_flush_denormal(b); | ||
| c = __clc_soft_flush_denormal(c); | ||
|
||
|
|
||
| if (a == 0.0f || b == 0.0f) { | ||
| return c; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ | |
|
|
||
| _CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y, | ||
| __CLC_ADDRESS_SPACE int *quo) { | ||
| x = __clc_flush_denormal_if_not_supported(x); | ||
| y = __clc_flush_denormal_if_not_supported(y); | ||
| x = __clc_soft_flush_denormal(x); | ||
| y = __clc_soft_flush_denormal(y); | ||
|
Comment on lines
+11
to
+12
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. I don't think this is necessary. In the rocm-device-libs version of this, I managed to delete the explicit canonicalizes 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. See this series of patches: Should just copy what these did 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.
I have tried to port both libclc __clc_remquo and ocml remquo2 to replace intel gpu implementation at https://github.com/intel/intel-graphics-compiler/blob/fc97dc482697b320667a52914f1225556f0856e8/IGC/BiFModule/Implementation/Math/remquo.cl#L12-L104, however, the ported code can't pass OpenCL CTS test |
||
| int ux = __clc_as_int(x); | ||
| int ax = ux & EXSIGNBIT_SP32; | ||
| float xa = __clc_as_float(ax); | ||
|
|
||
| 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.