Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add sycl_external attribute #140282

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
Loading
from
Draft

Add sycl_external attribute #140282

wants to merge 4 commits into from

Conversation

schittir
Copy link
Contributor

No description provided.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @schittir! I completed an initial pass of all of the code, but still need to look more closely at the documentation updates.

clang/lib/AST/ASTContext.cpp Outdated Show resolved Hide resolved
clang/lib/AST/ASTContext.cpp Outdated Show resolved Hide resolved
clang/include/clang/Sema/SemaSYCL.h Outdated Show resolved Hide resolved
Comment on lines 12750 to 12752
def err_sycl_attribute_internal_decl
: Error<"%0 attribute cannot be applied to a %select{function|variable}1"
" without external linkage">;
Copy link
Contributor

Choose a reason for hiding this comment

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

The only other uses of this diagnostic in downstream Intel repositories are for Intel extensions, so I don't think we need a generalized diagnostic.

The SYCL 2020 specification doesn't support use of the SYCL_EXTERNAL macro with variables, so we don't need to support that (if we need such an extension, we might want to introduce a different attribute for it later).

The suggested change below includes renaming, removal of applicability to variables, rephrasing inspired from err_attribute_selectany_non_extern_data, and style changes to match other nearby declarations.

Suggested change
def err_sycl_attribute_internal_decl
: Error<"%0 attribute cannot be applied to a %select{function|variable}1"
" without external linkage">;
def err_sycl_external_invalid_linkage : Error<
"'sycl_external' can only be applied to functions with external linkage">;

We'll eventually need to add diagnostics for at least the following scenarios as indicated in the SYCL 2020 specification in section 5.10.1. I haven't checked whether diagnostics are already present in downstream Intel report. For scenarios that are straight forward to diagnose, we should add diagnostics now. For others, we need to ensure we file an issue or somehow track adding diagnostics later. Ideally, we would add tests for each of these now with appropriate FIXME annotations as needed.

  • The sycl_external attribute must be present on the first declaration of a function and may optionally be present on subsequent declarations.
  • If the device target does not support the generic address space, then functions declared with sycl_external cannot have parameter types or a return type that involves a raw pointer.
  • Functions declared with sycl_external cannot call group::parallel_for_work_item().
  • Functions declared with sycl_external cannot be called from a parallel_for_work_group scope.

clang/include/clang/Basic/Attr.td Outdated Show resolved Hide resolved
clang/include/clang/Basic/Attr.td Show resolved Hide resolved
clang/test/SemaSYCL/sycl-external-attribute.cpp Outdated Show resolved Hide resolved
__attribute__((sycl_external)) // expected-warning {{'sycl_external' attribute ignored}}
void baz() {}

#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few different concerns being exercised by this test. We have a precedent in place for exercising appertainment, grammar, and relevance by different test files in the sycl-kernel-entry-point-attr-* tests. Can we follow that pattern (and associated naming conventions) here? I'm not so concerned about the testing being as extensive as it is in those other tests, but splitting these concerns will allow additional cases to be added later with less disruption.

clang/lib/AST/ASTContext.cpp Outdated Show resolved Hide resolved
@schittir
Copy link
Contributor Author

Thanks for working on this @schittir! I completed an initial pass of all of the code, but still need to look more closely at the documentation updates.

Thank you for the initial pass review, Tom!

Copy link

github-actions bot commented May 26, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/test/SemaSYCL/sycl-external-attribute.cpp clang/include/clang/Sema/SemaSYCL.h clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaSYCL.cpp clang/test/CodeGenSYCL/address-space-deduction.cpp clang/test/CodeGenSYCL/address-space-mangling.cpp clang/test/CodeGenSYCL/debug-info-kernel-variables.cpp clang/test/CodeGenSYCL/field-annotate-addr-space.cpp clang/test/CodeGenSYCL/functionptr-addrspace.cpp clang/test/CodeGenSYCL/kernel-caller-entry-point.cpp
View the diff from clang-format here.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e22adf0aa..cd154ef47 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12965,8 +12965,8 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (D->hasAttr<WeakRefAttr>())
     return false;
 
-  if (LangOpts.SYCLIsDevice &&
-       !D->hasAttr<SYCLKernelEntryPointAttr>() && !D->hasAttr<SYCLExternalAttr>())
+  if (LangOpts.SYCLIsDevice && !D->hasAttr<SYCLKernelEntryPointAttr>() &&
+      !D->hasAttr<SYCLExternalAttr>())
     return false;
 
   // Aliases and used decls are required.

clang/lib/AST/ASTContext.cpp Outdated Show resolved Hide resolved
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.