-
Notifications
You must be signed in to change notification settings - Fork 787
[ESIMD] Revise log/exp implementation to be consistent with std/sycl #5211
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
Conversation
- Rename esimd::log/exp to esimd::log2/exp2 since they operate with base 2 - Add esimd::log/exp functions emulated via esimd::log2/exp2 Signed-off-by: Sergey Dmitriev <[email protected]>
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE simd<float, SZ> log(simd<float, SZ> src0, | ||
int flag = saturation_off) { | ||
constexpr float ln2 = 0.693147f; // std::numbers::ln2_v<float> in c++20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is this precision maximum float can reach? If so, could you please add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ln2 looks like it should be possible to add more digits after the dot. But for log2e (below) it seems to be the max precision already.
$ cat test.cpp
#include <stdio.h>
int main() {
float a1 = 0.693147180559945309417232121458176f;
float b1 = 0.69314718f;
int *ai1 = (int *)&a1;
int *bi1 = (int *)&b1;
printf("*ai1 == *bi1 %d\n", (*ai1 == *bi1));
float a2 = 1.442695040888963407359924681001892f;
float b2 = 1.442695f;
int *ai2 = (int *)&a2;
int *bi2 = (int *)&b2;
printf("*ai2 == *bi2 %d\n", (*ai2 == *bi2));
return 0;
}
$ g++ test.cpp; ./a.out
*ai1 == *bi1 1
*ai2 == *bi2 1
$
I can actually add a double initializer and let compiler truncate it to float.
@@ -25,7 +25,7 @@ SYCL_ESIMD_FUNCTION SYCL_EXTERNAL simd<float, 16> sycl_math(simd<float, 16> x) { | |||
return v; | |||
} | |||
|
|||
// Math sin,cos,log,exp functions from esimd namespace are translated | |||
// Math sin,cos,log2,exp2 functions from esimd namespace are translated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add E2E test link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// log | ||
|
||
template <int SZ> | ||
ESIMD_NODEBUG ESIMD_INLINE simd<float, SZ> log(simd<float, SZ> src0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a doc comment that this is s/w-emulated version based on h/w supported log2
/verify with intel/llvm-test-suite#673 |
/verify with intel/llvm-test-suite#673 |
/verify with intel/llvm-test-suite#673 |
@vladimirlaz, could you merge this PR, please? |
Signed-off-by: Sergey Dmitriev [email protected]