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] Link device lib via mlink-builtin-bitcode #2833

Closed
wants to merge 11 commits into from

Conversation

jinge90
Copy link
Contributor

@jinge90 jinge90 commented Nov 30, 2020

This is a prototype to implement SYCL device libraries via "-mlink-builtin-bitcode" suggested by Alexey. We have another options: #2783
We need more investigation to decide which way to choose.
Thanks very much.

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

jinge90 commented Nov 30, 2020

@bader
This PR is option1 you suggested. Technically, I think using "mlink-builtin-bitcode" can work but we have some issues to resolve.
We found using "-mlink-builtin-bitcode" to link complex device library will lead to runtime failure when using complex division (__divsc3/__divdc3)function in SYCL device code. Adding "-fno-sycl-early-optimizations" will resolve the runtime failure.
Thanks very much.

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

jinge90 commented Nov 30, 2020

/summary:run

@bader
Copy link
Contributor

bader commented Nov 30, 2020

We found using "-mlink-builtin-bitcode" to link complex device library will lead to runtime failure when using complex division (__divsc3/__divdc3)function in SYCL device code.

@jinge90, could you share a short reproducer for this problem, so I can take a look, please?

void SYCLToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadingKind) const {
if (DeviceOffloadingKind == Action::OFK_SYCL && doLLVMBCEmit(CC1Args))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to do doLLVMBCEmit(CC1Args) check?

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, @bader
If we don't do this check, "-mlink-builtin-bitcode ..." will be added when we generate sycl helper header file. We only need to link those device libraries when generating device code.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to link them always. Integration header is generated from Sema, so adding -m* options should have no impact.

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, @bader
Since the "-mlink" options have no impact to integration header generation, why don't remove the unused options to make the commands more clean?
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.

This is not the right place to make this decision. We must always link devicelib unless user explicitly disable the linking. We should have some "optimizing" logic here as it's a error prone. I can image a few cases already where this can lead to bugs.


bool NoDeviceLibs = false;
// Currently, libc, libm-fp32 will be linked in by default. In order
// to use libm-fp64, -fsycl-device-lib=libm-fp64/all should be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you see any problems with linking libm-fp64 by default?

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, @bader
I think it should be OK to link libm-fp64 by default too. I will find a some machine without fp64 extension to see if any problem exposed.
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.

There should be no problems. If math functions with doubles are not used there will be no unsupported functions in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bader @mdtoguchi @vzakhari
Have updated the patch to link libm-fp64 by default. But I suggest to re-discuss the behavior of "-fsycl-device-lib=..."
Currently, "-fsycl-device-lib=.." won't impact our "default" link behavior, it seems that current behavior of "-fsycl-device-lib=" is useless after we link all device libraries by default.
Maybe aligning behaviors of "-fsycl-device-lib" and "-fno-sycl-device-lib" is more reasonable, if user addes "-fsycl-device-lib=libm-fp32", we won't do "default" link, instead, we only link libm-fp32 device libraries, the same to libc, libm-fp64...
And I think we should re-consider the "-fsycl-device-lib=..." no matter we choose this PR or #2783 in the end.
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 would say we have just one option - -fsycl analog for -nostdlib i.e. -fno-sycl-device-lib.
I don't think we really need a fine grained control over which part of standard library is linked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @bader. We shouldn't modify what we link by default with an option that adjusts the adding of libs. Similar to adding -lgcc on the command line, that doesn't override the default libs already linked in. A single option that disables all is reasonable.

Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
Signed-off-by: gejin <ge.jin@intel.com>
@jinge90 jinge90 changed the title [SYCL]Link device lib via mlink-builtin-bitcode [SYCL] Link device lib via mlink-builtin-bitcode Jan 13, 2021
Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

libdevice LGTM

@bader
Copy link
Contributor

bader commented Dec 16, 2021

libdevice LGTM

Hm... this PR was updated more than a year ago and it looks outdated. There are multiple merge conflicts.
@jinge90, please, update the patch, if you plan to commit this change or close it otherwise.

@jinge90
Copy link
Contributor Author

jinge90 commented Dec 17, 2021

libdevice LGTM

Hm... this PR was updated more than a year ago and it looks outdated. There are multiple merge conflicts. @jinge90, please, update the patch, if you plan to commit this change or close it otherwise.

I think we can close it now.

@jinge90 jinge90 closed this Dec 17, 2021
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