Skip to content

Conversation

@GeorgeWeb
Copy link
Contributor

@GeorgeWeb GeorgeWeb commented Jun 16, 2023

Without it set, the logic in BitcodeReader::parseTypeTableBody takes place and when targeting multiple backends (including spirv) would result in compilation errors.

Fixes a current issue with -c and multiple targets, where spir64 is set as the first target in the list.

@GeorgeWeb GeorgeWeb requested a review from a team as a code owner June 16, 2023 09:25
@GeorgeWeb GeorgeWeb temporarily deployed to aws June 16, 2023 09:43 — with GitHub Actions Inactive
@GeorgeWeb GeorgeWeb temporarily deployed to aws June 16, 2023 10:24 — with GitHub Actions Inactive
@maksimsab
Copy link
Contributor

Could you please add tests?

@asudarsa
Copy link
Contributor

Adding @jcranmer-intel for review. Thanks

@asudarsa asudarsa requested a review from jcranmer-intel June 19, 2023 22:07
@GeorgeWeb GeorgeWeb force-pushed the georgi/sycl_fix_opaque_ptrs_offload_bundler branch from 299b443 to c96918c Compare July 6, 2023 14:54
@GeorgeWeb GeorgeWeb requested a review from a team as a code owner July 6, 2023 14:54
@GeorgeWeb
Copy link
Contributor Author

Could you please add tests?

Hey, Just came back off holidays.
Do you think the tests I've just pushed are okay and would suffice or you'd like me to test any more aspects?

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.

@GeorgeWeb GeorgeWeb temporarily deployed to aws July 6, 2023 15:22 — with GitHub Actions Inactive
@GeorgeWeb GeorgeWeb temporarily deployed to aws July 6, 2023 17:23 — with GitHub Actions Inactive
Copy link
Contributor

@jcranmer-intel jcranmer-intel left a 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.

@GeorgeWeb
Copy link
Contributor Author

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!

@GeorgeWeb GeorgeWeb temporarily deployed to aws July 7, 2023 13:30 — with GitHub Actions Inactive
@GeorgeWeb GeorgeWeb temporarily deployed to aws July 7, 2023 15:24 — with GitHub Actions Inactive
@GeorgeWeb
Copy link
Contributor Author

@jcranmer-intel Hi again. I was wondering if it's okay to elaborate a little more wrt requested changes. Thanks!

@GeorgeWeb GeorgeWeb changed the title [SYCL] Set default value for opaque pointers in offload bundler [SYCL][Driver] Set default value for opaque pointers in offload bundler Aug 2, 2023
@bader bader requested a review from jcranmer-intel August 15, 2023 15:18
@bader
Copy link
Contributor

bader commented Aug 15, 2023

@GeorgeWeb, please, fix the clang lit test failing in pre-commit.
You will need to update the branch as well.

@bader
Copy link
Contributor

bader commented Aug 16, 2023

@intel/dpcpp-tools-reviewers, @intel/dpcpp-clang-driver-reviewers, @jcranmer-intel, ping.

bader
bader previously requested changes Aug 16, 2023
/// reader will not fail because opaque pointers cannot be converted to typed pointers.
///

#include <sycl/sycl.hpp>
Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Contributor Author

@GeorgeWeb GeorgeWeb Aug 22, 2023

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!

Copy link
Contributor

@sarnex sarnex Aug 22, 2023

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.

Copy link
Contributor

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
#endif

On 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.

@bader
Copy link
Contributor

bader commented Aug 22, 2023

@jcranmer-intel, ping.

@bader bader changed the title [SYCL][Driver] Set default value for opaque pointers in offload bundler [Driver] Set default value for opaque pointers in offload bundler Aug 23, 2023
@bader bader dismissed their stale review August 23, 2023 15:54

Thanks! My concern has been resolved.

@bader
Copy link
Contributor

bader commented Aug 23, 2023

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!

@jcranmer-intel, your review is blocking this PR. Please, reply to @GeorgeWeb questions.

@bader bader self-assigned this Aug 29, 2023
const Triple TT = getTargetTriple(Target, BundlerConfig);
return !TT.isSPIR() && !TT.isSPIRV();
});
Context.setOpaquePointers(UseOpaquePointers);
Copy link
Contributor

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.

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 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?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Contributor

@jsji jsji Aug 29, 2023

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");
}

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 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!

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 If you are convinced too, I am happy to close this given the future direction.

@bader bader closed this Aug 30, 2023
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.

8 participants