Skip to content

[SYCL] Add sycl cpp header for imf libdevice API #6487

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 11 commits into from
Aug 25, 2022

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented Jul 28, 2022

We added some imf(intel math) APIs in libdevice: #5999, #6327, those APIs are C interface which means we don't expect users to call them directly in SYCL kernel since SYCL programming uses cpp. This PR will provide cpp wrapper for those imf APIs which users can call directly in source, the approach is similar to STL , std math functions will call corresponding C math functions or compiler math builtins. The user scenario should be following:
cpp
#include <sycl/ext/intel/math.hpp>
...
float x, y, z;
z = sycl::ext::intel::math::copysign(x, y);
...
``
Thanks very much.
Signed-off-by: jinge90 [email protected]

@jinge90 jinge90 requested a review from xtian-github July 28, 2022 12:27
@jinge90 jinge90 requested a review from a team as a code owner July 28, 2022 12:27
@jinge90 jinge90 marked this pull request as draft July 28, 2022 12:28
@jinge90 jinge90 marked this pull request as ready for review August 15, 2022 06:33
xtian-github
xtian-github previously approved these changes Aug 18, 2022
Copy link

@xtian-github xtian-github left a comment

Choose a reason for hiding this comment

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

LGTM

@jinge90 jinge90 requested a review from pvchupin August 20, 2022 03:32
@jinge90
Copy link
Contributor Author

jinge90 commented Aug 20, 2022

Hi, @pvchupin
could you take a look at this PR?

Thanks very much.

zettai-reido
zettai-reido previously approved these changes Aug 22, 2022
Copy link

@zettai-reido zettai-reido left a comment

Choose a reason for hiding this comment

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

LGTM.

@akolesov-nv
Copy link

Looks good to me. Is this file meant to be edited manually for every new function or any script exist? Which team should own (and update) the file? Thanks!

akolesov-nv
akolesov-nv previously approved these changes Aug 23, 2022
@jinge90
Copy link
Contributor Author

jinge90 commented Aug 23, 2022

Hi, @intel/llvm-reviewers-runtime and @cperkinsintel
Could you help review this patch? We need it ASAP.

Thanks very much.

return __imf_saturatef(x);
}

template <typename Tp> Tp copysign(Tp x, Tp y) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you went with SFINAE for saturate, maybe to keep it consistent it would make sense to do it for copysign too? That is, it would be something like:

template <typename Tp>
std::enable_if_t<std::is_same_v<Tp, float>, float> copysign(Tp x, Tp y) {
  return __imf_copysignf(x, y);
}

template <typename Tp>
std::enable_if_t<std::is_same_v<Tp, double>, double> copysign(Tp x, Tp y) {
  return __imf_copysign(x, y);
}

template <typename Tp>
std::enable_if_t<std::is_same_v<Tp, sycl::half>, sycl::half> copysign(Tp x, Tp y) {
  static_assert(sizeof(sycl::half) == sizeof(_iml_half_internal),
                "sycl::half is not compatible with _iml_half_internal.");
  _iml_half_internal xi = __builtin_bit_cast(_iml_half_internal, x);
  _iml_half_internal yi = __builtin_bit_cast(_iml_half_internal, y);
  return __builtin_bit_cast(sycl::half, __imf_copysignf16(xi, yi));
}

That should at least make the misuse of it give a similar error to that of saturate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @steffenlarsen
Your suggestion does make sense, already updated patch.

Thanks very much.

akolesov-nv
akolesov-nv previously approved these changes Aug 24, 2022
Copy link

@zettai-reido zettai-reido left a comment

Choose a reason for hiding this comment

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

New changes are fine.

Copy link

@xtian-github xtian-github left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

LGTM!

@steffenlarsen
Copy link
Contributor

@jinge90 - Are there tests for this?

@jinge90
Copy link
Contributor Author

jinge90 commented Aug 25, 2022

Hi, @pvchupin
Could you help merge this PR?
Thanks very much.

@jinge90
Copy link
Contributor Author

jinge90 commented Aug 25, 2022

@jinge90 - Are there tests for this?

We will extend imf libdevice imf tests: https://github.com/intel/llvm-test-suite/blob/intel/SYCL/DeviceLib/imf_fp32_test.cpp
https://github.com/intel/llvm-test-suite/blob/intel/SYCL/DeviceLib/imf_fp64_test.cpp

Currently, we directly call "_imf*" functions in SYCL kernel in those tests, we add function call to corresponding cpp wrappers.

Thanks very much.

@againull againull merged commit 830916a into intel:sycl Aug 25, 2022
@jinge90 jinge90 deleted the imf_sycl_header branch August 26, 2022 03:08
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.

7 participants