Skip to content

[SYCL] Force-emit more member functions into device code #13985

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

AlexeySachkov
Copy link
Contributor

We only emit unused member functions if they have been explicitly annotated with sycl_device attribute (through SYCL_EXTERNAL macro).

SYCL extension for virtual functions introduces an alternative markup for specifying which function and that markup is SYCL compile-time properties that we turn into attributes implicitly under the hood.

Essentially, we now have a situation where an implicit sycl_device attribute on a member function should be treated as an explicit one, because it could be a result of SYCL compile-time property being applied to that method.

We only emit unused member functions if they have been explicitly
annotated with `sycl_device` attribute (through `SYCL_EXTERNAL` macro).

SYCL extension for virtual functions introduces an alternative
markup for specifying which function and that markup is SYCL
compile-time properties that we turn into attributes implicitly under
the hood.

Essentially, we now have a situation where an implicit `sycl_device`
attribute on a member function should be treated as an explicit one,
because it could be a result of SYCL compile-time property being applied
to that method.
@AlexeySachkov AlexeySachkov requested a review from a team as a code owner May 31, 2024 12:35
@@ -12037,8 +12037,12 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (LangOpts.SYCLIsDevice && isa<CXXMethodDecl>(D)) {
if (auto *A = D->getAttr<SYCLDeviceIndirectlyCallableAttr>())
return !A->isImplicit();
// Implicit 'sycl_device' attribute is treated as explicit one if method
// is also annotated with 'add_ir_attributes_function' attribute, because
// the latter can work as an alias for SYCL_EXTERNAL.
if (auto *A = D->getAttr<SYCLDeviceAttr>())
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 know why we have the Implicit check? Why don't we emit functions irrespective of whether the attribute is implicit or explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know why we have the Implicit check? Why don't we emit functions irrespective of whether the attribute is implicit or explicit?

No, I don't. git blame just goes years back to some refactoring commit and there is not much info about why we specifically look for an explicit attribute (3baec18).

Looking at the clang codebase, there are only 3 places where we create implicit sycl_device attribute:

  • SemaLookup.cpp when we generate declarations for SPIR-V friendly IR built-ins
  • SemaDeclAttr.cpp when we handle legacy indirectly callable attribute we have
  • SemaDeclAttr.cpp when we handle add_ir_function_attributes attribute (my recent patch)

Let me try and just drop requirement for the attribute to be explicit and see if anything breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both check-clang and check-sycl pass if I remove !A->isImplicit() check for sycl_device attribute. I still have no idea why it was introduced in the first place. Perhaps it is some kind of legacy? Before 3baec18 we used to add the attribute everywhere alongside call graph (implicitly) to indicate which functions should be emitted and which are not.

Considering that now there is only a few places where we implicitly add the attribute and only a couple of them is relevant to CXXMethodDecls, what do you think about just dropping the requirement for the attribute to be explicit?

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 it makes sense dropping the isImplicit check. In the cases mentioned above it feels like we actually want the functions/builtins to be emitted? I don't know what the purpose of adding this attribute is, if we don't want to emit the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped the check in 5bcd485

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.

I see @elizabethandrews is reviewing this, but LGTM

@AlexeySachkov
Copy link
Contributor Author

Graph/Explicit/add_nodes_after_finalize.cpp should not be related to changes made in the PR and it passed after I restarted the job in GH UI. The test seems flaky and I've reported it into #11852, I will proceed with merge

@AlexeySachkov AlexeySachkov merged commit 97ed50d into intel:sycl Jun 6, 2024
14 checks passed
@AlexeySachkov AlexeySachkov deleted the private/asachkov/force-emit-more-cxxmethoddecls branch June 6, 2024 08:42
ianayl pushed a commit to ianayl/sycl that referenced this pull request Jun 13, 2024
By some reason, we used to only emit unused member functions if they
are explicitly annotated with `sycl_device` attribute (through
`SYCL_EXTERNAL` macro).

This logic was introduced in 3baec18
and there is no clear indication as to why exactly we have a check that
the attribute is explicit.

SYCL extension for virtual functions introduces an alternative markup
for specifying which function and that markup is SYCL compile-time
properties that we turn into attributes implicitly under the hood.

Essentially, we now have a situation where an implicit `sycl_device`
attribute on a member function should be treated as an explicit one,
because it could be a result of SYCL compile-time property being applied
to that method.

Considering our current codebase, it seems like we intend to
have member function to be emitted in all cases where 
`sycl_device` is being implicitly added and therefore this patch removes
the requirement for the attribute to be explicit.
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