Skip to content

[SYCL][ABI Break] Remove "cl" namespace #6518

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

Merged
merged 12 commits into from
Aug 11, 2022
Merged

Conversation

aelovikov-intel
Copy link
Contributor

As part of the change, also start using "inline namespace _V1" to allow
possible future ABI-affecting changes.

@aelovikov-intel aelovikov-intel force-pushed the ns-cl branch 2 times, most recently from 2336f6e to 75ef986 Compare August 2, 2022 20:00
@aelovikov-intel
Copy link
Contributor Author

SPIRV upstream change: KhronosGroup/SPIRV-LLVM-Translator#1564

As part of the change, also start using "inline namespace _V1" to allow
possible future ABI-affecting changes.
@@ -104,7 +104,7 @@ def __init__(self, class_type, result_type, depth):
self.depth = depth

def get_arg_types(self):
return gdb.lookup_type("cl::sycl::id<%s>" % self.depth)
return gdb.lookup_type("sycl::_V1::id<%s>" % self.depth)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how this file is being tested, so the changes here are "blind".

Copy link
Contributor

Choose a reason for hiding this comment

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

@stevemerr, do you know?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect any end-to-end testing that would run gdb-oneapi on a sycl sample would exercise this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be sycl::_V1::id or can we just do sycl::id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PRs makes it sycl::_V1::id to give us a chance to avoid ABI-breakage in the future by switching to sycl::_V2::id while preserving the binary impl for _V1.

@aelovikov-intel
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1128

premanandrao
premanandrao previously approved these changes Aug 4, 2022
Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

FE changes look good to me.

smanna12
smanna12 previously approved these changes Aug 4, 2022
Copy link
Contributor

@smanna12 smanna12 left a comment

Choose a reason for hiding this comment

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

FE changes OK to me.

