Skip to content

[SYCL][libdevice] Split MSVC specific math functions from cmath devicelib. #6120

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 9 commits into from
May 19, 2022

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented May 7, 2022

No description provided.

@jinge90 jinge90 requested review from a team as code owners May 7, 2022 06:27
@jinge90 jinge90 requested a review from againull May 7, 2022 06:27
@jinge90 jinge90 changed the title [SYCL]' [SYCL][libdevice] Split MSVC specific math functions from cmath devicelib. May 7, 2022
@jinge90 jinge90 requested a review from mdtoguchi May 7, 2022 06:30
jinge90 added 3 commits May 7, 2022 14:36
Signed-off-by: jinge90 <[email protected]>
Signed-off-by: jinge90 <[email protected]>
Signed-off-by: jinge90 <[email protected]>
@jinge90
Copy link
Contributor Author

jinge90 commented May 7, 2022

In cmath devicelib, we disabled ldexpf, hypotf, frexpf for Windows, the reason was we included "math.h" in the source and MSVC "math.h" has inlined those 3 functions in header file which would block us to implement those 3 functions, otherwise "multiple definition" error would happen in building cmath devicelib.
The reason why we had to include MSVC "math.h" was we implemented some MSVC internal math functions in cmath devicelib and those internal math functions depended on some constant which are defined in MSVC math header.
Now, some users reported that they encountered "undefined symbol" error for "hypotf" on SYCL GPU device when using 3rd-party math headers instead of MSVC math headers. In order to support such use case, we need to provide ldexpf, hypotf, frexpf in SYCL device library for Windows too.
And in order to resolve the multiple definition error introduced by inline for hypotf, ldexpf, frexpf in MSVC math header, we have to:

  1. split all MSVC internal function into a new source file msvc-math.cpp and we will include "math.h" in this source.
  2. enable hypotf, ldexpf, frexpf in cmath_wrapper.cpp since there is no "include <math.h>" in the source any more, building it using clang will succeed.
  3. we will build msvc-math.cpp to get a new .obj file libsycl-msvc-math.obj and this devicelib will be added to device link list by default and controlled by fsycl-device-lib=libm-fp32 too.

Thanks very much.

@jinge90
Copy link
Contributor Author

jinge90 commented May 7, 2022

Hi, @mdtoguchi
Could you help review the driver and driver lit test for this PR?

Thanks very much.

"crt", "cmath", "cmath-fp64", "complex", "complex-fp64",
#if defined(_WIN32)
"msvc-math",
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is off, I would assume that clang-format forced this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I ran clang-format before submitting the patch.

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!

@pvchupin pvchupin merged commit 476a351 into intel:sycl May 19, 2022
yinyangsx pushed a commit to yinyangsx/llvm that referenced this pull request May 25, 2022
…elib. (intel#6120)

In cmath devicelib, we disabled ldexpf, hypotf, frexpf for Windows, the reason was we included "math.h" in the source and MSVC "math.h" has inlined those 3 functions in header file which would block us to implement those 3 functions, otherwise "multiple definition" error would happen in building cmath devicelib.
The reason why we had to include MSVC "math.h" was we implemented some MSVC internal math functions in cmath devicelib and those internal math functions depended on some constant which are defined in MSVC math header.
Now, some users reported that they encountered "undefined symbol" error for "hypotf" on SYCL GPU device when using 3rd-party math headers instead of MSVC math headers. In order to support such use case, we need to provide ldexpf, hypotf, frexpf in SYCL device library for Windows too.
And in order to resolve the multiple definition error introduced by inline for hypotf, ldexpf, frexpf in MSVC math header, we have to:

* split all MSVC internal function into a new source file msvc-math.cpp and we will include "math.h" in this source.
* enable hypotf, ldexpf, frexpf in cmath_wrapper.cpp since there is no "include <math.h>" in the source any more, building it using clang will succeed.
* we will build msvc-math.cpp to get a new .obj file libsycl-msvc-math.obj and this devicelib will be added to device link list by default and controlled by fsycl-device-lib=libm-fp32 too.

Signed-off-by: jinge90 <[email protected]>
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