-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Enhance the sycl device libraries filename check when constructing ll… #2944
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
Conversation
…vm-link commands Signed-off-by: gejin <[email protected]>
/summary:run |
clang/lib/Driver/ToolChains/SYCL.cpp
Outdated
return false; | ||
}); | ||
bool LinkSYCLDeviceLibs = (SYCLDeviceLibIter != InputFiles.end()); | ||
bool LinkSYCLDeviceLibs = | ||
(SYCLDeviceLibIter != InputFiles.end()) && (InputFiles.size() > 1); |
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 you need to verify that all inputs except the first are sycl libraries. Otherwise I guess it will not work as you expect it to.
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.
Make sense, I have updated the patch.
Thanks very much.
…first one, we add -only-needed Signed-off-by: gejin <[email protected]>
/summary:run |
Signed-off-by: gejin <[email protected]>
/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.
Thanks, LGTM
@AGindinson |
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.
Could you please add a test of some sort, at least a negative one?
"crt", | ||
"cmath", | ||
"cmath-fp64", | ||
"complex", | ||
"complex-fp64", | ||
"fallback-cassert", | ||
"fallback-cmath", | ||
"fallback-cmath-fp64", | ||
"fallback-complex", | ||
"fallback-complex-fp64"}; |
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.
Does this mean that if we were to add a new device library, we'd have to put its base name here as well? Or is it that no new library is likely to be added?
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.
Currently, those device libraries can meet our requirements but we may add new ones in the future and we need to put the basename here as well then.
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.
The explanatory comment you've added should help, I think. I wonder if, in the future, we could make some sort of a configuration file with the device library base names, parsing that both in the relevant CMakeLists and in the driver code (via #include
for compile-time?). I understand this is somewhat a vague approach - for example, where should we put the configuration file so that it could be conveniently accessed from all relevant LLVM subprojects? But just as something to consider for future improvements.
Hi, @AGindinson
We need to recognize whether current llvm-link phase is used to do "step-2" link, in order to achieve this, we check llvm-link's input list. This PR aims to enhance check for SYCL device libraries, the logic is:
The SYCL device library modules are pre-built binary whose file name matches the pattern "libsycl-${pure file name}.o/obj" and after clang-offload-bundler extracting the internal LLVM IR as the input of llvm-link, the extracted LLVM IR file name matches pattern "libsycl-${pure file name}-${random temporary string}.o/obj", so the enhanced check logic is:
User's input device module is generated by llvm-link and will always have the postfix ".bc" which won't be recognized as SYCL device library module. The SYCL device library module's file name are defined in libdevice's CMakeFile. Thanks very much. |
Signed-off-by: gejin <[email protected]>
@jinge90, thanks a lot, your recent comment is really helpful! Based on your explanation, a following simple test case could be envisioned: clang driver is fed with a "user" object that is named "almost like" the actual device libraries (e.g. "libsycl-test-user-library.o"). The checks would have to ensure that the "user" object is processed in the regular Does this make sense, or am I missing some more nuances (or, for that matter, am I giving this too much of a priority)? |
So, do you mean we use a input file whose name is same as some SYCL device libraries to see if the 2-step llvm-link still works as expected? |
Yep, a name that would be almost similar to the real device library names. |
Signed-off-by: gejin <[email protected]>
/summary:run |
Hi, @mdtoguchi |
Hi, @mdtoguchi |
* sycl: [SYCL][NFC] Fix warnings reported by Clang (intel#3050) [SYCL] Enhance device libraries filename check when constructing llvm-link commands (intel#2944) [SYCL][NFC] Add vtable ABI checks (intel#3032) [SYCL] Cleanup the deprecated Intel attribute logic (intel#3036)
Motivations is similar as f729c49. This PR addresses SYCL device global which may have attributes "sycl-device-image-scope", "sycl-host-access" and "sycl-unique-id". Failure to preserve "sycl-unique-id" after llvm-spirv translation triggers assert at https://github.com/intel/llvm/blob/2824f61dd36790448a224cd596985bd01cbcd0f3/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp#L85 Also preserve GlobalVariable metadata as an improvement, though there is no test to show this is really needed. Original commit: KhronosGroup/SPIRV-LLVM-Translator@f2d913cb1a22cb3
…vm-link commands
Signed-off-by: gejin [email protected]
We check input files' name when constructing "llvm-link -only-needed" for linking SYCL device libraries. Currently, the criteria is:
Such check is too fragile, this PR aims to enhance the check, input SYCL device libraries' filename pattern is "libsycl-${pure-name}-$random.o" where ${pure-name} is in list {'crt', 'cmath', 'cmath-fp64', 'complex', 'complex-fp64', 'fallback-cassert', 'fallback-cmath', 'fallback-cmath-fp64', 'fallback-complex', 'fallback-complex-fp64'} and ${random} is a random string,
so the updated criteria is:
This enhancement can only mitigate the fragility since the check is still based on filename. If we switch to approach of "-mlink-builtin-bitcode" for SYCL device library link in the future, this problem will be gone automatically.