@@ -303,7 +303,7 @@ bool isSYCLBfloat16Type(llvm::Type *Ty) {
return false;
StringRef Name = ST->getName();
Name.consume_front("class.");
if ((Name.startswith("cl::sycl::") ||
if ((Name.startswith("cl::sycl::") || Name.startswith("sycl::_V1::") ||
Copy link
Contributor

@asudarsa asudarsa Aug 4, 2022

Choose a reason for hiding this comment

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

This is mostly my ignorance. can you please outline why we used sycl::_V1 here and just sycl earlier? Also, in the upstream change, I see only sycl here. 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.

This PR makes two independent changes at once, only because decoupling them would be lots of useless work with little benefit.

First change is to get rid of cl:: and put sycl directly into the global namespace.

The second part is groundwork for possible future ABI breaking changes. The idea is that if we'd need, for example, make ABI breaking changes into sycl::queue, we'll do something like this:

// sycl.hpp:
namespace sycl {
inline namespace _V2 {
class queue {};   // That's what new code compiled with new compiler/RT would refer to by sycl::queue
}
}

// sycl_queue_v1_compat.cpp, linked into future libsycl.so
namespace sycl {
namespace _V1 {
class queue { ... };   // Old binaries linked with new sycl.so would use this.
// Old implementation
}
}

The exact machinery for that is to be defined later when/if we'd actually need it. However, we need to introduce _V right now because if our current queue would be sycl::queue instead of sycl::_V1::queue (that's how inline namespace is being mangled) we won't have any possibility to implement the sketchy solution above.

Copy link
Contributor Author

@aelovikov-intel aelovikov-intel Aug 4, 2022

Choose a reason for hiding this comment

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

Actually, I probably misunderstood the question. The proper fix upstream is using ^sycl::, without _V1 so that it would work if/when we'll start using sycl::_V2 symbols.

The final version will be what upstream has.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation Andrei. I understand now. I think this is good as long as it is documented somewhere.
I can approve the SPIRV changes. Thanks for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow what problem llvm-spirv translator changes solves. What will happen when runtime will switch to sycl::_V2 symbols? Translator will leave bfloat16 types as user defined types instead of SPIR-V buillt-in types. Right?

In general, please, avoid making local changes to the translator. All changes should be committed to the Khronos repository. Ideally we should remove the copy of sources from our repository and fetch them directly from the Khronos repository.

asudarsa
asudarsa previously approved these changes Aug 4, 2022
Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 46 to +48
static std::array<Util::DeclContextDesc, 3> Scopes = {
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "cl"},
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "sycl"},
Util::DeclContextDesc{clang::Decl::Kind::Namespace, "_V1"},
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 we have SYCL 1.2.1 compatibility tests?
https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:headers-and-namespaces
We should have them in SYCL-CTS and make sure that DPC++ complies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we talking source-compatible or binary-compatible? The former is being done with namespace alias as part of this PR (I might need to add an explicit test for that though), while the latter shouldn't (can't?) be done.

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 we are talking about source-compatibility. Yes, please, add SYCL-1.2.1 compatibility test to make sure that when <CL/sycl.hpp> is included, we can still use data types defined in cl::sycl namespace in 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.

I think we would need to account for both scopes (here and in Sema) for compatibility right?

Copy link
Contributor

@elizabethandrews elizabethandrews Aug 9, 2022

Choose a reason for hiding this comment

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

We need to remove these name based checks. Now that we're modifying namespaces, this isn't future proof at all. We should instead modify sycl_special attribute to accept an argument and use that to do these checks where required.

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 think we would need to account for both scopes (here and in Sema) for compatibility right?

I don't think we do, but I'd like to hear your reasoning why you think we might need that.

We need to remove these name based checks. ... We should instead modify sycl_special attribute...

That is way above my comfort level with the FE - I guess I'd need someone from FE to make that part of the change.
Also, IMO, it should be done in a separate patch (either before or after this PR).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we do, but I'd like to hear your reasoning why you think we might need that.

If the cl/sycl header is used as @bader mentioned above and users declare types using cl::sycl::aspect, etc, wouldn't compiler checks like isDeviceAspectType fail since it checks hard-coded scope which is now sycl::_V1::aspect?

That is way above my comfort level with the FE - I guess I'd need someone from FE to make that part of the change.
Also, IMO, it should be done in a separate patch (either before or after this PR).

I can help with that. What is the timeline for this change like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using cl/sycl.h doesn't change ABI, only introduce namespace alias (https://godbolt.org/z/x17Toq5vY).

I can help with that. What is the timeline for this change like?

I don't think there are hard requirement other than the 2023 release, but this PR gets merge conflicts pretty easily and I really wouldn't want it to sit uncommitted for long.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok Thanks for explaining. I guess this should work then, as long as we don't use older versions of cl/sycl.h

kbobrovs
kbobrovs previously approved these changes Aug 8, 2022
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.

ESIMD part LGTM

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Some minor comments, otherwise the runtime and the device headers look good.

The interfaces are simple and *very* unlikely to change. Also, changing
_V1::cl_float to _V2::cl_float would work without versioning of the
routines in __host_std as the arguments' types are part of the mangling
already.
@aelovikov-intel
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1128

smanna12
smanna12 previously approved these changes Aug 10, 2022
Copy link
Contributor

@smanna12 smanna12 left a comment

Choose a reason for hiding this comment

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

FE changes look good to me.

steffenlarsen
steffenlarsen previously approved these changes Aug 10, 2022
asudarsa
asudarsa previously approved these changes Aug 10, 2022
Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

SPIR-V changes look good. Thanks.

@aelovikov-intel
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1128

@aelovikov-intel
Copy link
Contributor Author

Given how easy it is to get into a merge conflict and how many approvals are required (and hard to get quickly enough), I don't think it will ever be green...

@intel/llvm-gatekeepers , should we weaken the merge criteria here maybe?

@v-klochkov
Copy link
Contributor

Given how easy it is to get into a merge conflict and how many approvals are required (and hard to get quickly enough), I don't think it will ever be green...

@intel/llvm-gatekeepers , should we weaken the merge criteria here maybe?

If your changes only remove "cl", then you have pre-approval from ESIMD (no need for explicit approval here). Otherwise, please ping @intel/dpcpp-esimd-reviewers

v-klochkov
v-klochkov previously approved these changes Aug 10, 2022
@aelovikov-intel
Copy link
Contributor Author

If your changes only remove "cl", then you have pre-approval from ESIMD (no need for explicit approval here). Otherwise, please ping https://github.com/orgs/intel/teams/dpcpp-esimd-reviewers

They also contain corresponding changes in places where mangling matters, like ESIMDVerifier.cpp/LowerESIMD.cpp.

steffenlarsen
steffenlarsen previously approved these changes Aug 10, 2022
smanna12
smanna12 previously approved these changes Aug 10, 2022
@aelovikov-intel
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1128

@aelovikov-intel
Copy link
Contributor Author

aelovikov-intel commented Aug 11, 2022

Failures on LLVM Test Suite precommit are expected and expected to pass in "verify with" testing. An exception is

Timed Out Tests (1):
  SYCL :: HierPar/hier_par_basic.cpp

which is most likely unrelated. I'd argue that (pending Jenkins/llvm-test-suite) we should proceed with merging this. If, in an unlikely event, of the failure being real I'll address it post-commit.

Edit: Jenkins/precomit is clear. I believe this is as much ready for the merge as would ever be possible, despite missing some formal review approval statuses. @intel/llvm-gatekeepers would you agree to merge this in?

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.