Skip to content

[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

Merged
merged 3 commits into from
Dec 30, 2021

Conversation

sndmitriev
Copy link
Contributor

  • 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]

- 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]>
@sndmitriev sndmitriev marked this pull request as ready for review December 23, 2021 06:24
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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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

@sndmitriev
Copy link
Contributor Author

/verify with intel/llvm-test-suite#673

@sndmitriev
Copy link
Contributor Author

/verify with intel/llvm-test-suite#673

@sndmitriev
Copy link
Contributor Author

/verify with intel/llvm-test-suite#673

@bader
Copy link
Contributor

bader commented Dec 29, 2021

@vladimirlaz, could you merge this PR, please?

@vladimirlaz vladimirlaz merged commit ecfdaa1 into intel:sycl Dec 30, 2021
@sndmitriev sndmitriev deleted the sndmitriev/esimd-log-exp branch December 30, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants