-
Notifications
You must be signed in to change notification settings - Fork 733
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
[SYCL] Support stdlib function div, ldiv, lldiv in device library #3262
Conversation
std::div depends on C function div from , this PR aims to support in SYCL device. |
Would you add a LIT test please |
libdevice/crt_wrapper.cpp
Outdated
@@ -9,6 +9,14 @@ | |||
#include "wrapper.h" | |||
|
|||
#ifdef __SPIR__ | |||
DEVICE_EXTERN_C |
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.
I guess we'd better have a dedicated integer math file instead of placing this in the crt
portion, but we can do the clean-up later.
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.
I guess we'd better have a dedicated integer math file instead of placing this in the
crt
portion, but we can do the clean-up later.
It seems that "div" is declared in instead of but it makes sense to group all "math related" items into one math file. I will update it later.
Thanks.
libdevice/crt_wrapper.cpp
Outdated
@@ -9,6 +9,14 @@ | |||
#include "wrapper.h" | |||
|
|||
#ifdef __SPIR__ | |||
DEVICE_EXTERN_C | |||
div_t div(int x, int y) { return {x / y, x % y}; } |
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.
We have to allow device runtimes to provide their optimized versions of these functions, so we have to call __devicelib_
variants here, and put the actual implementation into the fallback part of the library.
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.
We have to allow device runtimes to provide their optimized versions of these functions, so we have to call
__devicelib_
variants here, and put the actual implementation into the fallback part of the library
To some complicated functions such as __divsc3/__mulsc3, putting the actual implementation into fallback spv is valuable since device runtime may have interest providing a more optimized version. To div, it looks like the implementation is too simple, I doubt whether device runtime would like to provide a more optimized version. If device runtime wouldn't like or there is not much value to optimize such "simple" functions, just providing the actual implementation in wrapper obj may be conciser.
Thanks very much.
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.
We have to allow device runtimes to provide their optimized versions of these functions, so we have to call
__devicelib_
variants here, and put the actual implementation into the fallback part of the library
To some complicated functions such as __divsc3/__mulsc3, putting the actual implementation into fallback spv is valuable since device runtime may have interest providing a more optimized version. To div, it looks like the implementation is too simple, I doubt whether device runtime would like to provide a more optimized version. If device runtime wouldn't like or there is not much value to optimize such "simple" functions, just providing the actual implementation in wrapper obj may be conciser.
Thanks very much.
I think there may be a hardware instruction that computes both values on some devices, so it does make sense to have devicelib api for these operations.
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.
We have to allow device runtimes to provide their optimized versions of these functions, so we have to call
__devicelib_
variants here, and put the actual implementation into the fallback part of the library
To some complicated functions such as __divsc3/__mulsc3, putting the actual implementation into fallback spv is valuable since device runtime may have interest providing a more optimized version. To div, it looks like the implementation is too simple, I doubt whether device runtime would like to provide a more optimized version. If device runtime wouldn't like or there is not much value to optimize such "simple" functions, just providing the actual implementation in wrapper obj may be conciser.
Thanks very much.I think there may be a hardware instruction that computes both values on some devices, so it does make sense to have devicelib api for these operations.
Hi, @vzakhari
If so, moving div into fallback spv makes sense. We have another libc item to add into devicelib which is also very simple:
int abs(int x);
Do you think we need to move its actual implementation into fallback lib or just provide the actual impl in wrapper obj?
I think the impl is very simple:
int abs(int x) { return i < 0 ? -i : i; }
Thanks very much.
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.
I think it is always easier to follow the common pattern/design, than to introduce exceptions :)
Signed-off-by: gejin <ge.jin@intel.com>
|
Please create a PR with a tests for DEVICE at llvm-test-suite and add a link to that PR here. And vice-versa, add a link to this PR in the LIT-test-PR. |
The lit test PR is: intel/llvm-test-suite#159 |
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.
sycl-post-link
changes LGTM
Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
libdevice/device_math.h
Outdated
@@ -10,9 +10,18 @@ | |||
#define __LIBDEVICE_DEVICE_MATH_H__ | |||
|
|||
#include "device.h" | |||
|
|||
#include <cstdlib> |
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 move this under __SPIR__
below.
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.
LGTM. I assume sycl-post-link changes will eventually go away together with the rest of DeviceLibFuncMap, as a part of #3291
Signed-off-by: gejin <ge.jin@intel.com>
This patch need rebase and resolve some conflicts with latest sycl-post-link.cpp. |
Signed-off-by: gejin <ge.jin@intel.com>
Hi, @AlexeySachkov and @intel/llvm-reviewers-runtime |
/summary:run |
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.
Looks good to me.
I suppose there are no rules requiring uplifting MINOR version of the library for libdevice when to ABI non-breaking changes (add new external symbols) as it is required for SYCL library, right?
Correct. |
No description provided.