-
Notifications
You must be signed in to change notification settings - Fork 801
[Driver] Set default value for opaque pointers in offload bundler #9933
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
[Driver] Set default value for opaque pointers in offload bundler #9933
Conversation
|
Could you please add tests? |
|
Adding @jcranmer-intel for review. Thanks |
299b443 to
c96918c
Compare
Hey, Just came back off holidays. TLDR; Pretty much needs to see if clang-offload-bundler works okay in the above explained scenario and allows mixing typed with opaque ptrs when the first input module contains typed ptrs. |
jcranmer-intel
left a comment
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.
This is going to use the same LLVM context to parse all of the IR modules, so if any one of those modules uses opaque pointers, it's going to crash the offload.
Setting the context to unconditionally use opaque pointers is probably a better move, and rely on a separate LLVM context which autodetects for pointer mode for the SPIR-specific bitcode munging.
@jcranmer-intel I understand the suggestion, thank you. But I still am not sure why that would be better and not saying it won't but I am trying to find an example that exhibits the problem you are referring to. Would it be possible clarify/elaborate more on this and/or share an example. Thanks again! |
…que_ptrs_offload_bundler
…que_ptrs_offload_bundler
|
@jcranmer-intel Hi again. I was wondering if it's okay to elaborate a little more wrt requested changes. Thanks! |
|
@GeorgeWeb, please, fix the clang lit test failing in pre-commit. |
…que_ptrs_offload_bundler
…que_ptrs_offload_bundler
|
@intel/dpcpp-tools-reviewers, @intel/dpcpp-clang-driver-reviewers, @jcranmer-intel, ping. |
| /// reader will not fail because opaque pointers cannot be converted to typed pointers. | ||
| /// | ||
|
|
||
| #include <sycl/sycl.hpp> |
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.
This test won't work unless SYCL project is built before.
There is much simpler way to get a device code - use SYCL_EXTERNAL attribute (see https://github.com/intel/llvm/blob/sycl/clang/test/Driver/sycl-bitfield-accesses.cpp as an example).
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.
@GeorgeWeb, please, remove the dependency on DPC++ headers from clang tests.
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.
Absolutely. I was on it earlier today, but I could not find a nice way due to:
// RUN: %clangxx -fsycl -target x86_64-unknown-linux-gnu %s -c -o %s.host.o
I need host.o as an input to clang-offload-bundler. I may need to rework the test to not be tied to DPC++/sycl at all as I get error: unknown type name 'SYCL_EXTERNAL' when I have to compile and link the object.
Do you have any suggestions? @bader Thanks!
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.
__attribute__((sycl_device)) should work without dpcpp headers.
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.
Suggestion from @sarnex should work.
You can also define the macro for the host
#ifndef __SYCL_DEVICE_ONLY__
#define SYCL_EXTERNAL
#endifOn the other hand, it looks like the test is not specific to SYCL at all. You use SYCL mode to create inputs for clang-offload-bundler, but you can use regular C++ mode to create inputs as well. You just need a LLVM bitcode file and an object file. Am I right?
I think we can use the C code from https://github.com/intel/llvm/blob/sycl/clang/test/Driver/clang-offload-bundler.c, but instead of global variable, pass a pointer to the test_func to test opaque pointers.
|
@jcranmer-intel, ping. |
@jcranmer-intel, your review is blocking this PR. Please, reply to @GeorgeWeb questions. |
| const Triple TT = getTargetTriple(Target, BundlerConfig); | ||
| return !TT.isSPIR() && !TT.isSPIRV(); | ||
| }); | ||
| Context.setOpaquePointers(UseOpaquePointers); |
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.
After poking around in more detail (I don't regularly develop this tool), I've come to the conclusion that this code is an elaborate way to set Context.setOpaquePointers(true). The host is included in TargetNames, and can't be SPIRV anyways, so there's always a non-SPIR-V module to cause it to be set to true. This of course obscures the failure modes of what would happen if UseOpaquePointers were false, since there's no realistic mode where it could be false.
Given that SPIRV_ENABLE_OPAQUE_POINTERS is enabled now and we're starting to remove support for typed pointers, I'm not sure there's any need for this PR anymore.
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.
Do you mean LLVMContext Context; uses opaque pointers by default and don't need to switch to non-opaque mode anymore?
@GeorgeWeb, are you okay to drop this change?
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.
#10888 means INTEL_SYCL_OPAQUEPOINTER_READY is now true and therefore everything is always in opaque pointer mode.
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.
Always?
Why do we add ifdef like this:
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
if (!CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL)
CmdArgs.push_back("-no-opaque-pointers");
else if ((Triple.isSPIRV() || Triple.isSPIR()) &&
!SPIRV_ENABLE_OPAQUE_POINTERS)
CmdArgs.push_back("-no-opaque-pointers");
#endif?
Shouldn't we just remove this code?
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.
In principle, it's a cmake option you can turn off. However, I suspect it doesn't actually work anymore. And I also suspect @jsji is likely to start ripping the code out in the near future, after the code bakes for a little bit more (the PR landed only yesterday).
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.
Yes, the plan is to remove the code in #ifndef INTEL_SYCL_OPAQUEPOINTER_READY once our downstream code works well.
ETA 1-2 weeks.
Keep it by guarding it within macros just in case we need to compare to INTEL_SYCL_OPAQUEPOINTER_READY=0 in some case for now.
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.
therefore everything is always in opaque pointer mode.
Yes. Also I believe setOpaquePointers is now an assert, so don't call it anymore.
void LLVMContext::setOpaquePointers(bool Enable) const {
assert(Enable && "Cannot disable opaque pointers");
}
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 see! So, assuming INTEL_SYCL_OPAQUEPOINTER_READY goes away soon-ish then it's all gonna look cleaner. My patch was I guess really a temporary mitigation for an awkward issue and from the insights of this discussion - thanks @jsji and @jcranmer-intel I am happy to close this PR as it seems unneeded for intel:sycl. Thanks!
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.
@bader If you are convinced too, I am happy to close this given the future direction.
Without it set, the logic in
BitcodeReader::parseTypeTableBodytakes place and when targeting multiple backends (including spirv) would result in compilation errors.Fixes a current issue with
-cand multiple targets, where spir64 is set as the first target in the list.