Skip to content
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

Merged
merged 7 commits into from
Mar 9, 2021

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented Feb 25, 2021

No description provided.

@jinge90 jinge90 requested review from vzakhari and a team as code owners February 25, 2021 07:02
@jinge90
Copy link
Contributor Author

jinge90 commented Feb 25, 2021

std::div depends on C function div from , this PR aims to support in SYCL device.

@v-klochkov
Copy link
Contributor

Would you add a LIT test please

@@ -9,6 +9,14 @@
#include "wrapper.h"

#ifdef __SPIR__
DEVICE_EXTERN_C
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -9,6 +9,14 @@
#include "wrapper.h"

#ifdef __SPIR__
DEVICE_EXTERN_C
div_t div(int x, int y) { return {x / y, x % y}; }
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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>
@jinge90
Copy link
Contributor Author

jinge90 commented Feb 26, 2021

Would you add a LIT test please
Hi, @v-klochkov
All SYCL DeviceLib lit tests have been moved to https://github.com/intel/llvm-test-suite , so should I commit the lit test to llvm-test-suite repo directly or do we have some process to add such lit test?
Thanks.

@v-klochkov
Copy link
Contributor

Would you add a LIT test please
Hi, @v-klochkov
All SYCL DeviceLib lit tests have been moved to https://github.com/intel/llvm-test-suite , so should I commit the lit test to llvm-test-suite repo directly or do we have some process to add such lit test?
Thanks.

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.

@jinge90
Copy link
Contributor Author

jinge90 commented Feb 26, 2021

Would you add a LIT test please
Hi, @v-klochkov
All SYCL DeviceLib lit tests have been moved to https://github.com/intel/llvm-test-suite , so should I commit the lit test to llvm-test-suite repo directly or do we have some process to add such lit test?
Thanks.

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

AlexeySachkov
AlexeySachkov previously approved these changes Feb 26, 2021
Copy link
Contributor

@AlexeySachkov AlexeySachkov left a 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>
@@ -10,9 +10,18 @@
#define __LIBDEVICE_DEVICE_MATH_H__

#include "device.h"

#include <cstdlib>
Copy link
Contributor

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.

kbobrovs
kbobrovs previously approved these changes Mar 4, 2021
Copy link
Contributor

@kbobrovs kbobrovs left a 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>
vzakhari
vzakhari previously approved these changes Mar 4, 2021
@jinge90
Copy link
Contributor Author

jinge90 commented Mar 4, 2021

This patch need rebase and resolve some conflicts with latest sycl-post-link.cpp.

Signed-off-by: gejin <ge.jin@intel.com>
@jinge90
Copy link
Contributor Author

jinge90 commented Mar 5, 2021

Hi, @vzakhari and @kbobrovs
I rebased the patch resolving conflicts with latest sycl-post-link.cpp and may need your approval again.
Thanks very much.

@jinge90 jinge90 requested a review from kbobrovs March 5, 2021 02:05
@jinge90
Copy link
Contributor Author

jinge90 commented Mar 9, 2021

Hi, @AlexeySachkov and @intel/llvm-reviewers-runtime
Could you help review this PR?
Thanks very much.

@jinge90
Copy link
Contributor Author

jinge90 commented Mar 9, 2021

/summary:run

Copy link
Contributor

@v-klochkov v-klochkov left a 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?

@romanovvlad
Copy link
Contributor

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.

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.

6 participants